From fc6029fca4ce7944fbdbd02b9d6f01a3fa8ece56 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Wed, 5 Oct 2011 22:13:52 +0000 Subject: [PATCH] Add a bit more XSSFDrawing testing, not all of which works properly yet... git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1179461 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xssf/usermodel/XSSFDrawing.java | 9 +++++++- .../poi/xssf/usermodel/TestXSSFDrawing.java | 22 ++++++++++++++++++- 2 files changed, 29 insertions(+), 2 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 803fdf0142..0c13db8ffc 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java @@ -85,6 +85,7 @@ 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; } /** @@ -116,7 +117,13 @@ 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) xmlOptions.setSaveSyntheticDocumentElement(new QName(CTDrawing.type.getName().getNamespaceURI(), "wsDr", "xdr")); + if(isNew) { + // Have it wrapped in a tag + xmlOptions.setSaveSyntheticDocumentElement( + new QName(CTDrawing.type.getName().getNamespaceURI(), "wsDr", "xdr") + ); + isNew = false; + } Map map = new HashMap(); map.put(NAMESPACE_A, "a"); map.put(STRelationshipId.type.getName().getNamespaceURI(), "r"); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java index 03f491d390..2ce1bf2793 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java @@ -23,6 +23,7 @@ import junit.framework.TestCase; import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.xssf.XSSFTestDataSamples; +import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTDrawing; /** * @author Yegor Kozlov @@ -44,7 +45,6 @@ public class TestXSSFDrawing extends TestCase { //there should be a relation to this drawing in the worksheet assertTrue(sheet.getCTWorksheet().isSetDrawing()); assertEquals(drawingId, sheet.getCTWorksheet().getDrawing().getId()); - } public void testNew(){ @@ -85,7 +85,27 @@ public class TestXSSFDrawing extends TestCase { c4.setText(rt); c4.setNoFill(true); + + + // Save and re-load it + wb = XSSFTestDataSamples.writeOutAndReadBack(wb); + sheet = wb.getSheetAt(0); + + // Check + dr1 = sheet.createDrawingPatriarch(); + CTDrawing ctDrawing = dr1.getCTDrawing(); + + // Connector, shapes and text boxes are all two cell anchors + assertEquals(0, ctDrawing.sizeOfAbsoluteAnchorArray()); + assertEquals(0, ctDrawing.sizeOfOneCellAnchorArray()); + // TODO Fix this! +// assertEquals(4, ctDrawing.sizeOfTwoCellAnchorArray()); + + // Ensure it got the right namespaces + String xml = ctDrawing.toString(); + assertEquals("