Search in sources :

Example 1 with PresentationDocument

use of org.openxmlformats.schemas.presentationml.x2006.main.PresentationDocument 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)

Aggregations

HashMap (java.util.HashMap)1 POIXMLDocumentPart (org.apache.poi.POIXMLDocumentPart)1 POIXMLException (org.apache.poi.POIXMLException)1 XmlException (org.apache.xmlbeans.XmlException)1 CTSlideIdListEntry (org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry)1 CTSlideMasterIdListEntry (org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry)1 PresentationDocument (org.openxmlformats.schemas.presentationml.x2006.main.PresentationDocument)1