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