001    /*
002     * JBoss DNA (http://www.jboss.org/dna)
003     * See the COPYRIGHT.txt file distributed with this work for information
004     * regarding copyright ownership.  Some portions may be licensed
005     * to Red Hat, Inc. under one or more contributor license agreements.
006    * See the AUTHORS.txt file in the distribution for a full listing of 
007    * individual contributors.
008     *
009     * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
010     * is licensed to you under the terms of the GNU Lesser General Public License as
011     * published by the Free Software Foundation; either version 2.1 of
012     * the License, or (at your option) any later version.
013     *
014     * JBoss DNA is distributed in the hope that it will be useful,
015     * but WITHOUT ANY WARRANTY; without even the implied warranty of
016     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017     * Lesser General Public License for more details.
018     *
019     * You should have received a copy of the GNU Lesser General Public
020     * License along with this software; if not, write to the Free
021     * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
022     * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
023     */
024    package org.jboss.dna.sequencer.msoffice;
025    
026    import java.util.Date;
027    import org.apache.poi.hpsf.PropertySetFactory;
028    import org.apache.poi.hpsf.SummaryInformation;
029    import org.apache.poi.poifs.eventfilesystem.POIFSReaderEvent;
030    import org.apache.poi.poifs.eventfilesystem.POIFSReaderListener;
031    import org.jboss.dna.common.util.Logger;
032    
033    public class MSOfficeMetadata implements POIFSReaderListener {
034    
035        private String title;
036        private String subject;
037        private String author;
038        private String keywords;
039        private String comment;
040        private String template;
041        private Date lastSavedBy;
042        private String revision;
043        private Long totalEditingTime;
044        private Date lastPrinted;
045        private Date created;
046        private Date saved;
047        private int pages;
048        private int words;
049        private int characters;
050        private String creatingApplication;
051        private byte[] thumbnail;
052    
053        public void processPOIFSReaderEvent( POIFSReaderEvent event ) {
054            try {
055                SummaryInformation si = (SummaryInformation)PropertySetFactory.create(event.getStream());
056                title = si.getTitle();
057                subject = si.getSubject();
058                author = si.getAuthor();
059                keywords = si.getKeywords();
060                comment = si.getComments();
061                template = si.getTemplate();
062                lastSavedBy = si.getLastSaveDateTime();
063                revision = si.getRevNumber();
064                totalEditingTime = si.getEditTime();
065                lastPrinted = si.getLastPrinted();
066                created = si.getCreateDateTime();
067                saved = si.getLastSaveDateTime();
068                pages = si.getPageCount();
069                words = si.getWordCount();
070                characters = si.getCharCount();
071                creatingApplication = si.getApplicationName();
072                thumbnail = si.getThumbnail();
073            } catch (Exception ex) {
074                Logger.getLogger(this.getClass()).debug(ex, "Error processing the metadata for the MS Office document");
075            }
076    
077        }
078    
079        public String getTitle() {
080            return title;
081        }
082    
083        public String getSubject() {
084            return subject;
085        }
086    
087        public String getAuthor() {
088            return author;
089        }
090    
091        public String getKeywords() {
092            return keywords;
093        }
094    
095        public String getComment() {
096            return comment;
097        }
098    
099        public String getTemplate() {
100            return template;
101        }
102    
103        public Date getLastSavedBy() {
104            return lastSavedBy;
105        }
106    
107        public String getRevision() {
108            return revision;
109        }
110    
111        public Long getTotalEditingTime() {
112            return totalEditingTime;
113        }
114    
115        public Date getLastPrinted() {
116            return lastPrinted;
117        }
118    
119        public Date getCreated() {
120            return created;
121        }
122    
123        public Date getSaved() {
124            return saved;
125        }
126    
127        public int getPages() {
128            return pages;
129        }
130    
131        public int getWords() {
132            return words;
133        }
134    
135        public int getCharacters() {
136            return characters;
137        }
138    
139        public String getCreatingApplication() {
140            return creatingApplication;
141        }
142    
143        public byte[] getThumbnail() {
144            return thumbnail;
145        }
146    }