Top Description Fields Constructors Methods
org.springframework.util.xml

public Class SimpleNamespaceContext

extends Object
implements NamespaceContext
Class Inheritance
All Implemented Interfaces
javax.xml.namespace.NamespaceContext
Imports
java.util.Collections, .HashMap, .Iterator, .LinkedHashSet, .Map, .Set, javax.xml.XMLConstants, javax.xml.namespace.NamespaceContext, org.springframework.lang.Nullable, org.springframework.util.Assert

Simple javax.xml.namespace.NamespaceContext implementation. Follows the standard NamespaceContext contract, and is loadable via a java.util.Map or java.util.Properties object
Authors
Arjen Poutsma, Juergen Hoeller
Since
3.0

Field Summary

Modifier and TypeField and Description
private String
private final Map<String, Set<String>>
private final Map<String, String>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
bindDefaultNamespaceUri(String
the namespace uri
namespaceUri
)

Bind the given namespace as default namespace.

public void
bindNamespaceUri(String
the namespace prefix
prefix
,
String
the namespace URI
namespaceUri
)

Bind the given prefix to the given namespace.

public void
clear()

Remove all declared prefixes.

public Iterator<String>
getBoundPrefixes()

Return all declared prefixes.

public String
getNamespaceURI(String
prefix to look up
prefix
)

Implements javax.xml.namespace.NamespaceContext.getNamespaceURI.

Get Namespace URI bound to a prefix in the current scope.

public String
getPrefix(String
URI of Namespace to lookup
namespaceUri
)

Implements javax.xml.namespace.NamespaceContext.getPrefix.

Get prefix bound to Namespace URI in the current scope.

public Iterator<String>
getPrefixes(String
URI of Namespace to lookup
namespaceUri
)

Implements javax.xml.namespace.NamespaceContext.getPrefixes.

Get all prefixes bound to a Namespace URI in the current scope.

private Set<String>
getPrefixesSet(String namespaceUri)

public void
removeBinding(String
the prefix to be removed
prefix
)

Remove the given prefix from this context.

public void
setBindings(Map<String, String> bindings)

Set the bindings for this namespace context.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

defaultNamespaceUriback to summary
private String defaultNamespaceUri
namespaceUriToPrefixesback to summary
private final Map<String, Set<String>> namespaceUriToPrefixes
prefixToNamespaceUriback to summary
private final Map<String, String> prefixToNamespaceUri

Constructor Detail

SimpleNamespaceContextback to summary
public SimpleNamespaceContext()

Method Detail

bindDefaultNamespaceUriback to summary
public void bindDefaultNamespaceUri(String namespaceUri)

Bind the given namespace as default namespace.

Parameters
namespaceUri:String

the namespace uri

bindNamespaceUriback to summary
public void bindNamespaceUri(String prefix, String namespaceUri)

Bind the given prefix to the given namespace.

Parameters
prefix:String

the namespace prefix

namespaceUri:String

the namespace URI

clearback to summary
public void clear()

Remove all declared prefixes.

getBoundPrefixesback to summary
public Iterator<String> getBoundPrefixes()

Return all declared prefixes.

getNamespaceURIback to summary
public String getNamespaceURI(String prefix)

Implements javax.xml.namespace.NamespaceContext.getNamespaceURI.

Doc from javax.xml.namespace.NamespaceContext.getNamespaceURI.

Get Namespace URI bound to a prefix in the current scope.

When requesting a Namespace URI by prefix, the following table describes the returned Namespace URI value for all possible prefix values:

Return value for specified prefixes
prefix parameter Namespace URI return value
DEFAULT_NS_PREFIX ("") default Namespace URI in the current scope or XMLConstants.NULL_NS_URI("") when there is no default Namespace URI in the current scope
bound prefix Namespace URI bound to prefix in current scope
unbound prefix XMLConstants.NULL_NS_URI("")
XMLConstants.XML_NS_PREFIX ("xml") XMLConstants.XML_NS_URI ("http://www.w3.org/XML/1998/namespace")
XMLConstants.XMLNS_ATTRIBUTE ("xmlns") XMLConstants.XMLNS_ATTRIBUTE_NS_URI ("http://www.w3.org/2000/xmlns/")
null IllegalArgumentException is thrown
Parameters
prefix:String

prefix to look up

Returns:String

Namespace URI bound to prefix in the current scope

Annotations
@Override
getPrefixback to summary
public String getPrefix(String namespaceUri)

Implements javax.xml.namespace.NamespaceContext.getPrefix.

Doc from javax.xml.namespace.NamespaceContext.getPrefix.

Get prefix bound to Namespace URI in the current scope.

To get all prefixes bound to a Namespace URI in the current scope, use getPrefixes(String namespaceURI).

When requesting a prefix by Namespace URI, the following table describes the returned prefix value for all Namespace URI values:

Return value for specified Namespace URIs
Namespace URI parameter prefix value returned
<default Namespace URI> XMLConstants.DEFAULT_NS_PREFIX ("")
bound Namespace URI prefix bound to Namespace URI in the current scope, if multiple prefixes are bound to the Namespace URI in the current scope, a single arbitrary prefix, whose choice is implementation dependent, is returned
unbound Namespace URI null
XMLConstants.XML_NS_URI ("http://www.w3.org/XML/1998/namespace") XMLConstants.XML_NS_PREFIX ("xml")
XMLConstants.XMLNS_ATTRIBUTE_NS_URI ("http://www.w3.org/2000/xmlns/") XMLConstants.XMLNS_ATTRIBUTE ("xmlns")
null IllegalArgumentException is thrown
Parameters
namespaceUri:String

URI of Namespace to lookup

Returns:String

prefix bound to Namespace URI in current context

Annotations
@Override
@Nullable
getPrefixesback to summary
public Iterator<String> getPrefixes(String namespaceUri)

Implements javax.xml.namespace.NamespaceContext.getPrefixes.

Doc from javax.xml.namespace.NamespaceContext.getPrefixes.

Get all prefixes bound to a Namespace URI in the current scope.

An Iterator over String elements is returned in an arbitrary, implementation dependent, order.

The Iterator is not modifiable. e.g. the remove() method will throw UnsupportedOperationException.

When requesting prefixes by Namespace URI, the following table describes the returned prefixes value for all Namespace URI values:

Return value for specified Namespace URIs
Namespace URI parameter prefixes value returned
bound Namespace URI, including the <default Namespace URI> Iterator over prefixes bound to Namespace URI in the current scope in an arbitrary, implementation dependent, order
unbound Namespace URI empty Iterator
XMLConstants.XML_NS_URI ("http://www.w3.org/XML/1998/namespace") Iterator with one element set to XMLConstants.XML_NS_PREFIX ("xml")
XMLConstants.XMLNS_ATTRIBUTE_NS_URI ("http://www.w3.org/2000/xmlns/") Iterator with one element set to XMLConstants.XMLNS_ATTRIBUTE ("xmlns")
null IllegalArgumentException is thrown
Parameters
namespaceUri:String

URI of Namespace to lookup

Returns:Iterator<String>

Iterator for all prefixes bound to the Namespace URI in the current scope

Annotations
@Override
getPrefixesSetback to summary
private Set<String> getPrefixesSet(String namespaceUri)
removeBindingback to summary
public void removeBinding(String prefix)

Remove the given prefix from this context.

Parameters
prefix:String

the prefix to be removed

setBindingsback to summary
public void setBindings(Map<String, String> bindings)

Set the bindings for this namespace context. The supplied map must consist of string key value pairs.