use of org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry 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);
}
}
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 XSLFSlideShow method getSlide.
/**
* Returns the low level slide object from
* the supplied slide reference
*/
@Internal
public CTSlide getSlide(CTSlideIdListEntry slide) throws IOException, XmlException {
PackagePart slidePart = getSlidePart(slide);
SldDocument slideDoc = SldDocument.Factory.parse(slidePart.getInputStream(), DEFAULT_XML_OPTIONS);
return slideDoc.getSld();
}
use of org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry in project poi by apache.
the class XSLFSlideShow method getNotes.
/**
* Returns the low level notes object for the given
* slide, as found from the supplied slide reference
*/
@Internal
public CTNotesSlide getNotes(CTSlideIdListEntry slide) throws IOException, XmlException {
PackagePart notesPart = getNodesPart(slide);
if (notesPart == null)
return null;
NotesDocument notesDoc = NotesDocument.Factory.parse(notesPart.getInputStream(), DEFAULT_XML_OPTIONS);
return notesDoc.getNotes();
}
Aggregations