]> source.dussan.org Git - poi.git/commitdiff
Add a disabled test for bug #51850, and tweak the OPC package exceptions to make...
authorNick Burch <nick@apache.org>
Thu, 22 Sep 2011 10:26:33 +0000 (10:26 +0000)
committerNick Burch <nick@apache.org>
Thu, 22 Sep 2011 10:26:33 +0000 (10:26 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1174045 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/openxml4j/exceptions/InvalidOperationException.java
src/ooxml/java/org/apache/poi/openxml4j/exceptions/PartAlreadyExistsException.java [new file with mode: 0644]
src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java
src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
test-data/spreadsheet/51850.xlsx [new file with mode: 0644]

index 814edd1179979121b1cefdf079b929067c93557a..a2538a6d1932c0a974289fd41f9c2a97bc13c091 100644 (file)
@@ -19,13 +19,9 @@ package org.apache.poi.openxml4j.exceptions;
 
 /**
  * Throw when an invalid operation is done.
- *
- * @author Julien Chable
- * @version 1.0
  */
 @SuppressWarnings("serial")
-public final class InvalidOperationException extends OpenXML4JRuntimeException{
-
+public class InvalidOperationException extends OpenXML4JRuntimeException{
        public InvalidOperationException(String message){
                super(message);
        }
diff --git a/src/ooxml/java/org/apache/poi/openxml4j/exceptions/PartAlreadyExistsException.java b/src/ooxml/java/org/apache/poi/openxml4j/exceptions/PartAlreadyExistsException.java
new file mode 100644 (file)
index 0000000..e469ace
--- /dev/null
@@ -0,0 +1,31 @@
+/* ====================================================================
+   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.openxml4j.exceptions;
+
+import org.apache.poi.openxml4j.opc.PackagePart;
+
+/**
+ * Throw when trying to create a {@link PackagePart} but one
+ *  already exists with that name.
+ */
+@SuppressWarnings("serial")
+public final class PartAlreadyExistsException extends InvalidOperationException {
+       public PartAlreadyExistsException(String message){
+               super(message);
+       }
+}
index 6ec685cb4e43be1b8fb7f28ec213bac100581461..541700a136bb67997c21b023eac69b1ee3285f43 100644 (file)
@@ -40,6 +40,7 @@ import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
 import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
 import org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException;
+import org.apache.poi.openxml4j.exceptions.PartAlreadyExistsException;
 import org.apache.poi.openxml4j.opc.internal.ContentType;
 import org.apache.poi.openxml4j.opc.internal.ContentTypeManager;
 import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart;
@@ -716,7 +717,7 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
                // Check if the specified part name already exists
                if (partList.containsKey(partName)
                                && !partList.get(partName).isDeleted()) {
-                       throw new InvalidOperationException(
+                       throw new PartAlreadyExistsException(
                                        "A part with the name '"
                                                        + partName.getName()
                                                        + "' already exists : Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]");
index 446e0ecea760f9b3203c8c5c08edae1a0951853d..803fdf0142bc24dc26ec6f3d77e7050989ce3f72 100644 (file)
@@ -37,15 +37,14 @@ import org.apache.poi.util.Internal;
 import org.apache.poi.xssf.model.CommentsTable;
 import org.apache.xmlbeans.XmlException;
 import org.apache.xmlbeans.XmlOptions;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps;
 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.spreadsheetDrawing.CTGraphicalObjectFrame;
 import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
 
 /**
index e3c54f367e533bc8249cf80ff07a79aae41bf570..a39edd3a6258ad58e787bf96aedcd71c2620097a 100644 (file)
 
 package org.apache.poi.openxml4j.opc.compliance;
 
-import java.io.File;
 import java.io.IOException;
 
 import junit.framework.TestCase;
 
+import org.apache.poi.POIDataSamples;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
+import org.apache.poi.openxml4j.exceptions.PartAlreadyExistsException;
 import org.apache.poi.openxml4j.opc.ContentTypes;
 import org.apache.poi.openxml4j.opc.OPCPackage;
 import org.apache.poi.openxml4j.opc.PackagePartName;
 import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
 import org.apache.poi.openxml4j.opc.PackagingURIHelper;
 import org.apache.poi.openxml4j.opc.TargetMode;
-import org.apache.poi.POIDataSamples;
 
 /**
  * Test Open Packaging Convention package model compliance.
@@ -102,7 +102,7 @@ public class TestOPCCompliancePackageModel extends TestCase {
                pkg.createPart(name1, ContentTypes.XML);
                try {
                        pkg.createPart(name2, ContentTypes.XML);
-               } catch (InvalidOperationException e) {
+               } catch (PartAlreadyExistsException e) {
                        return;
                }
                fail("Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]");
index 364e4120d65456622d9d74d9308fba0ceac89590..045e043fc65169367c51228a75be66506a125d4d 100644 (file)
@@ -23,7 +23,6 @@ import java.util.List;
 
 import org.apache.poi.POIXMLDocumentPart;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.util.PaneInformation;
 import org.apache.poi.openxml4j.opc.OPCPackage;
 import org.apache.poi.openxml4j.opc.PackagePart;
 import org.apache.poi.openxml4j.opc.PackagingURIHelper;
@@ -31,7 +30,11 @@ import org.apache.poi.ss.usermodel.BaseTestBugzillaIssues;
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.CellStyle;
 import org.apache.poi.ss.usermodel.CellValue;
+import org.apache.poi.ss.usermodel.ClientAnchor;
+import org.apache.poi.ss.usermodel.Comment;
+import org.apache.poi.ss.usermodel.CreationHelper;
 import org.apache.poi.ss.usermodel.DataFormatter;
+import org.apache.poi.ss.usermodel.Drawing;
 import org.apache.poi.ss.usermodel.Font;
 import org.apache.poi.ss.usermodel.FormulaError;
 import org.apache.poi.ss.usermodel.FormulaEvaluator;
@@ -1169,4 +1172,38 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
 
         assertEquals(rels0.get(0).getPackageRelationship(), rels1.get(0).getPackageRelationship());
     }
+    
+    /**
+     * Add comments to Sheet 1, when Sheet 2 already has
+     *  comments (so /xl/comments1.xml is taken)
+     */
+    public void DISABLEDtest51850() {
+       XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("51850.xlsx");
+       XSSFSheet sh1 = wb.getSheetAt(0);
+       XSSFSheet sh2 = wb.getSheetAt(1);
+       // Sheet 2 has comments
+       assertNotNull(sh2.getCommentsTable(false));
+       
+       // Sheet 1 doesn't (yet)
+       assertNull(sh1.getCommentsTable(false));
+       
+       // Try to add comments to Sheet 1
+       CreationHelper factory = wb.getCreationHelper();
+       Drawing drawing = sh1.createDrawingPatriarch();
+
+       ClientAnchor anchor = factory.createClientAnchor();
+       anchor.setCol1(0);
+       anchor.setCol2(4);
+       anchor.setRow1(0);
+       anchor.setRow2(1);
+
+       Comment excelComment = drawing.createCellComment(anchor);
+       excelComment.setString(
+             factory.createRichTextString("I like this cell. It's my favourite."));
+       excelComment.setAuthor("Bob T. Fish");
+
+       Cell c = sh1.getRow(0).getCell(4);
+       c.setCellComment(excelComment);
+    }
 }
diff --git a/test-data/spreadsheet/51850.xlsx b/test-data/spreadsheet/51850.xlsx
new file mode 100644 (file)
index 0000000..c04129a
Binary files /dev/null and b/test-data/spreadsheet/51850.xlsx differ