Java Code Examples for org.apache.poi.poifs.filesystem.DirectoryEntry#setStorageClsid()

The following examples show how to use org.apache.poi.poifs.filesystem.DirectoryEntry#setStorageClsid() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HSSFWorkbook.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int addOlePackage(byte[] oleData, String label, String fileName, String command)
throws IOException {
	// check if we were created by POIFS otherwise create a new dummy POIFS for storing the package data
	if (initDirectory()) {
		preserveNodes = true;
	}

    // get free MBD-Node
    int storageId = 0;
    DirectoryEntry oleDir = null;
    do {
        String storageStr = "MBD"+ HexDump.toHex(++storageId);
        if (!getDirectory().hasEntry(storageStr)) {
            oleDir = getDirectory().createDirectory(storageStr);
            oleDir.setStorageClsid(ClassID.OLE10_PACKAGE);
        }
    } while (oleDir == null);

    // the following data was taken from an example libre office document
    // beside this "\u0001Ole" record there were several other records, e.g. CompObj,
    // OlePresXXX, but it seems, that they aren't neccessary
    byte oleBytes[] = { 1, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
    oleDir.createDocument("\u0001Ole", new ByteArrayInputStream(oleBytes));

    Ole10Native oleNative = new Ole10Native(label, fileName, command, oleData);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    oleNative.writeOut(bos);
    oleDir.createDocument(Ole10Native.OLE10_NATIVE, new ByteArrayInputStream(bos.toByteArray()));

	return storageId;
}
 
Example 2
Source File: OLE2Bleach.java    From DocBleach with MIT License 5 votes vote down vote up
protected void sanitize(BleachSession session, DirectoryEntry rootIn, DirectoryEntry rootOut) {
  LOGGER.debug("Entries before: {}", rootIn.getEntryNames());
  // Save the changes to a new file

  // Returns false if the entry should be removed
  Predicate<Entry> visitor =
      ((Predicate<Entry>) (e -> true))
          .and(new MacroRemover(session))
          .and(new ObjectRemover(session))
          .and(new SummaryInformationSanitiser(session));

  LOGGER.debug("Root ClassID: {}", rootIn.getStorageClsid());
  // https://blogs.msdn.microsoft.com/heaths/2006/02/27/identifying-windows-installer-file-types/
  rootOut.setStorageClsid(rootIn.getStorageClsid());

  rootIn
      .getEntries()
      .forEachRemaining(
          entry -> {
            if (!visitor.test(entry)) {
              return;
            }
            copyNodesRecursively(session, entry, rootOut);
          });

  LOGGER.debug("Entries after: {}", rootOut.getEntryNames());
  // Save the changes to a new file
}