You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TestXSSFVMLDrawing.java 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.xssf.usermodel;
  16. import java.io.ByteArrayOutputStream;
  17. import java.io.ByteArrayInputStream;
  18. import java.math.BigInteger;
  19. import java.util.List;
  20. import junit.framework.TestCase;
  21. import org.apache.poi.POIDataSamples;
  22. import org.apache.xmlbeans.XmlObject;
  23. import schemasMicrosoftComVml.*;
  24. import schemasMicrosoftComOfficeOffice.CTShapeLayout;
  25. import schemasMicrosoftComOfficeOffice.STConnectType;
  26. import schemasMicrosoftComOfficeOffice.STInsetMode;
  27. import schemasMicrosoftComOfficeExcel.CTClientData;
  28. import schemasMicrosoftComOfficeExcel.STObjectType;
  29. /**
  30. * @author Yegor Kozlov
  31. */
  32. public class TestXSSFVMLDrawing extends TestCase {
  33. public void testNew() throws Exception {
  34. XSSFVMLDrawing vml = new XSSFVMLDrawing();
  35. List<XmlObject> items = vml.getItems();
  36. assertEquals(2, items.size());
  37. assertTrue(items.get(0) instanceof CTShapeLayout);
  38. CTShapeLayout layout = (CTShapeLayout)items.get(0);
  39. assertEquals(STExt.EDIT, layout.getExt());
  40. assertEquals(STExt.EDIT, layout.getIdmap().getExt());
  41. assertEquals("1", layout.getIdmap().getData());
  42. assertTrue(items.get(1) instanceof CTShapetype);
  43. CTShapetype type = (CTShapetype)items.get(1);
  44. assertEquals("21600,21600", type.getCoordsize());
  45. assertEquals(202.0f, type.getSpt());
  46. assertEquals("m,l,21600r21600,l21600,xe", type.getPath2());
  47. assertEquals("_xssf_cell_comment", type.getId());
  48. assertEquals(STTrueFalse.T, type.getPathArray(0).getGradientshapeok());
  49. assertEquals(STConnectType.RECT, type.getPathArray(0).getConnecttype());
  50. CTShape shape = vml.newCommentShape();
  51. assertEquals(3, items.size());
  52. assertSame(items.get(2), shape);
  53. assertEquals("#_xssf_cell_comment", shape.getType());
  54. assertEquals("position:absolute; visibility:hidden", shape.getStyle());
  55. assertEquals("#ffffe1", shape.getFillcolor());
  56. assertEquals(STInsetMode.AUTO, shape.getInsetmode());
  57. assertEquals("#ffffe1", shape.getFillArray(0).getColor());
  58. CTShadow shadow = shape.getShadowArray(0);
  59. assertEquals(STTrueFalse.T, shadow.getOn());
  60. assertEquals("black", shadow.getColor());
  61. assertEquals(STTrueFalse.T, shadow.getObscured());
  62. assertEquals(STConnectType.NONE, shape.getPathArray(0).getConnecttype());
  63. assertEquals("mso-direction-alt:auto", shape.getTextboxArray(0).getStyle());
  64. CTClientData cldata = shape.getClientDataArray(0);
  65. assertEquals(STObjectType.NOTE, cldata.getObjectType());
  66. assertEquals(1, cldata.sizeOfMoveWithCellsArray());
  67. assertEquals(1, cldata.sizeOfSizeWithCellsArray());
  68. assertEquals("1, 15, 0, 2, 3, 15, 3, 16", cldata.getAnchorArray(0));
  69. assertEquals("False", cldata.getAutoFillArray(0).toString());
  70. assertEquals(0, cldata.getRowArray(0).intValue());
  71. assertEquals(0, cldata.getColumnArray(0).intValue());
  72. //serialize and read again
  73. ByteArrayOutputStream out = new ByteArrayOutputStream();
  74. vml.write(out);
  75. XSSFVMLDrawing vml2 = new XSSFVMLDrawing();
  76. vml2.read(new ByteArrayInputStream(out.toByteArray()));
  77. List<XmlObject> items2 = vml2.getItems();
  78. assertEquals(3, items2.size());
  79. assertTrue(items2.get(0) instanceof CTShapeLayout);
  80. assertTrue(items2.get(1) instanceof CTShapetype);
  81. assertTrue(items2.get(2) instanceof CTShape);
  82. }
  83. public void testFindCommentShape() throws Exception {
  84. XSSFVMLDrawing vml = new XSSFVMLDrawing();
  85. vml.read(POIDataSamples.getSpreadSheetInstance().openResourceAsStream("vmlDrawing1.vml"));
  86. CTShape sh_a1 = vml.findCommentShape(0, 0);
  87. assertNotNull(sh_a1);
  88. assertEquals("_x0000_s1025", sh_a1.getId());
  89. CTShape sh_b1 = vml.findCommentShape(0, 1);
  90. assertNotNull(sh_b1);
  91. assertEquals("_x0000_s1026", sh_b1.getId());
  92. CTShape sh_c1 = vml.findCommentShape(0, 2);
  93. assertNull(sh_c1);
  94. CTShape sh_d1 = vml.newCommentShape();
  95. assertEquals("_x0000_s1027", sh_d1.getId());
  96. sh_d1.getClientDataArray(0).setRowArray(0, new BigInteger("0"));
  97. sh_d1.getClientDataArray(0).setColumnArray(0, new BigInteger("3"));
  98. assertSame(sh_d1, vml.findCommentShape(0, 3));
  99. //newly created drawing
  100. XSSFVMLDrawing newVml = new XSSFVMLDrawing();
  101. assertNull(newVml.findCommentShape(0, 0));
  102. sh_a1 = newVml.newCommentShape();
  103. assertEquals("_x0000_s1025", sh_a1.getId());
  104. sh_a1.getClientDataArray(0).setRowArray(0, new BigInteger("0"));
  105. sh_a1.getClientDataArray(0).setColumnArray(0, new BigInteger("1"));
  106. assertSame(sh_a1, newVml.findCommentShape(0, 1));
  107. }
  108. public void testRemoveCommentShape() throws Exception {
  109. XSSFVMLDrawing vml = new XSSFVMLDrawing();
  110. vml.read(POIDataSamples.getSpreadSheetInstance().openResourceAsStream("vmlDrawing1.vml"));
  111. CTShape sh_a1 = vml.findCommentShape(0, 0);
  112. assertNotNull(sh_a1);
  113. assertTrue(vml.removeCommentShape(0, 0));
  114. assertNull(vml.findCommentShape(0, 0));
  115. }
  116. }