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; }
/** * Returns the ExObjList, which holds the references to * external objects used in the slides. This may be null, if * there are no external references. * * @param create if true, create an ExObjList if it doesn't exist */ public ExObjList getExObjList(boolean create) { if (exObjList == null && create) { exObjList = new ExObjList(); addChildAfter(exObjList, getDocumentAtom()); } return exObjList; }
/** * Find hyperlinks in a text run * * @param run <code>TextRun</code> to lookup hyperlinks in * @return found hyperlinks or <code>null</code> if not found */ protected static Hyperlink[] find(TextRun run){ ArrayList lst = new ArrayList(); SlideShow ppt = run.getSheet().getSlideShow(); //document-level container which stores info about all links in a presentation ExObjList exobj = ppt.getDocumentRecord().getExObjList(); if (exobj == null) { return null; } Record[] records = run._records; if(records != null) find(records, exobj, lst); Hyperlink[] links = null; if (lst.size() > 0){ links = new Hyperlink[lst.size()]; lst.toArray(links); } return links; }
/** * Attach this HeadersFootersContainer to the parent Document record */ private void attach(){ Document doc = _ppt.getDocumentRecord(); Record[] ch = doc.getChildRecords(); Record lst = null; for (int i=0; i < ch.length; i++){ if(ch[i].getRecordType() == RecordTypes.List.typeID){ lst = ch[i]; break; } } doc.addChildAfter(_container, lst); _newRecord = false; }
/** * Add a hyperlink to this presentation * * @return 0-based index of the hyperlink */ public int addHyperlink(Hyperlink link) { ExObjList lst = (ExObjList) _documentRecord.findFirstOfType(RecordTypes.ExObjList.typeID); if (lst == null) { lst = new ExObjList(); _documentRecord.addChildAfter(lst, _documentRecord.getDocumentAtom()); } ExObjListAtom objAtom = lst.getExObjListAtom(); // increment the object ID seed int objectId = (int) objAtom.getObjectIDSeed() + 1; objAtom.setObjectIDSeed(objectId); ExHyperlink ctrl = new ExHyperlink(); ExHyperlinkAtom obj = ctrl.getExHyperlinkAtom(); obj.setNumber(objectId); ctrl.setLinkURL(link.getAddress()); ctrl.setLinkTitle(link.getTitle()); lst.addChildAfter(ctrl, objAtom); link.setId(objectId); return objectId; } }
ExObjList lst = _documentRecord.getExObjList(); if (lst == null) { lst = new ExObjList(); _documentRecord.addChildAfter(lst, _documentRecord.getDocumentAtom()); try { Field f = Document.class.getDeclaredField("exObjList");
SlideListWithText slwt = _documentRecord.getSlideSlideListWithText(); if (slwt == null) { throw new IllegalStateException("Slide record not defined."); _documentRecord.removeSlideListWithText(slwt); } else { slwt.setSlideAtomsSets(sa.toArray(new SlideAtomsSet[0])); SlideListWithText nslwt = _documentRecord.getNotesSlideListWithText(); records = new ArrayList<>(); ArrayList<SlideAtomsSet> na = new ArrayList<>(); _documentRecord.removeSlideListWithText(nslwt);
private void extractMacros(HSLFSlideShow ppt, XHTMLContentHandler xhtml) { //get macro persist id DocInfoListContainer list = (DocInfoListContainer)ppt.getDocumentRecord().findFirstOfType(RecordTypes.List.typeID); if (list == null) { return; } VBAInfoContainer vbaInfo = (VBAInfoContainer)list.findFirstOfType(RecordTypes.VBAInfo.typeID); if (vbaInfo == null) { return; } VBAInfoAtom vbaAtom = (VBAInfoAtom)vbaInfo.findFirstOfType(RecordTypes.VBAInfoAtom.typeID); if (vbaAtom == null) { return; } long persistId = vbaAtom.getPersistIdRef(); for (HSLFObjectData objData : ppt.getEmbeddedObjects()) { if (objData.getExOleObjStg().getPersistId() == persistId) { try (POIFSFileSystem poifsFileSystem = new POIFSFileSystem(objData.getInputStream())) { try { OfficeParser.extractMacros(poifsFileSystem, xhtml, EmbeddedDocumentUtil.getEmbeddedDocumentExtractor(context)); } catch (IOException|SAXException inner) { EmbeddedDocumentUtil.recordException(inner, parentMetadata); } } catch (IOException e) { EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata);//swallow } } } }
SlideListWithText masterSLWT = _documentRecord.getMasterSlideListWithText(); SlideListWithText slidesSLWT = _documentRecord.getSlideSlideListWithText(); SlideListWithText notesSLWT = _documentRecord.getNotesSlideListWithText();
/** * Add a font in this presentation * * @param fontInfo the font to add * @return the registered HSLFFontInfo - the font info object is unique based on the typeface */ public HSLFFontInfo addFont(FontInfo fontInfo) { return getDocumentRecord().getEnvironment().getFontCollection().addFont(fontInfo); }
/** * Return the current page size */ public Dimension getPageSize() { DocumentAtom docatom = _documentRecord.getDocumentAtom(); int pgx = (int) docatom.getSlideSizeX() * Shape.POINT_DPI / Shape.MASTER_DPI; int pgy = (int) docatom.getSlideSizeY() * Shape.POINT_DPI / Shape.MASTER_DPI; return new Dimension(pgx, pgy); }
SlideListWithText slist = _documentRecord.getSlideSlideListWithText(); if (slist == null) { _documentRecord.addSlideListWithText(slist);
/** * Find all sound records in the supplied Document records * * @param document the document to find in * @return the array with the sound data */ public static HSLFSoundData[] find(Document document){ ArrayList<HSLFSoundData> lst = new ArrayList<>(); Record[] ch = document.getChildRecords(); for (int i = 0; i < ch.length; i++) { if(ch[i].getRecordType() == RecordTypes.SoundCollection.typeID){ RecordContainer col = (RecordContainer)ch[i]; Record[] sr = col.getChildRecords(); for (int j = 0; j < sr.length; j++) { if(sr[j] instanceof Sound){ lst.add(new HSLFSoundData((Sound)sr[j])); } } } } return lst.toArray(new HSLFSoundData[lst.size()]); } }
/** * Adds a new SlideListWithText record, at the appropriate * point in the child records. */ public void addSlideListWithText(SlideListWithText slwt) { // The new SlideListWithText should go in // just before the EndDocumentRecord Record endDoc = _children[_children.length - 1]; if(endDoc.getRecordType() != RecordTypes.EndDocument.typeID) { throw new IllegalStateException("The last child record of a Document should be EndDocument, but it was " + endDoc); } // Add in the record addChildBefore(slwt, endDoc); // Updated our cached list of SlideListWithText records int newSize = slwts.length + 1; SlideListWithText[] nl = new SlideListWithText[newSize]; System.arraycopy(slwts, 0, nl, 0, slwts.length); nl[nl.length-1] = slwt; slwts = nl; }
/** * Find master slides * These can be MainMaster records, but oddly they can also be * Slides or Notes, and possibly even other odd stuff.... * About the only thing you can say is that the master details are in the first SLWT. */ private void findMasterSlides() { SlideListWithText masterSLWT = _documentRecord.getMasterSlideListWithText(); if (masterSLWT == null) { return; } for (SlideAtomsSet sas : masterSLWT.getSlideAtomsSets()) { Record r = getCoreRecordForSAS(sas); int sheetNo = sas.getSlidePersistAtom().getSlideIdentifier(); if (r instanceof Slide) { HSLFTitleMaster master = new HSLFTitleMaster((Slide)r, sheetNo); master.setSlideShow(this); _titleMasters.add(master); } else if (r instanceof MainMaster) { HSLFSlideMaster master = new HSLFSlideMaster((MainMaster)r, sheetNo); master.setSlideShow(this); _masters.add(master); } } }
private void findNotesSlides(Map<Integer,Integer> slideIdToNotes) { SlideListWithText notesSLWT = _documentRecord.getNotesSlideListWithText();
ExObjList lst = (ExObjList) _documentRecord.findFirstOfType(RecordTypes.ExObjList.typeID); if (lst == null) { lst = new ExObjList(); _documentRecord.addChildAfter(lst, _documentRecord.getDocumentAtom());
SlideListWithText slwt = _documentRecord.getSlideSlideListWithText(); SlideAtomsSet[] sas = slwt.getSlideAtomsSets(); _documentRecord.removeSlideListWithText(slwt); } else { slwt.setSlideAtomsSets(sa.toArray(new SlideAtomsSet[sa.size()])); int notesId = removedSlide.getSlideRecord().getSlideAtom().getNotesID(); if (notesId != 0) { SlideListWithText nslwt = _documentRecord.getNotesSlideListWithText(); records = new ArrayList<Record>(); ArrayList<SlideAtomsSet> na = new ArrayList<SlideAtomsSet>(); _documentRecord.removeSlideListWithText(nslwt); } else { nslwt.setSlideAtomsSets(na.toArray(new SlideAtomsSet[na.size()]));
/** * 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; }
/** * Get a font by index * * @param idx * 0-based index of the font * @return of an instance of <code>PPFont</code> or <code>null</code> if not * found */ public HSLFFontInfo getFont(int idx) { return getDocumentRecord().getEnvironment().getFontCollection().getFontInfo(idx); }