Package net.sf.okapi.lib.xliff2
Class URIParser
- java.lang.Object
-
- net.sf.okapi.lib.xliff2.URIParser
-
public class URIParser extends Object
Implements a URI supporting the fragment identification mechanism for XLIFF 2.
-
-
Constructor Summary
Constructors Constructor Description URIParser()Creates a new URIParser object without custom prefixes.URIParser(File extraPrefixes)Creates a new empty URIParser object that can use custom prefixes.URIParser(String urilOrFragment)Creates a new URIParser object for a given URI.URIParser(String urilOrFragment, String contextFileId, String contextGroupId, String contextUnitId)Creates a new URIParser object for a given URI and context identifiers.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddPrefixes(Map<String,String> map)Adds a collection of uri/prefix to the prefixes resolver associated with this object.URIParsercomplementReference()Changes this object to represent a complete fragment identifier if the initial one was relative.StringgetContextFileId()Gets the context file identifier of this URI's fragment.StringgetContextGroupId()Gets the context group identifier of this URI's fragment.StringgetContextUnitId()Gets the context unit identifier of this URI's fragment.StringgetDataId()Gets the original data identifier of this URI's fragment.booleangetErrorOnUnknownPrefix()Gets the option to generate or not an error when finding an unknown prefix.AbstractMap.SimpleEntry<String,List<String>>getExtensionInfo()Gets the extension information for this fragment.StringgetFileId()Gets the file identifier of this URI's fragment.StringgetGroupId()Gets the group identifier of this URI's fragment.StringgetNoteId()Gets the note identifier of this URI's fragment.chargetRefContainer()Gets the type of container for this URI reference.chargetRefType()Gets the type of reference for this URI's fragment.StringgetScope()Gets the scope string for this URI's fragment.StringgetSourceInlineId()Gets the segment or ignorable or source inline element of this URI's fragment.StringgetTargetInlineId()Gets the target inline element identifier of this URI's fragment.StringgetUnitId()Gets the unit identifier of this URI's fragment.URIgetURI()Gets the URI object for this object.booleanisFragmentOnly()Indicates if this URI has only a fragment.booleanisXLIFF()Indicates if this URI has an XLIFF 2 fragment identifier.voidsetErrorOnUnknownPrefix(boolean errorOnUnknownPrefix)Sets the option of generating or not an error when finding an unknown prefix.URIParsersetURL(String urilOrFragment)Sets the URI for this object.URIParsersetURL(String urilOrFragment, String contextFileId, String contextGroupId, String contextUnitId)Sets the URI and context identifiers for this object.StringtoString()
-
-
-
Constructor Detail
-
URIParser
public URIParser()
Creates a new URIParser object without custom prefixes.
-
URIParser
public URIParser(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(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(String urilOrFragment, String contextFileId, String contextGroupId, 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
-
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(Map<String,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(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(String urilOrFragment, String contextFileId, String contextGroupId, 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 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 forgetRefContainer().- 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 String getFileId()
Gets the file identifier of this URI's fragment.- Returns:
- the file identifier.
-
getGroupId
public String getGroupId()
Gets the group identifier of this URI's fragment.- Returns:
- the group identifier.
-
getUnitId
public String getUnitId()
Gets the unit identifier of this URI's fragment.- Returns:
- the unit identifier.
-
getNoteId
public String getNoteId()
Gets the note identifier of this URI's fragment.- Returns:
- the note identifier.
-
getSourceInlineId
public 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 String getTargetInlineId()
Gets the target inline element identifier of this URI's fragment.- Returns:
- the target inline element identifier.
-
getDataId
public String getDataId()
Gets the original data identifier of this URI's fragment.- Returns:
- the original data identifier.
-
getContextFileId
public String getContextFileId()
Gets the context file identifier of this URI's fragment.- Returns:
- the context file identifier.
-
getContextGroupId
public String getContextGroupId()
Gets the context group identifier of this URI's fragment.- Returns:
- the context group identifier.
-
getContextUnitId
public String getContextUnitId()
Gets the context unit identifier of this URI's fragment.- Returns:
- the context unit identifier.
-
getExtensionInfo
public AbstractMap.SimpleEntry<String,List<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 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).
-
-