Package org.jaxen

Class SimpleNamespaceContext

  • All Implemented Interfaces:
    java.io.Serializable, NamespaceContext

    public class SimpleNamespaceContext
    extends java.lang.Object
    implements NamespaceContext, java.io.Serializable
    Provides mappings from namespace prefix to namespace URI to the XPath engine.
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      SimpleNamespaceContext()
      Creates a new empty namespace context.
      SimpleNamespaceContext​(java.util.Map namespaces)
      Creates a new namespace context pre-populated with the specified bindings.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addElementNamespaces​(Navigator nav, java.lang.Object element)
      Adds all the namespace declarations that are in scope on the given element.
      void addNamespace​(java.lang.String prefix, java.lang.String URI)
      Binds a prefix to a URI in this context.
      java.lang.String translateNamespacePrefixToUri​(java.lang.String prefix)
      Translate the provided namespace prefix into the matching bound namespace URI.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SimpleNamespaceContext

        public SimpleNamespaceContext()
        Creates a new empty namespace context.
      • SimpleNamespaceContext

        public SimpleNamespaceContext​(java.util.Map namespaces)
        Creates a new namespace context pre-populated with the specified bindings.
        Parameters:
        namespaces - the initial namespace bindings in scope. The keys in this must be strings containing the prefixes and the values are strings containing the namespace URIs.
        Throws:
        java.lang.NullPointerException - if the argument is null
        java.lang.ClassCastException - if any keys or values in the map are not strings
    • Method Detail

      • addElementNamespaces

        public void addElementNamespaces​(Navigator nav,
                                         java.lang.Object element)
                                  throws UnsupportedAxisException
        Adds all the namespace declarations that are in scope on the given element. In the case of an XSLT stylesheet, this would be the element that has the XPath expression in one of its attributes; e.g. <xsl:if test="condition/xpath/expression">.
        Parameters:
        nav - the navigator for use in conjunction with element
        element - the element to copy the namespaces from
        Throws:
        UnsupportedAxisException - if the navigator does not support the namespace axis
      • addNamespace

        public void addNamespace​(java.lang.String prefix,
                                 java.lang.String URI)
        Binds a prefix to a URI in this context.
        Parameters:
        prefix - the namespace prefix
        URI - the namespace URI
      • translateNamespacePrefixToUri

        public java.lang.String translateNamespacePrefixToUri​(java.lang.String prefix)
        Description copied from interface: NamespaceContext
        Translate the provided namespace prefix into the matching bound namespace URI.

        In XPath, there is no such thing as a 'default namespace'. The empty prefix always resolves to the empty namespace URI. This method should return null for the empty prefix. Similarly, the prefix "xml" always resolves to the URI "http://www.w3.org/XML/1998/namespace".

        Specified by:
        translateNamespacePrefixToUri in interface NamespaceContext
        Parameters:
        prefix - the namespace prefix to resolve
        Returns:
        the namespace URI bound to the prefix; or null if there is no such namespace