mirror of https://github.com/apache/poi.git
[bug-65678] add XSLFGraphicFrame hasDiagram
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894962 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
530af684b3
commit
20c0ac1637
|
@ -51,6 +51,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape;
|
||||||
@Beta
|
@Beta
|
||||||
public class XSLFGraphicFrame extends XSLFShape implements GraphicalFrame<XSLFShape, XSLFTextParagraph> {
|
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 String DRAWINGML_CHART_URI = "http://schemas.openxmlformats.org/drawingml/2006/chart";
|
||||||
|
private static final String DRAWINGML_DIAGRAM_URI = "http://schemas.openxmlformats.org/drawingml/2006/diagram";
|
||||||
private static final Logger LOG = LogManager.getLogger(XSLFGraphicFrame.class);
|
private static final Logger LOG = LogManager.getLogger(XSLFGraphicFrame.class);
|
||||||
|
|
||||||
/*package*/ XSLFGraphicFrame(CTGraphicalObjectFrame shape, XSLFSheet sheet){
|
/*package*/ XSLFGraphicFrame(CTGraphicalObjectFrame shape, XSLFSheet sheet){
|
||||||
|
@ -169,6 +170,14 @@ public class XSLFGraphicFrame extends XSLFShape implements GraphicalFrame<XSLFSh
|
||||||
return uri.equals(DRAWINGML_CHART_URI);
|
return uri.equals(DRAWINGML_CHART_URI);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since POI 5.2.0
|
||||||
|
*/
|
||||||
|
public boolean hasDiagram() {
|
||||||
|
String uri = getGraphicalData().getUri();
|
||||||
|
return uri.equals(DRAWINGML_DIAGRAM_URI);
|
||||||
|
}
|
||||||
|
|
||||||
private CTGraphicalObjectData getGraphicalData() {
|
private CTGraphicalObjectData getGraphicalData() {
|
||||||
return ((CTGraphicalObjectFrame)getXmlObject()).getGraphic().getGraphicData();
|
return ((CTGraphicalObjectFrame)getXmlObject()).getGraphic().getGraphicData();
|
||||||
}
|
}
|
||||||
|
@ -200,7 +209,7 @@ public class XSLFGraphicFrame extends XSLFShape implements GraphicalFrame<XSLFSh
|
||||||
|
|
||||||
CTGraphicalObjectData data = getGraphicalData();
|
CTGraphicalObjectData data = getGraphicalData();
|
||||||
String uri = data.getUri();
|
String uri = data.getUri();
|
||||||
if(uri.equals("http://schemas.openxmlformats.org/drawingml/2006/diagram")){
|
if(uri.equals(DRAWINGML_DIAGRAM_URI)){
|
||||||
copyDiagram(data, (XSLFGraphicFrame)sh);
|
copyDiagram(data, (XSLFGraphicFrame)sh);
|
||||||
} if(uri.equals(DRAWINGML_CHART_URI)){
|
} if(uri.equals(DRAWINGML_CHART_URI)){
|
||||||
copyChart(data, (XSLFGraphicFrame)sh);
|
copyChart(data, (XSLFGraphicFrame)sh);
|
||||||
|
@ -235,9 +244,9 @@ public class XSLFGraphicFrame extends XSLFShape implements GraphicalFrame<XSLFSh
|
||||||
|
|
||||||
// TODO should be moved to a sub-class
|
// TODO should be moved to a sub-class
|
||||||
private void copyDiagram(CTGraphicalObjectData objData, XSLFGraphicFrame srcShape){
|
private void copyDiagram(CTGraphicalObjectData objData, XSLFGraphicFrame srcShape){
|
||||||
String xpath = "declare namespace dgm='http://schemas.openxmlformats.org/drawingml/2006/diagram' $this//dgm:relIds";
|
String xpath = "declare namespace dgm='" + DRAWINGML_DIAGRAM_URI + "' $this//dgm:relIds";
|
||||||
XmlObject[] obj = objData.selectPath(xpath);
|
XmlObject[] obj = objData.selectPath(xpath);
|
||||||
if(obj != null && obj.length == 1){
|
if(obj != null && obj.length == 1) {
|
||||||
XmlCursor c = obj[0].newCursor();
|
XmlCursor c = obj[0].newCursor();
|
||||||
|
|
||||||
XSLFSheet sheet = srcShape.getSheet();
|
XSLFSheet sheet = srcShape.getSheet();
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
/* ====================================================================
|
||||||
|
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.xslf.usermodel;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
import static org.apache.poi.xslf.XSLFTestDataSamples.openSampleDocument;
|
||||||
|
|
||||||
|
class TestXSLFGraphicFrame {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testHasDiagram() throws IOException {
|
||||||
|
try (XMLSlideShow ppt = openSampleDocument("SmartArt.pptx")) {
|
||||||
|
XSLFSlide slide = ppt.getSlides().get(0);
|
||||||
|
XSLFGraphicFrame gf = (XSLFGraphicFrame) slide.getShapes().get(0);
|
||||||
|
|
||||||
|
assertTrue(gf.hasDiagram());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,6 +27,6 @@
|
||||||
|
|
||||||
|
|
||||||
java.lang.System#gc() @ Please do not try to stop the world
|
java.lang.System#gc() @ Please do not try to stop the world
|
||||||
java.lang.Throwable#printStackTrace() @ Please use POILogger for exceptions
|
java.lang.Throwable#printStackTrace() @ Please use Log4J 2.x for exceptions
|
||||||
java.lang.Throwable#printStackTrace(java.io.PrintStream) @ Please use POILogger for exceptions
|
java.lang.Throwable#printStackTrace(java.io.PrintStream) @ Please use Log4J 2.x for exceptions
|
||||||
java.lang.Throwable#printStackTrace(java.io.PrintWriter) @ Please use POILogger for exceptions
|
java.lang.Throwable#printStackTrace(java.io.PrintWriter) @ Please use Log4J 2.x for exceptions
|
Binary file not shown.
Loading…
Reference in New Issue