Package org.docx4j.openpackaging.parts
Class PartName
java.lang.Object
org.docx4j.openpackaging.parts.PartName
- All Implemented Interfaces:
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
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanFlag to know if this part name is from a relationship part name.private static org.slf4j.Loggerprivate URIPart name stored as an URI.private static String[]Authorized reserved characters for pChar.private static String[]Reserved characters for sub delimitations.private static String[]Unreserved character (+ ALPHA & DIGIT). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidcheckPCharCompliance(String segment) Throws an exception if a segment any characters other than pchar characters.intCompare two part name following the rule M1.12 : Part name equivalence is determined by comparing part names as case-insensitive ASCII strings.booleanPart name equivalence is determined by comparing part names as case-insensitive ASCII strings.static StringgenerateUniqueName(Base sourcePart, String proposedRelId, String directoryPrefix, String after_, String ext) Retrieves the extension of the part name if any.getName()Get this part name.static StringgetRelationshipsPartName(String partName) getURI()Part name property getter.inthashCode()booleanTo know if this part name is a relationship part name.private booleanisRelationshipPartURI(URI partUri) Check if the specified part name is a relationship part name.private static voidthrowExceptionIfAbsoluteUri(URI partUri) Throws an exception if the specified URI is absolute.private static voidthrowExceptionIfEmptyURI(URI partURI) Throws an exception if the specified URI is empty.private static voidthrowExceptionIfInvalidPartUri(URI partUri) Throws an exception (of any kind) if the specified part name does not follow the Open Packaging Convention specifications naming rules.private static voidThrows an exception if the specified part name ends with a forward slash character '/'.private static voidThrows an exception if the part name has empty segments.private static voidThrows an exception if the specified part name doesn't start with a forward slash character '/'.toString()
-
Field Details
-
log
private static org.slf4j.Logger log -
partNameURI
Part name stored as an URI. -
RFC3986_PCHAR_SUB_DELIMS
Reserved characters for sub delimitations. -
RFC3986_PCHAR_UNRESERVED_SUP
Unreserved character (+ ALPHA & DIGIT). -
RFC3986_PCHAR_AUTHORIZED_SUP
Authorized reserved characters for pChar. -
isRelationship
private boolean isRelationshipFlag to know if this part name is from a relationship part name.
-
-
Constructor Details
-
PartName
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 alwaystrueexcept 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:
-
PartName
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
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 alwaystrueexcept 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
Check if the specified part name is a relationship part name.- Parameters:
partUri- The URI to check.- Returns:
trueif this part name respect the relationship part naming convention elsefalse.
-
isRelationshipPartURI
public boolean isRelationshipPartURI()To know if this part name is a relationship part name.- Returns:
trueif this part name respect the relationship part naming convention elsefalse.
-
throwExceptionIfInvalidPartUri
Throws an exception (of any kind) if the specified part name does not follow the Open Packaging Convention specifications naming rules.- Parameters:
partUri- The part name to check.- Throws:
Exception- Throws if the part name is invalid.InvalidFormatException
-
throwExceptionIfEmptyURI
Throws an exception if the specified URI is empty. [M1.1]- Parameters:
partURI- Part URI to check.- Throws:
InvalidFormatException- If the specified URI is empty.
-
throwExceptionIfPartNameHaveInvalidSegments
private static void throwExceptionIfPartNameHaveInvalidSegments(URI partUri) throws InvalidFormatException Throws an exception if the part name has empty segments. [M1.3] Throws an exception if a segment any characters other than pchar characters. [M1.6] Throws an exception if a segment contain percent-encoded forward slash ('/'), or backward slash ('\') characters. [M1.7] Throws an exception if a segment contain percent-encoded unreserved characters. [M1.8] Throws an exception if the specified part name's segments end with a dot ('.') character. [M1.9] Throws an exception if a segment doesn't include at least one non-dot character. [M1.10]- Parameters:
partUri- The part name to check.- Throws:
InvalidFormatException- if the specified URI contain an empty segments or if one the segments contained in the part name, ends with a dot ('.') character.
-
checkPCharCompliance
Throws an exception if a segment any characters other than pchar characters. [M1.6] Throws an exception if a segment contain percent-encoded forward slash ('/'), or backward slash ('\') characters. [M1.7] Throws an exception if a segment contain percent-encoded unreserved characters. [M1.8]- Parameters:
segment- The segment to check- Throws:
InvalidFormatException
-
throwExceptionIfPartNameNotStartsWithForwardSlashChar
private static void throwExceptionIfPartNameNotStartsWithForwardSlashChar(URI partUri) throws InvalidFormatException Throws an exception if the specified part name doesn't start with a forward slash character '/'. [M1.4]- Parameters:
partUri- The part name to check.- Throws:
InvalidFormatException- If the specified part name doesn't start with a forward slash character '/'.
-
throwExceptionIfPartNameEndsWithForwardSlashChar
private static void throwExceptionIfPartNameEndsWithForwardSlashChar(URI partUri) throws InvalidFormatException Throws an exception if the specified part name ends with a forward slash character '/'. [M1.5]- Parameters:
partUri- The part name to check.- Throws:
InvalidFormatException- If the specified part name ends with a forwar slash character '/'.
-
throwExceptionIfAbsoluteUri
Throws an exception if the specified URI is absolute.- Parameters:
partUri- The URI to check.- Throws:
InvalidFormatException- Throws if the specified URI is absolute.
-
compareTo
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:
compareToin interfaceComparable<PartName>
-
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
Get this part name.- Returns:
- The name of this part name.
-
equals
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] -
hashCode
public int hashCode() -
toString
-
getURI
Part name property getter.- Returns:
- This part name URI.
-
generateUniqueName
-
getRelationshipsPartName
- See Also:
-
for Wygwam's implementation which I only found after writing this
-