From eb850f02ded1753ec04bfcc53fb6a47eeb266f03 Mon Sep 17 00:00:00 2001 From: Sayi Date: Sun, 9 Aug 2020 08:05:37 +0000 Subject: [PATCH] Use the existing CTExternalData element git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1880707 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xddf/usermodel/chart/XDDFChart.java | 6 +++++ .../xddf/usermodel/chart/TestXDDFChart.java | 24 +++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java index dd959dddee..f5cc461cc3 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java @@ -67,6 +67,7 @@ import org.openxmlformats.schemas.drawingml.x2006.chart.CTChart; import org.openxmlformats.schemas.drawingml.x2006.chart.CTChartSpace; import org.openxmlformats.schemas.drawingml.x2006.chart.CTDateAx; import org.openxmlformats.schemas.drawingml.x2006.chart.CTDoughnutChart; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTExternalData; import org.openxmlformats.schemas.drawingml.x2006.chart.CTLine3DChart; import org.openxmlformats.schemas.drawingml.x2006.chart.CTLineChart; import org.openxmlformats.schemas.drawingml.x2006.chart.CTPie3DChart; @@ -1057,6 +1058,11 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai */ public void setExternalId(String id) { getCTChartSpace().addNewExternalData().setId(id); + CTChartSpace ctChartSpace = getCTChartSpace(); + CTExternalData externalData = ctChartSpace.isSetExternalData() + ? ctChartSpace.getExternalData() + : ctChartSpace.addNewExternalData(); + externalData.setId(id); } /** diff --git a/src/ooxml/testcases/org/apache/poi/xddf/usermodel/chart/TestXDDFChart.java b/src/ooxml/testcases/org/apache/poi/xddf/usermodel/chart/TestXDDFChart.java index 6d345991f4..fe838bbe77 100644 --- a/src/ooxml/testcases/org/apache/poi/xddf/usermodel/chart/TestXDDFChart.java +++ b/src/ooxml/testcases/org/apache/poi/xddf/usermodel/chart/TestXDDFChart.java @@ -21,13 +21,34 @@ package org.apache.poi.xddf.usermodel.chart; import org.apache.poi.ooxml.POIXMLFactory; import org.apache.poi.ooxml.POIXMLRelation; import org.junit.Test; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTChartSpace; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; public class TestXDDFChart { @Test public void testConstruct() { // minimal test to cause ooxml-lite to include all the classes in poi-ooxml-schemas + XDDFChart xddfChart = newXDDFChart(); + + assertNotNull(xddfChart.getCTChartSpace()); + assertNotNull(xddfChart.getCTPlotArea()); + } + + @Test + public void testSetExternalId() { + XDDFChart xddfChart = newXDDFChart(); + CTChartSpace ctChartSpace = xddfChart.getCTChartSpace(); + + xddfChart.setExternalId("rid1"); + assertEquals("rid1", ctChartSpace.getExternalData().getId()); + + xddfChart.setExternalId("rid2"); + assertEquals("rid2", ctChartSpace.getExternalData().getId()); + } + + private XDDFChart newXDDFChart() { XDDFChart xddfChart = new XDDFChart() { @Override protected POIXMLRelation getChartRelation() { @@ -44,7 +65,6 @@ public class TestXDDFChart { return null; } }; - - assertNotNull(xddfChart.getCTPlotArea()); + return xddfChart; } } \ No newline at end of file -- 2.39.5