Package com.complexible.common.util
Class PrefixMapping
- java.lang.Object
-
- com.complexible.common.util.PrefixMapping
-
public class PrefixMapping extends java.lang.Object
A class to convert URI's to QNames.
- Since:
- 2.0
- Version:
- 2.0
- Author:
- Evren Sirin, Michael Grove
-
-
Field Summary
Fields Modifier and Type Field Description static PrefixMapping
GLOBAL
-
Constructor Summary
Constructors Constructor Description PrefixMapping()
Create 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addMapping(java.lang.String prefix, java.lang.String uri)
Add a new prefix/namespace mapping.void
clear()
Clears all existing prefix/namespace mappingsjava.lang.String
getNamespace(java.lang.String prefix)
Return the namespace for the given prefixjava.lang.String
getPrefix(java.lang.String uri)
Return the prefix for the namespacejava.util.Collection<java.lang.String>
getPrefixes()
Return the list of prefixes currently bound in this PrefixMappingjava.lang.String
qname(java.lang.String uri)
Return the qname for the given URI.java.lang.String
qname(java.lang.String uri, boolean autoGenerate)
Return the URI as a qname.boolean
removeMapping(java.lang.String prefix, java.lang.String uri)
Remove a prefix/namespace mapping.void
setMapping(java.lang.String prefix, java.lang.String uri)
Set a prefix/namespace mapping.java.lang.String
toString()
java.lang.String
uri(java.lang.String qname)
Return the full URI for the provided qname.
-
-
-
Field Detail
-
GLOBAL
public static final PrefixMapping GLOBAL
-
-
Constructor Detail
-
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 Detail
-
getPrefix
public java.lang.String getPrefix(java.lang.String uri)
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
public java.lang.String getNamespace(java.lang.String prefix)
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
public boolean addMapping(java.lang.String prefix, java.lang.String uri)
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
public void setMapping(java.lang.String prefix, java.lang.String uri)
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
public boolean removeMapping(java.lang.String prefix, java.lang.String uri)
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
public java.util.Collection<java.lang.String> getPrefixes()
Return the list of prefixes currently bound in this PrefixMapping- Returns:
- the list of currently used prefixes
-
qname
public java.lang.String qname(java.lang.String uri)
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
public java.lang.String qname(java.lang.String uri, boolean autoGenerate)
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
public java.lang.String uri(java.lang.String qname)
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
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-