/** * Provides a short description of the object, to be used when a * POIFSViewable object has not provided its contents. * * @return short description */ public String getShortDescription() { return getName(); }
@Override public EmbeddedData extract(DirectoryNode dn) throws IOException { EmbeddedData ed = super.extract(dn); ed.setFilename(dn.getName() + ".ole"); // TODO: read the content type from CombObj stream return ed; } }
@Override public EmbeddedData extract(DirectoryNode dn) throws IOException { try(ByteArrayOutputStream bos = new ByteArrayOutputStream(); InputStream is = dn.createDocumentInputStream("CONTENTS")) { IOUtils.copy(is, bos); return new EmbeddedData(dn.getName() + ".pdf", bos.toByteArray(), CONTENT_TYPE_PDF); } }
/** * Recursively traverses directory structure rooted at <tt>dir</tt>. * For each macro module that is found, the module's name and code are * added to <tt>modules<tt>. * * @param dir The directory of entries to look at * @param modules The resulting map of modules * @throws IOException If reading the VBA module fails * @since 3.15-beta2 */ protected void findMacros(DirectoryNode dir, ModuleMap modules) throws IOException { if (VBA_PROJECT_POIFS.equalsIgnoreCase(dir.getName())) { // VBA project directory, process readMacros(dir, modules); } else { // Check children for (Entry child : dir) { if (child instanceof DirectoryNode) { findMacros((DirectoryNode)child, modules); } } } }
public static void displayDirectory(DirectoryNode dir, String indent, boolean withSizes) { System.out.println(indent + dir.getName() + " -"); String newIndent = indent + " "; boolean hadChildren = false; for(Iterator<Entry> it = dir.getEntries(); it.hasNext();) { hadChildren = true; Entry entry = it.next(); if (entry instanceof DirectoryNode) { displayDirectory((DirectoryNode) entry, newIndent, withSizes); } else { DocumentNode doc = (DocumentNode) entry; String name = doc.getName(); String size = ""; if (name.charAt(0) < 10) { String altname = "(0x0" + (int) name.charAt(0) + ")" + name.substring(1); name = name.substring(1) + " <" + altname + ">"; } if (withSizes) { size = " [" + doc.getSize() + " / 0x" + Integer.toHexString(doc.getSize()) + "]"; } System.out.println(newIndent + name + size); } } if (!hadChildren) { System.out.println(newIndent + "(no children)"); } } }
protected EmbeddedData extract(DirectoryNode dn) throws IOException { assert(canExtract(dn)); ByteArrayOutputStream bos = new ByteArrayOutputStream(20000); try (POIFSFileSystem dest = new POIFSFileSystem()) { copyNodes(dn, dest.getRoot()); // start with a reasonable big size dest.writeFilesystem(bos); } return new EmbeddedData(dn.getName(), bos.toByteArray(), CONTENT_TYPE_BYTES); }
@Override public EmbeddedData extract(DirectoryNode dn) throws IOException { EmbeddedData ed = super.extract(dn); if (canExtractExcel(dn)) { ed.setFilename(dn.getName() + ".xls"); ed.setContentType(CONTENT_TYPE_XLS); } else if (canExtractWord(dn)) { ed.setFilename(dn.getName() + ".doc"); ed.setContentType(CONTENT_TYPE_DOC); } return ed; } }
protected static void copyNodes(DirectoryNode src, DirectoryNode dest) throws IOException { for (Entry e : src) { if (e instanceof DirectoryNode) { DirectoryNode srcDir = (DirectoryNode)e; DirectoryNode destDir = (DirectoryNode)dest.createDirectory(srcDir.getName()); destDir.setStorageClsid(srcDir.getStorageClsid()); copyNodes(srcDir, destDir); } else { try (InputStream is = src.createDocumentInputStream(e)) { dest.createDocument(e.getName(), is); } } } }
@Override public EmbeddedData extract(DirectoryNode dn) throws IOException { ClassIDPredefined clsId = ClassIDPredefined.lookup(dn.getStorageClsid()); String contentType = null; String ext = null; if (clsId != null) { contentType = clsId.getContentType(); ext = clsId.getFileExtension(); } if (contentType == null || ext == null) { contentType = "application/zip"; ext = ".zip"; } DocumentInputStream dis = dn.createDocumentInputStream("package"); byte data[] = IOUtils.toByteArray(dis); dis.close(); return new EmbeddedData(dn.getName()+ext, data, contentType); } }
/** * Provides a short description of the object, to be used when a * POIFSViewable object has not provided its contents. * * @return short description */ public String getShortDescription() { return getName(); }
/** * Provides a short description of the object, to be used when a * POIFSViewable object has not provided its contents. * * @return short description */ public String getShortDescription() { return getName(); }
/** * Provides a short description of the object, to be used when a * POIFSViewable object has not provided its contents. * * @return short description */ public String getShortDescription() { return getName(); }
@Override public EmbeddedData extract(DirectoryNode dn) throws IOException { try(ByteArrayOutputStream bos = new ByteArrayOutputStream(); InputStream is = dn.createDocumentInputStream("CONTENTS")) { IOUtils.copy(is, bos); return new EmbeddedData(dn.getName() + ".pdf", bos.toByteArray(), CONTENT_TYPE_PDF); } }
@Override public EmbeddedData extract(DirectoryNode dn) throws IOException { EmbeddedData ed = super.extract(dn); ed.setFilename(dn.getName() + ".ole"); // TODO: read the content type from CombObj stream return ed; } }
/** * Recursively traverses directory structure rooted at <tt>dir</tt>. * For each macro module that is found, the module's name and code are * added to <tt>modules<tt>. * * @param dir The directory of entries to look at * @param modules The resulting map of modules * @throws IOException If reading the VBA module fails * @since 3.15-beta2 */ protected void findMacros(DirectoryNode dir, ModuleMap modules) throws IOException { if (VBA_PROJECT_POIFS.equalsIgnoreCase(dir.getName())) { // VBA project directory, process readMacros(dir, modules); } else { // Check children for (Entry child : dir) { if (child instanceof DirectoryNode) { findMacros((DirectoryNode)child, modules); } } } }
public static void displayDirectory(DirectoryNode dir, String indent, boolean withSizes) { System.out.println(indent + dir.getName() + " -"); String newIndent = indent + " "; boolean hadChildren = false; for(Iterator<Entry> it = dir.getEntries(); it.hasNext();) { hadChildren = true; Entry entry = it.next(); if (entry instanceof DirectoryNode) { displayDirectory((DirectoryNode) entry, newIndent, withSizes); } else { DocumentNode doc = (DocumentNode) entry; String name = doc.getName(); String size = ""; if (name.charAt(0) < 10) { String altname = "(0x0" + (int) name.charAt(0) + ")" + name.substring(1); name = name.substring(1) + " <" + altname + ">"; } if (withSizes) { size = " [" + doc.getSize() + " / 0x" + Integer.toHexString(doc.getSize()) + "]"; } System.out.println(newIndent + name + size); } } if (!hadChildren) { System.out.println(newIndent + "(no children)"); } } }
protected EmbeddedData extract(DirectoryNode dn) throws IOException { assert(canExtract(dn)); ByteArrayOutputStream bos = new ByteArrayOutputStream(20000); try (POIFSFileSystem dest = new POIFSFileSystem()) { copyNodes(dn, dest.getRoot()); // start with a reasonable big size dest.writeFilesystem(bos); } return new EmbeddedData(dn.getName(), bos.toByteArray(), CONTENT_TYPE_BYTES); }
@Override public EmbeddedData extract(DirectoryNode dn) throws IOException { EmbeddedData ed = super.extract(dn); if (canExtractExcel(dn)) { ed.setFilename(dn.getName() + ".xls"); ed.setContentType(CONTENT_TYPE_XLS); } else if (canExtractWord(dn)) { ed.setFilename(dn.getName() + ".doc"); ed.setContentType(CONTENT_TYPE_DOC); } return ed; } }
protected static void copyNodes(DirectoryNode src, DirectoryNode dest) throws IOException { for (Entry e : src) { if (e instanceof DirectoryNode) { DirectoryNode srcDir = (DirectoryNode)e; DirectoryNode destDir = (DirectoryNode)dest.createDirectory(srcDir.getName()); destDir.setStorageClsid(srcDir.getStorageClsid()); copyNodes(srcDir, destDir); } else { try (InputStream is = src.createDocumentInputStream(e)) { dest.createDocument(e.getName(), is); } } } }
@Override public EmbeddedData extract(DirectoryNode dn) throws IOException { ClassIDPredefined clsId = ClassIDPredefined.lookup(dn.getStorageClsid()); String contentType = null; String ext = null; if (clsId != null) { contentType = clsId.getContentType(); ext = clsId.getFileExtension(); } if (contentType == null || ext == null) { contentType = "application/zip"; ext = ".zip"; } DocumentInputStream dis = dn.createDocumentInputStream("package"); byte data[] = IOUtils.toByteArray(dis); dis.close(); return new EmbeddedData(dn.getName()+ext, data, contentType); } }