Search in sources :

Example 1 with CTSlideIdList

use of org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdList 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 2 with CTSlideIdList

use of org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdList 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 3 with CTSlideIdList

use of org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdList in project tika by apache.

the class XSLFPowerPointExtractorDecorator method getMainDocumentParts.

/**
     * In PowerPoint files, slides have things embedded in them,
     * and slide drawings which have the images
     */
@Override
protected List<PackagePart> getMainDocumentParts() throws TikaException {
    List<PackagePart> parts = new ArrayList<>();
    XSLFSlideShow document = null;
    try {
        document = new XSLFSlideShow(extractor.getPackage());
    } catch (Exception e) {
        // Shouldn't happen
        throw new TikaException(e.getMessage());
    }
    CTSlideIdList ctSlideIdList = document.getSlideReferences();
    if (ctSlideIdList != null) {
        for (int i = 0; i < ctSlideIdList.sizeOfSldIdArray(); i++) {
            CTSlideIdListEntry ctSlide = ctSlideIdList.getSldIdArray(i);
            // Add the slide
            PackagePart slidePart;
            try {
                slidePart = document.getSlidePart(ctSlide);
            } catch (IOException e) {
                throw new TikaException("Broken OOXML file", e);
            } catch (XmlException xe) {
                throw new TikaException("Broken OOXML file", xe);
            }
            addSlideParts(slidePart, parts);
        }
    }
    //add full document to include macros
    parts.add(document.getPackagePart());
    for (String rel : new String[] { XSLFRelation.SLIDE_MASTER.getRelation(), HANDOUT_MASTER }) {
        try {
            PackageRelationshipCollection prc = document.getPackagePart().getRelationshipsByType(rel);
            for (int i = 0; i < prc.size(); i++) {
                PackagePart pp = document.getPackagePart().getRelatedPart(prc.getRelationship(i));
                if (pp != null) {
                    parts.add(pp);
                }
            }
        } catch (InvalidFormatException e) {
        //log
        }
    }
    return parts;
}
Also used : TikaException(org.apache.tika.exception.TikaException) PackageRelationshipCollection(org.apache.poi.openxml4j.opc.PackageRelationshipCollection) ArrayList(java.util.ArrayList) IOException(java.io.IOException) PackagePart(org.apache.poi.openxml4j.opc.PackagePart) CTSlideIdListEntry(org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry) InvalidFormatException(org.apache.poi.openxml4j.exceptions.InvalidFormatException) TikaException(org.apache.tika.exception.TikaException) InvalidFormatException(org.apache.poi.openxml4j.exceptions.InvalidFormatException) IOException(java.io.IOException) XmlException(org.apache.xmlbeans.XmlException) SAXException(org.xml.sax.SAXException) CTSlideIdList(org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdList) XmlException(org.apache.xmlbeans.XmlException)

Aggregations

CTSlideIdList (org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdList)3 CTSlideIdListEntry (org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry)3 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 POIXMLDocumentPart (org.apache.poi.POIXMLDocumentPart)1 InvalidFormatException (org.apache.poi.openxml4j.exceptions.InvalidFormatException)1 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)1 PackageRelationshipCollection (org.apache.poi.openxml4j.opc.PackageRelationshipCollection)1 TikaException (org.apache.tika.exception.TikaException)1 XmlException (org.apache.xmlbeans.XmlException)1 SAXException (org.xml.sax.SAXException)1