HSLFObjectData data = null; try { data = oleShape.getObjectData(); } catch (NullPointerException e) { String objID = Integer.toString(oleShape.getObjectID()); if ("Excel.Chart.8".equals(oleShape.getProgId())) { mediaType = "application/vnd.ms-excel"; } else {
@Override public HSLFObjectShape createOleShape(PictureData pictureData) { if (!(pictureData instanceof HSLFPictureData)) { throw new IllegalArgumentException("pictureData needs to be of type HSLFPictureData"); } HSLFObjectShape s = new HSLFObjectShape((HSLFPictureData)pictureData, this); s.setAnchor(new Rectangle2D.Double(0, 0, 100, 100)); addShape(s); return s; } }
/** * Returns unique identifier for the OLE object. * * @return the unique identifier for the OLE object */ public int getObjectID(){ return getEscherProperty(EscherProperties.BLIP__PICTUREID); }
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()); } } };
oleIdx++; HSLFObjectShape ole = (HSLFObjectShape) shape; HSLFObjectData data = ole.getObjectData(); String name = ole.getInstanceName(); if ("Worksheet".equals(name)) { doc.close(); } else { FileOutputStream out = new FileOutputStream(ole.getProgId() + "-"+(oleIdx+1)+".dat"); InputStream dis = data.getInputStream(); byte[] chunk = new byte[2048];
/** * Set the unique identifier for the OLE object and * register it in the necessary structures * * @param objectId the unique identifier for the OLE object */ public void setObjectID(int objectId){ setEscherProperty(EscherProperties.BLIP__PICTUREID, objectId); EscherContainerRecord ecr = getSpContainer(); EscherSpRecord spRecord = ecr.getChildById(EscherSpRecord.RECORD_ID); spRecord.setFlags(spRecord.getFlags()|EscherSpRecord.FLAG_OLESHAPE); HSLFEscherClientDataRecord cldata = getClientData(true); ExObjRefAtom uer = null; for (Record r : cldata.getHSLFChildRecords()) { if (r.getRecordType() == RecordTypes.ExObjRefAtom.typeID) { uer = (ExObjRefAtom)r; break; } } if (uer == null) { uer = new ExObjRefAtom(); cldata.addChild(uer); } uer.setExObjIdRef(objectId); }
private ExEmbed getExEmbed(boolean create) { if (_exEmbed == null) { HSLFSlideShow ppt = getSheet().getSlideShow(); ExObjList lst = ppt.getDocumentRecord().getExObjList(create); if(lst == null){ LOG.log(POILogger.WARN, "ExObjList not found"); return null; } int id = getObjectID(); for (Record ch : lst.getChildRecords()) { if(ch instanceof ExEmbed){ ExEmbed embd = (ExEmbed)ch; if( embd.getExOleObjAtom().getObjID() == id) { _exEmbed = embd; } } } if (_exEmbed == null && create) { _exEmbed = new ExEmbed(); _exEmbed.getExOleObjAtom().setObjID(id); lst.appendChildRecord(_exEmbed); } } return _exEmbed; }
/** * Return the record container for this embedded object. * * <p> * It contains: * 1. ExEmbedAtom.(4045) * 2. ExOleObjAtom (4035) * 3. CString (4026), Instance MenuName (1) used for menus and the Links dialog box. * 4. CString (4026), Instance ProgID (2) that stores the OLE Programmatic Identifier. * A ProgID is a string that uniquely identifies a given object. * 5. CString (4026), Instance ClipboardName (3) that appears in the paste special dialog. * 6. MetaFile( 4033), optional * </p> */ public ExEmbed getExEmbed(){ return getExEmbed(false); }
/** * Returns unique identifier for the OLE object. * * @return the unique identifier for the OLE object */ public HSLFObjectData getObjectData(){ HSLFSlideShow ppt = getSheet().getSlideShow(); HSLFObjectData[] ole = ppt.getEmbeddedObjects(); //persist reference ExEmbed exEmbed = getExEmbed(); HSLFObjectData data = null; if(exEmbed != null) { int ref = exEmbed.getExOleObjAtom().getObjStgDataRef(); for (HSLFObjectData hod : ole) { if(hod.getExOleObjStg().getPersistId() == ref) { data=hod; // keep searching to return the last persistent object with that refId } } } if (data==null) { LOG.log(POILogger.WARN, "OLE data not found"); } return data; }
private static HSLFShape createFrame(EscherContainerRecord spContainer, ShapeContainer<HSLFShape,HSLFTextParagraph> parent) { InteractiveInfo info = getClientDataRecord(spContainer, RecordTypes.InteractiveInfo.typeID); if(info != null && info.getInteractiveInfoAtom() != null){ switch(info.getInteractiveInfoAtom().getAction()){ case InteractiveInfoAtom.ACTION_OLE: return new HSLFObjectShape(spContainer, parent); case InteractiveInfoAtom.ACTION_MEDIA: return new MovieShape(spContainer, parent); default: break; } } ExObjRefAtom oes = getClientDataRecord(spContainer, RecordTypes.ExObjRefAtom.typeID); return (oes != null) ? new HSLFObjectShape(spContainer, parent) : new HSLFPictureShape(spContainer, parent); }
public void setProgId(final String progId) { final ExEmbed ex = getExEmbed(true); if (ex != null) { ex.setProgId(progId); } }
HSLFObjectData data = null; try { data = oleShape.getObjectData(); } catch (NullPointerException e) { String objID = Integer.toString(oleShape.getObjectID()); if ("Excel.Chart.8".equals(oleShape.getProgId())) { mediaType = "application/vnd.ms-excel"; } else {
@Override public HSLFObjectShape createOleShape(PictureData pictureData) { if (!(pictureData instanceof HSLFPictureData)) { throw new IllegalArgumentException("pictureData needs to be of type HSLFPictureData"); } HSLFObjectShape s = new HSLFObjectShape((HSLFPictureData)pictureData); s.setAnchor(new Rectangle2D.Double(0, 0, 100, 100)); addShape(s); return s; }
public void setFullName(final String fullName) { final ExEmbed ex = getExEmbed(true); if (ex != null) { ex.setClipboardName(fullName); } }
@Override public String getFullName(){ ExEmbed ee = getExEmbed(); return (ee == null) ? null : ee.getClipboardName(); }
/** * Returns the instance name of the embedded object, e.g. "Document" or "Workbook". * * @return the instance name of the embedded object */ public String getInstanceName(){ ExEmbed ee = getExEmbed(); return (ee == null) ? null : ee.getMenuName(); }
@Override public String getProgId(){ ExEmbed ee = getExEmbed(); return (ee == null) ? null : ee.getProgId(); }