/** * Supply the Sheet we belong to, which might have an assigned SlideShow * Also passes it on to our child RichTextRuns */ public static void supplySheet(List<HSLFTextParagraph> paragraphs, HSLFSheet sheet) { if (paragraphs == null) { return; } for (HSLFTextParagraph p : paragraphs) { p.supplySheet(sheet); } assert(sheet.getSlideShow() != null); }
/** * Find hyperlinks in a text paragraph * * @param paragraphs List of <code>TextParagraph</code> to lookup hyperlinks * @return found hyperlinks */ @SuppressWarnings("resource") protected static List<HSLFHyperlink> find(List<HSLFTextParagraph> paragraphs){ List<HSLFHyperlink> lst = new ArrayList<>(); if (paragraphs == null || paragraphs.isEmpty()) return lst; HSLFTextParagraph firstPara = paragraphs.get(0); HSLFSlideShow ppt = firstPara.getSheet().getSlideShow(); //document-level container which stores info about all links in a presentation ExObjList exobj = ppt.getDocumentRecord().getExObjList(false); if (exobj != null) { Record[] records = firstPara.getRecords(); find(Arrays.asList(records), exobj, lst); } return lst; }
/** * Find hyperlink assigned to the supplied shape * * @param shape <code>Shape</code> to lookup hyperlink in * @return found hyperlink or <code>null</code> */ @SuppressWarnings("resource") protected static HSLFHyperlink find(HSLFShape shape){ HSLFSlideShow ppt = shape.getSheet().getSlideShow(); //document-level container which stores info about all links in a presentation ExObjList exobj = ppt.getDocumentRecord().getExObjList(false); HSLFEscherClientDataRecord cldata = shape.getClientData(false); if (exobj != null && cldata != null) { List<HSLFHyperlink> lst = new ArrayList<>(); find(cldata.getHSLFChildRecords(), exobj, lst); return lst.isEmpty() ? null : lst.get(0); } return null; }
@SuppressWarnings("resource") protected EscherBSERecord getEscherBSERecord(int idx){ HSLFSheet sheet = shape.getSheet(); if(sheet == null) { LOG.log(POILogger.DEBUG, "Fill has not yet been assigned to a sheet"); return null; } HSLFSlideShow ppt = sheet.getSlideShow(); Document doc = ppt.getDocumentRecord(); EscherContainerRecord dggContainer = doc.getPPDrawingGroup().getDggContainer(); EscherContainerRecord bstore = HSLFShape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER); if(bstore == null) { LOG.log(POILogger.DEBUG, "EscherContainerRecord.BSTORE_CONTAINER was not found "); return null; } List<EscherRecord> lst = bstore.getChildRecords(); return (EscherBSERecord)lst.get(idx-1); }
/** * Returns the bullet font */ public String getBulletFont() { TextProp tp = getPropVal(_paragraphStyle, "bullet.font"); boolean hasFont = getFlag(ParagraphFlagsTextProp.BULLET_HARDFONT_IDX); if (tp == null || !hasFont) { return getDefaultFontFamily(); } HSLFFontInfo ppFont = getSheet().getSlideShow().getFont(tp.getValue()); assert(ppFont != null); return ppFont.getTypeface(); }
@SuppressWarnings("resource") protected EscherBSERecord getEscherBSERecord(){ HSLFSlideShow ppt = getSheet().getSlideShow(); Document doc = ppt.getDocumentRecord(); EscherContainerRecord dggContainer = doc.getPPDrawingGroup().getDggContainer(); EscherContainerRecord bstore = HSLFShape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER); if(bstore == null) { LOG.log(POILogger.DEBUG, "EscherContainerRecord.BSTORE_CONTAINER was not found "); return null; } List<EscherRecord> lst = bstore.getChildRecords(); int idx = getPictureIndex(); if (idx == 0){ LOG.log(POILogger.DEBUG, "picture index was not found, returning "); return null; } return (EscherBSERecord)lst.get(idx-1); }
public HeadersFooters(HSLFSheet sheet, short headerFooterType) { _sheet = sheet; @SuppressWarnings("resource") HSLFSlideShow ppt = _sheet.getSlideShow(); Document doc = ppt.getDocumentRecord(); // detect if this ppt was saved in Office2007 String tag = ppt.getSlideMasters().get(0).getProgrammableTag(); _ppt2007 = _ppt2007tag.equals(tag); SheetContainer sc = _sheet.getSheetContainer(); HeadersFootersContainer hdd = (HeadersFootersContainer)sc.findFirstOfType(RecordTypes.HeadersFooters.typeID); // boolean ppt2007 = sc.findFirstOfType(RecordTypes.RoundTripContentMasterId.typeID) != null; if (hdd == null) { for (Record ch : doc.getChildRecords()) { if (ch instanceof HeadersFootersContainer && ((HeadersFootersContainer) ch).getOptions() == headerFooterType) { hdd = (HeadersFootersContainer) ch; break; } } } if (hdd == null) { hdd = new HeadersFootersContainer(headerFooterType); Record lst = doc.findFirstOfType(RecordTypes.List.typeID); doc.addChildAfter(hdd, lst); } _container = hdd; }
/** * Sets the bullet font */ public void setBulletFont(String typeface) { if (typeface == null) { setPropVal(_paragraphStyle, "bullet.font", null); setFlag(ParagraphFlagsTextProp.BULLET_HARDFONT_IDX, false); return; } HSLFFontInfo fi = new HSLFFontInfo(typeface); fi = getSheet().getSlideShow().addFont(fi); setParagraphTextPropVal("bullet.font", fi.getIndex()); setFlag(ParagraphFlagsTextProp.BULLET_HARDFONT_IDX, true); }
/** * Document-level container that specifies information about an ActiveX control * * @return container that specifies information about an ActiveX control */ public ExControl getExControl(){ int idx = getControlIndex(); Document doc = getSheet().getSlideShow().getDocumentRecord(); ExObjList lst = (ExObjList)doc.findFirstOfType(RecordTypes.ExObjList.typeID); if (lst == null) { return null; } for (Record ch : lst.getChildRecords()) { if(ch instanceof ExControl){ ExControl c = (ExControl)ch; if(c.getExOleObjAtom().getObjID() == idx){ return c; } } } return null; }
@SuppressWarnings("resource") @Override public HSLFPictureData getPictureData(){ HSLFSlideShow ppt = getSheet().getSlideShow(); List<HSLFPictureData> pict = ppt.getPictureData(); EscherBSERecord bse = getEscherBSERecord(); if (bse == null){ LOG.log(POILogger.ERROR, "no reference to picture data found "); } else { for (HSLFPictureData pd : pict) { if (pd.getOffset() == bse.getOffset()){ return pd; } } LOG.log(POILogger.ERROR, "no picture found for our BSE offset " + bse.getOffset()); } return null; }
@Override public HSLFFontInfo getFontInfo(final FontGroup fontGroup) { FontGroup fg = safeFontGroup(fontGroup); HSLFSheet sheet = parentParagraph.getSheet(); @SuppressWarnings("resource") HSLFSlideShow slideShow = (sheet == null) ? null : sheet.getSlideShow(); if (sheet == null || slideShow == null) { return (cachedFontInfo != null) ? cachedFontInfo[fg.ordinal()] : null; } String propName; switch (fg) { default: case LATIN: propName = "font.index,ansi.font.index"; break; case COMPLEX_SCRIPT: case EAST_ASIAN: propName = "asian.font.index"; break; case SYMBOL: propName = "symbol.font.index"; break; } TextProp tp = getTextParagraph().getPropVal(characterStyle, propName); return (tp != null) ? slideShow.getFont(tp.getValue()) : null; }
/** * 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; }
HSLFSlideShow slideShow = (sheet == null) ? null : sheet.getSlideShow(); if (sheet == null || slideShow == null) {
/** * <code>PictureData</code> object used in a texture, pattern of picture fill. */ @SuppressWarnings("resource") public HSLFPictureData getPictureData(){ AbstractEscherOptRecord opt = shape.getEscherOptRecord(); EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__PATTERNTEXTURE); if (p == null) { return null; } HSLFSlideShow ppt = shape.getSheet().getSlideShow(); List<HSLFPictureData> pict = ppt.getPictureData(); Document doc = ppt.getDocumentRecord(); EscherContainerRecord dggContainer = doc.getPPDrawingGroup().getDggContainer(); EscherContainerRecord bstore = HSLFShape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER); java.util.List<EscherRecord> lst = bstore.getChildRecords(); int idx = p.getPropertyValue(); if (idx == 0){ LOG.log(POILogger.WARN, "no reference to picture data found "); } else { EscherBSERecord bse = (EscherBSERecord)lst.get(idx - 1); for (HSLFPictureData pd : pict) { if (pd.getOffset() == bse.getOffset()){ return pd; } } } return null; }
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()); } } };
/** * @return UNC or local path to a video file */ @SuppressWarnings("resource") public String getPath(){ ExObjRefAtom oe = getClientDataRecord(RecordTypes.ExObjRefAtom.typeID); int idx = oe.getExObjIdRef(); HSLFSlideShow ppt = getSheet().getSlideShow(); ExObjList lst = (ExObjList)ppt.getDocumentRecord().findFirstOfType(RecordTypes.ExObjList.typeID); if(lst == null) { return null; } Record[] r = lst.getChildRecords(); for (int i = 0; i < r.length; i++) { if(r[i] instanceof ExMCIMovie){ ExMCIMovie mci = (ExMCIMovie)r[i]; ExVideoContainer exVideo = mci.getExVideo(); int objectId = exVideo.getExMediaAtom().getObjectId(); if(objectId == idx){ return exVideo.getPathAtom().getText(); } } } return null; } }
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; }
/** * Creates a new Hyperlink and assign it to a shape * This is only a helper method - use {@link HSLFSimpleShape#createHyperlink()} instead! * * @param shape the shape which receives the hyperlink * @return the new hyperlink * * @see HSLFSimpleShape#createHyperlink() */ /* package */ static HSLFHyperlink createHyperlink(HSLFSimpleShape shape) { // TODO: check if a hyperlink already exists ExHyperlink exHyper = new ExHyperlink(); int linkId = shape.getSheet().getSlideShow().addToObjListAtom(exHyper); ExHyperlinkAtom obj = exHyper.getExHyperlinkAtom(); obj.setNumber(linkId); InteractiveInfo info = new InteractiveInfo(); info.getInteractiveInfoAtom().setHyperlinkID(linkId); HSLFEscherClientDataRecord cldata = shape.getClientData(true); cldata.addChild(info); HSLFHyperlink hyper = new HSLFHyperlink(exHyper, info); hyper.linkToNextSlide(); shape.setHyperlink(hyper); return hyper; }
int linkId = run.getTextParagraph().getSheet().getSlideShow().addToObjListAtom(exHyper); ExHyperlinkAtom obj = exHyper.getExHyperlinkAtom(); obj.setNumber(linkId);