You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ab...@apache.org on 2017/11/26 14:03:03 UTC
svn commit: r1816383 [3/5] - in /poi/trunk: ./
src/examples/src/org/apache/poi/xslf/usermodel/
src/examples/src/org/apache/poi/xssf/usermodel/examples/
src/java/org/apache/poi/hssf/usermodel/
src/java/org/apache/poi/ss/usermodel/ src/java/org/apache/po...
Added: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLayout.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLayout.java?rev=1816383&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLayout.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLayout.java Sun Nov 26 14:03:01 2017
@@ -0,0 +1,73 @@
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.xddf.usermodel.chart;
+
+import org.apache.poi.util.Beta;
+import org.apache.poi.util.Internal;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTLayout;
+
+@Beta
+public class XDDFLayout {
+ private CTLayout layout;
+
+ public XDDFLayout() {
+ this(CTLayout.Factory.newInstance());
+ }
+
+ @Internal
+ protected XDDFLayout(CTLayout layout) {
+ this.layout = layout;
+ }
+
+ @Internal
+ protected CTLayout getXmlObject() {
+ return layout;
+ }
+
+ public void setExtensionList(XDDFChartExtensionList list) {
+ if (list == null) {
+ layout.unsetExtLst();
+ } else {
+ layout.setExtLst(list.getXmlObject());
+ }
+ }
+
+ public XDDFChartExtensionList getExtensionList() {
+ if (layout.isSetExtLst()) {
+ return new XDDFChartExtensionList(layout.getExtLst());
+ } else {
+ return null;
+ }
+ }
+
+ public void setManualLayout(XDDFManualLayout manual) {
+ if (manual == null) {
+ layout.unsetManualLayout();
+ } else {
+ layout.setManualLayout(manual.getXmlObject());
+ }
+ }
+
+ public XDDFManualLayout getManualLayout() {
+ if (layout.isSetManualLayout()) {
+ return new XDDFManualLayout(layout);
+ } else {
+ return null;
+ }
+ }
+}
Added: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLegendEntry.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLegendEntry.java?rev=1816383&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLegendEntry.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLegendEntry.java Sun Nov 26 14:03:01 2017
@@ -0,0 +1,98 @@
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.xddf.usermodel.chart;
+
+import org.apache.poi.util.Beta;
+import org.apache.poi.util.Internal;
+import org.apache.poi.xddf.usermodel.text.XDDFTextBody;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTLegendEntry;
+
+@Beta
+public class XDDFLegendEntry {
+ private CTLegendEntry entry;
+
+ @Internal
+ protected XDDFLegendEntry(CTLegendEntry entry) {
+ this.entry = entry;
+ }
+
+ @Internal
+ protected CTLegendEntry getXmlObject() {
+ return entry;
+ }
+
+ public XDDFTextBody getTextBody() {
+ if (entry.isSetTxPr()) {
+ return new XDDFTextBody(entry.getTxPr());
+ } else {
+ return null;
+ }
+ }
+
+ public void setTextBody(XDDFTextBody body) {
+ if (body == null) {
+ entry.unsetTxPr();
+ } else {
+ entry.setTxPr(body.getXmlObject());
+ }
+ }
+
+ public boolean getDelete() {
+ if (entry.isSetDelete()) {
+ return entry.getDelete().getVal();
+ } else {
+ return false;
+ }
+ }
+
+ public void setDelete(Boolean delete) {
+ if (delete == null) {
+ entry.unsetDelete();
+ } else {
+ if (entry.isSetDelete()) {
+ entry.getDelete().setVal(delete);
+ } else {
+ entry.addNewDelete().setVal(delete);
+ }
+ }
+ }
+
+ public long getIndex() {
+ return entry.getIdx().getVal();
+ }
+
+ public void setIndex(long index) {
+ entry.getIdx().setVal(index);
+ }
+
+ public void setExtensionList(XDDFChartExtensionList list) {
+ if (list == null) {
+ entry.unsetExtLst();
+ } else {
+ entry.setExtLst(list.getXmlObject());
+ }
+ }
+
+ public XDDFChartExtensionList getExtensionList() {
+ if (entry.isSetExtLst()) {
+ return new XDDFChartExtensionList(entry.getExtLst());
+ } else {
+ return null;
+ }
+ }
+}
Added: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLineChartData.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLineChartData.java?rev=1816383&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLineChartData.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLineChartData.java Sun Nov 26 14:03:01 2017
@@ -0,0 +1,141 @@
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.xddf.usermodel.chart;
+
+import java.util.Map;
+
+import org.apache.poi.util.Beta;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTLineChart;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTLineSer;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTMarker;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTSerTx;
+
+@Beta
+public class XDDFLineChartData extends XDDFChartData {
+ private CTLineChart chart;
+
+ public XDDFLineChartData(CTLineChart chart, Map<Long, XDDFChartAxis> categories,
+ Map<Long, XDDFValueAxis> values) {
+ this.chart = chart;
+ for (CTLineSer series : chart.getSerList()) {
+ this.series.add(new Series(series, series.getCat(), series.getVal()));
+ }
+ defineAxes(chart.getAxIdArray(), categories, values);
+ }
+
+ @Override
+ public void setVaryColors(boolean varyColors) {
+ if (chart.isSetVaryColors()) {
+ chart.getVaryColors().setVal(varyColors);
+ } else {
+ chart.addNewVaryColors().setVal(varyColors);
+ }
+ }
+
+ public Grouping getGrouping() {
+ return Grouping.valueOf(chart.getGrouping().getVal());
+ }
+
+ public void setGrouping(Grouping grouping) {
+ chart.getGrouping().setVal(grouping.underlying);
+ }
+
+ @Override
+ public XDDFChartData.Series addSeries(XDDFDataSource<?> category,
+ XDDFNumericalDataSource<? extends Number> values) {
+ final int index = this.series.size();
+ final CTLineSer ctSer = this.chart.addNewSer();
+ ctSer.addNewCat();
+ ctSer.addNewVal();
+ ctSer.addNewIdx().setVal(index);
+ ctSer.addNewOrder().setVal(index);
+ final Series added = new Series(ctSer, category, values);
+ this.series.add(added);
+ return added;
+ }
+
+ public class Series extends XDDFChartData.Series {
+ private CTLineSer series;
+
+ protected Series(CTLineSer series, XDDFDataSource<?> category,
+ XDDFNumericalDataSource<? extends Number> values) {
+ super(category, values);
+ this.series = series;
+ }
+
+ protected Series(CTLineSer series, CTAxDataSource category, CTNumDataSource values) {
+ super(XDDFDataSourcesFactory.fromDataSource(category), XDDFDataSourcesFactory.fromDataSource(values));
+ this.series = series;
+ }
+
+ @Override
+ protected CTSerTx getSeriesText() {
+ return series.getTx();
+ }
+
+ @Override
+ public void setShowLeaderLines(boolean showLeaderLines) {
+ if (!series.isSetDLbls()) {
+ series.addNewDLbls();
+ }
+ if (series.getDLbls().isSetShowLeaderLines()) {
+ series.getDLbls().getShowLeaderLines().setVal(showLeaderLines);
+ } else {
+ series.getDLbls().addNewShowLeaderLines().setVal(showLeaderLines);
+ }
+ }
+
+ public void setMarkerSize(short size) {
+ CTMarker marker = getMarker();
+ if (marker.isSetSize()) {
+ marker.getSize().setVal(size);
+ } else {
+ marker.addNewSize().setVal(size);
+ }
+ }
+
+ public void setMarkerStyle(MarkerStyle style) {
+ CTMarker marker = getMarker();
+ if (marker.isSetSymbol()) {
+ marker.getSymbol().setVal(style.underlying);
+ } else {
+ marker.addNewSymbol().setVal(style.underlying);
+ }
+ }
+
+ private CTMarker getMarker() {
+ if (series.isSetMarker()) {
+ return series.getMarker();
+ } else {
+ return series.addNewMarker();
+ }
+ }
+
+ @Override
+ protected CTAxDataSource getAxDS() {
+ return series.getCat();
+ }
+
+ @Override
+ protected CTNumDataSource getNumDS() {
+ return series.getVal();
+ }
+ }
+}
Added: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFManualLayout.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFManualLayout.java?rev=1816383&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFManualLayout.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFManualLayout.java Sun Nov 26 14:03:01 2017
@@ -0,0 +1,221 @@
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ ==================================================================== */
+
+package org.apache.poi.xddf.usermodel.chart;
+
+import org.apache.poi.util.Beta;
+import org.apache.poi.util.Internal;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTLayout;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTManualLayout;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea;
+
+/**
+ * Represents a DrawingML manual layout.
+ */
+@Beta
+public final class XDDFManualLayout {
+
+ /**
+ * Underlaying CTManualLayout bean.
+ */
+ private CTManualLayout layout;
+
+ private static final LayoutMode defaultLayoutMode = LayoutMode.EDGE;
+ private static final LayoutTarget defaultLayoutTarget = LayoutTarget.INNER;
+
+ /**
+ * Create a new DrawingML manual layout.
+ *
+ * @param ctLayout
+ * a DrawingML layout that should be used as base.
+ */
+ public XDDFManualLayout(CTLayout ctLayout) {
+ initializeLayout(ctLayout);
+ }
+
+ /**
+ * Create a new DrawingML manual layout for chart.
+ *
+ * @param ctPlotArea
+ * a chart's plot area to create layout for.
+ */
+ public XDDFManualLayout(CTPlotArea ctPlotArea) {
+ CTLayout ctLayout = ctPlotArea.isSetLayout() ? ctPlotArea.getLayout() : ctPlotArea.addNewLayout();
+
+ initializeLayout(ctLayout);
+ }
+
+ /**
+ * Return the underlying CTManualLayout bean.
+ *
+ * @return the underlying CTManualLayout bean.
+ */
+ @Internal
+ protected CTManualLayout getXmlObject() {
+ return layout;
+ }
+
+ public void setExtensionList(XDDFChartExtensionList list) {
+ if (list == null) {
+ layout.unsetExtLst();
+ } else {
+ layout.setExtLst(list.getXmlObject());
+ }
+ }
+
+ public XDDFChartExtensionList getExtensionList() {
+ if (layout.isSetExtLst()) {
+ return new XDDFChartExtensionList(layout.getExtLst());
+ } else {
+ return null;
+ }
+ }
+
+ public void setWidthRatio(double ratio) {
+ if (!layout.isSetW()) {
+ layout.addNewW();
+ }
+ layout.getW().setVal(ratio);
+ }
+
+ public double getWidthRatio() {
+ if (!layout.isSetW()) {
+ return 0.0;
+ }
+ return layout.getW().getVal();
+ }
+
+ public void setHeightRatio(double ratio) {
+ if (!layout.isSetH()) {
+ layout.addNewH();
+ }
+ layout.getH().setVal(ratio);
+ }
+
+ public double getHeightRatio() {
+ if (!layout.isSetH()) {
+ return 0.0;
+ }
+ return layout.getH().getVal();
+ }
+
+ public LayoutTarget getTarget() {
+ if (!layout.isSetLayoutTarget()) {
+ return defaultLayoutTarget;
+ }
+ return LayoutTarget.valueOf(layout.getLayoutTarget().getVal());
+ }
+
+ public void setTarget(LayoutTarget target) {
+ if (!layout.isSetLayoutTarget()) {
+ layout.addNewLayoutTarget();
+ }
+ layout.getLayoutTarget().setVal(target.underlying);
+ }
+
+ public LayoutMode getXMode() {
+ if (!layout.isSetXMode()) {
+ return defaultLayoutMode;
+ }
+ return LayoutMode.valueOf(layout.getXMode().getVal());
+ }
+
+ public void setXMode(LayoutMode mode) {
+ if (!layout.isSetXMode()) {
+ layout.addNewXMode();
+ }
+ layout.getXMode().setVal(mode.underlying);
+ }
+
+ public LayoutMode getYMode() {
+ if (!layout.isSetYMode()) {
+ return defaultLayoutMode;
+ }
+ return LayoutMode.valueOf(layout.getYMode().getVal());
+ }
+
+ public void setYMode(LayoutMode mode) {
+ if (!layout.isSetYMode()) {
+ layout.addNewYMode();
+ }
+ layout.getYMode().setVal(mode.underlying);
+ }
+
+ public double getX() {
+ if (!layout.isSetX()) {
+ return 0.0;
+ }
+ return layout.getX().getVal();
+ }
+
+ public void setX(double x) {
+ if (!layout.isSetX()) {
+ layout.addNewX();
+ }
+ layout.getX().setVal(x);
+ }
+
+ public double getY() {
+ if (!layout.isSetY()) {
+ return 0.0;
+ }
+ return layout.getY().getVal();
+ }
+
+ public void setY(double y) {
+ if (!layout.isSetY()) {
+ layout.addNewY();
+ }
+ layout.getY().setVal(y);
+ }
+
+ public LayoutMode getWidthMode() {
+ if (!layout.isSetWMode()) {
+ return defaultLayoutMode;
+ }
+ return LayoutMode.valueOf(layout.getWMode().getVal());
+ }
+
+ public void setWidthMode(LayoutMode mode) {
+ if (!layout.isSetWMode()) {
+ layout.addNewWMode();
+ }
+ layout.getWMode().setVal(mode.underlying);
+ }
+
+ public LayoutMode getHeightMode() {
+ if (!layout.isSetHMode()) {
+ return defaultLayoutMode;
+ }
+ return LayoutMode.valueOf(layout.getHMode().getVal());
+ }
+
+ public void setHeightMode(LayoutMode mode) {
+ if (!layout.isSetHMode()) {
+ layout.addNewHMode();
+ }
+ layout.getHMode().setVal(mode.underlying);
+ }
+
+ private void initializeLayout(CTLayout ctLayout) {
+ if (ctLayout.isSetManualLayout()) {
+ this.layout = ctLayout.getManualLayout();
+ } else {
+ this.layout = ctLayout.addNewManualLayout();
+ }
+ }
+}
Added: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFNumericalDataSource.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFNumericalDataSource.java?rev=1816383&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFNumericalDataSource.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFNumericalDataSource.java Sun Nov 26 14:03:01 2017
@@ -0,0 +1,29 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ */
+
+package org.apache.poi.xddf.usermodel.chart;
+
+import org.apache.poi.util.Beta;
+
+@Beta
+public interface XDDFNumericalDataSource<T extends Number> extends XDDFDataSource<T> {
+ String getFormatCode();
+
+ void setFormatCode(String formatCode);
+}
Added: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFPieChartData.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFPieChartData.java?rev=1816383&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFPieChartData.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFPieChartData.java Sun Nov 26 14:03:01 2017
@@ -0,0 +1,118 @@
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.xddf.usermodel.chart;
+
+import org.apache.poi.util.Beta;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTPieChart;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTPieSer;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTSerTx;
+
+@Beta
+public class XDDFPieChartData extends XDDFChartData {
+ private CTPieChart chart;
+
+ public XDDFPieChartData(CTPieChart chart) {
+ this.chart = chart;
+ for (CTPieSer series : chart.getSerList()) {
+ this.series.add(new Series(series, series.getCat(), series.getVal()));
+ }
+ }
+
+ @Override
+ public void setVaryColors(boolean varyColors) {
+ if (chart.isSetVaryColors()) {
+ chart.getVaryColors().setVal(varyColors);
+ } else {
+ chart.addNewVaryColors().setVal(varyColors);
+ }
+ }
+
+ @Override
+ public XDDFChartData.Series addSeries(XDDFDataSource<?> category,
+ XDDFNumericalDataSource<? extends Number> values) {
+ final int index = this.series.size();
+ final CTPieSer ctSer = this.chart.addNewSer();
+ ctSer.addNewCat();
+ ctSer.addNewVal();
+ ctSer.addNewIdx().setVal(index);
+ ctSer.addNewOrder().setVal(index);
+ final Series added = new Series(ctSer, category, values);
+ this.series.add(added);
+ return added;
+ }
+
+ public class Series extends XDDFChartData.Series {
+ private CTPieSer series;
+
+ protected Series(CTPieSer series, XDDFDataSource<?> category,
+ XDDFNumericalDataSource<? extends Number> values) {
+ super(category, values);
+ this.series = series;
+ }
+
+ protected Series(CTPieSer series, CTAxDataSource category, CTNumDataSource values) {
+ super(XDDFDataSourcesFactory.fromDataSource(category), XDDFDataSourcesFactory.fromDataSource(values));
+ this.series = series;
+ }
+
+ @Override
+ protected CTSerTx getSeriesText() {
+ return series.getTx();
+ }
+
+ @Override
+ public void setShowLeaderLines(boolean showLeaderLines) {
+ if (!series.isSetDLbls()) {
+ series.addNewDLbls();
+ }
+ if (series.getDLbls().isSetShowLeaderLines()) {
+ series.getDLbls().getShowLeaderLines().setVal(showLeaderLines);
+ } else {
+ series.getDLbls().addNewShowLeaderLines().setVal(showLeaderLines);
+ }
+ }
+
+ public long getExplosion() {
+ if (series.isSetExplosion()) {
+ return series.getExplosion().getVal();
+ } else {
+ return 0;
+ }
+ }
+
+ public void setExplosion(long explosion) {
+ if (series.isSetExplosion()) {
+ series.getExplosion().setVal(explosion);
+ } else {
+ series.addNewExplosion().setVal(explosion);
+ }
+ }
+
+ @Override
+ protected CTAxDataSource getAxDS() {
+ return series.getCat();
+ }
+
+ @Override
+ protected CTNumDataSource getNumDS() {
+ return series.getVal();
+ }
+ }
+}
Added: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFRadarChartData.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFRadarChartData.java?rev=1816383&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFRadarChartData.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFRadarChartData.java Sun Nov 26 14:03:01 2017
@@ -0,0 +1,119 @@
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.xddf.usermodel.chart;
+
+import java.util.Map;
+
+import org.apache.poi.util.Beta;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTRadarChart;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTRadarSer;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTRadarStyle;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTSerTx;
+
+@Beta
+public class XDDFRadarChartData extends XDDFChartData {
+ private CTRadarChart chart;
+
+ public XDDFRadarChartData(CTRadarChart chart, Map<Long, XDDFChartAxis> categories,
+ Map<Long, XDDFValueAxis> values) {
+ this.chart = chart;
+ for (CTRadarSer series : chart.getSerList()) {
+ this.series.add(new Series(series, series.getCat(), series.getVal()));
+ }
+ defineAxes(chart.getAxIdArray(), categories, values);
+ }
+
+ @Override
+ public void setVaryColors(boolean varyColors) {
+ if (chart.isSetVaryColors()) {
+ chart.getVaryColors().setVal(varyColors);
+ } else {
+ chart.addNewVaryColors().setVal(varyColors);
+ }
+ }
+
+ public RadarStyle getStyle() {
+ return RadarStyle.valueOf(chart.getRadarStyle().getVal());
+ }
+
+ public void setStyle(RadarStyle style) {
+ CTRadarStyle radarStyle = chart.getRadarStyle();
+ if (radarStyle == null) {
+ radarStyle = chart.addNewRadarStyle();
+ }
+ radarStyle.setVal(style.underlying);
+ }
+
+ @Override
+ public XDDFChartData.Series addSeries(XDDFDataSource<?> category,
+ XDDFNumericalDataSource<? extends Number> values) {
+ final int index = this.series.size();
+ final CTRadarSer ctSer = this.chart.addNewSer();
+ ctSer.addNewCat();
+ ctSer.addNewVal();
+ ctSer.addNewIdx().setVal(index);
+ ctSer.addNewOrder().setVal(index);
+ final Series added = new Series(ctSer, category, values);
+ this.series.add(added);
+ return added;
+ }
+
+ public class Series extends XDDFChartData.Series {
+ private CTRadarSer series;
+
+ protected Series(CTRadarSer series, XDDFDataSource<?> category,
+ XDDFNumericalDataSource<? extends Number> values) {
+ super(category, values);
+ this.series = series;
+ }
+
+ protected Series(CTRadarSer series, CTAxDataSource category, CTNumDataSource values) {
+ super(XDDFDataSourcesFactory.fromDataSource(category), XDDFDataSourcesFactory.fromDataSource(values));
+ this.series = series;
+ }
+
+ @Override
+ protected CTSerTx getSeriesText() {
+ return series.getTx();
+ }
+
+ @Override
+ public void setShowLeaderLines(boolean showLeaderLines) {
+ if (!series.isSetDLbls()) {
+ series.addNewDLbls();
+ }
+ if (series.getDLbls().isSetShowLeaderLines()) {
+ series.getDLbls().getShowLeaderLines().setVal(showLeaderLines);
+ } else {
+ series.getDLbls().addNewShowLeaderLines().setVal(showLeaderLines);
+ }
+ }
+
+ @Override
+ protected CTAxDataSource getAxDS() {
+ return series.getCat();
+ }
+
+ @Override
+ protected CTNumDataSource getNumDS() {
+ return series.getVal();
+ }
+ }
+}
Added: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFScatterChartData.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFScatterChartData.java?rev=1816383&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFScatterChartData.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFScatterChartData.java Sun Nov 26 14:03:01 2017
@@ -0,0 +1,123 @@
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.xddf.usermodel.chart;
+
+import java.util.Map;
+
+import org.apache.poi.util.Beta;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTScatterChart;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTScatterSer;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTScatterStyle;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTSerTx;
+
+@Beta
+public class XDDFScatterChartData extends XDDFChartData {
+ private CTScatterChart chart;
+
+ public XDDFScatterChartData(CTScatterChart chart, Map<Long, XDDFChartAxis> categories,
+ Map<Long, XDDFValueAxis> values) {
+ this.chart = chart;
+ for (CTScatterSer series : chart.getSerList()) {
+ this.series.add(new Series(series, series.getXVal(), series.getYVal()));
+ }
+ defineAxes(chart.getAxIdArray(), categories, values);
+ }
+
+ @Override
+ public void setVaryColors(boolean varyColors) {
+ if (chart.isSetVaryColors()) {
+ chart.getVaryColors().setVal(varyColors);
+ } else {
+ chart.addNewVaryColors().setVal(varyColors);
+ }
+ }
+
+ public ScatterStyle getStyle() {
+ CTScatterStyle scatterStyle = chart.getScatterStyle();
+ if (scatterStyle == null) {
+ scatterStyle = chart.addNewScatterStyle();
+ scatterStyle.setVal(ScatterStyle.LINE_MARKER.underlying);
+ }
+ return ScatterStyle.valueOf(scatterStyle.getVal());
+ }
+
+ public void setStyle(ScatterStyle style) {
+ CTScatterStyle scatterStyle = chart.getScatterStyle();
+ if (scatterStyle == null) {
+ scatterStyle = chart.addNewScatterStyle();
+ }
+ scatterStyle.setVal(style.underlying);
+ }
+
+ @Override
+ public XDDFChartData.Series addSeries(XDDFDataSource<?> category,
+ XDDFNumericalDataSource<? extends Number> values) {
+ final int index = this.series.size();
+ final CTScatterSer ctSer = this.chart.addNewSer();
+ ctSer.addNewXVal();
+ ctSer.addNewYVal();
+ ctSer.addNewIdx().setVal(index);
+ ctSer.addNewOrder().setVal(index);
+ final Series added = new Series(ctSer, category, values);
+ this.series.add(added);
+ return added;
+ }
+
+ public class Series extends XDDFChartData.Series {
+ private CTScatterSer series;
+
+ protected Series(CTScatterSer series, XDDFDataSource<?> category, XDDFNumericalDataSource<?> values) {
+ super(category, values);
+ this.series = series;
+ }
+
+ protected Series(CTScatterSer series, CTAxDataSource category, CTNumDataSource values) {
+ super(XDDFDataSourcesFactory.fromDataSource(category), XDDFDataSourcesFactory.fromDataSource(values));
+ this.series = series;
+ }
+
+ @Override
+ protected CTSerTx getSeriesText() {
+ return series.getTx();
+ }
+
+ @Override
+ public void setShowLeaderLines(boolean showLeaderLines) {
+ if (!series.isSetDLbls()) {
+ series.addNewDLbls();
+ }
+ if (series.getDLbls().isSetShowLeaderLines()) {
+ series.getDLbls().getShowLeaderLines().setVal(showLeaderLines);
+ } else {
+ series.getDLbls().addNewShowLeaderLines().setVal(showLeaderLines);
+ }
+ }
+
+ @Override
+ protected CTAxDataSource getAxDS() {
+ return series.getXVal();
+ }
+
+ @Override
+ protected CTNumDataSource getNumDS() {
+ return series.getYVal();
+ }
+ }
+}
Added: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFValueAxis.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFValueAxis.java?rev=1816383&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFValueAxis.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFValueAxis.java Sun Nov 26 14:03:01 2017
@@ -0,0 +1,153 @@
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.xddf.usermodel.chart;
+
+import org.apache.poi.util.Beta;
+import org.apache.poi.util.Internal;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxPos;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTBoolean;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTCrosses;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumFmt;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTScaling;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTTickMark;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTUnsignedInt;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTValAx;
+import org.openxmlformats.schemas.drawingml.x2006.chart.STTickLblPos;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties;
+
+@Beta
+public class XDDFValueAxis extends XDDFChartAxis {
+
+ private CTValAx ctValAx;
+
+ public XDDFValueAxis(CTPlotArea plotArea, AxisPosition position) {
+ initializeAxis(plotArea, position);
+ }
+
+ public XDDFValueAxis(CTValAx ctValAx) {
+ this.ctValAx = ctValAx;
+ }
+
+ @Override
+ @Internal
+ public CTShapeProperties getMajorGridLines() {
+ if (!ctValAx.isSetMajorGridlines()) {
+ ctValAx.addNewMajorGridlines();
+ }
+ if (!ctValAx.getMajorGridlines().isSetSpPr()) {
+ ctValAx.getMajorGridlines().addNewSpPr();
+ }
+ return ctValAx.getMajorGridlines().getSpPr();
+ }
+
+ @Override
+ @Internal
+ public CTShapeProperties getLine() {
+ return ctValAx.getSpPr();
+ }
+
+ @Override
+ public void crossAxis(XDDFChartAxis axis) {
+ ctValAx.getCrossAx().setVal(axis.getId());
+ }
+
+ @Override
+ protected CTUnsignedInt getCTAxId() {
+ return ctValAx.getAxId();
+ }
+
+ @Override
+ protected CTAxPos getCTAxPos() {
+ return ctValAx.getAxPos();
+ }
+
+ @Override
+ public boolean hasNumberFormat() {
+ return ctValAx.isSetNumFmt();
+ }
+
+ @Override
+ protected CTNumFmt getCTNumFmt() {
+ if (ctValAx.isSetNumFmt()) {
+ return ctValAx.getNumFmt();
+ }
+ return ctValAx.addNewNumFmt();
+ }
+
+ @Override
+ protected CTScaling getCTScaling() {
+ return ctValAx.getScaling();
+ }
+
+ @Override
+ protected CTCrosses getCTCrosses() {
+ CTCrosses crosses = ctValAx.getCrosses();
+ if (crosses == null) {
+ return ctValAx.addNewCrosses();
+ } else {
+ return crosses;
+ }
+ }
+
+ @Override
+ protected CTBoolean getDelete() {
+ return ctValAx.getDelete();
+ }
+
+ @Override
+ protected CTTickMark getMajorCTTickMark() {
+ return ctValAx.getMajorTickMark();
+ }
+
+ @Override
+ protected CTTickMark getMinorCTTickMark() {
+ return ctValAx.getMinorTickMark();
+ }
+
+ public AxisCrossBetween getCrossBetween() {
+ return AxisCrossBetween.valueOf(ctValAx.getCrossBetween().getVal());
+ }
+
+ public void setCrossBetween(AxisCrossBetween crossBetween) {
+ ctValAx.getCrossBetween().setVal(crossBetween.underlying);
+ }
+
+ private void initializeAxis(CTPlotArea plotArea, AxisPosition position) {
+ final long id = getNextAxId(plotArea);
+ ctValAx = plotArea.addNewValAx();
+ ctValAx.addNewAxId().setVal(id);
+ ctValAx.addNewAxPos();
+ ctValAx.addNewScaling();
+ ctValAx.addNewCrossBetween();
+ ctValAx.addNewCrosses();
+ ctValAx.addNewCrossAx();
+ ctValAx.addNewTickLblPos().setVal(STTickLblPos.NEXT_TO);
+ ctValAx.addNewDelete();
+ ctValAx.addNewMajorTickMark();
+ ctValAx.addNewMinorTickMark();
+
+ setPosition(position);
+ setOrientation(AxisOrientation.MIN_MAX);
+ setCrossBetween(AxisCrossBetween.MIDPOINT_CATEGORY);
+ setCrosses(AxisCrosses.AUTO_ZERO);
+ setVisible(true);
+ setMajorTickMark(AxisTickMark.CROSS);
+ setMinorTickMark(AxisTickMark.NONE);
+ }
+}
Copied: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextBody.java (from r1816205, poi/trunk/src/java/org/apache/poi/ss/usermodel/charts/LineChartSeries.java)
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextBody.java?p2=poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextBody.java&p1=poi/trunk/src/java/org/apache/poi/ss/usermodel/charts/LineChartSeries.java&r1=1816205&r2=1816383&rev=1816383&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/charts/LineChartSeries.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextBody.java Sun Nov 26 14:03:01 2017
@@ -15,24 +15,27 @@
limitations under the License.
==================================================================== */
-package org.apache.poi.ss.usermodel.charts;
+package org.apache.poi.xddf.usermodel.text;
import org.apache.poi.util.Beta;
+import org.apache.poi.util.Internal;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody;
-/**
- * Represents a line chart series.
- */
@Beta
-public interface LineChartSeries extends ChartSeries {
-
- /**
- * @return data source used for category axis data.
- */
- ChartDataSource<?> getCategoryAxisData();
-
- /**
- * @return data source used for value axis.
- */
- ChartDataSource<? extends Number> getValues();
+public class XDDFTextBody {
+ private CTTextBody body;
+ public XDDFTextBody() {
+ this(CTTextBody.Factory.newInstance());
+ }
+
+ @Internal
+ public XDDFTextBody(CTTextBody body) {
+ this.body = body;
+ }
+
+ @Internal
+ public CTTextBody getXmlObject() {
+ return body;
+ }
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java?rev=1816383&r1=1816382&r2=1816383&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java Sun Nov 26 14:03:01 2017
@@ -38,6 +38,7 @@ import org.apache.poi.POIXMLException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.apache.poi.sl.usermodel.MasterSheet;
import org.apache.poi.sl.usermodel.PictureData.PictureType;
import org.apache.poi.sl.usermodel.Resources;
@@ -80,6 +81,7 @@ implements SlideShow<XSLFShape,XSLFTextP
private List<XSLFSlide> _slides;
private List<XSLFSlideMaster> _masters;
private List<XSLFPictureData> _pictures;
+ private List<XSLFChart> _charts;
private XSLFTableStyles _tableStyles;
private XSLFNotesMaster _notesMaster;
private XSLFCommentAuthors _commentAuthors;
@@ -93,7 +95,7 @@ implements SlideShow<XSLFShape,XSLFTextP
try {
if(getCorePart().getContentType().equals(XSLFRelation.THEME_MANAGER.getContentType())) {
- rebase(getPackage());
+ rebase(getPackage());
}
//build a tree of POIXMLDocumentParts, this presentation being the root
@@ -130,10 +132,16 @@ implements SlideShow<XSLFShape,XSLFTextP
Map<String, XSLFSlideMaster> masterMap = new HashMap<>();
Map<String, XSLFSlide> shIdMap = new HashMap<>();
+ Map<String, XSLFChart> chartMap = new HashMap<>();
for (RelationPart rp : getRelationParts()) {
POIXMLDocumentPart p = rp.getDocumentPart();
if (p instanceof XSLFSlide) {
shIdMap.put(rp.getRelationship().getId(), (XSLFSlide) p);
+ for (POIXMLDocumentPart c : p.getRelations()) {
+ if (c instanceof XSLFChart) {
+ chartMap.put(c.getPackagePart().getPartName().getName(), (XSLFChart) c);
+ }
+ }
} else if (p instanceof XSLFSlideMaster) {
masterMap.put(getRelationId(p), (XSLFSlideMaster) p);
} else if (p instanceof XSLFTableStyles){
@@ -145,6 +153,11 @@ implements SlideShow<XSLFShape,XSLFTextP
}
}
+ _charts = new ArrayList<>(chartMap.size());
+ for(XSLFChart chart : chartMap.values()) {
+ _charts.add(chart);
+ }
+
_masters = new ArrayList<>(masterMap.size());
for (CTSlideMasterIdListEntry masterId : _presentation.getSldMasterIdLst().getSldMasterIdList()) {
XSLFSlideMaster master = masterMap.get(masterId.getId2());
@@ -208,6 +221,7 @@ implements SlideShow<XSLFShape,XSLFTextP
public XSLFSlide createSlide(XSLFSlideLayout layout) {
int slideNumber = 256, cnt = 1;
CTSlideIdList slideList;
+ XSLFRelation relationType = XSLFRelation.SLIDE;
if (!_presentation.isSetSldIdLst()) {
slideList = _presentation.addNewSldIdLst();
} else {
@@ -217,35 +231,11 @@ implements SlideShow<XSLFShape,XSLFTextP
cnt++;
}
- // Bug 55791: We also need to check that the resulting file name is not already taken
- // this can happen when removing/adding slides
- while(true) {
- String slideName = XSLFRelation.SLIDE.getFileName(cnt);
- boolean found = false;
- for (POIXMLDocumentPart relation : getRelations()) {
- if (relation.getPackagePart() != null &&
- slideName.equals(relation.getPackagePart().getPartName().getName())) {
- // name is taken => try next one
- found = true;
- break;
- }
- }
-
- if(!found &&
- getPackage().getPartsByName(Pattern.compile(Pattern.quote(slideName))).size() > 0) {
- // name is taken => try next one
- found = true;
- }
-
- if (!found) {
- break;
- }
- cnt++;
- }
+ cnt = findNextAvailableFileNameIndex(relationType, cnt);
}
- RelationPart rp = createRelationship(
- XSLFRelation.SLIDE, XSLFFactory.getInstance(), cnt, false);
+ RelationPart rp = createRelationship
+ (relationType, XSLFFactory.getInstance(), cnt, false);
XSLFSlide slide = rp.getDocumentPart();
CTSlideIdListEntry slideId = slideList.addNewSldId();
@@ -260,6 +250,35 @@ implements SlideShow<XSLFShape,XSLFTextP
return slide;
}
+ private int findNextAvailableFileNameIndex(XSLFRelation relationType, int idx) {
+ // Bug 55791: We also need to check that the resulting file name is not already taken
+ // this can happen when removing/adding slides, notes or charts
+ while(true) {
+ String fileName = relationType.getFileName(idx);
+ boolean found = false;
+ for (POIXMLDocumentPart relation : getRelations()) {
+ if (relation.getPackagePart() != null &&
+ fileName.equals(relation.getPackagePart().getPartName().getName())) {
+ // name is taken => try next one
+ found = true;
+ break;
+ }
+ }
+
+ if(!found &&
+ getPackage().getPartsByName(Pattern.compile(Pattern.quote(fileName))).size() > 0) {
+ // name is taken => try next one
+ found = true;
+ }
+
+ if (!found) {
+ break;
+ }
+ idx++;
+ }
+ return idx;
+ }
+
/**
* Create a blank slide using the default (first) master.
*/
@@ -275,11 +294,28 @@ implements SlideShow<XSLFShape,XSLFTextP
}
layout = sl[0];
}
-
+
return createSlide(layout);
}
/**
+ * Create a blank chart on the given slide.
+ */
+ public XSLFChart createChart(XSLFSlide slide) {
+ int chartIdx = findNextAvailableFileNameIndex(XSLFRelation.CHART, _charts.size() + 1);
+ XSLFChart chart = (XSLFChart) createRelationship(XSLFRelation.CHART, XSLFFactory.getInstance(), chartIdx, true).getDocumentPart();
+ slide.addRelation(null, XSLFRelation.CHART, chart);
+ createWorkbookRelationship(chart, chartIdx);
+ _charts.add(chart);
+ return chart;
+ }
+
+ protected PackageRelationship createWorkbookRelationship(XSLFChart chart, int chartIdx) {
+ POIXMLDocumentPart worksheet = createRelationship(XSLFChart.WORKBOOK_RELATIONSHIP, XSLFFactory.getInstance(), chartIdx, true).getDocumentPart();
+ return chart.addRelation(null, XSLFChart.WORKBOOK_RELATIONSHIP, worksheet).getRelationship();
+ }
+
+ /**
* Return notes slide for the specified slide or create new if it does not exist yet.
*/
public XSLFNotes getNotesSlide(XSLFSlide slide) {
@@ -301,39 +337,16 @@ implements SlideShow<XSLFShape,XSLFTextP
createNotesMaster();
}
- Integer slideIndex = XSLFRelation.SLIDE.getFileNameIndex(slide);
+ int slideIndex = XSLFRelation.SLIDE.getFileNameIndex(slide);
- // Bug 55791: We also need to check that the resulting file name is not already taken
- // this can happen when removing/adding slides
- while(true) {
- String slideName = XSLFRelation.NOTES.getFileName(slideIndex);
- boolean found = false;
- for (POIXMLDocumentPart relation : getRelations()) {
- if (relation.getPackagePart() != null &&
- slideName.equals(relation.getPackagePart().getPartName().getName())) {
- // name is taken => try next one
- found = true;
- break;
- }
- }
-
- if(!found &&
- getPackage().getPartsByName(Pattern.compile(Pattern.quote(slideName))).size() > 0) {
- // name is taken => try next one
- found = true;
- }
-
- if (!found) {
- break;
- }
- slideIndex++;
- }
+ XSLFRelation relationType = XSLFRelation.NOTES;
+ slideIndex = findNextAvailableFileNameIndex(relationType, slideIndex);
// add notes slide to presentation
XSLFNotes notesSlide = (XSLFNotes) createRelationship
- (XSLFRelation.NOTES, XSLFFactory.getInstance(), slideIndex);
+ (relationType, XSLFFactory.getInstance(), slideIndex);
// link slide and notes slide with each other
- slide.addRelation(null, XSLFRelation.NOTES, notesSlide);
+ slide.addRelation(null, relationType, notesSlide);
notesSlide.addRelation(null, XSLFRelation.NOTES_MASTER, _notesMaster);
notesSlide.addRelation(null, XSLFRelation.SLIDE, slide);
@@ -405,6 +418,13 @@ implements SlideShow<XSLFShape,XSLFTextP
}
/**
+ * Return all the charts in the slideshow
+ */
+ public List<XSLFChart> getCharts() {
+ return _charts;
+ }
+
+ /**
* Returns the list of comment authors, if there is one.
* Will only be present if at least one slide has comments on it.
*/
@@ -444,7 +464,17 @@ implements SlideShow<XSLFShape,XSLFTextP
public XSLFSlide removeSlide(int index){
XSLFSlide slide = _slides.remove(index);
removeRelation(slide);
- _presentation.getSldIdLst().removeSldId(index);
+ _presentation.getSldIdLst().removeSldId(index);
+ for (POIXMLDocumentPart p : slide.getRelations()) {
+ if (p instanceof XSLFChart) {
+ XSLFChart chart = (XSLFChart) p;
+ slide.removeChartRelation(chart);
+ _charts.remove(chart);
+ } else if (p instanceof XSLFSlideLayout) {
+ XSLFSlideLayout layout = (XSLFSlideLayout) p;
+ slide.removeLayoutRelation(layout);
+ }
+ }
return slide;
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFChart.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFChart.java?rev=1816383&r1=1816382&r2=1816383&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFChart.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFChart.java Sun Nov 26 14:03:01 2017
@@ -26,15 +26,28 @@ import java.io.OutputStream;
import javax.xml.namespace.QName;
+import org.apache.poi.POIXMLDocument;
import org.apache.poi.POIXMLDocumentPart;
+import org.apache.poi.POIXMLException;
+import org.apache.poi.POIXMLRelation;
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException;
import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.ss.util.CellReference;
import org.apache.poi.util.Beta;
-import org.apache.poi.util.Internal;
+import org.apache.poi.xddf.usermodel.chart.XDDFChart;
+import org.apache.poi.xddf.usermodel.chart.XDDFChartData;
+import org.apache.poi.xddf.usermodel.chart.XDDFDataSource;
+import org.apache.poi.xddf.usermodel.chart.XDDFNumericalDataSource;
+import org.apache.poi.xssf.usermodel.XSSFRow;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlOptions;
-import org.openxmlformats.schemas.drawingml.x2006.chart.CTChart;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTChartSpace;
-import org.openxmlformats.schemas.drawingml.x2006.chart.ChartSpaceDocument;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody;
/**
* Represents a Chart in a .pptx presentation
@@ -42,63 +55,173 @@ import org.openxmlformats.schemas.drawin
*
*/
@Beta
-public final class XSLFChart extends POIXMLDocumentPart {
+public final class XSLFChart extends XDDFChart {
+ protected static final POIXMLRelation WORKBOOK_RELATIONSHIP = new POIXMLRelation(
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
+ POIXMLDocument.PACK_OBJECT_REL_TYPE,
+ "/ppt/embeddings/Microsoft_Excel_Worksheet#.xlsx",
+ XSSFWorkbook.class
+ ){};
- /**
- * Root element of the Chart part
- */
- private CTChartSpace chartSpace;
/**
- * The Chart within that
- */
- private CTChart chart;
+ * Underlying workbook
+ */
+ private XSSFWorkbook workbook;
+
+
+ /**
+ * Construct a PresentationML chart.
+ */
+ protected XSLFChart() {
+ super();
+ }
/**
- * Construct a chart from a package part.
+ * Construct a PresentationML chart from a package part.
*
* @param part the package part holding the chart data,
* the content type must be <code>application/vnd.openxmlformats-officedocument.drawingml.chart+xml</code>
- *
+ *
* @since POI 3.14-Beta1
*/
protected XSLFChart(PackagePart part) throws IOException, XmlException {
super(part);
+ }
- chartSpace = ChartSpaceDocument.Factory.parse(part.getInputStream(), DEFAULT_XML_OPTIONS).getChartSpace();
- chart = chartSpace.getChart();
+ public XSLFTextShape getTitle() {
+ if (!chart.isSetTitle()) {
+ chart.addNewTitle();
+ }
+ final CTTitle title = chart.getTitle();
+ if (title.getTx() != null && title.getTx().isSetRich()) {
+ return new XSLFTextShape(title, null) {
+ @Override
+ protected CTTextBody getTextBody(boolean create) {
+ return title.getTx().getRich();
+ }
+ };
+ } else {
+ return new XSLFTextShape(title, null) {
+ @Override
+ protected CTTextBody getTextBody(boolean create) {
+ return title.getTxPr();
+ }
+ };
+ }
}
- /**
- * Return the underlying CTChartSpace bean, the root element of the Chart part.
- *
- * @return the underlying CTChartSpace bean
- */
- @Internal
- public CTChartSpace getCTChartSpace(){
- return chartSpace;
- }
-
- /**
- * Return the underlying CTChart bean, within the Chart Space
- *
- * @return the underlying CTChart bean
- */
- @Internal
- public CTChart getCTChart(){
- return chart;
- }
-
- @Override
- protected void commit() throws IOException {
- XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
- xmlOptions.setSaveSyntheticDocumentElement(new QName(CTChartSpace.type.getName().getNamespaceURI(), "chartSpace", "c"));
-
- PackagePart part = getPackagePart();
- OutputStream out = part.getOutputStream();
- chartSpace.save(out, xmlOptions);
- out.close();
- }
+ public CellReference setSheetTitle(String title) {
+ XSSFSheet sheet = getSheet();
+ sheet.createRow(0).createCell(1).setCellValue(title);
+ return new CellReference(sheet.getSheetName(), 0, 1, true, true);
+ }
+
+ public String formatRange(CellRangeAddress range) {
+ return range.formatAsString(getSheet().getSheetName(), true);
+ }
+ private XSSFSheet getSheet() {
+ XSSFSheet sheet = null;
+ try {
+ sheet = getWorkbook().getSheetAt(0);
+ } catch (InvalidFormatException ife) {
+ } catch (IOException ioe) {
+ }
+ return sheet;
+ }
+ private PackagePart getWorksheetPart() throws InvalidFormatException {
+ for (RelationPart part : getRelationParts()) {
+ if (WORKBOOK_RELATIONSHIP.getRelation().equals(part.getRelationship().getRelationshipType())) {
+ return getTargetPart(part.getRelationship());
+ }
+ }
+ return null;
+ }
+
+ protected XSSFWorkbook getWorkbook() throws IOException, InvalidFormatException {
+ if (workbook == null) {
+ try {
+ PackagePart worksheetPart = getWorksheetPart();
+ if (worksheetPart == null) {
+ workbook = new XSSFWorkbook();
+ workbook.createSheet();
+ } else {
+ workbook = new XSSFWorkbook(worksheetPart.getInputStream());
+ }
+ } catch (NotOfficeXmlFileException e) {
+ workbook = new XSSFWorkbook();
+ workbook.createSheet();
+ }
+ }
+ return workbook;
+ }
+
+ private XMLSlideShow getSlideShow() {
+ POIXMLDocumentPart p = getParent();
+ while(p != null) {
+ if(p instanceof XMLSlideShow){
+ return (XMLSlideShow)p;
+ }
+ p = p.getParent();
+ }
+ throw new IllegalStateException("SlideShow was not found");
+ }
+
+ private PackagePart createWorksheetPart() throws InvalidFormatException {
+ Integer chartIdx = XSLFRelation.CHART.getFileNameIndex(this);
+ return getTargetPart(getSlideShow().createWorkbookRelationship(this, chartIdx));
+ }
+
+ protected void saveWorkbook(XSSFWorkbook workbook) throws IOException, InvalidFormatException {
+ PackagePart worksheetPart = getWorksheetPart();
+ if (worksheetPart == null) {
+ worksheetPart = createWorksheetPart();
+ }
+ try (OutputStream xlsOut = worksheetPart.getOutputStream()) {
+ workbook.write(xlsOut);
+ }
+ }
+
+ private void fillSheet(XSSFSheet sheet, XDDFDataSource<?> categoryData, XDDFNumericalDataSource<?> valuesData) {
+ int numOfPoints = categoryData.getPointCount();
+ for (int i = 0; i < numOfPoints; i++) {
+ XSSFRow row = sheet.createRow(i + 1); // first row is for title
+ row.createCell(0).setCellValue(categoryData.getPointAt(i).toString());
+ row.createCell(1).setCellValue(valuesData.getPointAt(i).doubleValue());
+ }
+ }
+
+ @Override
+ public void plot(XDDFChartData data) {
+ super.plot(data);
+ XSSFSheet sheet = getSheet();
+ for(XDDFChartData.Series series : data.getSeries()) {
+ fillSheet(sheet, series.getCategoryData(), series.getValuesData());
+ }
+ }
+
+ public void importContent(XSLFChart other) {
+ this.chart.set(other.chart);
+ }
+
+ @Override
+ protected void commit() throws IOException {
+ XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
+ xmlOptions.setSaveSyntheticDocumentElement(new QName(CTChartSpace.type.getName().getNamespaceURI(), "chartSpace", "c"));
+
+ if (workbook != null) {
+ try {
+ saveWorkbook(workbook);
+ } catch (InvalidFormatException e) {
+ throw new POIXMLException(e);
+ }
+ }
+
+ PackagePart part = getPackagePart();
+ try (OutputStream out = part.getOutputStream()) {
+ chartSpace.save(out, xmlOptions);
+ }
+ }
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java?rev=1816383&r1=1816382&r2=1816383&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java Sun Nov 26 14:03:01 2017
@@ -20,6 +20,7 @@
package org.apache.poi.xslf.usermodel;
import java.awt.geom.Rectangle2D;
+import java.io.IOException;
import javax.xml.namespace.QName;
@@ -102,6 +103,7 @@ public class XSLFGraphicFrame extends XS
*
* @param theta the rotation angle in degrees.
*/
+ @Override
public void setRotation(double theta){
throw new IllegalArgumentException("Operation not supported");
}
@@ -115,15 +117,18 @@ public class XSLFGraphicFrame extends XS
*
* @return rotation angle in degrees
*/
- public double getRotation(){
+ @Override
+ public double getRotation(){
return 0;
}
- public void setFlipHorizontal(boolean flip){
+ @Override
+ public void setFlipHorizontal(boolean flip){
throw new IllegalArgumentException("Operation not supported");
}
- public void setFlipVertical(boolean flip){
+ @Override
+ public void setFlipVertical(boolean flip){
throw new IllegalArgumentException("Operation not supported");
}
@@ -132,11 +137,13 @@ public class XSLFGraphicFrame extends XS
*
* @return whether the shape is horizontally flipped
*/
- public boolean getFlipHorizontal(){
+ @Override
+ public boolean getFlipHorizontal(){
return false;
}
- public boolean getFlipVertical(){
+ @Override
+ public boolean getFlipVertical(){
return false;
}
@@ -148,12 +155,39 @@ public class XSLFGraphicFrame extends XS
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")){
+ copyChart(data, (XSLFGraphicFrame)sh);
} else {
// TODO support other types of objects
}
}
+ 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";
+ XmlObject[] obj = objData.selectPath(xpath);
+ if (obj != null && obj.length == 1) {
+ XmlCursor c = obj[0].newCursor();
+ try {
+ // duplicate chart with embedded workbook
+ QName idQualifiedName = new QName("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "id");
+ String id = c.getAttributeText(idQualifiedName);
+ XSLFChart srcChart = (XSLFChart) src.getRelationById(id);
+ XSLFChart chartCopy = slide.getSlideShow().createChart(slide);
+ chartCopy.importContent(srcChart);
+ chartCopy.saveWorkbook(srcChart.getWorkbook());
+ c.setAttributeText(idQualifiedName, slide.getRelationId(chartCopy));
+ } catch (InvalidFormatException e) {
+ throw new POIXMLException(e);
+ } catch (IOException e) {
+ throw new POIXMLException(e);
+ }
+ c.dispose();
+ }
+ }
+
// TODO should be moved to a sub-class
private void copyDiagram(CTGraphicalObjectData objData, XSLFGraphicFrame srcShape){
String xpath = "declare namespace dgm='http://schemas.openxmlformats.org/drawingml/2006/diagram' $this//dgm:relIds";
@@ -216,4 +250,4 @@ public class XSLFGraphicFrame extends XS
return new XSLFPictureShape(gs.getPicArray(0), getSheet());
}
-}
\ No newline at end of file
+}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java?rev=1816383&r1=1816382&r2=1816383&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java Sun Nov 26 14:03:01 2017
@@ -57,7 +57,7 @@ import org.openxmlformats.schemas.presen
public abstract class XSLFSheet extends POIXMLDocumentPart
implements XSLFShapeContainer, Sheet<XSLFShape,XSLFTextParagraph> {
private static POILogger LOG = POILogFactory.getLogger(XSLFSheet.class);
-
+
private XSLFDrawing _drawing;
private List<XSLFShape> _shapes;
private CTGroupShape _spTree;
@@ -69,13 +69,13 @@ implements XSLFShapeContainer, Sheet<XSL
public XSLFSheet() {
super();
}
-
+
/**
* @since POI 3.14-Beta1
*/
public XSLFSheet(PackagePart part) {
super(part);
- }
+ }
/**
* @return the XMLSlideShow this sheet belongs to
@@ -155,7 +155,7 @@ implements XSLFShapeContainer, Sheet<XSL
initDrawingAndShapes();
return _shapes;
}
-
+
/**
* Helper method for initializing drawing and shapes in one go.
* If they are initialized separately, there's a risk that shapes
@@ -255,7 +255,7 @@ implements XSLFShapeContainer, Sheet<XSL
return sh;
}
-
+
/**
* Returns an iterator over the shapes in this sheet
*
@@ -272,7 +272,7 @@ implements XSLFShapeContainer, Sheet<XSL
"Adding a shape from a different container is not supported -"
+ " create it from scratch witht XSLFSheet.create* methods");
}
-
+
/**
* Removes the specified shape from this sheet, if it is present
* (optional operation). If this sheet does not contain the element,
@@ -356,28 +356,35 @@ implements XSLFShapeContainer, Sheet<XSL
* @return modified 'this'
*/
public XSLFSheet importContent(XSLFSheet src){
- _shapes = null;
- _spTree = null;
- _drawing = null;
_spTree = null;
- _placeholders = null;
- // fix-me: wth would this ever happen to work ...
-
-
// first copy the source xml
- getSpTree().set(src.getSpTree());
+ getSpTree().set(src.getSpTree().copy());
+
+ wipeAndReinitialize(src, 0);
- // recursively update each shape
+ return this;
+ }
+
+ private void wipeAndReinitialize(XSLFSheet src, int offset) {
+ // explicitly initialize drawing and shapes from _spTree
+ _shapes = null;
+ _drawing = null;
+ initDrawingAndShapes();
+
+ // placeholders will be implicitly initialized when requested
+ _placeholders = null;
+
+ // update each shape according to its own additional copy rules
List<XSLFShape> tgtShapes = getShapes();
List<XSLFShape> srcShapes = src.getShapes();
- for(int i = 0; i < tgtShapes.size(); i++){
+ for(int i = 0; i < srcShapes.size(); i++){
XSLFShape s1 = srcShapes.get(i);
- XSLFShape s2 = tgtShapes.get(i);
+ XSLFShape s2 = tgtShapes.get(offset + i);
s2.copy(s1);
}
- return this;
+
}
/**
@@ -387,39 +394,26 @@ implements XSLFShapeContainer, Sheet<XSL
* @return modified <code>this</code>.
*/
public XSLFSheet appendContent(XSLFSheet src){
- CTGroupShape spTree = getSpTree();
int numShapes = getShapes().size();
-
+ CTGroupShape spTree = getSpTree();
CTGroupShape srcTree = src.getSpTree();
+
for(XmlObject ch : srcTree.selectPath("*")){
if(ch instanceof CTShape){ // simple shape
- spTree.addNewSp().set(ch);
+ spTree.addNewSp().set(ch.copy());
} else if (ch instanceof CTGroupShape){
- spTree.addNewGrpSp().set(ch);
+ spTree.addNewGrpSp().set(ch.copy());
} else if (ch instanceof CTConnector){
- spTree.addNewCxnSp().set(ch);
+ spTree.addNewCxnSp().set(ch.copy());
} else if (ch instanceof CTPicture){
- spTree.addNewPic().set(ch);
+ spTree.addNewPic().set(ch.copy());
} else if (ch instanceof CTGraphicalObjectFrame){
- spTree.addNewGraphicFrame().set(ch);
+ spTree.addNewGraphicFrame().set(ch.copy());
}
}
- _shapes = null;
- _spTree = null;
- _drawing = null;
- _spTree = null;
- _placeholders = null;
-
- // recursively update each shape
- List<XSLFShape> tgtShapes = getShapes();
- List<XSLFShape> srcShapes = src.getShapes();
- for(int i = 0; i < srcShapes.size(); i++){
- XSLFShape s1 = srcShapes.get(i);
- XSLFShape s2 = tgtShapes.get(numShapes + i);
+ wipeAndReinitialize(src, numShapes);
- s2.copy(s1);
- }
return this;
}
@@ -430,7 +424,7 @@ implements XSLFShapeContainer, Sheet<XSL
* method and return the corresponding package part.
*/
XSLFTheme getTheme(){
- return null;
+ return null;
}
protected XSLFTextShape getTextShapeByType(Placeholder type){
@@ -574,7 +568,7 @@ implements XSLFShapeContainer, Sheet<XSL
PackagePart pic = pictureData.getPackagePart();
RelationPart rp = addRelation(blipId, XSLFRelation.IMAGES, new XSLFPictureData(pic));
-
+
return rp.getRelationship().getId();
}
@@ -584,13 +578,13 @@ implements XSLFShapeContainer, Sheet<XSL
PackagePart importPart(PackageRelationship srcRel, PackagePart srcPafrt) {
PackagePart destPP = getPackagePart();
PackagePartName srcPPName = srcPafrt.getPartName();
-
+
OPCPackage pkg = destPP.getPackage();
if(pkg.containPart(srcPPName)){
// already exists
return pkg.getPart(srcPPName);
- }
-
+ }
+
destPP.addRelationship(srcPPName, TargetMode.INTERNAL, srcRel.getRelationshipType());
PackagePart part = pkg.createPart(srcPPName, srcPafrt.getContentType());
@@ -605,7 +599,7 @@ implements XSLFShapeContainer, Sheet<XSL
}
return part;
}
-
+
/**
* Helper method for sheet and group shapes
*
@@ -614,4 +608,4 @@ implements XSLFShapeContainer, Sheet<XSL
void removePictureRelation(XSLFPictureShape pictureShape) {
removeRelation(pictureShape.getBlipId());
}
-}
\ No newline at end of file
+}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java?rev=1816383&r1=1816382&r2=1816383&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java Sun Nov 26 14:03:01 2017
@@ -49,10 +49,10 @@ import org.xml.sax.SAXException;
@Beta
public final class XSLFSlide extends XSLFSheet
implements Slide<XSLFShape,XSLFTextParagraph> {
- private final CTSlide _slide;
- private XSLFSlideLayout _layout;
- private XSLFComments _comments;
- private XSLFNotes _notes;
+ private final CTSlide _slide;
+ private XSLFSlideLayout _layout;
+ private XSLFComments _comments;
+ private XSLFNotes _notes;
/**
* Create a new slide
@@ -67,7 +67,7 @@ implements Slide<XSLFShape,XSLFTextParag
*
* @param part the package part holding the slide data,
* the content type must be <code>application/vnd.openxmlformats-officedocument.slide+xml</code>
- *
+ *
* @since POI 3.14-Beta1
*/
XSLFSlide(PackagePart part) throws IOException, XmlException {
@@ -79,11 +79,11 @@ implements Slide<XSLFShape,XSLFTextParag
} catch (SAXException e) {
throw new IOException(e);
}
-
+
SldDocument doc = SldDocument.Factory.parse(_doc, DEFAULT_XML_OPTIONS);
_slide = doc.getSld();
}
-
+
private static CTSlide prototype(){
CTSlide ctSlide = CTSlide.Factory.newInstance();
CTCommonSlideData cSld = ctSlide.addNewCSld();
@@ -115,13 +115,21 @@ implements Slide<XSLFShape,XSLFTextParag
}
@Override
- public CTSlide getXmlObject() {
- return _slide;
- }
+ public CTSlide getXmlObject() {
+ return _slide;
+ }
@Override
protected String getRootElementName(){
- return "sld";
+ return "sld";
+ }
+
+ protected void removeChartRelation(XSLFChart chart) {
+ removeRelation(chart);
+ }
+
+ protected void removeLayoutRelation(XSLFSlideLayout layout) {
+ removeRelation(layout, false);
}
@Override
@@ -131,9 +139,9 @@ implements Slide<XSLFShape,XSLFTextParag
public XSLFSlideLayout getSlideLayout(){
if(_layout == null){
- for (POIXMLDocumentPart p : getRelations()) {
+ for (POIXMLDocumentPart p : getRelations()) {
if (p instanceof XSLFSlideLayout){
- _layout = (XSLFSlideLayout)p;
+ _layout = (XSLFSlideLayout)p;
}
}
}
@@ -148,36 +156,36 @@ implements Slide<XSLFShape,XSLFTextParag
}
public XSLFComments getComments() {
- if(_comments == null) {
- for (POIXMLDocumentPart p : getRelations()) {
- if (p instanceof XSLFComments) {
- _comments = (XSLFComments)p;
- }
- }
- }
- if(_comments == null) {
- // This slide lacks comments
- // Not all have them, sorry...
- return null;
- }
- return _comments;
+ if(_comments == null) {
+ for (POIXMLDocumentPart p : getRelations()) {
+ if (p instanceof XSLFComments) {
+ _comments = (XSLFComments)p;
+ }
+ }
+ }
+ if(_comments == null) {
+ // This slide lacks comments
+ // Not all have them, sorry...
+ return null;
+ }
+ return _comments;
}
@Override
public XSLFNotes getNotes() {
- if(_notes == null) {
- for (POIXMLDocumentPart p : getRelations()) {
- if (p instanceof XSLFNotes){
- _notes = (XSLFNotes)p;
- }
- }
- }
- if(_notes == null) {
- // This slide lacks notes
- // Not all have them, sorry...
- return null;
- }
- return _notes;
+ if(_notes == null) {
+ for (POIXMLDocumentPart p : getRelations()) {
+ if (p instanceof XSLFNotes){
+ _notes = (XSLFNotes)p;
+ }
+ }
+ }
+ if(_notes == null) {
+ // This slide lacks notes
+ // Not all have them, sorry...
+ return null;
+ }
+ return _notes;
}
@Override
@@ -185,10 +193,10 @@ implements Slide<XSLFShape,XSLFTextParag
XSLFTextShape txt = getTextShapeByType(Placeholder.TITLE);
return txt == null ? null : txt.getText();
}
-
+
@Override
public XSLFTheme getTheme(){
- return getSlideLayout().getSlideMaster().getTheme();
+ return getSlideLayout().getSlideMaster().getTheme();
}
/**
@@ -241,7 +249,7 @@ implements Slide<XSLFShape,XSLFTextParag
if (bgOther == null) {
return this;
}
-
+
CTBackground bgThis = _slide.getCSld().getBg();
// remove existing background
if (bgThis != null) {
@@ -251,14 +259,14 @@ implements Slide<XSLFShape,XSLFTextParag
}
_slide.getCSld().unsetBg();
}
-
+
bgThis = (CTBackground)_slide.getCSld().addNewBg().set(bgOther);
-
+
if(bgOther.isSetBgPr() && bgOther.getBgPr().isSetBlipFill()){
String idOther = bgOther.getBgPr().getBlipFill().getBlip().getEmbed();
String idThis = importBlip(idOther, src.getPackagePart());
bgThis.getBgPr().getBlipFill().getBlip().setEmbed(idThis);
-
+
}
return this;
@@ -294,7 +302,7 @@ implements Slide<XSLFShape,XSLFTextParag
assert(notes instanceof XSLFNotes);
// TODO Auto-generated method stub
}
-
+
@Override
public int getSlideNumber() {
int idx = getSlideShow().getSlides().indexOf(this);
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFDrawing.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFDrawing.java?rev=1816383&r1=1816382&r2=1816383&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFDrawing.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFDrawing.java Sun Nov 26 14:03:01 2017
@@ -19,7 +19,6 @@ package org.apache.poi.xssf.streaming;
import java.util.Iterator;
-import org.apache.poi.ss.usermodel.Chart;
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.ss.usermodel.Comment;
import org.apache.poi.ss.usermodel.Drawing;
@@ -54,11 +53,6 @@ public class SXSSFDrawing implements Dra
}
@Override
- public Chart createChart(ClientAnchor anchor) {
- return _drawing.createChart(anchor);
- }
-
- @Override
public ClientAnchor createAnchor(int dx1, int dy1, int dx2, int dy2, int col1, int row1, int col2, int row2) {
return _drawing.createAnchor(dx1, dy1, dx2, dy2, col1, row1, col2, row2);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org