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);
}
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;
}
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();
}
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;
}
Aggregations