Search in sources :

Example 1 with CTSlideIdListEntry

use of org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry in project poi by apache.

the class XMLSlideShow method onDocumentRead.

@Override
protected void onDocumentRead() throws IOException {
    try {
        PresentationDocument doc = PresentationDocument.Factory.parse(getCorePart().getInputStream(), DEFAULT_XML_OPTIONS);
        _presentation = doc.getPresentation();
        Map<String, XSLFSlideMaster> masterMap = new HashMap<String, XSLFSlideMaster>();
        Map<String, XSLFSlide> shIdMap = new HashMap<String, XSLFSlide>();
        for (RelationPart rp : getRelationParts()) {
            POIXMLDocumentPart p = rp.getDocumentPart();
            if (p instanceof XSLFSlide) {
                shIdMap.put(rp.getRelationship().getId(), (XSLFSlide) p);
            } else if (p instanceof XSLFSlideMaster) {
                masterMap.put(getRelationId(p), (XSLFSlideMaster) p);
            } else if (p instanceof XSLFTableStyles) {
                _tableStyles = (XSLFTableStyles) p;
            } else if (p instanceof XSLFNotesMaster) {
                _notesMaster = (XSLFNotesMaster) p;
            } else if (p instanceof XSLFCommentAuthors) {
                _commentAuthors = (XSLFCommentAuthors) p;
            }
        }
        _masters = new ArrayList<XSLFSlideMaster>(masterMap.size());
        for (CTSlideMasterIdListEntry masterId : _presentation.getSldMasterIdLst().getSldMasterIdList()) {
            XSLFSlideMaster master = masterMap.get(masterId.getId2());
            _masters.add(master);
        }
        _slides = new ArrayList<XSLFSlide>(shIdMap.size());
        if (_presentation.isSetSldIdLst()) {
            for (CTSlideIdListEntry slId : _presentation.getSldIdLst().getSldIdList()) {
                XSLFSlide sh = shIdMap.get(slId.getId2());
                if (sh == null) {
                    LOG.log(POILogger.WARN, "Slide with r:id " + slId.getId() + " was defined, but didn't exist in package, skipping");
                    continue;
                }
                _slides.add(sh);
            }
        }
    } catch (XmlException e) {
        throw new POIXMLException(e);
    }
}
Also used : HashMap(java.util.HashMap) POIXMLDocumentPart(org.apache.poi.POIXMLDocumentPart) POIXMLException(org.apache.poi.POIXMLException) CTSlideMasterIdListEntry(org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry) CTSlideIdListEntry(org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry) XmlException(org.apache.xmlbeans.XmlException) PresentationDocument(org.openxmlformats.schemas.presentationml.x2006.main.PresentationDocument)

Example 2 with CTSlideIdListEntry

use of org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry in project poi by apache.

the class XMLSlideShow method setSlideOrder.

/**
     *
     * @param newIndex 0-based index of the slide
     */
public void setSlideOrder(XSLFSlide slide, int newIndex) {
    int oldIndex = _slides.indexOf(slide);
    if (oldIndex == -1) {
        throw new IllegalArgumentException("Slide not found");
    }
    if (oldIndex == newIndex) {
        return;
    }
    // fix the usermodel container
    _slides.add(newIndex, _slides.remove(oldIndex));
    // fix ordering in the low-level xml
    CTSlideIdList sldIdLst = _presentation.getSldIdLst();
    CTSlideIdListEntry[] entries = sldIdLst.getSldIdArray();
    CTSlideIdListEntry oldEntry = entries[oldIndex];
    if (oldIndex < newIndex) {
        System.arraycopy(entries, oldIndex + 1, entries, oldIndex, newIndex - oldIndex);
    } else {
        System.arraycopy(entries, newIndex, entries, newIndex + 1, oldIndex - newIndex);
    }
    entries[newIndex] = oldEntry;
    sldIdLst.setSldIdArray(entries);
}
Also used : CTSlideIdList(org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdList) CTSlideIdListEntry(org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry)

Example 3 with CTSlideIdListEntry

use of org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry in project poi by apache.

the class XMLSlideShow method createSlide.

/**
     * Create a slide and initialize it from the specified layout.
     *
     * @param layout The layout to use for the new slide.
     * @return created slide
     */
