You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2021/01/30 18:42:05 UTC

svn commit: r1886061 - in /poi/trunk/src: integrationtest/org/apache/poi/stress/ java/org/apache/poi/common/usermodel/ ooxml/java/org/apache/poi/openxml4j/opc/ ooxml/java/org/apache/poi/xwpf/usermodel/ ooxml/testcases/org/apache/poi/openxml4j/opc/compl...

Author: centic
Date: Sat Jan 30 18:42:05 2021
New Revision: 1886061

URL: http://svn.apache.org/viewvc?rev=1886061&view=rev
Log:
Apply IDE suggestions, add toString(), adjust JavaDoc and simplify code slightly

Modified:
    poi/trunk/src/integrationtest/org/apache/poi/stress/AbstractFileHandler.java
    poi/trunk/src/java/org/apache/poi/common/usermodel/Hyperlink.java
    poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java
    poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePart.java
    poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationship.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java

Modified: poi/trunk/src/integrationtest/org/apache/poi/stress/AbstractFileHandler.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/integrationtest/org/apache/poi/stress/AbstractFileHandler.java?rev=1886061&r1=1886060&r2=1886061&view=diff
==============================================================================
--- poi/trunk/src/integrationtest/org/apache/poi/stress/AbstractFileHandler.java (original)
+++ poi/trunk/src/integrationtest/org/apache/poi/stress/AbstractFileHandler.java Sat Jan 30 18:42:05 2021
@@ -35,10 +35,8 @@ import org.apache.poi.extractor.POITextE
 import org.apache.poi.hpsf.extractor.HPSFPropertiesExtractor;
 import org.apache.poi.hssf.extractor.EventBasedExcelExtractor;
 import org.apache.poi.ooxml.POIXMLException;
-import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
 import org.apache.poi.ss.extractor.ExcelExtractor;
 import org.apache.poi.util.IOUtils;
-import org.apache.xmlbeans.XmlException;
 
 /**
  * Base class with things that can be run for any supported file handler
@@ -161,7 +159,7 @@ public abstract class AbstractFileHandle
         }
     }
 
-    private void handleExtractingAsStream(File file) throws IOException, OpenXML4JException, XmlException {
+    private void handleExtractingAsStream(File file) throws IOException {
         try (InputStream stream = new FileInputStream(file)) {
             try (POITextExtractor streamExtractor = ExtractorFactory.createExtractor(stream)) {
                 assertNotNull(streamExtractor);

Modified: poi/trunk/src/java/org/apache/poi/common/usermodel/Hyperlink.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/common/usermodel/Hyperlink.java?rev=1886061&r1=1886060&r2=1886061&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/common/usermodel/Hyperlink.java (original)
+++ poi/trunk/src/java/org/apache/poi/common/usermodel/Hyperlink.java Sat Jan 30 18:42:05 2021
@@ -16,45 +16,43 @@
 ==================================================================== */
 package org.apache.poi.common.usermodel;
 
-import org.apache.poi.util.Removal;
-
 /**
  * Represents a hyperlink.
  */
 public interface Hyperlink {
-    
+
     /**
      * Hyperlink address. Depending on the hyperlink type it can be URL, e-mail, path to a file, etc.
      *
      * @return  the address of this hyperlink
      */
-    public String getAddress();
+    String getAddress();
 
     /**
      * Hyperlink address. Depending on the hyperlink type it can be URL, e-mail, path to a file, etc.
      *
      * @param address  the address of this hyperlink
      */
-    public void setAddress(String address);
+    void setAddress(String address);
 
     /**
      * Return text label for this hyperlink
      *
      * @return  text to display
      */
-    public String getLabel();
+    String getLabel();
 
     /**
      * Sets text label for this hyperlink
      *
      * @param label text label for this hyperlink
      */
-    public void setLabel(String label);
+    void setLabel(String label);
 
     /**
      * Return the type of this hyperlink
      *
      * @return the type of this hyperlink
      */
-    public HyperlinkType getType();
+    HyperlinkType getType();
 }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java?rev=1886061&r1=1886060&r2=1886061&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java Sat Jan 30 18:42:05 2021
