aboutsummaryrefslogtreecommitdiffstats
path: root/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java
diff options
context:
space:
mode:
authorYegor Kozlov <yegor@apache.org>2011-12-07 08:49:09 +0000
committerYegor Kozlov <yegor@apache.org>2011-12-07 08:49:09 +0000
commitfc4c8d077ecb24cb6702f1b7792adb3d40455459 (patch)
treed548bb5a831e562b4dadbb04ba8cd9c88336e4c8 /src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java
parent6ea60a0623f99bfe3e836ac2a993ec43a83aa82a (diff)
downloadpoi-fc4c8d077ecb24cb6702f1b7792adb3d40455459.tar.gz
poi-fc4c8d077ecb24cb6702f1b7792adb3d40455459.zip
Bugzilla 52268 - support cloning sheets with drawings in XSSF
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1211339 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java')
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java45
1 files changed, 26 insertions, 19 deletions
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java
index 0c13db8ffc..72794b6eff 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java
@@ -36,15 +36,10 @@ import org.apache.poi.ss.usermodel.Drawing;
import org.apache.poi.util.Internal;
import org.apache.poi.xssf.model.CommentsTable;
import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;
-import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTConnector;
-import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTDrawing;
-import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGraphicalObjectFrame;
-import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGroupShape;
-import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTPicture;
-import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape;
-import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor;
-import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.STEditAs;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps;
+import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.*;
import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
/**
@@ -57,7 +52,6 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing {
* Root element of the SpreadsheetML Drawing part
*/
private CTDrawing drawing;
- private boolean isNew;
private long numOfGraphicFrames = 0L;
protected static final String NAMESPACE_A = "http://schemas.openxmlformats.org/drawingml/2006/main";
@@ -71,7 +65,6 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing {
protected XSSFDrawing() {
super();
drawing = newDrawing();
- isNew = true;
}
/**
@@ -84,8 +77,10 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing {
*/
protected XSSFDrawing(PackagePart part, PackageRelationship rel) throws IOException, XmlException {
super(part, rel);
- drawing = CTDrawing.Factory.parse(part.getInputStream());
- isNew = false;
+ XmlOptions options = new XmlOptions(DEFAULT_XML_OPTIONS);
+ //Removing root element
+ options.setLoadReplaceDocumentElement(null);
+ drawing = CTDrawing.Factory.parse(part.getInputStream(),options);
}
/**
@@ -117,13 +112,9 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing {
xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"
xmlns:xdr="http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing">
*/
- if(isNew) {
- // Have it wrapped in a <xdr:wsDr> tag
- xmlOptions.setSaveSyntheticDocumentElement(
- new QName(CTDrawing.type.getName().getNamespaceURI(), "wsDr", "xdr")
- );
- isNew = false;
- }
+ xmlOptions.setSaveSyntheticDocumentElement(
+ new QName(CTDrawing.type.getName().getNamespaceURI(), "wsDr", "xdr")
+ );
Map<String, String> map = new HashMap<String, String>();
map.put(NAMESPACE_A, "a");
map.put(STRelationshipId.type.getName().getNamespaceURI(), "r");
@@ -372,4 +363,20 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing {
private long newShapeId(){
return drawing.sizeOfTwoCellAnchorArray() + 1;
}
+
+ /**
+ *
+ * @return list of shapes in this drawing
+ */
+ public List<XSSFShape> getShapes(){
+ List<XSSFShape> lst = new ArrayList<XSSFShape>();
+ for(XmlObject obj : drawing.selectPath("./*/*")) {
+ if(obj instanceof CTPicture) lst.add(new XSSFPicture(this, (CTPicture)obj)) ;
+ else if(obj instanceof CTConnector) lst.add(new XSSFConnector(this, (CTConnector)obj)) ;
+ else if(obj instanceof CTShape) lst.add(new XSSFSimpleShape(this, (CTShape)obj)) ;
+ else if(obj instanceof CTGraphicalObjectFrame) lst.add(new XSSFGraphicFrame(this, (CTGraphicalObjectFrame)obj)) ;
+ else if(obj instanceof CTGroupShape) lst.add(new XSSFShapeGroup(this, (CTGroupShape)obj)) ;
+ }
+ return lst;
+ }
}