You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2021/11/09 10:40:57 UTC
svn commit: r1894860 - in /poi/trunk:
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java
poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFPictureShape.java
test-data/slideshow/EmbeddedVideo.pptx
Author: fanningpj
Date: Tue Nov 9 10:40:57 2021
New Revision: 1894860
URL: http://svn.apache.org/viewvc?rev=1894860&view=rev
Log:
[bug-65674] add isVideoFile to XSLFPictureShape
Added:
poi/trunk/test-data/slideshow/EmbeddedVideo.pptx
Modified:
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java
poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFPictureShape.java
Modified: poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java?rev=1894860&r1=1894859&r2=1894860&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java (original)
+++ poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java Tue Nov 9 10:40:57 2021
@@ -279,15 +279,11 @@ public class XSLFPictureShape extends XS
*/
public String getName() {
String name = null;
- XmlObject xmlObject = getXmlObject();
- if (xmlObject instanceof CTPicture) {
- CTPicture ctPicture = (CTPicture)xmlObject;
- CTPictureNonVisual nvPicPr = ctPicture.getNvPicPr();
- if (nvPicPr != null) {
- CTNonVisualDrawingProps cnvdProps = nvPicPr.getCNvPr();
- if (cnvdProps != null) {
- name = cnvdProps.getName();
- }
+ CTPictureNonVisual nvPicPr = getCTPictureNonVisual();
+ if (nvPicPr != null) {
+ CTNonVisualDrawingProps cnvdProps = nvPicPr.getCNvPr();
+ if (cnvdProps != null) {
+ name = cnvdProps.getName();
}
}
return name;
@@ -412,17 +408,17 @@ public class XSLFPictureShape extends XS
}
String relId = getSheet().importBlip(blipId, p.getSheet());
-
- CTPicture ct = (CTPicture)getXmlObject();
CTBlip blip = getBlipFill().getBlip();
blip.setEmbed(relId);
- CTApplicationNonVisualDrawingProps nvPr = ct.getNvPicPr().getNvPr();
- if(nvPr.isSetCustDataLst()) {
+ CTPictureNonVisual nvPicPr = getCTPictureNonVisual();
+ CTApplicationNonVisualDrawingProps nvPr = nvPicPr == null ? null : nvPicPr.getNvPr();
+
+ if(nvPr != null && nvPr.isSetCustDataLst()) {
// discard any custom tags associated with the picture being copied
nvPr.unsetCustDataLst();
}
- if(blip.isSetExtLst()) {
+ if (blip.isSetExtLst()) {
// TODO: check for SVG copying
CTOfficeArtExtensionList extLst = blip.getExtLst();
for(CTOfficeArtExtension ext : extLst.getExtArray()){
@@ -438,4 +434,45 @@ public class XSLFPictureShape extends XS
}
}
}
+
+ /**
+ * @return boolean; true if the picture is a video
+ * @since POI 5.2.0
+ */
+ public boolean isVideoFile() {
+ CTPictureNonVisual nvPicPr = getCTPictureNonVisual();
+ if (nvPicPr != null) {
+ CTApplicationNonVisualDrawingProps nvPr = nvPicPr.getNvPr();
+ if (nvPr != null) {
+ return nvPr.isSetVideoFile();
+ }
+ }
+ return false;
+ }
+
+ /**
+ * @return the link ID for the video file
+ * @since POI 5.2.0
+ */
+ public String getVideoFileLink() {
+ if (isVideoFile()) {
+ CTPictureNonVisual nvPicPr = getCTPictureNonVisual();
+ if (nvPicPr != null) {
+ CTApplicationNonVisualDrawingProps nvPr = nvPicPr.getNvPr();
+ if (nvPr != null && nvPr.getVideoFile() != null) {
+ return nvPr.getVideoFile().getLink();
+ }
+ }
+ }
+ return null;
+ }
+
+ private CTPictureNonVisual getCTPictureNonVisual() {
+ XmlObject xmlObject = getXmlObject();
+ if (xmlObject instanceof CTPicture) {
+ CTPicture ctPicture = (CTPicture) xmlObject;
+ return ctPicture.getNvPicPr();
+ }
+ return null;
+ }
}
\ No newline at end of file
Modified: poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFPictureShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFPictureShape.java?rev=1894860&r1=1894859&r2=1894860&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFPictureShape.java (original)
+++ poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFPictureShape.java Tue Nov 9 10:40:57 2021
@@ -339,4 +339,24 @@ class TestXSLFPictureShape {
}
}
}
+
+ @Test
+ void testIsSetVideoFile() throws IOException {
+ try (XMLSlideShow ppt = openSampleDocument("EmbeddedVideo.pptx")) {
+ XSLFSlide slide = ppt.getSlides().get(0);
+ XSLFPictureShape ps = (XSLFPictureShape) slide.getShapes().get(0);
+
+ assertTrue(ps.isVideoFile());
+ }
+ }
+
+ @Test
+ void testGetVideoLink() throws IOException {
+ try (XMLSlideShow ppt = openSampleDocument("EmbeddedVideo.pptx")) {
+ XSLFSlide slide = ppt.getSlides().get(0);
+ XSLFPictureShape ps = (XSLFPictureShape) slide.getShapes().get(0);
+
+ assertEquals(ps.getVideoFileLink(), "rId2");
+ }
+ }
}
\ No newline at end of file
Added: poi/trunk/test-data/slideshow/EmbeddedVideo.pptx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/slideshow/EmbeddedVideo.pptx?rev=1894860&view=auto
==============================================================================
Binary files poi/trunk/test-data/slideshow/EmbeddedVideo.pptx (added) and poi/trunk/test-data/slideshow/EmbeddedVideo.pptx Tue Nov 9 10:40:57 2021 differ
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org