throw new IndexOutOfBoundsException("the specified Index is out of slide count when call newSlide method.");
}
// if insert page at the beginning of the document,
// get the next page style as the new page style
// else get the previous page style as the new page style
DrawPageElement refStyleSlide = null;
int refSlideIndex = 0;
if (index > 0) {
refSlideIndex = index - 1;
}
refStyleSlide = (DrawPageElement) slideList.item(refSlideIndex);
String masterPageStyleName = "Default";
String masterName = refStyleSlide.getDrawMasterPageNameAttribute();
if (masterName != null) {
masterPageStyleName = masterName;
}
DrawPageElement newSlideElement = contentRoot.newDrawPageElement(masterPageStyleName);
newSlideElement.setDrawNameAttribute(name);
String drawStyleName = refStyleSlide.getDrawStyleNameAttribute();
if (drawStyleName != null) {
newSlideElement.setDrawStyleNameAttribute(drawStyleName);
}
String pageLayoutName = refStyleSlide.getPresentationPresentationPageLayoutNameAttribute();
if (pageLayoutName != null) {
newSlideElement.setPresentationPresentationPageLayoutNameAttribute(pageLayoutName);
}
setSlideLayout(newSlideElement, slideLayout);
// insert notes page
NodeList noteNodes = refStyleSlide.getElementsByTagNameNS(OdfDocumentNamespace.PRESENTATION.getUri(), "notes");
if (noteNodes.getLength() > 0) {
PresentationNotesElement notePage = (PresentationNotesElement) noteNodes.item(0);
PresentationNotesElement cloneNotePage = (PresentationNotesElement) notePage.cloneNode(true);
newSlideElement.appendChild(cloneNotePage);
}
if (index < slideCount) {
DrawPageElement refSlide = (DrawPageElement) slideList.item(index);
contentRoot.insertBefore(newSlideElement, refSlide);
}
adjustNotePageNumber(index);
// in case that the appended new slide have the same name with the
// original slide