Class PartName

java.lang.Object
org.docx4j.openpackaging.parts.PartName
All Implemented Interfaces:
java.lang.Comparable<PartName>

public final class PartName
extends java.lang.Object
implements java.lang.Comparable<PartName>
An immutable Open Packaging Convention compliant part name. [Docx4J comment: Note that in docx4J, part names should be resolved, before being set, so that they are absolute (ie start with '/'). In contrast, this class enforces the OPC specification, which says that a part name can't be absolute. For this reason, you'll see the leading '/' being added and removed in various places :( ]
Version:
0.1
Author:
Julien Chable
  • Constructor Summary

    Constructors 
    Constructor Description
    PartName​(java.lang.String partName)
    Constructor.
    PartName​(java.lang.String partName, boolean checkConformance)
    Constructor.
    PartName​(java.net.URI uri, boolean checkConformance)
    Constructor.
  • Method Summary

    Modifier and Type Method Description
    int compareTo​(PartName otherPartName)
    Compare two part name following the rule M1.12 : Part name equivalence is determined by comparing part names as case-insensitive ASCII strings.
    boolean equals​(java.lang.Object otherPartName)
    Part name equivalence is determined by comparing part names as case-insensitive ASCII strings.
    static java.lang.String generateUniqueName​(Base sourcePart, java.lang.String proposedRelId, java.lang.String directoryPrefix, java.lang.String after_, java.lang.String ext)  
    java.lang.String getExtension()
    Retrieves the extension of the part name if any.
    java.lang.String getName()
    Get this part name.
    static java.lang.String getRelationshipsPartName​(java.lang.String partName)  
    java.net.URI getURI()
    Part name property getter.
    int hashCode()  
    boolean isRelationshipPartURI()
    To know if this part name is a relationship part name.
    java.lang.String toString()  

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • PartName

      public PartName​(java.net.URI uri, boolean checkConformance) throws InvalidFormatException
      Constructor. Makes a ValidPartName object from a java.net.URI
      Parameters:
      uri - The URI to validate and to transform into ValidPartName.
      checkConformance - Flag to specify if the contructor have to validate the OPC conformance. Must be always true except for special URI like '/' which is needed for internal use by OpenXML4J but is not valid.
      Throws:
      InvalidFormatException - Throw if the specified part name is not conform to Open Packaging Convention specifications.
      See Also:
      URI
    • PartName

      public PartName​(java.lang.String partName) throws InvalidFormatException
      Constructor. Makes a ValidPartName object from a String part name, provided it validates against OPC conformance.
      Parameters:
      partName - Part name to valid and to create.
      Throws:
      InvalidFormatException - Throw if the specified part name is not conform to Open Packaging Convention specifications.
    • PartName

      public PartName​(java.lang.String partName, boolean checkConformance) throws InvalidFormatException
      Constructor. Makes a ValidPartName object from a String part name.
      Parameters:
      partName - Part name to valid and to create.
      checkConformance - Flag to specify if the contructor have to validate the OPC conformance. Must be always true except for special URI like '/' which is needed for internal use by OpenXML4J but is not valid.
      Throws:
      InvalidFormatException - Throw if the specified part name is not conform to Open Packaging Convention specifications.
  • Method Details

    • isRelationshipPartURI

      public boolean isRelationshipPartURI()
      To know if this part name is a relationship part name.
      Returns:
      true if this part name respect the relationship part naming convention else false.
    • compareTo

      public int compareTo​(PartName otherPartName)
      Compare two part name following the rule M1.12 : Part name equivalence is determined by comparing part names as case-insensitive ASCII strings. Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]
      Specified by:
      compareTo in interface java.lang.Comparable<PartName>
    • getExtension

      public java.lang.String getExtension()
      Retrieves the extension of the part name if any. If there is no extension returns an empty String. Example : '/document/content.xml' => 'xml'
      Returns:
      The extension of the part name.
    • getName

      public java.lang.String getName()
      Get this part name.
      Returns:
      The name of this part name.
    • equals

      public boolean equals​(java.lang.Object otherPartName)
      Part name equivalence is determined by comparing part names as case-insensitive ASCII strings. Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]
      Overrides:
      equals in class java.lang.Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class java.lang.Object
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object
    • getURI

      public java.net.URI getURI()
      Part name property getter.
      Returns:
      This part name URI.
    • generateUniqueName

      public static java.lang.String generateUniqueName​(Base sourcePart, java.lang.String proposedRelId, java.lang.String directoryPrefix, java.lang.String after_, java.lang.String ext)
    • getRelationshipsPartName

      public static java.lang.String getRelationshipsPartName​(java.lang.String partName)
      See Also:
      for Wygwam's implementation which I only found after writing this