KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > content > metadata > OpenDocumentMetadataExtracter


1 /*
2  * Copyright (C) 2005 Antti Jokipii
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.content.metadata;
18
19 import java.io.IOException JavaDoc;
20 import java.io.InputStream JavaDoc;
21 import java.io.Serializable JavaDoc;
22 import java.util.Arrays JavaDoc;
23 import java.util.HashSet JavaDoc;
24 import java.util.Map JavaDoc;
25
26 import org.alfresco.model.ContentModel;
27 import org.alfresco.repo.content.MimetypeMap;
28 import org.alfresco.service.cmr.repository.ContentReader;
29 import org.alfresco.service.namespace.QName;
30
31 import com.catcode.odf.ODFMetaFileAnalyzer;
32 import com.catcode.odf.OpenDocumentMetadata;
33
34 /**
35  * Metadata extractor for the
36  * {@link org.alfresco.repo.content.MimetypeMap#MIMETYPE_OPENDOCUMENT_TEXT MIMETYPE_OPENDOCUMENT_XXX}
37  * mimetypes.
38  *
39  * @author Antti Jokipii
40  */

41 public class OpenDocumentMetadataExtracter extends AbstractMetadataExtracter
42 {
43     private static String JavaDoc[] mimeTypes = new String JavaDoc[] {
44             MimetypeMap.MIMETYPE_OPENDOCUMENT_TEXT,
45             MimetypeMap.MIMETYPE_OPENDOCUMENT_TEXT_TEMPLATE,
46             MimetypeMap.MIMETYPE_OPENDOCUMENT_GRAPHICS,
47             MimetypeMap.MIMETYPE_OPENDOCUMENT_GRAPHICS_TEMPLATE,
48             MimetypeMap.MIMETYPE_OPENDOCUMENT_PRESENTATION,
49             MimetypeMap.MIMETYPE_OPENDOCUMENT_PRESENTATION_TEMPLATE,
50             MimetypeMap.MIMETYPE_OPENDOCUMENT_SPREADSHEET,
51             MimetypeMap.MIMETYPE_OPENDOCUMENT_SPREADSHEET_TEMPLATE,
52             MimetypeMap.MIMETYPE_OPENDOCUMENT_CHART,
53             MimetypeMap.MIMETYPE_OPENDOCUMENT_CHART_TEMPLATE,
54             MimetypeMap.MIMETYPE_OPENDOCUMENT_IMAGE,
55             MimetypeMap.MIMETYPE_OPENDOCUMENT_IMAGE_TEMPLATE,
56             MimetypeMap.MIMETYPE_OPENDOCUMENT_FORMULA,
57             MimetypeMap.MIMETYPE_OPENDOCUMENT_FORMULA_TEMPLATE,
58             MimetypeMap.MIMETYPE_OPENDOCUMENT_TEXT_MASTER,
59             MimetypeMap.MIMETYPE_OPENDOCUMENT_TEXT_WEB,
60             MimetypeMap.MIMETYPE_OPENDOCUMENT_DATABASE, };
61
62     public OpenDocumentMetadataExtracter()
63     {
64         super(new HashSet JavaDoc<String JavaDoc>(Arrays.asList(mimeTypes)), 1.00, 1000);
65     }
66
67     public void extractInternal(ContentReader reader, Map JavaDoc<QName, Serializable JavaDoc> destination) throws Throwable JavaDoc
68     {
69         ODFMetaFileAnalyzer analyzer = new ODFMetaFileAnalyzer();
70         InputStream JavaDoc is = null;
71         try
72         {
73             is = reader.getContentInputStream();
74             // stream the document in
75
OpenDocumentMetadata docInfo = analyzer.analyzeZip(is);
76
77             if (docInfo != null)
78             {
79                 // set the metadata
80
destination.put(ContentModel.PROP_AUTHOR, docInfo.getCreator());
81                 destination.put(ContentModel.PROP_TITLE, docInfo.getTitle());
82                 destination.put(ContentModel.PROP_DESCRIPTION, docInfo.getDescription());
83                 destination.put(ContentModel.PROP_CREATED, docInfo.getCreationDate());
84             }
85         }
86         finally
87         {
88             if (is != null)
89             {
90                 try { is.close(); } catch (IOException JavaDoc e) {}
91             }
92         }
93     }
94 }
Popular Tags