/** * Creates an instance of this class from an embedded OLE Object. The OLE Object is expected * to include a stream "{01}Ole10Native" which contains the actual * data relevant for this class. * * @param directory POI Filesystem object * @return Returns an instance of this class * @throws IOException on IO error * @throws Ole10NativeException on invalid or unexcepted data format */ public static Ole10Native createFromEmbeddedOleObject(DirectoryNode directory) throws IOException, Ole10NativeException { DocumentEntry nativeEntry = (DocumentEntry)directory.getEntry(OLE10_NATIVE); byte[] data = IOUtils.safelyAllocate(nativeEntry.getSize(), MAX_RECORD_LENGTH); int readBytes = directory.createDocumentInputStream(nativeEntry).read(data); assert(readBytes == data.length); return new Ole10Native(data, 0); }
@Override public int addOlePackage(byte[] oleData, String label, String fileName, String command) throws IOException { // find an unused part name OPCPackage opc = getPackage(); PackagePartName pnOLE; int oleId=0; do { try { pnOLE = PackagingURIHelper.createPartName( "/xl/embeddings/oleObject"+(++oleId)+".bin" ); } catch (InvalidFormatException e) { throw new IOException("ole object name not recognized", e); } } while (opc.containPart(pnOLE)); PackagePart pp = opc.createPart( pnOLE, "application/vnd.openxmlformats-officedocument.oleObject" ); Ole10Native ole10 = new Ole10Native(label, fileName, command, oleData); try (ByteArrayOutputStream bos = new ByteArrayOutputStream(oleData.length+500)) { ole10.writeOut(bos); try (POIFSFileSystem poifs = new POIFSFileSystem()) { DirectoryNode root = poifs.getRoot(); root.createDocument(Ole10Native.OLE10_NATIVE, new ByteArrayInputStream(bos.toByteArray())); root.setStorageClsid(ClassIDPredefined.OLE_V1_PACKAGE.getClassID()); // TODO: generate CombObj stream try (OutputStream os = pp.getOutputStream()) { poifs.writeFilesystem(os); } } } return oleId; }
@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(ClassIDPredefined.OLE_V1_PACKAGE.getClassID()); } } while (oleDir == null); Ole10Native.createOleMarkerEntry(oleDir); 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; }
/** * Creates an instance of this class from an embedded OLE Object. The OLE Object is expected * to include a stream "{01}Ole10Native" which contains the actual * data relevant for this class. * * @param directory POI Filesystem object * @return Returns an instance of this class * @throws IOException on IO error * @throws Ole10NativeException on invalid or unexcepted data format */ public static Ole10Native createFromEmbeddedOleObject(DirectoryNode directory) throws IOException, Ole10NativeException { DocumentEntry nativeEntry = (DocumentEntry)directory.getEntry(OLE10_NATIVE); byte[] data = IOUtils.safelyAllocate(nativeEntry.getSize(), MAX_RECORD_LENGTH); int readBytes = directory.createDocumentInputStream(nativeEntry).read(data); assert(readBytes == data.length); return new Ole10Native(data, 0); }
Ole10Native ole10 = new Ole10Native("html"+oleId+".html", "html"+oleId+".html", "html"+oleId+".html", html10.getBytes("ISO-8859-1"));
@Override public int addOlePackage(byte[] oleData, String label, String fileName, String command) throws IOException { // find an unused part name OPCPackage opc = getPackage(); PackagePartName pnOLE; int oleId=0; do { try { pnOLE = PackagingURIHelper.createPartName( "/xl/embeddings/oleObject"+(++oleId)+".bin" ); } catch (InvalidFormatException e) { throw new IOException("ole object name not recognized", e); } } while (opc.containPart(pnOLE)); PackagePart pp = opc.createPart( pnOLE, "application/vnd.openxmlformats-officedocument.oleObject" ); Ole10Native ole10 = new Ole10Native(label, fileName, command, oleData); try (ByteArrayOutputStream bos = new ByteArrayOutputStream(oleData.length+500)) { ole10.writeOut(bos); try (POIFSFileSystem poifs = new POIFSFileSystem()) { DirectoryNode root = poifs.getRoot(); root.createDocument(Ole10Native.OLE10_NATIVE, new ByteArrayInputStream(bos.toByteArray())); root.setStorageClsid(ClassIDPredefined.OLE_V1_PACKAGE.getClassID()); // TODO: generate CombObj stream try (OutputStream os = pp.getOutputStream()) { poifs.writeFilesystem(os); } } } return oleId; }
@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(ClassIDPredefined.OLE_V1_PACKAGE.getClassID()); } } while (oleDir == null); Ole10Native.createOleMarkerEntry(oleDir); 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; }
/** * Creates an instance of this class from an embedded OLE Object. The OLE Object is expected * to include a stream "{01}Ole10Native" which contains the actual * data relevant for this class. * * @param directory POI Filesystem object * @return Returns an instance of this class * @throws IOException on IO error * @throws Ole10NativeException on invalid or unexcepted data format */ public static Ole10Native createFromEmbeddedOleObject(DirectoryNode directory) throws IOException, Ole10NativeException { boolean plain = false; try { directory.getEntry("\u0001Ole10ItemName"); plain = true; } catch (FileNotFoundException ex) { plain = false; } DocumentEntry nativeEntry = (DocumentEntry)directory.getEntry(OLE10_NATIVE); byte[] data = new byte[nativeEntry.getSize()]; directory.createDocumentInputStream(nativeEntry).read(data); return new Ole10Native(data, 0, plain); }
/** * Creates an instance of this class from an embedded OLE Object. The OLE Object is expected * to include a stream "{01}Ole10Native" which contains the actual * data relevant for this class. * * @param directory POI Filesystem object * @return Returns an instance of this class * @throws IOException on IO error * @throws Ole10NativeException on invalid or unexcepted data format */ public static Ole10Native createFromEmbeddedOleObject(DirectoryNode directory) throws IOException, Ole10NativeException { boolean plain = false; try { directory.getEntry("\u0001Ole10ItemName"); plain = true; } catch (FileNotFoundException ex) { plain = false; } DocumentEntry nativeEntry = (DocumentEntry)directory.getEntry(OLE10_NATIVE); byte[] data = new byte[nativeEntry.getSize()]; directory.createDocumentInputStream(nativeEntry).read(data); return new Ole10Native(data, 0, plain); }