]> source.dussan.org Git - poi.git/commitdiff
Fix various IDE warnings and some JavaDoc adjustments
authorDominik Stadler <centic@apache.org>
Wed, 26 Dec 2018 13:28:10 +0000 (13:28 +0000)
committerDominik Stadler <centic@apache.org>
Wed, 26 Dec 2018 13:28:10 +0000 (13:28 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1849763 13f79535-47bb-0310-9956-ffa450edef68

13 files changed:
src/java/org/apache/poi/ss/formula/functions/Complex.java
src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java
src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePartName.java
src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationship.java
src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java
src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java
src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ContentType.java
src/ooxml/java/org/apache/poi/openxml4j/opc/internal/FileHelper.java
src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PartUnmarshaller.java
src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestContentType.java
src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestFileHelper.java
src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java
src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug47563.java

index 2282247a5983c35e494c990068e278b27afe9f44..b616eba7a78d6268a4922e1c3bd93197bafeb986 100644 (file)
@@ -72,7 +72,7 @@ public class Complex extends Var2or3ArgFunction implements FreeRefFunction {
         } catch (EvaluationException e) {
             return e.getErrorEval();
         }
-        double realNum = 0;
+        double realNum;
         try {
             realNum = OperandResolver.coerceValueToDouble(veText1);
         } catch (EvaluationException e) {
@@ -85,7 +85,7 @@ public class Complex extends Var2or3ArgFunction implements FreeRefFunction {
         } catch (EvaluationException e) {
             return e.getErrorEval();
         }
-        double realINum = 0;
+        double realINum;
         try {
             realINum = OperandResolver.coerceValueToDouble(veINum);
         } catch (EvaluationException e) {
@@ -104,7 +104,7 @@ public class Complex extends Var2or3ArgFunction implements FreeRefFunction {
             return ErrorEval.VALUE_INVALID;
         }
 
-        StringBuffer strb = new StringBuffer("");
+        StringBuilder strb = new StringBuilder();
         if (realNum != 0) {
             if (isDoubleAnInt(realNum)) {
                 strb.append((int)realNum);
index 767abc239dec91a2f8aedf4b217d88fab1083843..1a4bef5939ceaccdf4092ed95fcba3018f52017f 100644 (file)
@@ -293,6 +293,8 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
         * @return A PackageBase object
         *
         * @throws InvalidFormatException
+        *                              Throws if the specified file exist and is not valid.
+        * @throws IOException If reading the stream fails
         */
        public static OPCPackage open(InputStream in) throws InvalidFormatException,
                        IOException {
@@ -1466,14 +1468,8 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
                }
                
                // Do the save
-               FileOutputStream fos = null;
-               try {
-                       fos = new FileOutputStream(targetFile);
+               try (FileOutputStream fos = new FileOutputStream(targetFile)) {
                        this.save(fos);
-               } finally {
-                       if (fos != null) {
-                fos.close();
-            }
                }
        }
 
index baee7e2abd804920b38a8034177dd6ba038a02b7..8bcfb33e92481119c604f921b893979b26fe48f2 100644 (file)
@@ -161,7 +161,7 @@ public final class PackagePartName implements Comparable<PackagePartName> {
         *
         * @param partUri
         *            The part name to check.
-        * @throws Exception
+        * @throws InvalidFormatException
         *             Throws if the part name is invalid.
         */
        private static void throwExceptionIfInvalidPartUri(URI partUri)
@@ -513,7 +513,7 @@ public final class PackagePartName implements Comparable<PackagePartName> {
      * (lexigraphical sort)
      *
      * @param str1 first string to compare
-     * @param str1 second string to compare
+     * @param str2 second string to compare
      * @return a negative integer, zero, or a positive integer as the first argument is less than,
      *         equal to, or greater than the second.
      */
index 174f2f901b7775f5b29750066d5b629a6f3f45d3..9f82d512fa0885f0c0d132e546006b9e96cbffed 100644 (file)
@@ -210,18 +210,11 @@ public final class PackageRelationship {
 
        @Override
        public String toString() {
-               StringBuilder sb = new StringBuilder();
-               sb.append(id == null ? "id=null" : "id=" + id);
-               sb.append(container == null ? " - container=null" : " - container="
-                               + container);
-               sb.append(relationshipType == null ? " - relationshipType=null"
-                               : " - relationshipType=" + relationshipType);
-               sb.append(source == null ? " - source=null" : " - source="
-                               + getSourceURI().toASCIIString());
-               sb.append(targetUri == null ? " - target=null" : " - target="
-                               + getTargetURI().toASCIIString());
-               sb.append(targetMode == null ? ",targetMode=null" : ",targetMode="
-                               + targetMode);
-               return sb.toString();
+               return (id == null ? "id=null" : "id=" + id) +
+                               (container == null ? " - container=null" : " - container=" + container) +
+                               (relationshipType == null ? " - relationshipType=null" : " - relationshipType=" + relationshipType) +
+                               (source == null ? " - source=null" : " - source=" + getSourceURI().toASCIIString()) +
+                               (targetUri == null ? " - target=null" : " - target=" + getTargetURI().toASCIIString()) +
+                               (targetMode == null ? ",targetMode=null" : ",targetMode=" + targetMode);
        }
 }
index 5a8db38ff0a79b1c72ae9829eff74dbc51f20a94..b5da3d9bcb726fb1de33131fa761d34ccd2f6017 100644 (file)
@@ -48,32 +48,32 @@ public final class PackagingURIHelper {
        /**
         * Extension name of a relationship part.
         */
-       public static final String RELATIONSHIP_PART_EXTENSION_NAME;
+       public static final String RELATIONSHIP_PART_EXTENSION_NAME = ".rels";
 
        /**
         * Segment name of a relationship part.
         */
-       public static final String RELATIONSHIP_PART_SEGMENT_NAME;
+       public static final String RELATIONSHIP_PART_SEGMENT_NAME = "_rels";
 
        /**
         * Segment name of the package properties folder.
         */
-       public static final String PACKAGE_PROPERTIES_SEGMENT_NAME;
+       public static final String PACKAGE_PROPERTIES_SEGMENT_NAME = "docProps";
 
        /**
         * Core package properties art name.
         */
-       public static final String PACKAGE_CORE_PROPERTIES_NAME;
+       public static final String PACKAGE_CORE_PROPERTIES_NAME = "core.xml";
 
        /**
         * Forward slash URI separator.
         */
-       public static final char FORWARD_SLASH_CHAR;
+       public static final char FORWARD_SLASH_CHAR = '/';
 
        /**
         * Forward slash URI separator.
         */
-       public static final String FORWARD_SLASH_STRING;
+       public static final String FORWARD_SLASH_STRING = "/";
 
        /**
         * Package relationships part URI
@@ -107,13 +107,6 @@ public final class PackagingURIHelper {
 
        /* Static initialization */
        static {
-               RELATIONSHIP_PART_SEGMENT_NAME = "_rels";
-               RELATIONSHIP_PART_EXTENSION_NAME = ".rels";
-               FORWARD_SLASH_CHAR = '/';
-               FORWARD_SLASH_STRING = "/";
-               PACKAGE_PROPERTIES_SEGMENT_NAME = "docProps";
-               PACKAGE_CORE_PROPERTIES_NAME = "core.xml";
-
                // Make URI
                URI uriPACKAGE_ROOT_URI = null;
                URI uriPACKAGE_RELATIONSHIPS_ROOT_URI = null;
index ecec63ce9f12b51a42449d0a78e5e5e40afaa0d3..f31808f69703ea715c50f4b0d3fa0fe500261ecd 100644 (file)
@@ -94,7 +94,7 @@ public final class ZipPackage extends OPCPackage {
      * @param access
      *            The package access mode.
      * @throws IllegalArgumentException
-     *             If the specified input stream not an instance of
+     *             If the specified input stream is not an instance of
      *             ZipInputStream.
      * @throws IOException
      *            if input stream cannot be opened, read, or closed
index 43449b20a9e124a1df39db108a72844dc46af143..ec4a1a2080eb9e828ffabe9b1d2a3b5e3ecabd6b 100644 (file)
@@ -92,7 +92,7 @@ public final class ContentType {
                 *
                 * CHAR = <any US-ASCII character (octets 0 - 127)>
                 */
-               String token = "[\\x21-\\x7E&&[^\\(\\)<>@,;:\\\\/\"\\[\\]\\?={}\\x20\\x09]]";
+               String token = "[\\x21-\\x7E&&[^()<>@,;:\\\\/\"\\[\\]?={}\\x20\\x09]]";
 
                /*
                 * parameter = attribute "=" value
@@ -248,7 +248,7 @@ public final class ContentType {
        public String[] getParameterKeys() {
            if (parameters == null)
                return new String[0];
-           return parameters.keySet().toArray(new String[parameters.size()]);
+           return parameters.keySet().toArray(new String[0]);
        }
 
        /**
index b1e8192d529a93e5a64e63fe42c771a87dd930c3..44e3766eb11f2d40aa662b44055f584893396aa3 100644 (file)
@@ -69,7 +69,6 @@ public final class FileHelper {
              FileChannel destinationChannel = fos.getChannel()) {
             
             sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
-            sourceChannel.close();
         }
     }
 
index e5487a6381cce0f622e07ffae682c3f361e231ec..b3f74323f3606a23c12b081946e96a63201c8f4b 100644 (file)
@@ -26,7 +26,7 @@ import org.apache.poi.openxml4j.opc.PackagePart;
 import org.apache.poi.openxml4j.opc.internal.unmarshallers.UnmarshallContext;
 
 /**
- * Object implemented this interface are considered as part unmarshaller. A part
+ * Classes implementing this interface are considered as part unmarshaller. A part
  * unmarshaller is responsible to unmarshall a part in order to load it from a
  * package.
  *
@@ -38,12 +38,10 @@ public interface PartUnmarshaller {
        /**
         * Save the content of the package in the stream
         *
-        * @param in
-        *            The input stream from which the part will be unmarshall.
-        * @return The part freshly unmarshall from the input stream.
-        * @throws OpenXML4JException
-        *             Throws only if any other exceptions are thrown by inner
-        *             methods.
+        * @param in The input stream from which the part will be read.
+        * @return The part freshly read from the input stream.
+        * @throws InvalidFormatException If the data can not be interpreted correctly
+        * @throws IOException if reading from the stream fails
         */
        public PackagePart unmarshall(UnmarshallContext context, InputStream in)
                        throws InvalidFormatException, IOException;
index 4e97633285bf20a9e4d74bd36804111671909723..9050e01a59d81f56e129abe5dbbc60467721c5cf 100644 (file)
@@ -17,9 +17,6 @@
 
 package org.apache.poi.openxml4j.opc;
 
-import java.io.InputStream;
-import java.net.URL;
-
 import org.apache.poi.ooxml.util.POIXMLConstants;
 import org.apache.poi.openxml4j.OpenXML4JTestDataSamples;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
@@ -28,9 +25,13 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 
-import static org.junit.Assert.*;
-
 import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.InputStream;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 /**
  * Tests for content type (ContentType class).
@@ -169,67 +170,67 @@ public final class TestContentType {
      */
     @Test
     public void testFileWithContentTypeParams() throws Exception {
-        InputStream is = OpenXML4JTestDataSamples.openSampleStream("ContentTypeHasParameters.ooxml");
-
-        OPCPackage p = OPCPackage.open(is);
-
-        final String typeResqml = "application/x-resqml+xml";
-
-        // Check the types on everything
-        for (PackagePart part : p.getParts()) {
-            final String contentType = part.getContentType();
-            final ContentType details = part.getContentTypeDetails();
-            final int length = details.getParameterKeys().length;
-            final boolean hasParameters = details.hasParameters();
-
-            // _rels type doesn't have any params
-            if (part.isRelationshipPart()) {
-                assertEquals(ContentTypes.RELATIONSHIPS_PART, contentType);
-                assertEquals(ContentTypes.RELATIONSHIPS_PART, details.toString());
-                assertEquals(false, hasParameters);
-                assertEquals(0, length);
-            }
-            // Core type doesn't have any params
-            else if (part.getPartName().toString().equals("/docProps/core.xml")) {
-                assertEquals(ContentTypes.CORE_PROPERTIES_PART, contentType);
-                assertEquals(ContentTypes.CORE_PROPERTIES_PART, details.toString());
-                assertEquals(false, hasParameters);
-                assertEquals(0, length);
-            }
-            // Global Crs types do have params
-            else if (part.getPartName().toString().equals("/global1dCrs.xml")) {
-                assertTrue(part.getContentType().startsWith(typeResqml));
-                assertEquals(typeResqml, details.toString(false));
-                assertEquals(true, hasParameters);
-                assertContains("version=2.0", details.toString());
-                assertContains("type=obj_global1dCrs", details.toString());
-                assertEquals(2, length);
-                assertEquals("2.0", details.getParameter("version"));
-                assertEquals("obj_global1dCrs", details.getParameter("type"));
-            } else if (part.getPartName().toString().equals("/global2dCrs.xml")) {
-                assertTrue(part.getContentType().startsWith(typeResqml));
-                assertEquals(typeResqml, details.toString(false));
-                assertEquals(true, hasParameters);
-                assertContains("version=2.0", details.toString());
-                assertContains("type=obj_global2dCrs", details.toString());
-                assertEquals(2, length);
-                assertEquals("2.0", details.getParameter("version"));
-                assertEquals("obj_global2dCrs", details.getParameter("type"));
-            }
-            // Other thingy
-            else if (part.getPartName().toString().equals("/myTestingGuid.xml")) {
-                assertTrue(part.getContentType().startsWith(typeResqml));
-                assertEquals(typeResqml, details.toString(false));
-                assertEquals(true, hasParameters);
-                assertContains("version=2.0", details.toString());
-                assertContains("type=obj_tectonicBoundaryFeature", details.toString());
-                assertEquals(2, length);
-                assertEquals("2.0", details.getParameter("version"));
-                assertEquals("obj_tectonicBoundaryFeature", details.getParameter("type"));
-            }
-            // That should be it!
-            else {
-                fail("Unexpected part " + part);
+        try (InputStream is = OpenXML4JTestDataSamples.openSampleStream("ContentTypeHasParameters.ooxml");
+             OPCPackage p = OPCPackage.open(is)) {
+
+            final String typeResqml = "application/x-resqml+xml";
+
+            // Check the types on everything
+            for (PackagePart part : p.getParts()) {
+                final String contentType = part.getContentType();
+                final ContentType details = part.getContentTypeDetails();
+                final int length = details.getParameterKeys().length;
+                final boolean hasParameters = details.hasParameters();
+
+                // _rels type doesn't have any params
+                if (part.isRelationshipPart()) {
+                    assertEquals(ContentTypes.RELATIONSHIPS_PART, contentType);
+                    assertEquals(ContentTypes.RELATIONSHIPS_PART, details.toString());
+                    assertFalse(hasParameters);
+                    assertEquals(0, length);
+                }
+                // Core type doesn't have any params
+                else if (part.getPartName().toString().equals("/docProps/core.xml")) {
+                    assertEquals(ContentTypes.CORE_PROPERTIES_PART, contentType);
+                    assertEquals(ContentTypes.CORE_PROPERTIES_PART, details.toString());
+                    assertFalse(hasParameters);
+                    assertEquals(0, length);
+                }
+                // Global Crs types do have params
+                else if (part.getPartName().toString().equals("/global1dCrs.xml")) {
+                    assertTrue(part.getContentType().startsWith(typeResqml));
+                    assertEquals(typeResqml, details.toString(false));
+                    assertTrue(hasParameters);
+                    assertContains("version=2.0", details.toString());
+                    assertContains("type=obj_global1dCrs", details.toString());
+                    assertEquals(2, length);
+                    assertEquals("2.0", details.getParameter("version"));
+                    assertEquals("obj_global1dCrs", details.getParameter("type"));
+                } else if (part.getPartName().toString().equals("/global2dCrs.xml")) {
+                    assertTrue(part.getContentType().startsWith(typeResqml));
+                    assertEquals(typeResqml, details.toString(false));
+                    assertTrue(hasParameters);
+                    assertContains("version=2.0", details.toString());
+                    assertContains("type=obj_global2dCrs", details.toString());
+                    assertEquals(2, length);
+                    assertEquals("2.0", details.getParameter("version"));
+                    assertEquals("obj_global2dCrs", details.getParameter("type"));
+                }
+                // Other thingy
+                else if (part.getPartName().toString().equals("/myTestingGuid.xml")) {
+                    assertTrue(part.getContentType().startsWith(typeResqml));
+                    assertEquals(typeResqml, details.toString(false));
+                    assertTrue(hasParameters);
+                    assertContains("version=2.0", details.toString());
+                    assertContains("type=obj_tectonicBoundaryFeature", details.toString());
+                    assertEquals(2, length);
+                    assertEquals("2.0", details.getParameter("version"));
+                    assertEquals("obj_tectonicBoundaryFeature", details.getParameter("type"));
+                }
+                // That should be it!
+                else {
+                    fail("Unexpected part " + part);
+                }
             }
         }
     }
index 8bccffb3eebfaeb39e7c8ed95dd6cb9e0ea94fca..d15281b2d3bec86b9fb357a219792b3e0ead71dc 100644 (file)
@@ -17,7 +17,7 @@
 
 package org.apache.poi.openxml4j.opc;
 
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
 
 import java.io.File;
 import java.util.TreeMap;
@@ -52,7 +52,7 @@ public final class TestFileHelper {
 //                             assertTrue(expectedValue.get(filename).equalsIgnoreCase(f2.getAbsolutePath()));
 //                             // This comparison is platform dependent. A better approach is below
 //                     }
-                       assertTrue(f1.equals(f2));
+                       assertEquals(f1, f2);
                }
        }
 }
index 3cf0c9a100aa1648d830a2712081d423717c3c88..f2a111ea3bbfd74527dcbc38c4cd4657c41916f1 100644 (file)
@@ -579,20 +579,20 @@ public final class TestBugs {
 
     @Test
     public void bug47261() throws IOException {
-        HSLFSlideShow ppt = open("bug47261.ppt");
-        ppt.removeSlide(0);
-        ppt.createSlide();
-        HSLFTestDataSamples.writeOutAndReadBack(ppt).close();
-        ppt.close();
+        try (HSLFSlideShow ppt = open("bug47261.ppt")) {
+            ppt.removeSlide(0);
+            ppt.createSlide();
+            HSLFTestDataSamples.writeOutAndReadBack(ppt).close();
+        }
     }
 
     @Test
     public void bug56240() throws IOException {
-        HSLFSlideShow ppt = open("bug56240.ppt");
-        int slideCnt = ppt.getSlides().size();
-        assertEquals(105, slideCnt);
-        HSLFTestDataSamples.writeOutAndReadBack(ppt).close();
-        ppt.close();
+        try (HSLFSlideShow ppt = open("bug56240.ppt")) {
+            int slideCnt = ppt.getSlides().size();
+            assertEquals(105, slideCnt);
+            HSLFTestDataSamples.writeOutAndReadBack(ppt).close();
+        }
     }
 
     @Test
index 5dbef749d6e482deb63e9ddd9ca1ed892a65ebf3..a96460c1a8943aa446d54985048d27d5ca0b547b 100644 (file)
@@ -69,7 +69,6 @@ public class TestBug47563 extends TestCase {
                                row.sanityCheck();
                                table.sanityCheck();
                                range.sanityCheck();
-
                        }
                }
 
@@ -77,7 +76,8 @@ public class TestBug47563 extends TestCase {
                int mustBeAfter = 0;
                for (int i = 0; i < rows * columns; i++) {
                        int next = text.indexOf(Integer.toString(i), mustBeAfter);
-                       assertTrue("Test with " + rows + "/" + columns + ": Should not find " + i + " but found it at " + next + " in " + text, 
+                       assertTrue("Test with " + rows + "/" + columns + ": Should not find " + i + " but found it at " + next + " with " + mustBeAfter + " in " + text + "\n" +
+                                                       text.indexOf(Integer.toString(i), mustBeAfter),
                                        next != -1);
                        mustBeAfter = next;
                }