* Throw IndexOutOfBoundsException if the slide index is out of the presentation document slide count.
* If copy the slide at the end of document, destIndex should set the same value with the slide count.
*/
public OdfSlide copySlide(int source, int dest, String newName) {
checkAllSlideName();
OfficePresentationElement contentRoot = null;
try {
contentRoot = getContentRoot();
} catch (Exception e) {
Logger.getLogger(OdfPresentationDocument.class.getName()).log(Level.SEVERE, null, e);
return null;
}
NodeList slideList = contentRoot.getElementsByTagNameNS(OdfDocumentNamespace.DRAW.getUri(), "page");
int slideCount = slideList.getLength();
if ((source < 0) || (source >= slideCount)
|| (dest < 0) || (dest > slideCount)) {
throw new IndexOutOfBoundsException("the specified Index is out of slide count when call copySlide method.");
}
DrawPageElement sourceSlideElement = (DrawPageElement) slideList.item(source);
DrawPageElement cloneSlideElement = (DrawPageElement) sourceSlideElement.cloneNode(true);
cloneSlideElement.setDrawNameAttribute(newName);
if (dest == slideCount) {
contentRoot.appendChild(cloneSlideElement);
} else {
DrawPageElement refSlide = (DrawPageElement) slideList.item(dest);
contentRoot.insertBefore(cloneSlideElement, refSlide);
}
adjustNotePageNumber(Math.min(source, dest));
//in case that the appended new slide have the same name with the original slide
hasCheckSlideName = false;
checkAllSlideName();