Package org.apache.jackrabbit.commons
Class NamespaceHelper
- java.lang.Object
-
- org.apache.jackrabbit.commons.NamespaceHelper
-
public class NamespaceHelper extends java.lang.ObjectHelper class for working with JCR namespaces.- Since:
- Jackrabbit JCR Commons 1.5
-
-
Constructor Summary
Constructors Constructor Description NamespaceHelper(javax.jcr.Session session)Creates a namespace helper for the given session.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringgetJcrName(java.lang.String name)Replaces the standardjcr,nt, ormixprefix in the given name with the prefix mapped to that namespace in the current session.java.lang.StringgetJcrName(java.lang.String uri, java.lang.String name)Returns the prefixed JCR name for the given namespace URI and local name in the current session.java.util.Map<java.lang.String,java.lang.String>getNamespaces()Returns a map containing all prefix to namespace URI mappings of the current session.java.lang.StringgetPrefix(java.lang.String uri)Returns the prefix mapped to the given namespace URI in the current session, ornullif the namespace does not exist.java.lang.StringgetURI(java.lang.String prefix)Returns the namespace URI mapped to the given prefix in the current session, ornullif the namespace does not exist.java.lang.StringregisterNamespace(java.lang.String prefix, java.lang.String uri)Safely registers the given namespace.voidregisterNamespaces(java.util.Map<java.lang.String,java.lang.String> namespaces)Safely registers all namespaces in the given map from prefixes to namespace URIs.
-
-
-
Field Detail
-
JCR
public static final java.lang.String JCR
Thejcrnamespace URI.- See Also:
- Constant Field Values
-
NT
public static final java.lang.String NT
Thentnamespace URI.- See Also:
- Constant Field Values
-
MIX
public static final java.lang.String MIX
Themixnamespace URI.- See Also:
- Constant Field Values
-
-
Method Detail
-
getNamespaces
public java.util.Map<java.lang.String,java.lang.String> getNamespaces() throws javax.jcr.RepositoryExceptionReturns a map containing all prefix to namespace URI mappings of the current session. The returned map is newly allocated and can can be freely modified by the caller.- Returns:
- namespace mappings
- Throws:
javax.jcr.RepositoryException- if the namespaces could not be retrieved- See Also:
Session.getNamespacePrefixes()
-
getPrefix
public java.lang.String getPrefix(java.lang.String uri) throws javax.jcr.RepositoryExceptionReturns the prefix mapped to the given namespace URI in the current session, ornullif the namespace does not exist.- Parameters:
uri- namespace URI- Returns:
- namespace prefix, or
null - Throws:
javax.jcr.RepositoryException- if the namespace could not be retrieved- See Also:
Session.getNamespacePrefix(String)
-
getURI
public java.lang.String getURI(java.lang.String prefix) throws javax.jcr.RepositoryExceptionReturns the namespace URI mapped to the given prefix in the current session, ornullif the namespace does not exist.- Parameters:
prefix- namespace prefix- Returns:
- namespace prefix, or
null - Throws:
javax.jcr.RepositoryException- if the namespace could not be retrieved- See Also:
Session.getNamespaceURI(String)
-
getJcrName
public java.lang.String getJcrName(java.lang.String uri, java.lang.String name) throws javax.jcr.NamespaceException, javax.jcr.RepositoryExceptionReturns the prefixed JCR name for the given namespace URI and local name in the current session.- Parameters:
uri- namespace URIname- local name- Returns:
- prefixed JCR name
- Throws:
javax.jcr.NamespaceException- if the namespace does not existjavax.jcr.RepositoryException- if the namespace could not be retrieved
-
getJcrName
public java.lang.String getJcrName(java.lang.String name) throws java.lang.IllegalArgumentException, javax.jcr.RepositoryExceptionReplaces the standardjcr,nt, ormixprefix in the given name with the prefix mapped to that namespace in the current session.The purpose of this method is to make it easier to write namespace-aware code that uses names in the standard JCR namespaces. For example:
node.getProperty(helper.getName("jcr:data"));- Parameters:
name- prefixed name using the standard JCR prefixes- Returns:
- prefixed name using the current session namespace mappings
- Throws:
java.lang.IllegalArgumentException- if the prefix is unknownjavax.jcr.RepositoryException- if the namespace could not be retrieved
-
registerNamespace
public java.lang.String registerNamespace(java.lang.String prefix, java.lang.String uri) throws javax.jcr.RepositoryExceptionSafely registers the given namespace. If the namespace already exists, then the prefix mapped to the namespace in the current session is returned. Otherwise the namespace is registered to the namespace registry. If the given prefix is already registered for some other namespace or otherwise invalid, then another prefix is automatically generated. After the namespace has been registered, the prefix mapped to it in the current session is returned.- Parameters:
prefix- namespace prefixuri- namespace URI- Returns:
- namespace prefix in the current session
- Throws:
javax.jcr.RepositoryException- if the namespace could not be registered- See Also:
NamespaceRegistry.registerNamespace(String, String)
-
registerNamespaces
public void registerNamespaces(java.util.Map<java.lang.String,java.lang.String> namespaces) throws javax.jcr.RepositoryExceptionSafely registers all namespaces in the given map from prefixes to namespace URIs.- Parameters:
namespaces- namespace mappings- Throws:
javax.jcr.RepositoryException- if the namespaces could not be registered
-
-