Bug 60810: Check for duplicate relation-names for notes similar to the fix for slides themselves in bug 55791
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1787663 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
eef36a1580
commit
a22b4aaa2d
@ -300,6 +300,32 @@ implements SlideShow<XSLFShape,XSLFTextParagraph> {
|
|||||||
|
|
||||||
Integer slideIndex = XSLFRelation.SLIDE.getFileNameIndex(slide);
|
Integer slideIndex = XSLFRelation.SLIDE.getFileNameIndex(slide);
|
||||||
|
|
||||||
|
// Bug 55791: We also need to check that the resulting file name is not already taken
|
||||||
|
// this can happen when removing/adding slides
|
||||||
|
while(true) {
|
||||||
|
String slideName = XSLFRelation.NOTES.getFileName(slideIndex);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
slideIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
// add notes slide to presentation
|
// add notes slide to presentation
|
||||||
XSLFNotes notesSlide = (XSLFNotes) createRelationship
|
XSLFNotes notesSlide = (XSLFNotes) createRelationship
|
||||||
(XSLFRelation.NOTES, XSLFFactory.getInstance(), slideIndex);
|
(XSLFRelation.NOTES, XSLFFactory.getInstance(), slideIndex);
|
||||||
|
@ -16,27 +16,6 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xslf;
|
package org.apache.poi.xslf;
|
||||||
|
|
||||||
import static org.apache.poi.POITestCase.assertContains;
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
import java.awt.Color;
|
|
||||||
import java.awt.Dimension;
|
|
||||||
import java.awt.Graphics2D;
|
|
||||||
import java.awt.RenderingHints;
|
|
||||||
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.Collection;
|
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
|
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.POIXMLDocumentPart;
|
import org.apache.poi.POIXMLDocumentPart;
|
||||||
import org.apache.poi.POIXMLDocumentPart.RelationPart;
|
import org.apache.poi.POIXMLDocumentPart.RelationPart;
|
||||||
@ -50,27 +29,28 @@ import org.apache.poi.sl.usermodel.PictureData.PictureType;
|
|||||||
import org.apache.poi.sl.usermodel.ShapeType;
|
import org.apache.poi.sl.usermodel.ShapeType;
|
||||||
import org.apache.poi.sl.usermodel.VerticalAlignment;
|
import org.apache.poi.sl.usermodel.VerticalAlignment;
|
||||||
import org.apache.poi.xslf.extractor.XSLFPowerPointExtractor;
|
import org.apache.poi.xslf.extractor.XSLFPowerPointExtractor;
|
||||||
import org.apache.poi.xslf.usermodel.XMLSlideShow;
|
import org.apache.poi.xslf.usermodel.*;
|
||||||
import org.apache.poi.xslf.usermodel.XSLFAutoShape;
|
|
||||||
import org.apache.poi.xslf.usermodel.XSLFGroupShape;
|
|
||||||
import org.apache.poi.xslf.usermodel.XSLFHyperlink;
|
|
||||||
import org.apache.poi.xslf.usermodel.XSLFPictureData;
|
|
||||||
import org.apache.poi.xslf.usermodel.XSLFPictureShape;
|
|
||||||
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.apache.poi.xslf.usermodel.XSLFTable;
|
|
||||||
import org.apache.poi.xslf.usermodel.XSLFTableCell;
|
|
||||||
import org.apache.poi.xslf.usermodel.XSLFTableRow;
|
|
||||||
import org.apache.poi.xslf.usermodel.XSLFTextParagraph;
|
|
||||||
import org.apache.poi.xslf.usermodel.XSLFTextRun;
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTOuterShadowEffect;
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTOuterShadowEffect;
|
||||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.RenderingHints;
|
||||||
|
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.Collection;
|
||||||
|
|
||||||
|
import static org.apache.poi.POITestCase.assertContains;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
|
||||||
public class TestXSLFBugs {
|
public class TestXSLFBugs {
|
||||||
private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
|
private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
|
||||||
@ -109,6 +89,7 @@ public class TestXSLFBugs {
|
|||||||
|
|
||||||
private static void assertRelation(XSLFSlide slide, String exp, String rId) {
|
private static void assertRelation(XSLFSlide slide, String exp, String rId) {
|
||||||
POIXMLDocumentPart pd = (rId != null) ? slide.getRelationById(rId) : slide;
|
POIXMLDocumentPart pd = (rId != null) ? slide.getRelationById(rId) : slide;
|
||||||
|
assertNotNull(pd);
|
||||||
assertEquals(exp, pd.getPackagePart().getPartName().getName());
|
assertEquals(exp, pd.getPackagePart().getPartName().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,6 +129,7 @@ public class TestXSLFBugs {
|
|||||||
if(p.getRelationship().getRelationshipType().equals(XSLFRelation.HYPERLINK.getRelation())) {
|
if(p.getRelationship().getRelationshipType().equals(XSLFRelation.HYPERLINK.getRelation())) {
|
||||||
URI target = p.getRelationship().getTargetURI();
|
URI target = p.getRelationship().getTargetURI();
|
||||||
|
|
||||||
|
//noinspection StatementWithEmptyBody
|
||||||
if(target.getFragment().equals("_ftn1") ||
|
if(target.getFragment().equals("_ftn1") ||
|
||||||
target.getFragment().equals("_ftnref1")) {
|
target.getFragment().equals("_ftnref1")) {
|
||||||
// Good
|
// Good
|
||||||
@ -624,4 +606,22 @@ public class TestXSLFBugs {
|
|||||||
dst.close();
|
dst.close();
|
||||||
src.close();
|
src.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test60810() throws IOException {
|
||||||
|
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("60810.pptx");
|
||||||
|
for(XSLFSlide slide : ppt.getSlides()) {
|
||||||
|
XSLFNotes notesSlide = ppt.getNotesSlide(slide);
|
||||||
|
assertNotNull(notesSlide);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*OutputStream stream = new FileOutputStream("/tmp/test.pptx");
|
||||||
|
try {
|
||||||
|
ppt.write(stream);
|
||||||
|
} finally {
|
||||||
|
stream.close();
|
||||||
|
}*/
|
||||||
|
|
||||||
|
ppt.close();
|
||||||
|
}
|
||||||
}
|
}
|
BIN
test-data/slideshow/60810.pptx
Normal file
BIN
test-data/slideshow/60810.pptx
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user