2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 package org
.apache
.tika
.parser
.microsoft
;
19 import org
.apache
.poi
.hpsf
.PropertySetFactory
;
20 import org
.apache
.poi
.hpsf
.SummaryInformation
;
21 import org
.apache
.poi
.poifs
.eventfilesystem
.POIFSReaderEvent
;
22 import org
.apache
.poi
.poifs
.eventfilesystem
.POIFSReaderListener
;
23 import org
.apache
.tika
.metadata
.Metadata
;
25 class PropertiesReaderListener
implements POIFSReaderListener
{
27 private final Metadata metadata
;
29 public PropertiesReaderListener(Metadata metadata
) {
30 this.metadata
= metadata
;
33 public void processPOIFSReaderEvent(POIFSReaderEvent event
) {
34 if (!event
.getName().startsWith(
35 SummaryInformation
.DEFAULT_STREAM_NAME
)) {
40 SummaryInformation si
= (SummaryInformation
)
41 PropertySetFactory
.create(event
.getStream());
42 if (si
.getTitle() != null) {
43 metadata
.set(Metadata
.TITLE
, si
.getTitle());
45 if (si
.getAuthor() != null) {
46 metadata
.set(Metadata
.AUTHOR
, si
.getAuthor());
48 if (si
.getKeywords() != null) {
49 metadata
.set(Metadata
.KEYWORDS
, si
.getKeywords());
51 if (si
.getSubject() != null) {
52 metadata
.set(Metadata
.SUBJECT
, si
.getSubject());
54 if (si
.getLastAuthor() != null) {
55 metadata
.set(Metadata
.LAST_AUTHOR
, si
.getLastAuthor());
57 if (si
.getComments() != null) {
58 metadata
.set(Metadata
.COMMENTS
, si
.getComments());
60 if (si
.getTemplate() != null) {
61 metadata
.set(Metadata
.TEMPLATE
, si
.getTemplate());
63 if (si
.getApplicationName() != null) {
64 metadata
.set(Metadata
.APPLICATION_NAME
, si
.getApplicationName());
66 if (si
.getRevNumber() != null) {
67 metadata
.set(Metadata
.REVISION_NUMBER
, si
.getRevNumber());
69 if (si
.getCreateDateTime() != null) {
70 metadata
.set("creationdate", si
.getCreateDateTime().toString());
72 if (si
.getCharCount() > 0) {
74 Metadata
.CHARACTER_COUNT
,
75 Integer
.toString(si
.getCharCount()));
77 if (si
.getEditTime() > 0) {
78 metadata
.set("edittime", Long
.toString(si
.getEditTime()));
80 if (si
.getLastSaveDateTime() != null) {
83 si
.getLastSaveDateTime().toString());
85 if (si
.getPageCount() > 0) {
88 Integer
.toString(si
.getPageCount()));
90 if (si
.getSecurity() > 0) {
92 "security", Integer
.toString(si
.getSecurity()));
94 if (si
.getWordCount() > 0) {
97 Integer
.toString(si
.getWordCount()));
99 if (si
.getLastPrinted() != null) {
101 Metadata
.LAST_PRINTED
,
102 si
.getLastPrinted().toString());
104 } catch (Exception ex
) {