Search in sources :

Example 11 with DirectoryNode

use of org.apache.poi.poifs.filesystem.DirectoryNode in project poi by apache.

the class LoadEmbedded method loadEmbedded.

public static void loadEmbedded(HSSFWorkbook workbook) throws IOException {
    for (HSSFObjectData obj : workbook.getAllEmbeddedObjects()) {
        //the OLE2 Class Name of the object
        String oleName = obj.getOLE2ClassName();
        if (oleName.equals("Worksheet")) {
            DirectoryNode dn = (DirectoryNode) obj.getDirectory();
            HSSFWorkbook embeddedWorkbook = new HSSFWorkbook(dn, false);
            embeddedWorkbook.close();
        } else if (oleName.equals("Document")) {
            DirectoryNode dn = (DirectoryNode) obj.getDirectory();
            HWPFDocument embeddedWordDocument = new HWPFDocument(dn);
            embeddedWordDocument.close();
        } else if (oleName.equals("Presentation")) {
            DirectoryNode dn = (DirectoryNode) obj.getDirectory();
            SlideShow<?, ?> embeddedSlieShow = new HSLFSlideShow(dn);
            embeddedSlieShow.close();
        } else {
            if (obj.hasDirectoryEntry()) {
                // The DirectoryEntry is a DocumentNode. Examine its entries to find out what it is
                DirectoryNode dn = (DirectoryNode) obj.getDirectory();
                for (Entry entry : dn) {
                //System.out.println(oleName + "." + entry.getName());
                }
            } else {
                // There is no DirectoryEntry
                // Recover the object's data from the HSSFObjectData instance.
                byte[] objectData = obj.getObjectData();
            }
        }
    }
}
Also used : HWPFDocument(org.apache.poi.hwpf.HWPFDocument) Entry(org.apache.poi.poifs.filesystem.Entry) HSSFObjectData(org.apache.poi.hssf.usermodel.HSSFObjectData) DirectoryNode(org.apache.poi.poifs.filesystem.DirectoryNode) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 12 with DirectoryNode

use of org.apache.poi.poifs.filesystem.DirectoryNode in project poi by apache.

the class HPSFFileHandler method hasPropertyStream.

private static boolean hasPropertyStream(POIFSFileSystem poifs, String streamName) throws IOException, MarkUnsupportedException {
    DirectoryNode root = poifs.getRoot();
    if (!root.hasEntry(streamName)) {
        return false;
    }
    DocumentInputStream dis = root.createDocumentInputStream(streamName);
    try {
        return PropertySet.isPropertySetStream(dis);
    } finally {
        dis.close();
        ;
    }
}
Also used : DirectoryNode(org.apache.poi.poifs.filesystem.DirectoryNode) DocumentInputStream(org.apache.poi.poifs.filesystem.DocumentInputStream)

Example 13 with DirectoryNode

use of org.apache.poi.poifs.filesystem.DirectoryNode in project poi by apache.

the class PPTXMLDump method readEntry.

private static byte[] readEntry(NPOIFSFileSystem fs, String entry) throws IOException {
    DirectoryNode dn = fs.getRoot();
    if (!dn.hasEntry(entry)) {
        return null;
    }
    InputStream is = dn.createDocumentInputStream(entry);
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        IOUtils.copy(is, bos);
        return bos.toByteArray();
    } finally {
        is.close();
    }
}
Also used : InputStream(java.io.InputStream) DirectoryNode(org.apache.poi.poifs.filesystem.DirectoryNode) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 14 with DirectoryNode

use of org.apache.poi.poifs.filesystem.DirectoryNode in project poi by apache.

the class HPBFDumper method dumpEscher.

/**
	 * Dump out the escher parts of the file.
	 * Escher -> EscherStm and EscherDelayStm
	 */
public void dumpEscher() throws IOException {
    DirectoryNode escherDir = (DirectoryNode) fs.getRoot().getEntry("Escher");
    dumpEscherStm(escherDir);
    dumpEscherDelayStm(escherDir);
}
Also used : DirectoryNode(org.apache.poi.poifs.filesystem.DirectoryNode)

Example 15 with DirectoryNode

use of org.apache.poi.poifs.filesystem.DirectoryNode in project poi by apache.

the class HPBFPart method writeOut.

public void writeOut(DirectoryNode baseDir) throws IOException {
    String[] path = getPath();
    // Ensure that all parent directories exist
    DirectoryNode dir = baseDir;
    for (int i = 0; i < path.length - 1; i++) {
        try {
            dir = (DirectoryNode) dir.getEntry(path[i]);
        } catch (FileNotFoundException e) {
            dir.createDirectory(path[i]);
        }
    }
    // Update the byte array with the latest data
    generateData();
    // Write out
    ByteArrayInputStream bais = new ByteArrayInputStream(data);
    dir.createDocument(path[path.length - 1], bais);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileNotFoundException(java.io.FileNotFoundException) DirectoryNode(org.apache.poi.poifs.filesystem.DirectoryNode)

Aggregations

DirectoryNode (org.apache.poi.poifs.filesystem.DirectoryNode)47 Test (org.junit.Test)16 InputStream (java.io.InputStream)15 POIFSFileSystem (org.apache.poi.poifs.filesystem.POIFSFileSystem)13 NPOIFSFileSystem (org.apache.poi.poifs.filesystem.NPOIFSFileSystem)12 Entry (org.apache.poi.poifs.filesystem.Entry)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 IOException (java.io.IOException)8 OPOIFSFileSystem (org.apache.poi.poifs.filesystem.OPOIFSFileSystem)6 FileInputStream (java.io.FileInputStream)5 FileNotFoundException (java.io.FileNotFoundException)5 DocumentInputStream (org.apache.poi.poifs.filesystem.DocumentInputStream)5 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)4 HWPFDocument (org.apache.poi.hwpf.HWPFDocument)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 AttachmentChunks (org.apache.poi.hsmf.datatypes.AttachmentChunks)3 DirectoryEntry (org.apache.poi.poifs.filesystem.DirectoryEntry)3 DocumentEntry (org.apache.poi.poifs.filesystem.DocumentEntry)3