|
|
|
|
|
|
|
|
@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){ |
|
|
|
|
|
|
|
|
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(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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(); |