List of usage examples for org.apache.poi.poifs.filesystem DirectoryEntry getEntries
public Iterator<Entry> getEntries();
From source file:edu.tsinghua.lumaqq.customface.EIPImporter.java
License:Open Source License
@SuppressWarnings("unchecked") public EIPImporter(String file, String destDir) { this.destDir = destDir; buffer = new byte[8192]; POIFSFileSystem eipSystem;//from ww w . ja v a2 s. c o m try { // eip eipStream = new FileInputStream(file); eipSystem = new POIFSFileSystem(eipStream); // DirectoryEntry configDir = null, fileDir = null; DirectoryEntry root = eipSystem.getRoot(); Iterator<Entry> i = root.getEntries(); while (i.hasNext()) { Entry e = i.next(); if (e.isDirectoryEntry()) { if (CONFIG_DIRECTORY.equals(e.getName().toLowerCase())) configDir = (DirectoryEntry) e; else if (FILES_DIRECTORY.equals(e.getName().toLowerCase())) fileDir = (DirectoryEntry) e; } } // ?? if (configDir == null || fileDir == null) throw new IOException("Can't find correct directories"); // ?face.xml i = configDir.getEntries(); while (i.hasNext()) { Entry e = i.next(); if (e.isDocumentEntry() && CONFIG_FILE.equals(e.getName().toLowerCase())) { DocumentInputStream dis = new DocumentInputStream((DocumentEntry) e); parser = new FaceXMLParser(dis); dis.close(); break; } } // ??face.xml if (parser == null) throw new IOException("Can't find " + CONFIG_FILE); // iterator groupIterator = fileDir.getEntries(); currentDir = fileDir; faceIterator = currentDir.getEntries(); } catch (IOException e) { eipSystem = null; try { if (eipStream != null) { eipStream.close(); eipStream = null; } } catch (IOException e1) { } } }
From source file:net.freeutils.tnef.msg.Msg.java
License:Open Source License
public static void printDirectory(DirectoryEntry dir, String linePrefix) throws IOException { for (Iterator iter = dir.getEntries(); iter.hasNext();) { Entry entry = (Entry) iter.next(); String name = entry.getName(); if (entry instanceof DirectoryEntry) { DirectoryEntry de = (DirectoryEntry) entry; System.out.println(linePrefix + name + "/"); printDirectory(de, linePrefix + " "); } else if (entry instanceof DocumentEntry) { System.out.println(linePrefix + name + " " + toRawInputStream((DocumentEntry) entry)); } else {/*w w w . j a v a 2 s . c o m*/ System.out.println(linePrefix + name + " (UNKNOWN entry type)"); } } }
From source file:net.freeutils.tnef.msg.Msg.java
License:Open Source License
protected static List processPropEntries(DirectoryEntry dir) throws IOException { List props = new ArrayList(); for (Iterator iter = dir.getEntries(); iter.hasNext();) { Entry entry = (Entry) iter.next(); if (entry instanceof DocumentEntry && entry.getName().startsWith("__substg1.0_")) props.add(processProperty((DocumentEntry) entry)); }//from ww w .j a va 2s. c o m return props; }
From source file:net.sf.mpxj.explorer.PoiTreeModel.java
License:Open Source License
/** * Retrieves child nodes from a directory entry. * /*from w ww . j av a 2s . c o m*/ * @param parent parent directory entry * @return list of child nodes */ private List<Entry> getChildNodes(DirectoryEntry parent) { List<Entry> result = new ArrayList<Entry>(); Iterator<Entry> entries = parent.getEntries(); while (entries.hasNext()) { result.add(entries.next()); } return result; }
From source file:net.sf.mpxj.sample.MppDump.java
License:Open Source License
/** * This method recursively descends the directory structure, dumping * details of any files it finds to the output file. * * @param pw Output PrintWriter/*from www .j ava 2 s. c o m*/ * @param dir DirectoryEntry to dump * @param prefix prefix used to identify path to this object * @param showData flag indicating if data is dumped, or just structure * @param hex set to true if hex output is required * @param indent indent used if displaying structure only * @throws Exception Thrown on file read errors */ private static void dumpTree(PrintWriter pw, DirectoryEntry dir, String prefix, boolean showData, boolean hex, String indent) throws Exception { long byteCount; for (Iterator<Entry> iter = dir.getEntries(); iter.hasNext();) { Entry entry = iter.next(); if (entry instanceof DirectoryEntry) { String childIndent = indent; if (childIndent != null) { childIndent += " "; } String childPrefix = prefix + "[" + entry.getName() + "]."; pw.println("start dir: " + prefix + entry.getName()); dumpTree(pw, (DirectoryEntry) entry, childPrefix, showData, hex, childIndent); pw.println("end dir: " + prefix + entry.getName()); } else if (entry instanceof DocumentEntry) { if (showData) { pw.println("start doc: " + prefix + entry.getName()); if (hex == true) { byteCount = hexdump(new DocumentInputStream((DocumentEntry) entry), pw); } else { byteCount = asciidump(new DocumentInputStream((DocumentEntry) entry), pw); } pw.println("end doc: " + prefix + entry.getName() + " (" + byteCount + " bytes read)"); } else { if (indent != null) { pw.print(indent); } pw.println("doc: " + prefix + entry.getName()); } } else { pw.println("found unknown: " + prefix + entry.getName()); } } }
From source file:nz.govt.natlib.adapter.excel.ExcelAdapter.java
License:Apache License
public void readDirectory(POIFSFileSystem fs, DirectoryEntry dir) throws Exception { if (dir.getEntryCount() == 0) { return;//from w ww .ja va 2 s .c o m } for (Iterator iter = dir.getEntries(); iter.hasNext();) { Entry entry = (Entry) iter.next(); if (entry instanceof DirectoryEntry) { // .. recurse into this directory readDirectory(fs, (DirectoryEntry) entry); } else if (entry instanceof DocumentEntry) { // entry is a document, which you can read DocumentEntry doc = (DocumentEntry) entry; readDocument(fs, doc); } else { // currently, either an Entry is a DirectoryEntry or a // DocumentEntry, // but in the future, there may be other entry subinterfaces. // The // internal data structure certainly allows for a lot more entry // types. } } }
From source file:nz.govt.natlib.adapter.powerpoint.PowerPointAdapter.java
License:Apache License
public void readDirectory(POIFSFileSystem fs, DirectoryEntry dir) throws Exception { if (dir.getEntryCount() == 0) { return;/*from ww w.j a v a 2 s . c om*/ } for (Iterator iter = dir.getEntries(); iter.hasNext();) { Entry entry = (Entry) iter.next(); System.out.println("found entry: " + entry.getName()); if (entry instanceof DirectoryEntry) { // .. recurse into this directory readDirectory(fs, (DirectoryEntry) entry); } else if (entry instanceof DocumentEntry) { // entry is a document, which you can read DocumentEntry doc = (DocumentEntry) entry; readDocument(fs, doc); } else { // currently, either an Entry is a DirectoryEntry or a // DocumentEntry, // but in the future, there may be other entry subinterfaces. // The // internal data structure certainly allows for a lot more entry // types. } } }
From source file:nz.govt.natlib.adapter.works.DocAdapter.java
License:Apache License
public void readDirectory(POIFSFileSystem fs, DirectoryEntry dir, ParserContext ctx) throws Exception { if (dir.getEntryCount() == 0) { return;//from w w w . ja v a 2s.c o m } for (Iterator iter = dir.getEntries(); iter.hasNext();) { Entry entry = (Entry) iter.next(); // System.out.println("found entry: " + entry.getName()); if (entry instanceof DirectoryEntry) { // .. recurse into this directory // System.out.println(" > Directory..."); readDirectory(fs, (DirectoryEntry) entry, ctx); } else if (entry instanceof DocumentEntry) { // entry is a document, which you can read // System.out.println(" > Document"); DocumentEntry doc = (DocumentEntry) entry; ArrayList list = readDocument(fs, doc); if (entry.getName().endsWith("CompObj")) { writeCompObjProps(list, ctx); } } else { // currently, either an Entry is a DirectoryEntry or a // DocumentEntry, // but in the future, there may be other entry subinterfaces. // The // internal data structure certainly allows for a lot more entry // types. // System.out.println(" > Other"); } } }
From source file:org.opencrx.application.uses.com.auxilii.msgparser.MsgParser.java
License:Open Source License
/** * Recursively parses the complete .msg file with the * help of the POI library. The parsed information is * put into the {@link Message} object./*from w w w .ja v a2 s. c o m*/ * * @param dir The current node in the .msg file. * @param msg The resulting {@link Message} object. * @throws IOException Thrown if the .msg file could not * be parsed. * @throws UnsupportedOperationException Thrown if * the .msg file contains unknown data. */ protected void checkDirectoryEntry(DirectoryEntry dir, Message msg) throws IOException, UnsupportedOperationException { // we iterate through all entries in the current directory for (Iterator<?> iter = dir.getEntries(); iter.hasNext();) { Entry entry = (Entry) iter.next(); // check whether the entry is either a directory entry // or a document entry if (entry.isDirectoryEntry()) { DirectoryEntry de = (DirectoryEntry) entry; // attachments have a special name and // have to be handled separately at this point if (de.getName().startsWith("__attach_version1.0")) { this.parseAttachment(de, msg); } else if (de.getName().startsWith("__recip_version1.0")) { // a recipient entry has been found (which is also a directory entry itself) this.checkRecipientDirectoryEntry(de, msg); } else { // a directory entry has been found. this // node will be recursively checked this.checkDirectoryEntry(de, msg); } } else if (entry.isDocumentEntry()) { // a document entry contains information about // the mail (e.g, from, to, subject, ...) DocumentEntry de = (DocumentEntry) entry; // the data is accessed by getting an input stream // for the given document entry DocumentInputStream dstream = new DocumentInputStream(de); // analyze the document entry // (i.e., get class and data type) FieldInformation info = this.analyzeDocumentEntry(de); // create a Java object from the data provided // by the input stream. depending on the field // information, either a String or a byte[] will // be returned. other datatypes are not yet supported Object data = this.getData(dstream, info); logger.finest(" Document data: " + ((data == null) ? "null" : data.toString())); // the data is written into the Message object msg.setProperty(info.getClazz(), data); } else { // any other type is not supported } } }
From source file:org.opencrx.application.uses.com.auxilii.msgparser.MsgParser.java
License:Open Source License
/** * Parses a recipient directory entry which holds informations about one of possibly multiple recipients. * The parsed information is put into the {@link Message} object. * //from w w w.j a va 2 s. co m * @param dir The current node in the .msg file. * @param msg The resulting {@link Message} object. * @throws IOException Thrown if the .msg file could not * be parsed. * @throws UnsupportedOperationException Thrown if * the .msg file contains unknown data. */ protected void checkRecipientDirectoryEntry(DirectoryEntry dir, Message msg) throws IOException, UnsupportedOperationException { RecipientEntry recipient = new RecipientEntry(); // we iterate through all entries in the current directory for (Iterator<?> iter = dir.getEntries(); iter.hasNext();) { Entry entry = (Entry) iter.next(); // check whether the entry is either a directory entry // or a document entry, while we are just interested in document entries on this level if (entry.isDirectoryEntry()) { // not expected within a recipient entry } else if (entry.isDocumentEntry()) { // a document entry contains information about // the mail (e.g, from, to, subject, ...) DocumentEntry de = (DocumentEntry) entry; // the data is accessed by getting an input stream // for the given document entry DocumentInputStream dstream = new DocumentInputStream(de); // analyze the document entry // (i.e., get class and data type) FieldInformation info = this.analyzeDocumentEntry(de); // create a Java object from the data provided // by the input stream. depending on the field // information, either a String or a byte[] will // be returned. other datatypes are not yet supported Object data = this.getData(dstream, info); logger.finest(" Document data: " + ((data == null) ? "null" : data.toString())); // the data is written into the Message object recipient.setProperty(info.getClazz(), data); } else { // any other type is not supported } } //after all properties are set -> add recipient to msg object msg.addRecipient(recipient); }