mirror of https://github.com/apache/poi.git
[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:
parent
161f02ad9e
commit
458369a64d
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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.
Loading…
Reference in New Issue