Class Namespaces


  • public final class Namespaces
    extends java.lang.Object
    A class for handling Namespace declaration and scoping
    Version:
    $Revision: 5951 $ $Date: 2004-09-09 23:04:08 -0600 (Thu, 09 Sep 2004) $
    Author:
    Keith Visco
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) class  Namespaces.Namespace
      An internal class used to represent a namespace
      (package private) static class  Namespaces.NamespaceEnumerator
      A simple Enumeration for Namespace objects
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String XML_NAMESPACE
      The reserved XML 1.0 Namespace URI
      static java.lang.String XML_NAMESPACE_PREFIX
      The reserved XML Namespace Prefix
    • Constructor Summary

      Constructors 
      Constructor Description
      Namespaces()
      Creates a new Namespaces instance
      Namespaces​(Namespaces parent)
      Creates a new Namespaces instance
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addNamespace​(java.lang.String prefix, java.lang.String uri)
      Adds the given namespace declaration to this Namespaces
      Namespaces createNamespaces()
      Creates a new Namespaces instance with this Namespaces as the parent
      void declareAsAttributes​(org.xml.sax.helpers.AttributeListImpl atts, boolean localOnly)
      Declare the namespaces of this stack in as attributes.
      java.util.Enumeration getLocalNamespacePrefixes()
      Returns all namespace prefixes declared locally
      java.util.Enumeration getLocalNamespaces()
      Returns an Enumeration of local namespace URIs for this Namespaces.
      java.lang.String getNamespacePrefix​(java.lang.String nsURI)
      Returns the Namespace prefix associated with the given URI.
      java.lang.String[] getNamespacePrefixes​(java.lang.String nsURI)
      Returns all namespace prefixes associated with the given URI, including those from parent scopes.
      java.lang.String[] getNamespacePrefixes​(java.lang.String nsURI, boolean local)
      Returns the Namespace prefixes associated with the given URI.
      java.lang.String getNamespaceURI​(java.lang.String prefix)
      Returns the Namespace URI associated with the given prefix
      java.lang.String getNonDefaultNamespacePrefix​(java.lang.String nsURI)
      Returns the Namespace prefix associated with the given URI.
      Namespaces getParent()
      Returns the parent Namespaces for this Namespaces instance.
      boolean removeNamespace​(java.lang.String prefix)
      Removes the namespace declaration for the given prefix.
      void sendEndEvents​(org.xml.sax.ContentHandler handler)
      Calls the given ContentHandler's endPrefixMapping method for each locally declared namespace
      void sendStartEvents​(org.xml.sax.ContentHandler handler)
      Calls the given ContentHandler's startPrefixMapping method for each locally declared namespace
      void setParent​(Namespaces namespaces)
      Sets the parent Namespaces for this Namespaces instance.
      • Methods inherited from class java.lang.Object

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

      • XML_NAMESPACE_PREFIX

        public static final java.lang.String XML_NAMESPACE_PREFIX
        The reserved XML Namespace Prefix
        See Also:
        Constant Field Values
      • XML_NAMESPACE

        public static final java.lang.String XML_NAMESPACE
        The reserved XML 1.0 Namespace URI
        See Also:
        Constant Field Values
    • Constructor Detail

      • Namespaces

        public Namespaces()
        Creates a new Namespaces instance
      • Namespaces

        public Namespaces​(Namespaces parent)
        Creates a new Namespaces instance
    • Method Detail

      • addNamespace

        public void addNamespace​(java.lang.String prefix,
                                 java.lang.String uri)
        Adds the given namespace declaration to this Namespaces
        Parameters:
        prefix - the namespace prefix
        uri - the namespace URI to be associated with the given prefix
      • createNamespaces

        public Namespaces createNamespaces()
        Creates a new Namespaces instance with this Namespaces as the parent
      • getLocalNamespaces

        public java.util.Enumeration getLocalNamespaces()
        Returns an Enumeration of local namespace URIs for this Namespaces.
        Returns:
        an Enumeration of local namespace URIs.
      • getNamespaceURI

        public java.lang.String getNamespaceURI​(java.lang.String prefix)
        Returns the Namespace URI associated with the given prefix
        Parameters:
        prefix - the namespace prefix to lookup
        Returns:
        the namespace URI associated with the given prefix
      • getNamespacePrefix

        public java.lang.String getNamespacePrefix​(java.lang.String nsURI)
        Returns the Namespace prefix associated with the given URI. If multiple namespace prefixes have been declared, then the first one found is returned. To obtain all prefixes see #getNamespacePrefixes.
        Parameters:
        nsURI - the namespace URI to lookup
        Returns:
        the namespace prefix associated with the given URI
      • getLocalNamespacePrefixes

        public java.util.Enumeration getLocalNamespacePrefixes()
        Returns all namespace prefixes declared locally
        Returns:
        an Enumeration of locally declared namespace prefixes
      • getNamespacePrefixes

        public java.lang.String[] getNamespacePrefixes​(java.lang.String nsURI)
        Returns all namespace prefixes associated with the given URI, including those from parent scopes.
        Parameters:
        nsURI - the namespace URI to lookup
        Returns:
        the namespace prefixes associated with the given URI
      • getNamespacePrefixes

        public java.lang.String[] getNamespacePrefixes​(java.lang.String nsURI,
                                                       boolean local)
        Returns the Namespace prefixes associated with the given URI.
        Parameters:
        nsURI - the namespace URI to lookup
        local - a boolean that when true indicates only the local scope is searched.
        Returns:
        the namespace prefixes associated with the given URI
      • getNonDefaultNamespacePrefix

        public java.lang.String getNonDefaultNamespacePrefix​(java.lang.String nsURI)
        Returns the Namespace prefix associated with the given URI. Or null if no prefix has been declared. This method will ignore the default namespace. This is useful when dealing with attributes that do not use the default namespace.
        Parameters:
        nsURI - the namespace URI to lookup
        Returns:
        the namespace prefix associated with the given URI
      • getParent

        public Namespaces getParent()
        Returns the parent Namespaces for this Namespaces instance.
        Returns:
        the parent Namespaces for this Namespaces instance.
      • removeNamespace

        public boolean removeNamespace​(java.lang.String prefix)
        Removes the namespace declaration for the given prefix. This is a local action only, the namespace declaration will not be removed from any parent Namespaces object.
        Parameters:
        prefix - the namespace prefix to remove the binding of
        Returns:
        true if the namespace declaration was removed, otherwise false.
      • setParent

        public void setParent​(Namespaces namespaces)
        Sets the parent Namespaces for this Namespaces instance.
        Parameters:
        namespaces - the parent Namespaces
      • sendEndEvents

        public void sendEndEvents​(org.xml.sax.ContentHandler handler)
                           throws org.xml.sax.SAXException
        Calls the given ContentHandler's endPrefixMapping method for each locally declared namespace
        Parameters:
        handler - the ContentHandler
        Throws:
        org.xml.sax.SAXException
      • sendStartEvents

        public void sendStartEvents​(org.xml.sax.ContentHandler handler)
                             throws org.xml.sax.SAXException
        Calls the given ContentHandler's startPrefixMapping method for each locally declared namespace
        Parameters:
        handler - the ContentHandler
        Throws:
        org.xml.sax.SAXException
      • declareAsAttributes

        public void declareAsAttributes​(org.xml.sax.helpers.AttributeListImpl atts,
                                        boolean localOnly)
        Declare the namespaces of this stack in as attributes.
        Parameters:
        atts - the Attribute List to fill in.