]> source.dussan.org Git - poi.git/commitdiff
refactor code that removes parts
authorPJ Fanning <fanningpj@apache.org>
Fri, 19 Apr 2024 14:12:13 +0000 (14:12 +0000)
committerPJ Fanning <fanningpj@apache.org>
Fri, 19 Apr 2024 14:12:13 +0000 (14:12 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1917154 13f79535-47bb-0310-9956-ffa450edef68

poi-ooxml/src/main/java/org/apache/poi/ooxml/ReferenceRelationship.java
poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/OPCPackage.java
poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/PackageRelationship.java
poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/ZipPackage.java

index 12dce49502bc11ec04405608fd09806b638ddfa8..dd9fbe8b99887342bb796cb736af6e79dbecfac9 100644 (file)
@@ -47,7 +47,7 @@ public abstract class ReferenceRelationship {
 \r
     protected ReferenceRelationship(POIXMLDocumentPart container, URI targetUri, boolean isExternal, String relationshipType, String id) {\r
         if (targetUri == null) {\r
-            throw new IllegalArgumentException("targetUri");\r
+            throw new NullPointerException("targetUri cannot be null");\r
         }\r
 \r
         this.container = container;\r
index 6c8ceeac24a6dd66d54f55e43fd3791dd44f4875..e15284806d7f951e50b66c96132546a6874107db 100644 (file)
@@ -1025,7 +1025,6 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
         if (this.partList.containsKey(partName)) {
             this.partList.get(partName).setDeleted(true);
             this.removePartImpl(partName);
-            this.partList.remove(partName);
         } else {
             this.removePartImpl(partName);
         }
@@ -1551,8 +1550,16 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
      *
      * @param partName
      *            The URI of the part to delete.
+     * @throws IllegalArgumentException if the partName is null.
+     * @throws InvalidOperationException if the package is in read-only mode.
      */
-    protected abstract void removePartImpl(PackagePartName partName);
+    protected void removePartImpl(PackagePartName partName) {
+        if (partName == null) {
+            throw new IllegalArgumentException("partName cannot be null");
+        }
+        throwExceptionIfReadOnly();
+        this.partList.remove(partName);
+    }
 
     /**
      * Flush the package but not save.
index 417f3899d92e2eaf0bf671ba11a98eaa6fed4cb3..96764718bedd7df8dfb5344875c889cee6b0edc5 100644 (file)
@@ -85,18 +85,20 @@ public final class PackageRelationship {
 
     /**
      * Constructor.
+     *
+     * @throws NullPointerException if inputs are null
      */
     public PackageRelationship(OPCPackage pkg, PackagePart sourcePart,
             URI targetUri, TargetMode targetMode, String relationshipType,
             String id) {
         if (pkg == null)
-            throw new IllegalArgumentException("pkg");
+            throw new NullPointerException("pkg cannot be null");
         if (targetUri == null)
-            throw new IllegalArgumentException("targetUri");
+            throw new NullPointerException("targetUri cannot be null");
         if (relationshipType == null)
-            throw new IllegalArgumentException("relationshipType");
+            throw new NullPointerException("relationshipType cannot be null");
         if (id == null)
-            throw new IllegalArgumentException("id");
+            throw new NullPointerException("id cannot be null");
 
         this.container = pkg;
         this.source = sourcePart;
index cc650df58856c2f1b6107d3144ce2ce1f3fe964b..46b3fd3b7f823f59272884f42ae707314b233d5d 100644 (file)
@@ -401,11 +401,11 @@ public final class ZipPackage extends OPCPackage {
     protected PackagePart createPartImpl(PackagePartName partName,
             String contentType, boolean loadRelationships) {
         if (contentType == null) {
-            throw new IllegalArgumentException("contentType");
+            throw new IllegalArgumentException("contentType cannot be null");
         }
 
         if (partName == null) {
-            throw new IllegalArgumentException("partName");
+            throw new IllegalArgumentException("partName cannot be null");
         }
 
         try {
@@ -424,19 +424,6 @@ public final class ZipPackage extends OPCPackage {
         }
     }
 
-    /**
-     * Delete a part from the package
-     *
-     * @throws IllegalArgumentException
-     *             Throws if the part URI is null or invalid.
-     */
-    @Override
-    protected void removePartImpl(PackagePartName partName) {
-        if (partName == null) {
-            throw new IllegalArgumentException("partUri");
-        }
-    }
-
     /**
      * Flush the package. Do nothing.
      */