@@ -1668,4 +1668,15 @@ public abstract class OPCPackage impleme
 	 * Has close been called already?
 	 */
 	public abstract boolean isClosed();
+
+	@Override
+	public String toString() {
+		return "OPCPackage{" +
+				"packageAccess=" + packageAccess +
+				", relationships=" + relationships +
+				", packageProperties=" + packageProperties +
+				", isDirty=" + isDirty +
+				//", originalPackagePath='" + originalPackagePath + '\'' +
+				'}';
+	}
 }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePart.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePart.java?rev=1886061&r1=1886060&r2=1886061&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePart.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePart.java Sat Jan 30 18:42:05 2021
@@ -51,7 +51,7 @@ public abstract class PackagePart implem
     /**
      * Flag to know if this part is a relationship.
      */
-    private boolean _isRelationshipPart;
+    private final boolean _isRelationshipPart;
 
     /**
      * Flag to know if this part has been logically deleted.

Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationship.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationship.java?rev=1886061&r1=1886060&r2=1886061&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationship.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationship.java Sat Jan 30 18:42:05 2021
@@ -58,42 +58,35 @@ public final class PackageRelationship {
 	/**
 	 * Relation id.
 	 */
-	private String id;
+	private final String id;
 
 	/**
 	 * Reference to the package.
 	 */
-	private OPCPackage container;
+	private final OPCPackage container;
 
 	/**
 	 * Relationship type
 	 */
-	private String relationshipType;
+	private final String relationshipType;
 
 	/**
 	 * Part of this relationship source
 	 */
-	private PackagePart source;
+	private final PackagePart source;
 
 	/**
 	 * Targeting mode [Internal|External]
 	 */
-	private TargetMode targetMode;
+	private final TargetMode targetMode;
 
 	/**
 	 * Target URI
 	 */
