[bug-65674] add isVideoFile to XSLFPictureShape

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894860 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2021-11-09 10:40:57 +00:00
parent 161f02ad9e
commit 458369a64d
3 changed files with 71 additions and 14 deletions

View File

@ -279,15 +279,11 @@ public class XSLFPictureShape extends XSLFSimpleShape
*/ */
public String getName() { public String getName() {
String name = null; String name = null;
XmlObject xmlObject = getXmlObject(); CTPictureNonVisual nvPicPr = getCTPictureNonVisual();
if (xmlObject instanceof CTPicture) { if (nvPicPr != null) {
CTPicture ctPicture = (CTPicture)xmlObject; CTNonVisualDrawingProps cnvdProps = nvPicPr.getCNvPr();
CTPictureNonVisual nvPicPr = ctPicture.getNvPicPr(); if (cnvdProps != null) {
if (nvPicPr != null) { name = cnvdProps.getName();
CTNonVisualDrawingProps cnvdProps = nvPicPr.getCNvPr();
if (cnvdProps != null) {
name = cnvdProps.getName();
}
} }
} }
return name; return name;
@ -412,17 +408,17 @@ public class XSLFPictureShape extends XSLFSimpleShape
} }
String relId = getSheet().importBlip(blipId, p.getSheet()); String relId = getSheet().importBlip(blipId, p.getSheet());
CTPicture ct = (CTPicture)getXmlObject();
CTBlip blip = getBlipFill().getBlip(); CTBlip blip = getBlipFill().getBlip();
blip.setEmbed(relId); blip.setEmbed(relId);
CTApplicationNonVisualDrawingProps nvPr = ct.getNvPicPr().getNvPr(); CTPictureNonVisual nvPicPr = getCTPictureNonVisual();
if(nvPr.isSetCustDataLst()) { CTApplicationNonVisualDrawingProps nvPr = nvPicPr == null ? null : nvPicPr.getNvPr();
if(nvPr != null && nvPr.isSetCustDataLst()) {
// discard any custom tags associated with the picture being copied // discard any custom tags associated with the picture being copied
nvPr.unsetCustDataLst(); nvPr.unsetCustDataLst();
} }
if(blip.isSetExtLst()) { if (blip.isSetExtLst()) {
// TODO: check for SVG copying // TODO: check for SVG copying
CTOfficeArtExtensionList extLst = blip.getExtLst(); CTOfficeArtExtensionList extLst = blip.getExtLst();
for(CTOfficeArtExtension ext : extLst.getExtArray()){ 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;
}
} }

View File

@ -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");
}
}
} }

Binary file not shown.