Class PackagingURIHelper
- java.lang.Object
-
- org.apache.poi.openxml4j.opc.PackagingURIHelper
-
public final class PackagingURIHelper extends Object
Helper for part and pack URI.
-
-
Field Summary
Fields Modifier and Type Field Description static PackagePartNameCORE_PROPERTIES_PART_NAMECore properties partname.static URICORE_PROPERTIES_URICore properties part URI.static charFORWARD_SLASH_CHARForward slash URI separator.static StringFORWARD_SLASH_STRINGForward slash URI separator.static StringPACKAGE_CORE_PROPERTIES_NAMECore package properties art name.static StringPACKAGE_PROPERTIES_SEGMENT_NAMESegment name of the package properties folder.static PackagePartNamePACKAGE_RELATIONSHIPS_ROOT_PART_NAMEPackage relationships part name.static URIPACKAGE_RELATIONSHIPS_ROOT_URIPackage relationships part URIstatic PackagePartNamePACKAGE_ROOT_PART_NAMERoot package part name.static URIPACKAGE_ROOT_URIRoot package URI.static StringRELATIONSHIP_PART_EXTENSION_NAMEExtension name of a relationship part.static StringRELATIONSHIP_PART_SEGMENT_NAMESegment name of a relationship part.
-
Constructor Summary
Constructors Constructor Description PackagingURIHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Stringcombine(String prefix, String suffix)Combine a string URI with a prefix and a suffix.static URIcombine(URI prefix, URI suffix)Combine two URIs.static PackagePartNamecreatePartName(String partName)Create an OPC compliant part name.static PackagePartNamecreatePartName(String partName, PackagePart relativePart)Create an OPC compliant part name by resolving it using a base part.static PackagePartNamecreatePartName(URI partUri)Create an OPC compliant part name by throwing an exception if the URI is not valid.static PackagePartNamecreatePartName(URI partName, PackagePart relativePart)Create an OPC compliant part name by resolving it using a base part.static StringdecodeURI(URI uri)Decode a URI by converting all percent encoded character into a String character.static Stringencode(String s)percent-encode white spaces and characters above 0x80.static StringgetFilename(URI uri)Get file name from the specified URI.static StringgetFilenameWithoutExtension(URI uri)Get the file name without the trailing extension.static URIgetPackageRootUri()Gets the URI for the package root.static URIgetPath(URI uri)Get the directory path from the specified URI.static PackagePartNamegetRelationshipPartName(PackagePartName partName)Build a part name where the relationship should be stored ((ex /word/document.xml -> /word/_rels/document.xml.rels)static URIgetSourcePartUriFromRelationshipPartUri(URI relationshipPartUri)Get the source part URI from a specified relationships part.static URIgetURIFromPath(String path)Get URI from a string path.static booleanisRelationshipPartURI(URI partUri)Know if the specified URI is a relationship part name.static booleanisValidPartName(URI partUri)Validate a part URI by returning a boolean.static URIrelativizeURI(URI sourceURI, URI targetURI)Fully relativize the source part URI against the target part URI.static URIrelativizeURI(URI sourceURI, URI targetURI, boolean msCompatible)Fully relativize the source part URI against the target part URI.static URIresolvePartUri(URI sourcePartUri, URI targetUri)Resolve a source uri against a target.static URItoURI(String value)Convert a string toURIIf part name is not a valid URI, it is resolved as follows:
-
-
-
Field Detail
-
RELATIONSHIP_PART_EXTENSION_NAME
public static final String RELATIONSHIP_PART_EXTENSION_NAME
Extension name of a relationship part.
-
RELATIONSHIP_PART_SEGMENT_NAME
public static final String RELATIONSHIP_PART_SEGMENT_NAME
Segment name of a relationship part.
-
PACKAGE_PROPERTIES_SEGMENT_NAME
public static final String PACKAGE_PROPERTIES_SEGMENT_NAME
Segment name of the package properties folder.
-
PACKAGE_CORE_PROPERTIES_NAME
public static final String PACKAGE_CORE_PROPERTIES_NAME
Core package properties art name.
-
FORWARD_SLASH_CHAR
public static final char FORWARD_SLASH_CHAR
Forward slash URI separator.
-
FORWARD_SLASH_STRING
public static final String FORWARD_SLASH_STRING
Forward slash URI separator.
-
PACKAGE_RELATIONSHIPS_ROOT_URI
public static final URI PACKAGE_RELATIONSHIPS_ROOT_URI
Package relationships part URI
-
PACKAGE_RELATIONSHIPS_ROOT_PART_NAME
public static final PackagePartName PACKAGE_RELATIONSHIPS_ROOT_PART_NAME
Package relationships part name.
-
CORE_PROPERTIES_URI
public static final URI CORE_PROPERTIES_URI
Core properties part URI.
-
CORE_PROPERTIES_PART_NAME
public static final PackagePartName CORE_PROPERTIES_PART_NAME
Core properties partname.
-
PACKAGE_ROOT_URI
public static final URI PACKAGE_ROOT_URI
Root package URI.
-
PACKAGE_ROOT_PART_NAME
public static final PackagePartName PACKAGE_ROOT_PART_NAME
Root package part name.
-
-
Method Detail
-
getPackageRootUri
public static URI getPackageRootUri()
Gets the URI for the package root.- Returns:
- URI of the package root.
-
isRelationshipPartURI
public static boolean isRelationshipPartURI(URI partUri)
Know if the specified URI is a relationship part name.- Parameters:
partUri- URI to check.- Returns:
- true if the URI false.
-
getFilenameWithoutExtension
public static String getFilenameWithoutExtension(URI uri)
Get the file name without the trailing extension.
-
combine
public static URI combine(URI prefix, URI suffix)
Combine two URIs.- Parameters:
prefix- the prefix URIsuffix- the suffix URI- Returns:
- the combined URI
-
combine
public static String combine(String prefix, String suffix)
Combine a string URI with a prefix and a suffix.
-
relativizeURI
public static URI relativizeURI(URI sourceURI, URI targetURI, boolean msCompatible)
Fully relativize the source part URI against the target part URI.- Parameters:
sourceURI- The source part URI.targetURI- The target part URI.msCompatible- if true then remove leading slash from the relativized URI. This flag violates [M1.4]: A part name shall start with a forward slash ('/') character, but allows generating URIs compatible with MS Office and OpenOffice.- Returns:
- A fully relativize part name URI ('word/media/image1.gif',
'/word/document.xml' => 'media/image1.gif') else
null.
-
relativizeURI
public static URI relativizeURI(URI sourceURI, URI targetURI)
Fully relativize the source part URI against the target part URI.- Parameters:
sourceURI- The source part URI.targetURI- The target part URI.- Returns:
- A fully relativize part name URI ('word/media/image1.gif',
'/word/document.xml' => 'media/image1.gif') else
null.
-
resolvePartUri
public static URI resolvePartUri(URI sourcePartUri, URI targetUri)
Resolve a source uri against a target.- Parameters:
sourcePartUri- The source URI.targetUri- The target URI.- Returns:
- The resolved URI.
-
getSourcePartUriFromRelationshipPartUri
public static URI getSourcePartUriFromRelationshipPartUri(URI relationshipPartUri)
Get the source part URI from a specified relationships part.- Parameters:
relationshipPartUri- The relationship part use to retrieve the source part.- Returns:
- The source part URI from the specified relationships part.
-
createPartName
public static PackagePartName createPartName(URI partUri) throws InvalidFormatException
Create an OPC compliant part name by throwing an exception if the URI is not valid.- Parameters:
partUri- The part name URI to validate.- Returns:
- A valid part name object, else
null. - Throws:
InvalidFormatException- Throws if the specified URI is not OPC compliant.
-
createPartName
public static PackagePartName createPartName(String partName) throws InvalidFormatException
Create an OPC compliant part name.- Parameters:
partName- The part name to validate.- Returns:
- The correspondant part name if valid, else
null. - Throws:
InvalidFormatException- Throws if the specified part name is not OPC compliant.- See Also:
createPartName(URI)
-
createPartName
public static PackagePartName createPartName(String partName, PackagePart relativePart) throws InvalidFormatException
Create an OPC compliant part name by resolving it using a base part.- Parameters:
partName- The part name to validate.relativePart- The relative base part.- Returns:
- The correspondant part name if valid, else
null. - Throws:
InvalidFormatException- Throws if the specified part name is not OPC compliant.- See Also:
createPartName(URI)
-
createPartName
public static PackagePartName createPartName(URI partName, PackagePart relativePart) throws InvalidFormatException
Create an OPC compliant part name by resolving it using a base part.- Parameters:
partName- The part name URI to validate.relativePart- The relative base part.- Returns:
- The correspondant part name if valid, else
null. - Throws:
InvalidFormatException- Throws if the specified part name is not OPC compliant.- See Also:
createPartName(URI)
-
isValidPartName
public static boolean isValidPartName(URI partUri)
Validate a part URI by returning a boolean. ([M1.1],[M1.3],[M1.4],[M1.5],[M1.6]) (OPC Specifications 8.1.1 Part names) : Part Name Syntax The part name grammar is defined as follows: part_name = 1*( "/" segment ) segment = 1*( pchar ) (pchar is defined in RFC 3986)- Parameters:
partUri- The URI to validate.- Returns:
- true if the URI is valid to the OPC Specifications, else false
- See Also:
createPartName(URI)
-
decodeURI
public static String decodeURI(URI uri)
Decode a URI by converting all percent encoded character into a String character.- Parameters:
uri- The URI to decode.- Returns:
- The specified URI in a String with converted percent encoded characters.
-
getRelationshipPartName
public static PackagePartName getRelationshipPartName(PackagePartName partName)
Build a part name where the relationship should be stored ((ex /word/document.xml -> /word/_rels/document.xml.rels)- Parameters:
partName- Source part URI- Returns:
- the full path (as URI) of the relation file
- Throws:
InvalidOperationException- Throws if the specified URI is a relationshp part.
-
toURI
public static URI toURI(String value) throws URISyntaxException
Convert a string toURIIf part name is not a valid URI, it is resolved as follows:1. Percent-encode each open bracket ([) and close bracket (]). 2. Percent-encode each percent (%) character that is not followed by a hexadecimal notation of an octet value. 3. Un-percent-encode each percent-encoded unreserved character. 4. Un-percent-encode each forward slash (/) and back slash (\). 5. Convert all back slashes to forward slashes. 6. If present in a segment containing non-dot (?.?) characters, remove trailing dot (?.?) characters from each segment. 7. Replace each occurrence of multiple consecutive forward slashes (/) with a single forward slash. 8. If a single trailing forward slash (/) is present, remove that trailing forward slash. 9. Remove complete segments that consist of three or more dots. 10. Resolve the relative reference against the base URI of the part holding the Unicode string, as it is defined in ?5.2 of RFC 3986. The path component of the resulting absolute URI is the part name.
- Parameters:
value- the string to be parsed into a URI- Returns:
- the resolved part name that should be OK to construct a URI TODO YK: for now this method does only (5). Finish the rest.
- Throws:
URISyntaxException
-
-