/** * Adds an OLE package manager object with the given POIFS to the sheet * * @param poiData an POIFS containing the embedded document, to be added * @param label the label of the payload * @param fileName the original filename * @param command the command to open the payload * @return the index of the added ole object * @throws IOException if the object can't be embedded */ public int addOlePackage(POIFSFileSystem poiData, String label, String fileName, String command) throws IOException { DirectoryNode root = poiData.getRoot(); Map<String,ClassID> olemap = getOleMap(); for (Map.Entry<String,ClassID> entry : olemap.entrySet()) { if (root.hasEntry(entry.getKey())) { root.setStorageClsid(entry.getValue()); break; } } ByteArrayOutputStream bos = new ByteArrayOutputStream(); poiData.writeFilesystem(bos); return addOlePackage(bos.toByteArray(), label, fileName, command); }
fs.getRoot().setStorageClsid(getDirectory().getStorageClsid());
@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; }
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); } } } }
public void close() throws IOException { objectPart.clear(); try (final OutputStream os = objectPart.getOutputStream()) { final ByteArrayInputStream bis = new ByteArrayInputStream(this.buf, 0, size()); final FileMagic fm = FileMagic.valueOf(this.buf); if (fm == FileMagic.OLE2) { try (final POIFSFileSystem poifs = new POIFSFileSystem(bis)) { poifs.getRoot().setStorageClsid(metaData.getClassID()); poifs.writeFilesystem(os); } } else if (metaData.getOleEntry() == null) { // OLE Name hasn't been specified, pass the input through os.write(this.buf, 0, size()); } else { try (final POIFSFileSystem poifs = new POIFSFileSystem()) { final ClassID clsId = metaData.getClassID(); if (clsId != null) { poifs.getRoot().setStorageClsid(clsId); } poifs.createDocument(bis, metaData.getOleEntry()); Ole10Native.createOleMarkerEntry(poifs); poifs.writeFilesystem(os); } } } } }
/** * Adds an OLE package manager object with the given POIFS to the sheet * * @param poiData an POIFS containing the embedded document, to be added * @param label the label of the payload * @param fileName the original filename * @param command the command to open the payload * @return the index of the added ole object * @throws IOException if the object can't be embedded */ public int addOlePackage(POIFSFileSystem poiData, String label, String fileName, String command) throws IOException { DirectoryNode root = poiData.getRoot(); Map<String,ClassID> olemap = getOleMap(); for (Map.Entry<String,ClassID> entry : olemap.entrySet()) { if (root.hasEntry(entry.getKey())) { root.setStorageClsid(entry.getValue()); break; } } ByteArrayOutputStream bos = new ByteArrayOutputStream(); poiData.writeFilesystem(bos); return addOlePackage(bos.toByteArray(), label, fileName, command); }
fs.getRoot().setStorageClsid(getDirectory().getStorageClsid());
fs.getRoot().setStorageClsid(this.directory.getStorageClsid());
fs.getRoot().setStorageClsid(this.directory.getStorageClsid());
@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; }
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); } } } }
public void close() throws IOException { objectPart.clear(); try (final OutputStream os = objectPart.getOutputStream()) { final ByteArrayInputStream bis = new ByteArrayInputStream(this.buf, 0, size()); final FileMagic fm = FileMagic.valueOf(this.buf); if (fm == FileMagic.OLE2) { try (final POIFSFileSystem poifs = new POIFSFileSystem(bis)) { poifs.getRoot().setStorageClsid(metaData.getClassID()); poifs.writeFilesystem(os); } } else if (metaData.getOleEntry() == null) { // OLE Name hasn't been specified, pass the input through os.write(this.buf, 0, size()); } else { try (final POIFSFileSystem poifs = new POIFSFileSystem()) { final ClassID clsId = metaData.getClassID(); if (clsId != null) { poifs.getRoot().setStorageClsid(clsId); } poifs.createDocument(bis, metaData.getOleEntry()); Ole10Native.createOleMarkerEntry(poifs); poifs.writeFilesystem(os); } } } } }
root.setStorageClsid(oleType.getClassID());
public void close() throws IOException { final FileMagic fm = FileMagic.valueOf(this.buf); final ByteArrayInputStream bis = new ByteArrayInputStream(this.buf, 0, this.count); final HSLFSlideShow ppt = getSheet().getSlideShow(); try (POIFSFileSystem poifs = (fm == FileMagic.OLE2) ? new POIFSFileSystem(bis) : new POIFSFileSystem()) { if (fm != FileMagic.OLE2) { poifs.createDocument(bis, md.getOleEntry()); } Ole10Native.createOleMarkerEntry(poifs); poifs.getRoot().setStorageClsid(md.getClassID()); int oid = getObjectID(); if (oid == 0) { // assign new embedding oid = ppt.addEmbed(poifs); setObjectID(oid); } else { final HSLFObjectData od = getObjectData(); if (od != null) { ByteArrayOutputStream bos = new ByteArrayOutputStream(this.size()+1000); poifs.writeFilesystem(bos); od.setData(bos.toByteArray()); } } setProgId(md.getProgId()); setFullName(md.getObjectName()); } } };
root.setStorageClsid(classID);
( DirectoryNode ) parent.createDirectory(name); new_dir.setStorageClsid( property.getStorageClsid() );
( DirectoryNode ) parent.createDirectory(name); new_dir.setStorageClsid( property.getStorageClsid() );
getRoot().setStorageClsid(properties.getRoot().getStorageClsid());
getRoot().setStorageClsid(properties.getRoot().getStorageClsid());