From dec55b8ead970f1e28ec6baee4a8939e7c869ebd Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Mon, 21 Jan 2013 20:46:32 +0000 Subject: [PATCH] fix exception when calling importContent, see Bugzilla 54407 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1436608 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xslf/usermodel/XSLFPictureData.java | 8 +++++- .../poi/xslf/usermodel/XSLFPictureShape.java | 25 ++++++++++++++----- .../poi/xslf/usermodel/XSLFRelation.java | 6 +++++ 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureData.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureData.java index d51e1c0d26..2122e62d26 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureData.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureData.java @@ -92,13 +92,18 @@ public final class XSLFPictureData extends POIXMLDocumentPart { */ public static final int PICTURE_TYPE_WPG = 12; + /** + * Microsoft Windows Media Photo image (.wdp) + */ + public static final int PICTURE_TYPE_WDP = 13; + /** * Relationships for each known picture type */ protected static final POIXMLRelation[] RELATIONS; static { - RELATIONS = new POIXMLRelation[13]; + RELATIONS = new POIXMLRelation[14]; RELATIONS[PICTURE_TYPE_EMF] = XSLFRelation.IMAGE_EMF; RELATIONS[PICTURE_TYPE_WMF] = XSLFRelation.IMAGE_WMF; RELATIONS[PICTURE_TYPE_PICT] = XSLFRelation.IMAGE_PICT; @@ -110,6 +115,7 @@ public final class XSLFPictureData extends POIXMLDocumentPart { RELATIONS[PICTURE_TYPE_EPS] = XSLFRelation.IMAGE_EPS; RELATIONS[PICTURE_TYPE_BMP] = XSLFRelation.IMAGE_BMP; RELATIONS[PICTURE_TYPE_WPG] = XSLFRelation.IMAGE_WPG; + RELATIONS[PICTURE_TYPE_WDP] = XSLFRelation.IMAGE_WDP; } private Long checksum = null; diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java index 035e15e438..872f82f83f 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java @@ -23,17 +23,15 @@ import org.apache.poi.POIXMLException; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.util.Beta; -import org.openxmlformats.schemas.drawingml.x2006.main.CTBlip; -import org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties; -import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps; -import org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D; -import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties; -import org.openxmlformats.schemas.drawingml.x2006.main.STShapeType; +import org.apache.xmlbeans.XmlCursor; +import org.apache.xmlbeans.XmlObject; +import org.openxmlformats.schemas.drawingml.x2006.main.*; import org.openxmlformats.schemas.presentationml.x2006.main.CTApplicationNonVisualDrawingProps; import org.openxmlformats.schemas.presentationml.x2006.main.CTPicture; import org.openxmlformats.schemas.presentationml.x2006.main.CTPictureNonVisual; import javax.imageio.ImageIO; +import javax.xml.namespace.QName; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; @@ -153,6 +151,21 @@ public class XSLFPictureShape extends XSLFSimpleShape { // discard any custom tags associated with the picture being copied nvPr.unsetCustDataLst(); } + if(blip.isSetExtLst()) { + + CTOfficeArtExtensionList extLst = blip.getExtLst(); + for(CTOfficeArtExtension ext : extLst.getExtList()){ + String xpath = "declare namespace a14='http://schemas.microsoft.com/office/drawing/2010/main' $this//a14:imgProps/a14:imgLayer"; + XmlObject[] obj = ext.selectPath(xpath); + if(obj != null && obj.length == 1){ + XmlCursor c = obj[0].newCursor(); + String id = c.getAttributeText(new QName("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "embed"));//selectPath("declare namespace r='http://schemas.openxmlformats.org/officeDocument/2006/relationships' $this//[@embed]"); + String newId = getSheet().importBlip(id, p.getSheet().getPackagePart()); + c.setAttributeText(new QName("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "embed"), newId); + c.dispose(); + } + } + } } } diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFRelation.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFRelation.java index 1ec3ac2d8a..046e71e6a5 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFRelation.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFRelation.java @@ -213,6 +213,12 @@ public class XSLFRelation extends POIXMLRelation { "/ppt/media/image#.wpg", XSLFPictureData.class ); + public static final XSLFRelation IMAGE_WDP = new XSLFRelation( + "image/vnd.ms-photo", + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", + "/ppt/media/image#.wdp", + XSLFPictureData.class + ); public static final XSLFRelation IMAGES = new XSLFRelation( null, -- 2.39.5