1 17 package org.alfresco.repo.content.metadata; 18 19 import java.io.IOException ; 20 import java.io.InputStream ; 21 import java.io.Serializable ; 22 import java.util.Arrays ; 23 import java.util.HashSet ; 24 import java.util.Map ; 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 41 public class OpenDocumentMetadataExtracter extends AbstractMetadataExtracter 42 { 43 private static String [] mimeTypes = new String [] { 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 <String >(Arrays.asList(mimeTypes)), 1.00, 1000); 65 } 66 67 public void extractInternal(ContentReader reader, Map <QName, Serializable > destination) throws Throwable 68 { 69 ODFMetaFileAnalyzer analyzer = new ODFMetaFileAnalyzer(); 70 InputStream is = null; 71 try 72 { 73 is = reader.getContentInputStream(); 74 OpenDocumentMetadata docInfo = analyzer.analyzeZip(is); 76 77 if (docInfo != null) 78 { 79 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 e) {} 91 } 92 } 93 } 94 } | Popular Tags |