public class NamespaceHelper extends Object
Modifier and Type | Field and Description |
---|---|
static String |
JCR
The
jcr namespace URI. |
static String |
MIX
The
mix namespace URI. |
static String |
NT
The
nt namespace URI. |
Constructor and Description |
---|
NamespaceHelper(Session session)
Creates a namespace helper for the given session.
|
Modifier and Type | Method and Description |
---|---|
String |
getJcrName(String name)
Replaces the standard
jcr , nt , or
mix prefix in the given name with the prefix
mapped to that namespace in the current session. |
String |
getJcrName(String uri,
String name)
Returns the prefixed JCR name for the given namespace URI and local
name in the current session.
|
Map<String,String> |
getNamespaces()
Returns a map containing all prefix to namespace URI mappings of
the current session.
|
String |
getPrefix(String uri)
Returns the prefix mapped to the given namespace URI in the current
session, or
null if the namespace does not exist. |
String |
getURI(String prefix)
Returns the namespace URI mapped to the given prefix in the current
session, or
null if the namespace does not exist. |
String |
registerNamespace(String prefix,
String uri)
Safely registers the given namespace.
|
void |
registerNamespaces(Map<String,String> namespaces)
Safely registers all namespaces in the given map from
prefixes to namespace URIs.
|
public static final String JCR
jcr
namespace URI.public static final String NT
nt
namespace URI.public static final String MIX
mix
namespace URI.public NamespaceHelper(Session session)
session
- current sessionpublic Map<String,String> getNamespaces() throws RepositoryException
RepositoryException
- if the namespaces could not be retrievedSession.getNamespacePrefixes()
public String getPrefix(String uri) throws RepositoryException
null
if the namespace does not exist.uri
- namespace URInull
RepositoryException
- if the namespace could not be retrievedSession.getNamespacePrefix(String)
public String getURI(String prefix) throws RepositoryException
null
if the namespace does not exist.prefix
- namespace prefixnull
RepositoryException
- if the namespace could not be retrievedSession.getNamespaceURI(String)
public String getJcrName(String uri, String name) throws NamespaceException, RepositoryException
uri
- namespace URIname
- local nameNamespaceException
- if the namespace does not existRepositoryException
- if the namespace could not be retrievedpublic String getJcrName(String name) throws IllegalArgumentException, RepositoryException
jcr
, nt
, or
mix
prefix 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"));
name
- prefixed name using the standard JCR prefixesIllegalArgumentException
- if the prefix is unknownRepositoryException
- if the namespace could not be retrievedpublic String registerNamespace(String prefix, String uri) throws RepositoryException
prefix
- namespace prefixuri
- namespace URIRepositoryException
- if the namespace could not be registeredNamespaceRegistry.registerNamespace(String, String)
public void registerNamespaces(Map<String,String> namespaces) throws RepositoryException
namespaces
- namespace mappingsRepositoryException
- if the namespaces could not be registeredCopyright © 2004–2021 The Apache Software Foundation. All rights reserved.