org.exolab.castor.xml
Class Namespaces

java.lang.Object
  extended by org.exolab.castor.xml.Namespaces

public final class Namespaces
extends Object

A class for handling Namespace declaration and scoping

Version:
$Revision: 9147 $ $Date: 2004-09-09 23:04:08 -0600 (Thu, 09 Sep 2004) $
Author:
Keith Visco

Field Summary
static String XML_NAMESPACE
          The reserved XML 1.0 Namespace URI
static String XML_NAMESPACE_PREFIX
          The reserved XML Namespace Prefix
 
Constructor Summary
Namespaces()
           
 
Method Summary
 void addNamespace(String prefix, String uri)
          Adds the given namespace declaration to this Namespaces instance
 void declareAsAttributes(AttributeListImpl atts)
          Declare the namespaces of this stack in as attributes.
 Enumeration<String> getLocalNamespacePrefixes()
          Returns all namespace prefixes declared locally
 Enumeration<String> getLocalNamespaces()
          Returns an Enumeration of local namespace URIs for this Namespaces.
 String getNamespacePrefix(String nsURI)
          Returns the Namespace prefix associated with the given URI.
 String[] getNamespacePrefixes(String nsURI)
          Returns the Namespace prefixes associated with the given URI.
 String getNamespaceURI(String prefix)
          Returns the Namespace URI associated with the given prefix
 String getNonDefaultNamespacePrefix(String nsURI)
          Returns the Namespace prefix associated with the given URI.
 boolean removeNamespace(String prefix)
          Removes the namespace declaration for the given prefix.
 void sendEndEvents(ContentHandler handler)
          Calls the given ContentHandler's endPrefixMapping method for each locally declared namespace
 void sendStartEvents(ContentHandler handler)
          Calls the given ContentHandler's startPrefixMapping method for each locally declared namespace
 
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 String XML_NAMESPACE_PREFIX
The reserved XML Namespace Prefix

See Also:
Constant Field Values

XML_NAMESPACE

public static final String XML_NAMESPACE
The reserved XML 1.0 Namespace URI

See Also:
Constant Field Values
Constructor Detail

Namespaces

public Namespaces()
Method Detail

addNamespace

public void addNamespace(String prefix,
                         String uri)
Adds the given namespace declaration to this Namespaces instance

Parameters:
prefix - the namespace prefix
uri - the namespace URI to be associated with the given prefix
Throws:
IllegalArgumentException - if uri is null

getLocalNamespaces

public Enumeration<String> getLocalNamespaces()
Returns an Enumeration of local namespace URIs for this Namespaces.

Returns:
an Enumeration of local namespace URIs.

getNamespaceURI

public String getNamespaceURI(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; null if the given namespace prefix is not bound.

getNamespacePrefix

public String getNamespacePrefix(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
Throws:
IllegalArgumentException - if nsURI is null

getLocalNamespacePrefixes

public Enumeration<String> getLocalNamespacePrefixes()
Returns all namespace prefixes declared locally

Returns:
an Enumeration of locally declared namespace prefixes

getNamespacePrefixes

public String[] getNamespacePrefixes(String nsURI)
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
Throws:
IllegalArgumentException - if nsURI is null

getNonDefaultNamespacePrefix

public String getNonDefaultNamespacePrefix(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
Throws:
IllegalArgumentException - if nsURI is null

removeNamespace

public boolean removeNamespace(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.

sendEndEvents

public void sendEndEvents(ContentHandler handler)
                   throws SAXException
Calls the given ContentHandler's endPrefixMapping method for each locally declared namespace

Parameters:
handler - the ContentHandler
Throws:
SAXException

sendStartEvents

public void sendStartEvents(ContentHandler handler)
                     throws SAXException
Calls the given ContentHandler's startPrefixMapping method for each locally declared namespace

Parameters:
handler - the ContentHandler
Throws:
SAXException

declareAsAttributes

public void declareAsAttributes(AttributeListImpl atts)
Declare the namespaces of this stack in as attributes.

Parameters:
atts - the Attribute List to fill in.


Copyright © 2013. All Rights Reserved.