Class NamespaceHelper

  • public class NamespaceHelper
    extends Object
    Helper class for working with JCR namespaces.
    Jackrabbit JCR Commons 1.5
    • Constructor Detail

      • NamespaceHelper

        public NamespaceHelper​(Session session)
        Creates a namespace helper for the given session.
        session - current session
    • Method Detail

      • getJcrName

        public String getJcrName​(String name)
                          throws IllegalArgumentException,
        Replaces the standard 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:

        name - prefixed name using the standard JCR prefixes
        prefixed name using the current session namespace mappings
        IllegalArgumentException - if the prefix is unknown
        RepositoryException - if the namespace could not be retrieved
      • registerNamespace

        public String registerNamespace​(String prefix,
                                        String uri)
                                 throws RepositoryException
        Safely 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.
        prefix - namespace prefix
        uri - namespace URI
        namespace prefix in the current session
        RepositoryException - if the namespace could not be registered
        See Also:
        NamespaceRegistry.registerNamespace(String, String)
      • registerNamespaces

        public void registerNamespaces​(Map<String,​String> namespaces)
                                throws RepositoryException
        Safely registers all namespaces in the given map from prefixes to namespace URIs.
        namespaces - namespace mappings
        RepositoryException - if the namespaces could not be registered