#58205 - getSlideMasters() returns the master slides in the incorrect order
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1694592 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1d6a728931
commit
d0e0f0cb97
@ -57,6 +57,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesMasterIdListE
|
||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTPresentation;
|
||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdList;
|
||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry;
|
||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry;
|
||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideSize;
|
||||
import org.openxmlformats.schemas.presentationml.x2006.main.PresentationDocument;
|
||||
|
||||
@ -72,7 +73,7 @@ public class XMLSlideShow extends POIXMLDocument implements SlideShow {
|
||||
|
||||
private CTPresentation _presentation;
|
||||
private List<XSLFSlide> _slides;
|
||||
private Map<String, XSLFSlideMaster> _masters;
|
||||
private List<XSLFSlideMaster> _masters;
|
||||
private List<XSLFPictureData> _pictures;
|
||||
private XSLFTableStyles _tableStyles;
|
||||
private XSLFNotesMaster _notesMaster;
|
||||
@ -120,21 +121,19 @@ public class XMLSlideShow extends POIXMLDocument implements SlideShow {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
protected void onDocumentRead() throws IOException {
|
||||
try {
|
||||
PresentationDocument doc =
|
||||
PresentationDocument.Factory.parse(getCorePart().getInputStream());
|
||||
_presentation = doc.getPresentation();
|
||||
Map<String, XSLFSlide> shIdMap = new HashMap<String, XSLFSlide>();
|
||||
|
||||
_masters = new HashMap<String, XSLFSlideMaster>();
|
||||
Map<String, XSLFSlideMaster> masterMap = new HashMap<String, XSLFSlideMaster>();
|
||||
Map<String, XSLFSlide> shIdMap = new HashMap<String, XSLFSlide>();
|
||||
for (POIXMLDocumentPart p : getRelations()) {
|
||||
if (p instanceof XSLFSlide) {
|
||||
shIdMap.put(p.getPackageRelationship().getId(), (XSLFSlide) p);
|
||||
} else if (p instanceof XSLFSlideMaster) {
|
||||
XSLFSlideMaster master = (XSLFSlideMaster)p;
|
||||
_masters.put(p.getPackageRelationship().getId(), master);
|
||||
masterMap.put(getRelationId(p), (XSLFSlideMaster) p);
|
||||
} else if (p instanceof XSLFTableStyles){
|
||||
_tableStyles = (XSLFTableStyles)p;
|
||||
} else if (p instanceof XSLFNotesMaster) {
|
||||
@ -144,9 +143,15 @@ public class XMLSlideShow extends POIXMLDocument implements SlideShow {
|
||||
}
|
||||
}
|
||||
|
||||
_slides = new ArrayList<XSLFSlide>();
|
||||
_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().getSldIdArray()) {
|
||||
for (CTSlideIdListEntry slId : _presentation.getSldIdLst().getSldIdList()) {
|
||||
XSLFSlide sh = shIdMap.get(slId.getId2());
|
||||
if (sh == null) {
|
||||
_logger.log(POILogger.WARN, "Slide with r:id " + slId.getId() + " was defined, but didn't exist in package, skipping");
|
||||
@ -239,13 +244,11 @@ public class XMLSlideShow extends POIXMLDocument implements SlideShow {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a blank slide.
|
||||
* Create a blank slide using the default (first) master.
|
||||
*/
|
||||
@Override
|
||||
public XSLFSlide createSlide() {
|
||||
String masterId = _presentation.getSldMasterIdLst().getSldMasterIdArray(0).getId2();
|
||||
XSLFSlideMaster master = _masters.get(masterId);
|
||||
|
||||
XSLFSlideLayout layout = master.getLayout(SlideLayout.BLANK);
|
||||
XSLFSlideLayout layout = _masters.get(0).getLayout(SlideLayout.BLANK);
|
||||
if(layout == null) throw new IllegalArgumentException("Blank layout was not found");
|
||||
|
||||
return createSlide(layout);
|
||||
@ -350,7 +353,7 @@ public class XMLSlideShow extends POIXMLDocument implements SlideShow {
|
||||
|
||||
@Override
|
||||
public List<XSLFSlideMaster> getSlideMasters() {
|
||||
return new ArrayList<XSLFSlideMaster>(_masters.values());
|
||||
return _masters;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -30,6 +30,7 @@ import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
|
||||
@ -47,6 +48,7 @@ import org.apache.poi.xslf.usermodel.XSLFRelation;
|
||||
import org.apache.poi.xslf.usermodel.XSLFShape;
|
||||
import org.apache.poi.xslf.usermodel.XSLFSlide;
|
||||
import org.apache.poi.xslf.usermodel.XSLFSlideLayout;
|
||||
import org.apache.poi.xslf.usermodel.XSLFSlideMaster;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -337,8 +339,8 @@ public class TestXSLFBugs {
|
||||
|
||||
|
||||
// Save and re-load
|
||||
ss = XSLFTestDataSamples.writeOutAndReadBack(ss);
|
||||
slide = ss.getSlides().get(0);
|
||||
XMLSlideShow ss2 = XSLFTestDataSamples.writeOutAndReadBack(ss);
|
||||
slide = ss2.getSlides().get(0);
|
||||
|
||||
// Check the 15 individual ones added
|
||||
for (int i=0; i<15; i++) {
|
||||
@ -353,14 +355,17 @@ public class TestXSLFBugs {
|
||||
assertArrayEquals(pics[3], shape.getPictureData().getData());
|
||||
|
||||
// Add another duplicate
|
||||
data = ss.addPicture(pics[5], PictureType.JPEG);
|
||||
data = ss2.addPicture(pics[5], PictureType.JPEG);
|
||||
assertEquals(5, data.getIndex());
|
||||
assertEquals(15, ss.getAllPictures().size());
|
||||
assertEquals(15, ss2.getAllPictures().size());
|
||||
|
||||
shape = slide.createPicture(data);
|
||||
assertNotNull(shape.getPictureData());
|
||||
assertArrayEquals(pics[5], shape.getPictureData().getData());
|
||||
assertEquals(18, slide.getShapes().size());
|
||||
|
||||
ss2.close();
|
||||
ss.close();
|
||||
}
|
||||
|
||||
private void validateSlides(XMLSlideShow ss, boolean saveAndReload, String... slideTexts) {
|
||||
@ -379,4 +384,16 @@ public class TestXSLFBugs {
|
||||
assertEquals(expected.getContentType(), relation.getPackagePart().getContentType());
|
||||
assertEquals(expected.getFileName(expected.getFileNameIndex(relation)), relation.getPackagePart().getPartName().getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug58205() throws IOException {
|
||||
XMLSlideShow ss = XSLFTestDataSamples.openSampleDocument("themes.pptx");
|
||||
|
||||
int i = 1;
|
||||
for (XSLFSlideMaster sm : ss.getSlideMasters()) {
|
||||
assertEquals("rId"+(i++), ss.getRelationId(sm));
|
||||
}
|
||||
|
||||
ss.close();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user