Class URIHelper

java.lang.Object
org.docx4j.openpackaging.URIHelper

public final class URIHelper
extends java.lang.Object
Helper for part and pack URI.
Version:
0.3
Author:
Julien Chable, CDubet
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static PartName CORE_PROPERTIES_PART_NAME
    Core properties partname.
    static java.net.URI CORE_PROPERTIES_URI
    Core properties part URI.
    static char FORWARD_SLASH_CHAR
    Forward slash URI separator.
    static java.lang.String FORWARD_SLASH_STRING
    Forward slash URI separator.
    static java.lang.String PACKAGE_CORE_PROPERTIES_NAME
    Core package properties art name.
    static java.lang.String PACKAGE_PROPERTIES_SEGMENT_NAME
    Segment name of the package properties folder.
    static PartName PACKAGE_RELATIONSHIPS_ROOT_PART_NAME
    Package relationships part name.
    static java.net.URI PACKAGE_RELATIONSHIPS_ROOT_URI
    Package relationships part URI
    static PartName PACKAGE_ROOT_PART_NAME
    Root package part name.
    static java.net.URI PACKAGE_ROOT_URI
    Root package URI.
    static java.lang.String RELATIONSHIP_PART_EXTENSION_NAME
    Extension name of a relationship part.
    static java.lang.String RELATIONSHIP_PART_SEGMENT_NAME
    Segment name of a relationship part.
  • Constructor Summary

    Constructors 
    Constructor Description
    URIHelper()  
  • Method Summary

    Modifier and Type Method Description
    static java.lang.String combine​(java.lang.String prefix, java.lang.String suffix)
    Combine a string URI with a prefix and a suffix.
    static java.net.URI combine​(java.net.URI prefix, java.net.URI suffix)
    Combine two URI.
    static PartName createPartName​(java.lang.String partName)
    Create an OPC compliant part name by throwing an exception if the specified name is not valid.
    static PartName createPartName​(java.net.URI partUri)
    Create an OPC compliant part name by throwing an exception if the URI is not valid.
    static java.lang.String decodeURI​(java.net.URI uri)
    Decode a URI by converting all percent encoded character into a String character.
    static java.lang.String getFilename​(java.net.URI uri)
    Get file name from the specified URI.
    static java.lang.String getFilenameWithoutExtension​(java.net.URI uri)
    Get the file name without the trailing extension.
    static java.net.URI getPackageRootUri()
    Gets the URI for the package root.
    static java.net.URI getPath​(java.net.URI uri)
    Get the directory path from the specified URI.
    static java.net.URI getSourcePartUriFromRelationshipPartUri​(java.net.URI relationshipPartUri)  
    static java.net.URI getURIFromPath​(java.lang.String path)
    Get URI from a string path.
    static boolean isValidPartName​(java.net.URI partUri)
    Validate a part URI by returning a boolean.
    static java.net.URI relativizeURI​(java.net.URI sourceURI, java.net.URI targetURI)
    Fully relativize the target part URI against the source part URI.
    static java.net.URI resolvePartUri​(java.net.URI sourcePartUri, java.net.URI targetUri)
    Resolve a target uri against a source.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

  • Method Details

    • getPackageRootUri

      public static java.net.URI getPackageRootUri()
      Gets the URI for the package root.
      Returns:
      URI of the package root.
    • getFilename

      public static java.lang.String getFilename​(java.net.URI uri)
      Get file name from the specified URI.
    • getFilenameWithoutExtension

      public static java.lang.String getFilenameWithoutExtension​(java.net.URI uri)
      Get the file name without the trailing extension.
    • getPath

      public static java.net.URI getPath​(java.net.URI uri)
      Get the directory path from the specified URI.
    • combine

      public static java.net.URI combine​(java.net.URI prefix, java.net.URI suffix)
      Combine two URI.
      Parameters:
      prefix -
      suffix -
      Returns:
    • combine

      public static java.lang.String combine​(java.lang.String prefix, java.lang.String suffix)
      Combine a string URI with a prefix and a suffix.
    • relativizeURI

      public static java.net.URI relativizeURI​(java.net.URI sourceURI, java.net.URI targetURI)
      Fully relativize the target part URI against the source 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 java.net.URI resolvePartUri​(java.net.URI sourcePartUri, java.net.URI targetUri)
      Resolve a target uri against a source.
      Parameters:
      sourcePartUri - The source URI.
      targetUri - The target URI.
      Returns:
      The resolved URI.
    • getURIFromPath

      public static java.net.URI getURIFromPath​(java.lang.String path)
      Get URI from a string path.
    • getSourcePartUriFromRelationshipPartUri

      public static java.net.URI getSourcePartUriFromRelationshipPartUri​(java.net.URI relationshipPartUri)
    • createPartName

      public static PartName createPartName​(java.net.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 PartName createPartName​(java.lang.String partName) throws InvalidFormatException
      Create an OPC compliant part name by throwing an exception if the specified name is not valid.
      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)
    • isValidPartName

      public static boolean isValidPartName​(java.net.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 java.lang.String decodeURI​(java.net.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.