#60715 - Blank layout was not found

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1782635 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2017-02-11 21:48:05 +00:00
parent faaa94d20a
commit 397771011f
3 changed files with 60 additions and 36 deletions

View File

@ -72,7 +72,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.PresentationDocument
@Beta @Beta
public class XMLSlideShow extends POIXMLDocument public class XMLSlideShow extends POIXMLDocument
implements SlideShow<XSLFShape,XSLFTextParagraph> { implements SlideShow<XSLFShape,XSLFTextParagraph> {
private final static POILogger _logger = POILogFactory.getLogger(XMLSlideShow.class); private static final POILogger LOG = POILogFactory.getLogger(XMLSlideShow.class);
private CTPresentation _presentation; private CTPresentation _presentation;
private List<XSLFSlide> _slides; private List<XSLFSlide> _slides;
@ -154,7 +154,7 @@ implements SlideShow<XSLFShape,XSLFTextParagraph> {
for (CTSlideIdListEntry slId : _presentation.getSldIdLst().getSldIdList()) { for (CTSlideIdListEntry slId : _presentation.getSldIdLst().getSldIdList()) {
XSLFSlide sh = shIdMap.get(slId.getId2()); XSLFSlide sh = shIdMap.get(slId.getId2());
if (sh == null) { if (sh == null) {
_logger.log(POILogger.WARN, "Slide with r:id " + slId.getId() + " was defined, but didn't exist in package, skipping"); LOG.log(POILogger.WARN, "Slide with r:id " + slId.getId() + " was defined, but didn't exist in package, skipping");
continue; continue;
} }
_slides.add(sh); _slides.add(sh);
@ -206,8 +206,9 @@ implements SlideShow<XSLFShape,XSLFTextParagraph> {
public XSLFSlide createSlide(XSLFSlideLayout layout) { public XSLFSlide createSlide(XSLFSlideLayout layout) {
int slideNumber = 256, cnt = 1; int slideNumber = 256, cnt = 1;
CTSlideIdList slideList; CTSlideIdList slideList;
if (!_presentation.isSetSldIdLst()) slideList = _presentation.addNewSldIdLst(); if (!_presentation.isSetSldIdLst()) {
else { slideList = _presentation.addNewSldIdLst();
} else {
slideList = _presentation.getSldIdLst(); slideList = _presentation.getSldIdLst();
for(CTSlideIdListEntry slideId : slideList.getSldIdArray()){ for(CTSlideIdListEntry slideId : slideList.getSldIdArray()){
slideNumber = (int)Math.max(slideId.getId() + 1, slideNumber); slideNumber = (int)Math.max(slideId.getId() + 1, slideNumber);
@ -261,8 +262,16 @@ implements SlideShow<XSLFShape,XSLFTextParagraph> {
*/ */
@Override @Override
public XSLFSlide createSlide() { public XSLFSlide createSlide() {
XSLFSlideLayout layout = _masters.get(0).getLayout(SlideLayout.BLANK); XSLFSlideMaster sm = _masters.get(0);
if(layout == null) throw new IllegalArgumentException("Blank layout was not found"); XSLFSlideLayout layout = sm.getLayout(SlideLayout.BLANK);
if (layout == null) {
LOG.log(POILogger.WARN, "Blank layout was not found - defaulting to first slide layout in master");
XSLFSlideLayout sl[] = sm.getSlideLayouts();
if (sl.length == 0) {
throw new POIXMLException("SlideMaster must contain a SlideLayout.");
}
layout = sl[0];
}
return createSlide(layout); return createSlide(layout);
} }
@ -361,6 +370,7 @@ implements SlideShow<XSLFShape,XSLFTextParagraph> {
/** /**
* Return all the slides in the slideshow * Return all the slides in the slideshow
*/ */
@Override
public List<XSLFSlide> getSlides() { public List<XSLFSlide> getSlides() {
return _slides; return _slides;
} }
@ -379,8 +389,12 @@ implements SlideShow<XSLFShape,XSLFTextParagraph> {
*/ */
public void setSlideOrder(XSLFSlide slide, int newIndex){ public void setSlideOrder(XSLFSlide slide, int newIndex){
int oldIndex = _slides.indexOf(slide); int oldIndex = _slides.indexOf(slide);
if(oldIndex == -1) throw new IllegalArgumentException("Slide not found"); if(oldIndex == -1) {
if (oldIndex == newIndex) return; throw new IllegalArgumentException("Slide not found");
}
if (oldIndex == newIndex) {
return;
}
// fix the usermodel container // fix the usermodel container
_slides.add(newIndex, _slides.remove(oldIndex)); _slides.add(newIndex, _slides.remove(oldIndex));
@ -435,10 +449,13 @@ implements SlideShow<XSLFShape,XSLFTextParagraph> {
* *
* @return the picture data * @return the picture data
*/ */
@Override
public XSLFPictureData addPicture(byte[] pictureData, PictureType format) { public XSLFPictureData addPicture(byte[] pictureData, PictureType format) {
XSLFPictureData img = findPictureData(pictureData); XSLFPictureData img = findPictureData(pictureData);
if (img != null) return img; if (img != null) {
return img;
}
int imageNumber = _pictures.size(); int imageNumber = _pictures.size();
XSLFRelation relType = XSLFPictureData.getRelationForType(format); XSLFRelation relType = XSLFPictureData.getRelationForType(format);
@ -560,6 +577,7 @@ implements SlideShow<XSLFShape,XSLFTextParagraph> {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override
public Resources getResources() { public Resources getResources() {
// TODO: implement! // TODO: implement!
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();

View File

@ -586,4 +586,10 @@ public class TestXSLFBugs {
return cell; return cell;
} }
@Test
public void bug60715() throws IOException {
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("bug60715.pptx");
ppt.createSlide();
ppt.close();
}
} }

Binary file not shown.