import org.openxmlformats.schemas.presentationml.x2006.main.CTConnector;\r
import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape;\r
import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShapeNonVisual;\r
+import org.openxmlformats.schemas.presentationml.x2006.main.CTPicture;\r
import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;\r
\r
/**\r
grpSp.getGrpSpList().remove(obj);\r
} else if (obj instanceof CTConnector){\r
grpSp.getCxnSpList().remove(obj);\r
+ } else if (obj instanceof CTPicture) {\r
+ XSLFPictureShape ps = (XSLFPictureShape)xShape;\r
+ XSLFSheet sh = getSheet();\r
+ if (sh != null) {\r
+ sh.removePictureRelation(ps);\r
+ }\r
+ grpSp.getPicList().remove(obj);\r
} else {\r
throw new IllegalArgumentException("Unsupported shape: " + xShape);\r
}\r
return null;\r
}\r
\r
- private CTBlip getBlip(){\r
+ protected CTBlip getBlip(){\r
CTPicture ct = (CTPicture)getXmlObject();\r
return ct.getBlipFill().getBlip();\r
}\r
- private String getBlipLink(){\r
+ \r
+ protected String getBlipLink(){\r
String link = getBlip().getLink();\r
if (link.isEmpty()) return null;\r
return link;\r
}\r
- private String getBlipId(){\r
+ \r
+ protected String getBlipId(){\r
String id = getBlip().getEmbed();\r
if (id.isEmpty()) return null;\r
return id;\r
import org.apache.poi.util.Internal;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;
-import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
import org.openxmlformats.schemas.presentationml.x2006.main.CTCommonSlideData;
import org.openxmlformats.schemas.presentationml.x2006.main.CTConnector;
import org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame;
spTree.getGrpSpList().remove(obj);
} else if (obj instanceof CTConnector){
spTree.getCxnSpList().remove(obj);
+ } else if (obj instanceof CTPicture) {
+ XSLFPictureShape ps = (XSLFPictureShape)xShape;
+ removePictureRelation(ps);
+ spTree.getPicList().remove(obj);
} else {
throw new IllegalArgumentException("Unsupported shape: " + xShape);
}
}
return part;
}
+
+ /**
+ * Helper method for sheet and group shapes
+ *
+ * @param pictureShape the picture shapes whose relation is to be removed
+ */
+ void removePictureRelation(XSLFPictureShape pictureShape) {
+ POIXMLDocumentPart pd = getRelationById(pictureShape.getBlipId());
+ removeRelation(pd);
+ }
}
\ No newline at end of file
import static org.junit.Assert.assertEquals;\r
import static org.junit.Assert.assertFalse;\r
import static org.junit.Assert.assertNotNull;\r
+import static org.junit.Assert.assertTrue;\r
\r
+import java.io.ByteArrayInputStream;\r
+import java.io.ByteArrayOutputStream;\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
import java.util.HashMap;\r
import java.util.List;\r
import java.util.Map;\r
\r
-import org.apache.poi.xslf.XSLFTestDataSamples;\r
+import org.apache.poi.POIDataSamples;\r
import org.apache.poi.sl.usermodel.PictureData.PictureType;\r
+import org.apache.poi.xslf.XSLFTestDataSamples;\r
import org.junit.Test;\r
import org.openxmlformats.schemas.presentationml.x2006.main.CTPicture;\r
\r
-/**\r
- * @author Yegor Kozlov\r
- */\r
public class TestXSLFPictureShape {\r
+ private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();\r
\r
@Test\r
public void testCreate() throws Exception {\r
ppt1.close();\r
ppt2.close();\r
}\r
+ \r
+ @Test\r
+ public void bug58663() throws IOException {\r
+ InputStream is = _slTests.openResourceAsStream("shapes.pptx");\r
+ XMLSlideShow ppt = new XMLSlideShow(is);\r
+ is.close();\r
+ \r
+ XSLFSlide slide = ppt.getSlides().get(0);\r
+ XSLFPictureShape ps = (XSLFPictureShape)slide.getShapes().get(3);\r
+ slide.removeShape(ps);\r
+ \r
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();\r
+ ppt.write(bos);\r
+ ppt.close();\r
+ \r
+ XMLSlideShow ppt2 = new XMLSlideShow(new ByteArrayInputStream(bos.toByteArray()));\r
+ assertTrue(ppt2.getPictureData().isEmpty());\r
+ ppt2.close();\r
+ }\r
}
\ No newline at end of file