-	private URI targetUri;
+	private final URI targetUri;
 
 	/**
 	 * Constructor.
-	 *
-	 * @param pkg
-	 * @param sourcePart
-	 * @param targetUri
-	 * @param targetMode
-	 * @param relationshipType
-	 * @param id
 	 */
 	public PackageRelationship(OPCPackage pkg, PackagePart sourcePart,
 			URI targetUri, TargetMode targetMode, String relationshipType,
@@ -123,7 +116,7 @@ public final class PackageRelationship {
 		PackageRelationship rel = (PackageRelationship) obj;
 		return (this.id.equals(rel.id)
 				&& this.relationshipType.equals(rel.relationshipType)
-				&& (rel.source != null ? rel.source.equals(this.source) : true)
+				&& (rel.source == null || rel.source.equals(this.source))
 				&& this.targetMode == rel.targetMode && this.targetUri
 				.equals(rel.targetUri));
 	}
@@ -207,11 +200,11 @@ public final class PackageRelationship {
 
 	@Override
 	public String toString() {
-		return (id == null ? "id=null" : "id=" + id) +
-				(container == null ? " - container=null" : " - container=" + container) +
-				(relationshipType == null ? " - relationshipType=null" : " - relationshipType=" + relationshipType) +
+		return "id=" + id +
+				" - container=" + container +
+				" - relationshipType=" + relationshipType +
 				(source == null ? " - source=null" : " - source=" + getSourceURI().toASCIIString()) +
-				(targetUri == null ? " - target=null" : " - target=" + getTargetURI().toASCIIString()) +
+				" - target=" + getTargetURI().toASCIIString() +
 				(targetMode == null ? ",targetMode=null" : ",targetMode=" + targetMode);
 	}
 }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java?rev=1886061&r1=1886060&r2=1886061&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java Sat Jan 30 18:42:05 2021
@@ -125,7 +125,7 @@ public class XWPFStyles extends POIXMLDo
     /**
      * Sets the ctStyles
      *
-     * @param styles
+     * @param styles The CTStyles object to set
      */
     public void setStyles(CTStyles styles) {
         ctStyles = styles;
@@ -160,8 +160,7 @@ public class XWPFStyles extends POIXMLDo
     /**
      * add a style to the document
      *
-     * @param style
-     * @throws IOException
+     * @param style The style to add
      */
     public void addStyle(XWPFStyle style) {
         listStyle.add(style);
@@ -190,9 +189,10 @@ public class XWPFStyles extends POIXMLDo
 
     /**
      * get the styles which are related to the parameter style and their relatives
+     *
      * this method can be used to copy all styles from one document to another document
      *
-     * @param style
+     * @param style The style to look for
      * @return a list of all styles which were used by this method
      */
     public List<XWPFStyle> getUsedStyleList(XWPFStyle style) {
@@ -204,8 +204,12 @@ public class XWPFStyles extends POIXMLDo
     /**
      * get the styles which are related to parameter style
      *
-     * @param style
-     * @return all Styles of the parameterList
+     * @param style The style to look for
+     * @param usedStyleList The list of current style, found
+     *                      related styles are added to this list.
+     *
+     * @return all Styles of the parameterList, returns the same object as
+     *          the input-parameter usedStyleList
      */
     private List<XWPFStyle> getUsedStyleList(XWPFStyle style, List<XWPFStyle> usedStyleList) {
         String basisStyleID = style.getBasisStyleID();
@@ -233,20 +237,17 @@ public class XWPFStyles extends POIXMLDo
     protected CTLanguage getCTLanguage() {
         ensureDocDefaults();
 
-        CTLanguage lang = null;
         if (defaultRunStyle.getRPr().sizeOfLangArray() > 0) {
-            lang = defaultRunStyle.getRPr().getLangArray(0);
+            return defaultRunStyle.getRPr().getLangArray(0);
         } else {
-            lang = defaultRunStyle.getRPr().addNewLang();
+            return defaultRunStyle.getRPr().addNewLang();
         }
-
-        return lang;
     }
 
     /**
      * Sets the default spelling language on ctStyles DocDefaults parameter
      *
-     * @param strSpellingLanguage
+     * @param strSpellingLanguage the default spelling language to use
      */
     public void setSpellingLanguage(String strSpellingLanguage) {
         CTLanguage lang = getCTLanguage();
@@ -257,7 +258,7 @@ public class XWPFStyles extends POIXMLDo
     /**
      * Sets the default East Asia spelling language on ctStyles DocDefaults parameter
      *
-     * @param strEastAsia
+     * @param strEastAsia The default East Asia spelling language to use
      */
     public void setEastAsia(String strEastAsia) {
         CTLanguage lang = getCTLanguage();

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java?rev=1886061&r1=1886060&r2=1886061&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java Sat Jan 30 18:42:05 2021
@@ -47,9 +47,9 @@ import org.openxmlformats.schemas.wordpr
  * Cell is the thing that holds the actual content (paragraphs etc)
  */
 public class XWPFTableCell implements IBody, ICell {
-    private static EnumMap<XWPFVertAlign, STVerticalJc.Enum> alignMap;
+    private static final EnumMap<XWPFVertAlign, STVerticalJc.Enum> alignMap;
     // Create a map from the STVerticalJc.Enum values to the XWPF-level enums
-    private static HashMap<Integer, XWPFVertAlign> stVertAlignTypeMap;
+    private static final HashMap<Integer, XWPFVertAlign> stVertAlignTypeMap;
 
     static {
         // populate enum maps
@@ -64,7 +64,6 @@ public class XWPFTableCell implements IB
         stVertAlignTypeMap.put(STVerticalJc.INT_CENTER, XWPFVertAlign.CENTER);
         stVertAlignTypeMap.put(STVerticalJc.INT_BOTH, XWPFVertAlign.BOTH);
         stVertAlignTypeMap.put(STVerticalJc.INT_BOTTOM, XWPFVertAlign.BOTTOM);
-
     }
 
     private final CTTc ctTc;
@@ -73,7 +72,7 @@ public class XWPFTableCell implements IB
     protected List<IBodyElement> bodyElements;
 
     protected IBody part;
-    private XWPFTableRow tableRow;
+    private final XWPFTableRow tableRow;
 
     /**
      * If a table cell does not include at least one block-level element, then this document shall be considered corrupt

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java?rev=1886061&r1=1886060&r2=1886061&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java Sat Jan 30 18:42:05 2021
@@ -17,6 +17,7 @@
 
 package org.apache.poi.openxml4j.opc.compliance;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
@@ -73,8 +74,8 @@ class TestOPCCompliancePackageModel {
             pkg.createPart(name, ContentTypes.XML);
 
             assertThrows(InvalidOperationException.class, () -> pkg.createPart(nameDerived, ContentTypes.EXTENSION_GIF),
-                "A package implementer shall neither create nor recognize a part with a part name derived from another " +
-                "part name by appending segments to it. [M1.11]");
+                    "A package implementer shall neither create nor recognize a part with a part name derived from another " +
+                            "part name by appending segments to it. [M1.11]");
             pkg.revert();
         }
     }
@@ -88,9 +89,9 @@ class TestOPCCompliancePackageModel {
     void testPartNameDerivationReadingFailure() {
         String filename = "OPCCompliance_DerivedPartNameFAIL.docx";
         assertThrows(InvalidFormatException.class, () ->
-            OPCPackage.open(POIDataSamples.getOpenXML4JInstance().openResourceAsStream(filename)),
-            "A package implementer shall neither create nor recognize a part with a part name derived from another" +
-            " part name by appending segments to it. [M1.11]"
+                        OPCPackage.open(POIDataSamples.getOpenXML4JInstance().openResourceAsStream(filename)),
+                "A package implementer shall neither create nor recognize a part with a part name derived from another" +
+                        " part name by appending segments to it. [M1.11]"
         );
     }
 
@@ -107,8 +108,8 @@ class TestOPCCompliancePackageModel {
 
             pkg.createPart(name1, ContentTypes.XML);
             assertThrows(PartAlreadyExistsException.class, () -> pkg.createPart(name2, ContentTypes.XML),
-                "Packages shall not contain equivalent part names and package implementers shall neither create nor " +
-                    "recognize packages with equivalent part names. [M1.12]"
+                    "Packages shall not contain equivalent part names and package implementers shall neither create nor " +
+                            "recognize packages with equivalent part names. [M1.12]"
             );
             pkg.revert();
         }
@@ -125,8 +126,8 @@ class TestOPCCompliancePackageModel {
             PackagePartName partName = PackagingURIHelper.createPartName("/word/document.xml");
             pkg.createPart(partName, ContentTypes.XML);
             assertThrows(InvalidOperationException.class, () -> pkg.createPart(partName, ContentTypes.XML),
-                "Packages shall not contain equivalent part names and package implementers shall neither create nor " +
-                    "recognize packages with equivalent part names. [M1.12]"
+                    "Packages shall not contain equivalent part names and package implementers shall neither create nor " +
+                            "recognize packages with equivalent part names. [M1.12]"
             );
             pkg.revert();
         }
@@ -134,7 +135,7 @@ class TestOPCCompliancePackageModel {
 
     /**
      * Try to add a relationship to a relationship part.
-     *
+     * <p>
      * Check rule M1.25: The Relationships part shall not have relationships to
      * any other part. Package implementers shall enforce this requirement upon
      * the attempt to create such a relationship and shall treat any such
@@ -146,10 +147,21 @@ class TestOPCCompliancePackageModel {
             PackagePartName name1 = PackagingURIHelper.createPartName("/test/_rels/document.xml.rels");
 
             assertThrows(InvalidOperationException.class,
-                () -> pkg.addRelationship(name1, TargetMode.INTERNAL, PackageRelationshipTypes.CORE_DOCUMENT),
-                "The Relationships part shall not have relationships to any other part [M1.25]"
+                    () -> pkg.addRelationship(name1, TargetMode.INTERNAL, PackageRelationshipTypes.CORE_DOCUMENT),
+                    "The Relationships part shall not have relationships to any other part [M1.25]"
             );
             pkg.revert();
         }
     }
+
+    @Test
+    void testToString() throws IOException {
+        try (OPCPackage pkg = OPCPackage.create(TESTFILE)) {
+            assertEquals("OPCPackage{" +
+                        "packageAccess=READ_WRITE, " +
+                        "relationships=null, " +
+                        "packageProperties=Name: /docProps/core.xml - Content Type: application/vnd.openxmlformats-package.core-properties+xml, " +
+                        "isDirty=false}", pkg.toString());
+        }
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org