aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2021-11-09 10:40:57 +0000
committerPJ Fanning <fanningpj@apache.org>2021-11-09 10:40:57 +0000
commit458369a64d2764b673def8f516aef2addb5d84fb (patch)
tree2e8ac322bc63145e4d445090d1fefc4af4809c5b
parent161f02ad9ef5868459abbfc94cb2365c63a8f2ea (diff)
downloadpoi-458369a64d2764b673def8f516aef2addb5d84fb.tar.gz
poi-458369a64d2764b673def8f516aef2addb5d84fb.zip
[bug-65674] add isVideoFile to XSLFPictureShape
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894860 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java65
-rw-r--r--poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFPictureShape.java20
-rw-r--r--test-data/slideshow/EmbeddedVideo.pptxbin0 -> 201418 bytes
3 files changed, 71 insertions, 14 deletions
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java
index c011c5db98..5c839f40fe 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java
@@ -279,15 +279,11 @@ public class XSLFPictureShape extends XSLFSimpleShape
*/
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 XSLFSimpleShape
}
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 XSLFSimpleShape
}
}
}
+
+ /**
+ * @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
diff --git a/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFPictureShape.java b/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFPictureShape.java
index b6cd26b9ee..65d18e9043 100644
--- a/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFPictureShape.java
+++ b/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFPictureShape.java
@@ -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
diff --git a/test-data/slideshow/EmbeddedVideo.pptx b/test-data/slideshow/EmbeddedVideo.pptx
new file mode 100644
index 0000000000..f7954228a8
--- /dev/null
+++ b/test-data/slideshow/EmbeddedVideo.pptx
Binary files differ