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); } } } } }
@Override public OutputStream updateObjectData(final Application application, final ObjectMetaData metaData) throws IOException { final ObjectMetaData md = (application != null) ? application.getMetaData() : metaData; if (md == null || md.getClassID() == null) { throw new IllegalArgumentException("either application and/or metaData needs to be set."); } final XSLFSheet sheet = getSheet(); final RelationPart rp; if (_oleObject.isSetId()) { // object data was already set rp = sheet.getRelationPartById(_oleObject.getId()); } else { // object data needs to be initialized try { final XSLFRelation descriptor = XSLFRelation.OLE_OBJECT; final OPCPackage pack = sheet.getPackagePart().getPackage(); int nextIdx = pack.getUnusedPartIndex(descriptor.getDefaultFileName()); rp = sheet.createRelationship(descriptor, XSLFFactory.getInstance(), nextIdx, false); _oleObject.setId(rp.getRelationship().getId()); } catch (InvalidFormatException e) { throw new IOException("Unable to add new ole embedding", e); } // setting spid only works with a vml drawing object // oleObj.setSpid("_x0000_s"+(1025+objectIdx)); } _oleObject.setProgId(md.getProgId()); _oleObject.setName(md.getObjectName()); return new XSLFObjectOutputStream(rp.getDocumentPart().getPackagePart(),md); }
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()); } } };
try (final POIFSFileSystem poifs = new POIFSFileSystem(is)) { String[] names = { (app == null) ? null : app.getMetaData().getOleEntry(),
try (final POIFSFileSystem poifs = new POIFSFileSystem(is)) { String[] names = { (app == null) ? null : app.getMetaData().getOleEntry(),
@Override public OutputStream updateObjectData(final Application application, final ObjectMetaData metaData) throws IOException { final ObjectMetaData md = (application != null) ? application.getMetaData() : metaData; if (md == null || md.getClassID() == null) { throw new IllegalArgumentException("either application and/or metaData needs to be set."); } final XSLFSheet sheet = getSheet(); final RelationPart rp; if (_oleObject.isSetId()) { // object data was already set rp = sheet.getRelationPartById(_oleObject.getId()); } else { // object data needs to be initialized try { final XSLFRelation descriptor = XSLFRelation.OLE_OBJECT; final OPCPackage pack = sheet.getPackagePart().getPackage(); int nextIdx = pack.getUnusedPartIndex(descriptor.getDefaultFileName()); rp = sheet.createRelationship(descriptor, XSLFFactory.getInstance(), nextIdx, false); _oleObject.setId(rp.getRelationship().getId()); } catch (InvalidFormatException e) { throw new IOException("Unable to add new ole embedding", e); } // setting spid only works with a vml drawing object // oleObj.setSpid("_x0000_s"+(1025+objectIdx)); } _oleObject.setProgId(md.getProgId()); _oleObject.setName(md.getObjectName()); return new XSLFObjectOutputStream(rp.getDocumentPart().getPackagePart(),md); }
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); } } } } }