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();
}
}
}
}
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();
;
}
}
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();
}
}
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);
}
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);
}
Aggregations