Search in sources :

Example 6 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 7 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 8 with CTSlideIdListEntry

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

the class TestXMLSlideShow method testSlideBasics.

@Test
public void testSlideBasics() throws IOException {
    XMLSlideShow xml = new XMLSlideShow(pack);
    // Should have 1 master
    assertEquals(1, xml.getSlideMasters().size());
    // Should have two sheets
    assertEquals(2, xml.getSlides().size());
    // Check they're as expected
    CTSlideIdListEntry[] slides = xml.getCTPresentation().getSldIdLst().getSldIdArray();
    assertEquals(256, slides[0].getId());
    assertEquals(257, slides[1].getId());
    assertEquals("rId2", slides[0].getId2());
    assertEquals("rId3", slides[1].getId2());
    // Now get those objects
    assertNotNull(xml.getSlides().get(0));
    assertNotNull(xml.getSlides().get(1));
    // And check they have notes as expected
    assertNotNull(xml.getSlides().get(0).getNotes());
    assertNotNull(xml.getSlides().get(1).getNotes());
    // Next up look for the slide master
    CTSlideMasterIdListEntry[] masters = xml.getCTPresentation().getSldMasterIdLst().getSldMasterIdArray();
    // see SlideAtom.USES_MASTER_SLIDE_ID
    assertEquals(0x80000000L, masters[0].getId());
    assertEquals("rId1", masters[0].getId2());
    assertNotNull(xml.getSlideMasters().get(0));
    // Finally look for the notes master
    CTNotesMasterIdListEntry notesMaster = xml.getCTPresentation().getNotesMasterIdLst().getNotesMasterId();
    assertNotNull(notesMaster);
    assertNotNull(xml.getNotesMaster());
    xml.close();
}
Also used : CTNotesMasterIdListEntry(org.openxmlformats.schemas.presentationml.x2006.main.CTNotesMasterIdListEntry) CTSlideIdListEntry(org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry) CTSlideMasterIdListEntry(org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry) Test(org.junit.Test)

Example 9 with CTSlideIdListEntry

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

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