diff options
author | Alain Béarez <abearez@apache.org> | 2019-12-07 23:39:20 +0000 |
---|---|---|
committer | Alain Béarez <abearez@apache.org> | 2019-12-07 23:39:20 +0000 |
commit | bb2ad49a2fc6c74948f8bb92701807093b525586 (patch) | |
tree | 6e8396a5e01077b82ea9ddf2a5c39dfc85b6c15a /src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java | |
parent | 4703c18b83d2796c8d7f67bd15c75b74b555fb45 (diff) | |
download | poi-bb2ad49a2fc6c74948f8bb92701807093b525586.tar.gz poi-bb2ad49a2fc6c74948f8bb92701807093b525586.zip |
Retrieve chart from graphical frame
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1871012 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java')
-rw-r--r-- | src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java index 8b9d152848..9ae6c9f956 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java @@ -47,6 +47,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape; @Beta public class XSLFGraphicFrame extends XSLFShape implements GraphicalFrame<XSLFShape, XSLFTextParagraph> { + private static final String DRAWINGML_CHART_URI = "http://schemas.openxmlformats.org/drawingml/2006/chart"; private static final POILogger LOG = POILogFactory.getLogger(XSLFGraphicFrame.class); /*package*/ XSLFGraphicFrame(CTGraphicalObjectFrame shape, XSLFSheet sheet){ @@ -97,7 +98,7 @@ public class XSLFGraphicFrame extends XSLFShape implements GraphicalFrame<XSLFSh return new XSLFGraphicFrame(shape, sheet); } } - + private static String getUri(CTGraphicalObjectFrame shape) { final CTGraphicalObject g = shape.getGraphic(); if (g == null) { @@ -160,15 +161,45 @@ public class XSLFGraphicFrame extends XSLFShape implements GraphicalFrame<XSLFSh return false; } + public boolean hasChart() { + String uri = getGraphicalData().getUri(); + return uri.equals(DRAWINGML_CHART_URI); + } + + private CTGraphicalObjectData getGraphicalData() { + return ((CTGraphicalObjectFrame)getXmlObject()).getGraphic().getGraphicData(); + } + + public XSLFChart getChart() { + if (hasChart()) { + String id = null; + String xpath = "declare namespace c='" + DRAWINGML_CHART_URI + "' c:chart"; + XmlObject[] obj = getGraphicalData().selectPath(xpath); + if (obj != null && obj.length == 1) { + XmlCursor c = obj[0].newCursor(); + QName idQualifiedName = new QName("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "id"); + id = c.getAttributeText(idQualifiedName); + c.dispose(); + } + if (id == null) { + return null; + } else { + return (XSLFChart) getSheet().getRelationById(id); + } + } else { + return null; + } + } + @Override void copy(XSLFShape sh){ super.copy(sh); - CTGraphicalObjectData data = ((CTGraphicalObjectFrame)getXmlObject()).getGraphic().getGraphicData(); + CTGraphicalObjectData data = getGraphicalData(); String uri = data.getUri(); if(uri.equals("http://schemas.openxmlformats.org/drawingml/2006/diagram")){ copyDiagram(data, (XSLFGraphicFrame)sh); - } if(uri.equals("http://schemas.openxmlformats.org/drawingml/2006/chart")){ + } if(uri.equals(DRAWINGML_CHART_URI)){ copyChart(data, (XSLFGraphicFrame)sh); } else { // TODO support other types of objects @@ -179,7 +210,7 @@ public class XSLFGraphicFrame extends XSLFShape implements GraphicalFrame<XSLFSh private void copyChart(CTGraphicalObjectData objData, XSLFGraphicFrame srcShape) { XSLFSlide slide = (XSLFSlide) getSheet(); XSLFSheet src = srcShape.getSheet(); - String xpath = "declare namespace c='http://schemas.openxmlformats.org/drawingml/2006/chart' c:chart"; + String xpath = "declare namespace c='" + DRAWINGML_CHART_URI + "' c:chart"; XmlObject[] obj = objData.selectPath(xpath); if (obj != null && obj.length == 1) { XmlCursor c = obj[0].newCursor(); |