public XSLFSlide createSlide(XSLFSlideLayout layout) {
    int slideNumber = 256, cnt = 1;
    CTSlideIdList slideList;
    if (!_presentation.isSetSldIdLst()) {
        slideList = _presentation.addNewSldIdLst();
    } else {
        slideList = _presentation.getSldIdLst();
        for (CTSlideIdListEntry slideId : slideList.getSldIdArray()) {
            slideNumber = (int) Math.max(slideId.getId() + 1, slideNumber);
            cnt++;
        }
        // this can happen when removing/adding slides
        while (true) {
            String slideName = XSLFRelation.SLIDE.getFileName(cnt);
            boolean found = false;
            for (POIXMLDocumentPart relation : getRelations()) {
                if (relation.getPackagePart() != null && slideName.equals(relation.getPackagePart().getPartName().getName())) {
                    // name is taken => try next one
                    found = true;
                    break;
                }
            }
            if (!found && getPackage().getPartsByName(Pattern.compile(Pattern.quote(slideName))).size() > 0) {
                // name is taken => try next one
                found = true;
            }
            if (!found) {
                break;
            }
            cnt++;
        }
    }
    RelationPart rp = createRelationship(XSLFRelation.SLIDE, XSLFFactory.getInstance(), cnt, false);
    XSLFSlide slide = rp.getDocumentPart();
    CTSlideIdListEntry slideId = slideList.addNewSldId();
    slideId.setId(slideNumber);
    slideId.setId2(rp.getRelationship().getId());
    layout.copyLayout(slide);
    slide.addRelation(null, XSLFRelation.SLIDE_LAYOUT, layout);
    _slides.add(slide);
    return slide;
}
Also used : CTSlideIdList(org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdList) POIXMLDocumentPart(org.apache.poi.POIXMLDocumentPart) CTSlideIdListEntry(org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry)

Example 4 with CTSlideIdListEntry

use of org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry in project poi by apache.

the class XSLFSlideShow method getSlide.

/**
	 * Returns the low level slide object from
	 *  the supplied slide reference
	 */
@Internal
public CTSlide getSlide(CTSlideIdListEntry slide) throws IOException, XmlException {
    PackagePart slidePart = getSlidePart(slide);
    SldDocument slideDoc = SldDocument.Factory.parse(slidePart.getInputStream(), DEFAULT_XML_OPTIONS);
    return slideDoc.getSld();
}
Also used : SldDocument(org.openxmlformats.schemas.presentationml.x2006.main.SldDocument) PackagePart(org.apache.poi.openxml4j.opc.PackagePart) Internal(org.apache.poi.util.Internal)

Example 5 with CTSlideIdListEntry

use of org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry in project poi by apache.

the class XSLFSlideShow method getNotes.

/**
	 * Returns the low level notes object for the given
	 *  slide, as found from the supplied slide reference
	 */
@Internal
public CTNotesSlide getNotes(CTSlideIdListEntry slide) throws IOException, XmlException {
    PackagePart notesPart = getNodesPart(slide);
    if (notesPart == null)
        return null;
    NotesDocument notesDoc = NotesDocument.Factory.parse(notesPart.getInputStream(), DEFAULT_XML_OPTIONS);
    return notesDoc.getNotes();
}
Also used : PackagePart(org.apache.poi.openxml4j.opc.PackagePart) NotesDocument(org.openxmlformats.schemas.presentationml.x2006.main.NotesDocument) Internal(org.apache.poi.util.Internal)

Aggregations

CTSlideIdListEntry (org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry)6 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)4 Internal (org.apache.poi.util.Internal)3 CTSlideIdList (org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdList)3 CTSlideMasterIdListEntry (org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry)3 POIXMLDocumentPart (org.apache.poi.POIXMLDocumentPart)2 InvalidFormatException (org.apache.poi.openxml4j.exceptions.InvalidFormatException)2 PackageRelationshipCollection (org.apache.poi.openxml4j.opc.PackageRelationshipCollection)2 XmlException (org.apache.xmlbeans.XmlException)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 POIXMLException (org.apache.poi.POIXMLException)1 XSLFSlideShow (org.apache.poi.xslf.usermodel.XSLFSlideShow)1 TikaException (org.apache.tika.exception.TikaException)1 CTNotesMasterIdListEntry (org.openxmlformats.schemas.presentationml.x2006.main.CTNotesMasterIdListEntry)1 CmLstDocument (org.openxmlformats.schemas.presentationml.x2006.main.CmLstDocument)1 NotesDocument (org.openxmlformats.schemas.presentationml.x2006.main.NotesDocument)1 PresentationDocument (org.openxmlformats.schemas.presentationml.x2006.main.PresentationDocument)1