1 7 package org.jahia.services.fileextraction; 8 9 import java.util.HashMap ; 10 import java.util.Iterator ; 11 import java.util.List ; 12 import java.util.Map ; 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 28 public class OfficePropertiesListener implements POIFSReaderListener { 29 30 private HashMap properties = new HashMap (); 31 32 public Map 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 ex) { 43 throw new RuntimeException ("Property set stream \"" + event.getPath() + event.getName() + "\": " + ex); 44 } 45 String eventName = event.getName().trim(); 46 final long sectionCount = ps.getSectionCount(); 47 List sections = ps.getSections(); 48 int nr = 0; 49 for (Iterator 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 value = p.getValue(); 58 String key = eventName + "-" + nr + "-" + id; 59 properties.put(key, value); 60 61 65 } 66 } 67 } 68 } 69 | Popular Tags |