KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > services > fileextraction > OfficePropertiesListener


1 /*
2  * Created on 27 janv. 2005
3  *
4  * TODO To change the template for this generated file go to
5  * Window - Preferences - Java - Code Style - Code Templates
6  */

7 package org.jahia.services.fileextraction;
8
9 import java.util.HashMap JavaDoc;
10 import java.util.Iterator JavaDoc;
11 import java.util.List JavaDoc;
12 import java.util.Map JavaDoc;
13
14 import org.apache.poi.hpsf.NoPropertySetStreamException;
15 import org.apache.poi.hpsf.Property;
16 import org.apache.poi.hpsf.PropertySet;
17 import org.apache.poi.hpsf.PropertySetFactory;
18 import org.apache.poi.hpsf.Section;
19 import org.apache.poi.poifs.eventfilesystem.POIFSReaderEvent;
20 import org.apache.poi.poifs.eventfilesystem.POIFSReaderListener;
21
22 /**
23  * @author hollis
24  *
25  * TODO To change the template for this generated type comment go to
26  * Window - Preferences - Java - Code Style - Code Templates
27  */

28 public class OfficePropertiesListener implements POIFSReaderListener {
29
30     private HashMap JavaDoc properties = new HashMap JavaDoc();
31
32     public Map JavaDoc getProperties() {
33             return properties;
34     }
35
36     public void processPOIFSReaderEvent(POIFSReaderEvent event) {
37         PropertySet ps = null;
38         try {
39             ps = PropertySetFactory.create(event.getStream());
40         } catch (NoPropertySetStreamException ex) {
41             return;
42         } catch (Exception JavaDoc ex) {
43             throw new RuntimeException JavaDoc("Property set stream \"" + event.getPath() + event.getName() + "\": " + ex);
44         }
45         String JavaDoc eventName = event.getName().trim();
46         final long sectionCount = ps.getSectionCount();
47         List JavaDoc sections = ps.getSections();
48         int nr = 0;
49         for (Iterator JavaDoc i = sections.iterator(); i.hasNext();) {
50             Section sec = (Section) i.next();
51             int propertyCount = sec.getPropertyCount();
52             Property[] props = sec.getProperties();
53             for (int i2 = 0; i2 < props.length; i2++) {
54                 Property p = props[i2];
55                 long id = p.getID();
56                 long type = p.getType();
57                 Object JavaDoc value = p.getValue();
58                 String JavaDoc key = eventName + "-" + nr + "-" + id;
59                 properties.put(key, value);
60
61                 /*
62                 if ( propertyMap.containsKey(key) ) {
63                     properties.put(propertyMap.get(key), value);
64                 }*/

65             }
66         }
67     }
68 }
69
Popular Tags