net.sf.okapi.lib.xliff2

## Class URIParser

- java.lang.Object
- - net.sf.okapi.lib.xliff2.URIParser

-     public class URIParser
      extends java.lang.Object

  Implements a URI supporting the fragment identification mechanism for XLIFF 2.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `URIParser()` Creates a new URIParser object without custom prefixes.
    `URIParser(java.io.File extraPrefixes)` Creates a new empty URIParser object that can use custom prefixes.
    `URIParser(java.lang.String urilOrFragment)` Creates a new URIParser object for a given URI.
    `URIParser(java.lang.String urilOrFragment, java.lang.String contextFileId, java.lang.String contextGroupId, java.lang.String contextUnitId)` Creates a new URIParser object for a given URI and context identifiers.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addPrefixes(java.util.Map<java.lang.String,java.lang.String> map)` Adds a collection of uri/prefix to the prefixes resolver associated with this object.
    `URIParser` | `complementReference()` Changes this object to represent a complete fragment identifier if the initial one was relative.
    `java.lang.String` | `getContextFileId()` Gets the context file identifier of this URI's fragment.
    `java.lang.String` | `getContextGroupId()` Gets the context group identifier of this URI's fragment.
    `java.lang.String` | `getContextUnitId()` Gets the context unit identifier of this URI's fragment.
    `java.lang.String` | `getDataId()` Gets the original data identifier of this URI's fragment.
    `boolean` | `getErrorOnUnknownPrefix()` Gets the option to generate or not an error when finding an unknown prefix.
    `java.util.AbstractMap.SimpleEntry<java.lang.String,java.util.List<java.lang.String>>` | `getExtensionInfo()` Gets the extension information for this fragment.
    `java.lang.String` | `getFileId()` Gets the file identifier of this URI's fragment.
    `java.lang.String` | `getGroupId()` Gets the group identifier of this URI's fragment.
    `java.lang.String` | `getNoteId()` Gets the note identifier of this URI's fragment.
    `char` | `getRefContainer()` Gets the type of container for this URI reference.
    `char` | `getRefType()` Gets the type of reference for this URI's fragment.
    `java.lang.String` | `getScope()` Gets the scope string for this URI's fragment.
    `java.lang.String` | `getSourceInlineId()` Gets the segment or ignorable or source inline element of this URI's fragment.
    `java.lang.String` | `getTargetInlineId()` Gets the target inline element identifier of this URI's fragment.
    `java.lang.String` | `getUnitId()` Gets the unit identifier of this URI's fragment.
    `java.net.URI` | `getURI()` Gets the URI object for this object.
    `boolean` | `isFragmentOnly()` Indicates if this URI has only a fragment.
    `boolean` | `isXLIFF()` Indicates if this URI has an XLIFF 2 fragment identifier.
    `void` | `setErrorOnUnknownPrefix(boolean errorOnUnknownPrefix)` Sets the option of generating or not an error when finding an unknown prefix.
    `URIParser` | `setURL(java.lang.String urilOrFragment)` Sets the URI for this object.
    `URIParser` | `setURL(java.lang.String urilOrFragment, java.lang.String contextFileId, java.lang.String contextGroupId, java.lang.String contextUnitId)` Sets the URI and context identifiers for this object.
    `java.lang.String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### URIParser

          public URIParser()

      Creates a new URIParser object without custom prefixes.

    - #### URIParser

          public URIParser(java.io.File extraPrefixes)

      Creates a new empty URIParser object that can use custom prefixes.
      Parameters:
        `extraPrefixes` - the file object where the custom prefixes are declared (or null).

    - #### URIParser

          public URIParser(java.lang.String urilOrFragment)

      Creates a new URIParser object for a given URI.
      Parameters:
        `urilOrFragment` - the URI to process (can be empty).
      Throws:
        `InvalidParameterException` - if there is an error in the fragment syntax.

    - #### URIParser

          public URIParser(java.lang.String urilOrFragment,
                   java.lang.String contextFileId,
                   java.lang.String contextGroupId,
                   java.lang.String contextUnitId)

      Creates a new URIParser object for a given URI and context identifiers.
      Parameters:
        `urilOrFragment` - the URI to process (can be empty).
        `contextFileId` - the id of the <file> element enclosing where this URI is located (or null).
        `contextGroupId` - the id of the <group> element enclosing where this URI is located (or null).
        `contextUnitId` - the id of the <unit> element enclosing where this URI is located (or null).
      Throws:
        `InvalidParameterException` - if there is an error in the fragment syntax.

  - ### Method Detail

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`

    - #### setErrorOnUnknownPrefix

          public void setErrorOnUnknownPrefix(boolean errorOnUnknownPrefix)

      Sets the option of generating or not an error when finding an unknown prefix.
      Parameters:
        `errorOnUnknownPrefix` - true to generate an error, false to not generate an error.

    - #### getErrorOnUnknownPrefix

          public boolean getErrorOnUnknownPrefix()

      Gets the option to generate or not an error when finding an unknown prefix.
      Returns:
        true when the option is to generate an error, false otherwise.

    - #### addPrefixes

          public void addPrefixes(java.util.Map<java.lang.String,java.lang.String> map)

      Adds a collection of uri/prefix to the prefixes resolver associated with this object.
      Parameters:
        `map` - the map to add.

    - #### setURL

          public URIParser setURL(java.lang.String urilOrFragment)

      Sets the URI for this object.
      Parameters:
        `urilOrFragment` - the URI to process (can be empty).
      Returns:
        the object itself.
      Throws:
        `InvalidParameterException` - if there is an error in the fragment syntax.

    - #### setURL

          public URIParser setURL(java.lang.String urilOrFragment,
                         java.lang.String contextFileId,
                         java.lang.String contextGroupId,
                         java.lang.String contextUnitId)

      Sets the URI and context identifiers for this object.
      Parameters:
        `urilOrFragment` - the URI to process (can be empty).
        `contextFileId` - the id of the <file> element enclosing where this URI is located (or null).
        `contextGroupId` - the id of the <group> element enclosing where this URI is located (or null).
        `contextUnitId` - the id of the <unit> element enclosing where this URI is located (or null).
      Returns:
        the object itself.
      Throws:
        `InvalidParameterException` - if there is an error in the fragment syntax.

    - #### getURI

          public java.net.URI getURI()

      Gets the URI object for this object.
      Returns:
        the URI object for this object.

    - #### complementReference

          public URIParser complementReference()

      Changes this object to represent a complete fragment identifier if the initial one was relative. This updates the value for `getRefContainer()`.
      Returns:
        the object itself.

    - #### isFragmentOnly

          public boolean isFragmentOnly()

      Indicates if this URI has only a fragment.
      Returns:
        true if this URI has only a fragment, false otherwise.

    - #### isXLIFF

          public boolean isXLIFF()

      Indicates if this URI has an XLIFF 2 fragment identifier.
      Returns:
        true if this URI has an XLIFF 2 fragment identifier, false if not.

    - #### getFileId

          public java.lang.String getFileId()

      Gets the file identifier of this URI's fragment.
      Returns:
        the file identifier.

    - #### getGroupId

          public java.lang.String getGroupId()

      Gets the group identifier of this URI's fragment.
      Returns:
        the group identifier.

    - #### getUnitId

          public java.lang.String getUnitId()

      Gets the unit identifier of this URI's fragment.
      Returns:
        the unit identifier.

    - #### getNoteId

          public java.lang.String getNoteId()

      Gets the note identifier of this URI's fragment.
      Returns:
        the note identifier.

    - #### getSourceInlineId

          public java.lang.String getSourceInlineId()

      Gets the segment or ignorable or source inline element of this URI's fragment.
      Returns:
        the segment, ignorable or source inline element identifier.

    - #### getTargetInlineId

          public java.lang.String getTargetInlineId()

      Gets the target inline element identifier of this URI's fragment.
      Returns:
        the target inline element identifier.

    - #### getDataId

          public java.lang.String getDataId()

      Gets the original data identifier of this URI's fragment.
      Returns:
        the original data identifier.

    - #### getContextFileId

          public java.lang.String getContextFileId()

      Gets the context file identifier of this URI's fragment.
      Returns:
        the context file identifier.

    - #### getContextGroupId

          public java.lang.String getContextGroupId()

      Gets the context group identifier of this URI's fragment.
      Returns:
        the context group identifier.

    - #### getContextUnitId

          public java.lang.String getContextUnitId()

      Gets the context unit identifier of this URI's fragment.
      Returns:
        the context unit identifier.

    - #### getExtensionInfo

          public java.util.AbstractMap.SimpleEntry<java.lang.String,java.util.List<java.lang.String>> getExtensionInfo()

      Gets the extension information for this fragment. It is provided as a SimpleEntry object where:
      - getKey() gives the extension id,
      - getValue() gets the list of namespace URIs associated to the prefix,
      Returns:
        the information or null.

    - #### getScope

          public java.lang.String getScope()

      Gets the scope string for this URI's fragment.
      Returns:
        the scope string for this URI's fragment.

    - #### getRefType

          public char getRefType()

      Gets the type of reference for this URI's fragment. This can be: 'f' (file), 'g' (group), 'u' (unit), 'n' (note), 'd' (data), 't' (target inline element), 's' (segment, ignorable, or source inline element, or 'x' (module or extension element).
      Returns:
        the type of reference specified (or '_' if undefined).

    - #### getRefContainer

          public char getRefContainer()

      Gets the type of container for this URI reference. This can return 'f' (file), 'g' (group) or 'u' (unit).
      Returns:
        the type of container for this reference (or '_' if undefined).