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