Package com.complexible.common.util
Class PrefixMapping
java.lang.Object
com.complexible.common.util.PrefixMapping
A class to convert URI's to QNames.
- Since:
- 2.0
- Version:
- 2.0
- Author:
- Evren Sirin, Michael Grove
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new PrefixMapping adding defaults for the common namespaces, OWL, RDF, RDFS and XSDPrefixMapping(boolean theAddDefaults) Create a new PrefixMapping optionally adding defaults for the common (OWL, RDF, RDFS, XSD) namespaces -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddMapping(String prefix, String uri) Add a new prefix/namespace mapping.voidclear()Clears all existing prefix/namespace mappingsgetNamespace(String prefix) Return the namespace for the given prefixReturn the prefix for the namespaceReturn the list of prefixes currently bound in this PrefixMappingReturn the qname for the given URI.Return the URI as a qname.booleanremoveMapping(String prefix, String uri) Remove a prefix/namespace mapping.voidsetMapping(String prefix, String uri) Set a prefix/namespace mapping.toString()Return the full URI for the provided qname.
-
Field Details
-
GLOBAL
-
-
Constructor Details
-
PrefixMapping
public PrefixMapping()Create a new PrefixMapping adding defaults for the common namespaces, OWL, RDF, RDFS and XSD -
PrefixMapping
public PrefixMapping(boolean theAddDefaults) Create a new PrefixMapping optionally adding defaults for the common (OWL, RDF, RDFS, XSD) namespaces- Parameters:
theAddDefaults- whether or not to add the default namespaces
-
-
Method Details
-
getPrefix
Return the prefix for the namespace- Parameters:
uri- the namespace URI- Returns:
- the prefix for the namespace or null if one does not exist
-
getNamespace
Return the namespace for the given prefix- Parameters:
prefix- the prefix- Returns:
- the namespace for the prefix, or null if one does not exist
-
addMapping
Add a new prefix/namespace mapping. This will not overrwrite existing mappings for the given prefix and namespace. If you wish to overwrite an existing mapping, usesetMapping(java.lang.String, java.lang.String)- Parameters:
prefix- the prefixuri- the namespace URI for the prefix- Returns:
- whether or not the mapping was added
-
setMapping
Set a prefix/namespace mapping. This will override any existing mapping. To optionally add the mapping, useaddMapping(java.lang.String, java.lang.String)- Parameters:
prefix- the prefixuri- the namespace URI for the prefix
-
removeMapping
Remove a prefix/namespace mapping. Only the exact mapping is removed.- Parameters:
prefix- the prefixuri- the uri- Returns:
- true if removed, false otherwise
-
clear
public void clear()Clears all existing prefix/namespace mappings -
getPrefixes
Return the list of prefixes currently bound in this PrefixMapping- Returns:
- the list of currently used prefixes
-
qname
Return the qname for the given URI. This will use the existing prefix definition if possible, and if one does not exist a new prefix of the form ns(int) (ex. ns2) will be created, saved, and returned. A null prefix returns a null qname.- Parameters:
uri- the URI- Returns:
- the URI as a qname
-
qname
Return the URI as a qname. A prefix for the URI will be auto generated if autoGenerate is set to true and a prefix does not already exist for the namespace of the URI. A null prefix returns a null qname.- Parameters:
uri- the URI to shortenautoGenerate- whether or not to auto-generate a qname prefix for the URI if one does not exist- Returns:
- the qname of the URI, or the URI itself if a prefix mapping does not exist and autoGenerate is false.
-
uri
Return the full URI for the provided qname. If there is no prefix mapping for the provided qname, the qname is returned, otherwise the prefix is replaced with the namespace as indicated byaddMapping(java.lang.String, java.lang.String)or if it was added viaqname(java.lang.String). A null qname returns a null URI.- Parameters:
qname- the qname to expand- Returns:
- the expanded qname, or the qname if it cannot be expanded
-
toString
-