List of usage examples for org.apache.poi.poifs.eventfilesystem POIFSReaderEvent getPath
public POIFSDocumentPath getPath()
From source file:com.knowgate.ole.OLEListener.java
License:Open Source License
public void processPOIFSReaderEvent(POIFSReaderEvent event) { try {/* w ww . j a va 2 s. c o m*/ si = (SummaryInformation) PropertySetFactory.create(event.getStream()); } catch (MarkUnsupportedException ex) { if (DebugFile.trace) DebugFile.writeln("com.knowgate.ole.OLEListener MarkUnsupportedException " + event.getPath() + event.getName() + " " + ex.getMessage()); } catch (NoPropertySetStreamException ex) { if (DebugFile.trace) DebugFile.writeln("com.knowgate.ole.OLEListener NoPropertySetStreamException " + event.getPath() + event.getName() + " " + ex.getMessage()); } catch (IOException ex) { if (DebugFile.trace) DebugFile.writeln("com.knowgate.ole.OLEListener IOException " + event.getPath() + event.getName() + " " + ex.getMessage()); } }
From source file:com.villemos.ispace.aperture.enricher.MicrosoftPropertyReader.java
License:Open Source License
public void processPOIFSReaderEvent(final POIFSReaderEvent event) { PropertySet ps = null;/*from w ww .j a v a 2s . c o m*/ try { ps = PropertySetFactory.create(event.getStream()); } catch (NoPropertySetStreamException ex) { LOG.debug("No property set stream: \"" + event.getPath() + event.getName() + "\""); return; } catch (Exception ex) { LOG.error("Exception while processing microsoft property set " + ex); } /* Print the name of the property set stream: */ LOG.debug("Property set stream \"" + event.getPath() + event.getName() + "\":"); /* Print the list of sections: */ List<Section> sections = ps.getSections(); int nr = 0; for (Section sec : sections) { String s = HexDump.dump(sec.getFormatID().getBytes(), 0L, 0); s = s.substring(0, s.length() - 1); /* Print the number of properties in this section. */ int propertyCount = sec.getPropertyCount(); /* Print the properties: */ Property[] properties = sec.getProperties(); for (int i2 = 0; i2 < properties.length; i2++) { /* Print a single property: */ Property p = properties[i2]; long id = p.getID(); long type = p.getType(); Object value = p.getValue(); String propertyName = sec.getPIDString(id); if (msProperties.containsKey(propertyName) == false) { String valueStr = value.toString(); if (valueStr.equals("") == false) { msProperties.put(propertyName, valueStr); } } } } }
From source file:org.ddt.listener.dsi.DocumentSummaryInfoListener.java
License:Apache License
public void processPOIFSReaderEvent(POIFSReaderEvent event) { log.log(Level.FINEST, "reading {0}{1}", new Object[] { event.getPath(), event.getName() }); DocumentInputStream is = event.getStream(); try {/*from www. j a v a 2 s . c o m*/ PropertySet ps = PropertySetFactory.create(is); if (!(ps instanceof DocumentSummaryInformation)) return; Property docparts = null; Property headings = null; for (Property prop : ps.getProperties()) { if (prop.getID() == PropertyIDMap.PID_HEADINGPAIR) // == 12 headings = prop; else if (prop.getID() == PropertyIDMap.PID_DOCPARTS) docparts = prop; } if (docparts == null) { log.log(Level.FINE, "No DOCPARTS section"); return; } if (headings == null) return; HeadingPairVector hdv = new HeadingPairVector((byte[]) headings.getValue(), 0); StringVector docpartsVector = new StringVector((byte[]) docparts.getValue(), 0, docparts.getType()); HeadingPairProperty linkHeader = hdv.getHeadingPairByName("Links"); //*NOT* null terminated if (linkHeader == null) { log.log(Level.INFO, "No 'Links' header found."); return; } else { log.log(Level.FINEST, "Found {0} link parts", linkHeader.getPartsCount()); } //need to iterate through all of the ones if there's more than one //docpart for the header. int part = linkHeader.getOffset(); for (int i = 0; i < linkHeader.getPartsCount(); i++) { String url = docpartsVector.get(part).getValue(); log.log(Level.FINEST, "adding {0} to list of links.", url); url = url.trim(); Link l = new Link(3); l.addUnkownPath(url); this.add(l); part++; } } catch (NoPropertySetStreamException ex) { log.log(Level.INFO, "Not a PropertySetStream {0}{1}", new Object[] { event.getPath(), event.getName() }); } catch (MarkUnsupportedException ex) { log.log(Level.INFO, "Couldn't create PropertySet: {0}", ex.getLocalizedMessage()); } catch (UnsupportedEncodingException ex) { log.log(Level.INFO, null, ex); } catch (IOException ex) { log.log(Level.INFO, null, ex); } catch (HPSFException ex) { log.log(Level.WARNING, "Couldn't construct HeadingPair vector.", ex); } finally { is.close(); } }
From source file:org.ddt.listener.ole.OleStreamListener.java
License:Apache License
/** * Reads a "\1Ole" stream and stores the links found in it. * <p/>/* w w w .j av a2 s . c o m*/ * This method returns (fairly) quietly if the stream fails (it doesn't throw exceptions) * There are a number of ways that this can fail, not all of which are bad. * For instance, POIFSReaderEvent doesn't contain an OLE stream, this is not * a disaster, we just need to return quickly. * * @param event document to process */ public void processPOIFSReaderEvent(POIFSReaderEvent event) { log.log(Level.FINEST, "Processing Document: {0}/{1}", new Object[] { event.getPath(), event.getName() }); DocumentInputStream docInStream = event.getStream(); if (docInStream.available() < LittleEndian.INT_SIZE) return; if (docInStream.readInt() != VALID_VERSION) { log.log(Level.INFO, "Invalid signature - not an OLE Stream."); docInStream.close(); return; } try { docInStream.skip(LittleEndian.INT_SIZE); //ignore what I think might be LinkUpdateOptions //check it's a linked object, not embedded if (docInStream.readInt() != 1) { log.log(Level.FINER, "Not a link"); docInStream.close(); return; } //check reserved field = 0 if (docInStream.readInt() != 0x000000) { docInStream.close(); return; } Moniker m; String relPath = null; String absPath = null; byte[] clsid = new byte[16]; //source moniker, not really interesting. if ((docInStream.readInt()) > 0) { docInStream.read(clsid); ClassID cid = new ClassID(clsid, 0); MonikerFactory.getMoniker(cid, docInStream); } if ((docInStream.readInt()) > 0) { docInStream.read(clsid); ClassID cid = new ClassID(clsid, 0); m = MonikerFactory.getMoniker(cid, docInStream); if (m != null) relPath = m.getLink(); } if ((docInStream.readInt()) > 0) { docInStream.read(clsid); ClassID cid = new ClassID(clsid, 0); m = MonikerFactory.getMoniker(cid, docInStream); if (m != null) absPath = m.getLink(); } Link l = new Link(1); l.addRelativePath(cleanURLString(relPath)); l.addAbsolutePath(absPath); this.add(l); } catch (IOException ex) { log.log(Level.FINE, ex.getLocalizedMessage()); } catch (BadOleStreamException ex) { log.log(Level.INFO, ex.getMessage()); } finally { docInStream.close(); } }
From source file:org.jab.docsearch.converters.MyPOIFSReaderListener.java
License:Open Source License
/** * Implementation for POIFSReaderListener *//*from w w w . ja v a 2 s . c om*/ @Override public void processPOIFSReaderEvent(final POIFSReaderEvent e) { SummaryInformation si = null; try { PropertySet ps = PropertySetFactory.create(e.getStream()); si = (SummaryInformation) ps; } catch (Exception ex) { throw new RuntimeException("Property set stream \"" + e.getPath() + e.getName() + "\": " + ex); } // title title = si.getTitle(); // author author = si.getLastAuthor(); // keywords keywords = si.getKeywords(); }
From source file:poi.poifs.poibrowser.TreeReaderListener.java
License:Apache License
/** * <p>A document in the POI filesystem has been opened for * reading. This method retrieves properties of the document and * adds them to a tree model.</p>//from w ww . j av a2 s.c om */ public void processPOIFSReaderEvent(final POIFSReaderEvent event) { DocumentDescriptor d; final DocumentInputStream is = event.getStream(); if (!is.markSupported()) throw new UnsupportedOperationException(is.getClass().getName() + " does not support mark()."); /* Try do handle this document as a property set. We receive * an exception if is no property set and handle it as a * document of some other format. We are not concerned about * that document's details. */ try { d = new PropertySetDescriptor(event.getName(), event.getPath(), is, nrOfBytes); } catch (HPSFException ex) { d = new DocumentDescriptor(event.getName(), event.getPath(), is, nrOfBytes); } catch (Throwable t) { System.err.println("Unexpected exception while processing " + event.getName() + " in " + event.getPath().toString()); t.printStackTrace(System.err); throw new RuntimeException(t.getMessage()); } is.close(); final MutableTreeNode parentNode = getNode(d.path, filename, rootNode); final MutableTreeNode nameNode = new DefaultMutableTreeNode(d.name); parentNode.insert(nameNode, 0); final MutableTreeNode dNode = new DefaultMutableTreeNode(d); nameNode.insert(dNode, 0); }