net.sf.xolite.dom
Class DomXMLEventParser

java.lang.Object
  extended by net.sf.xolite.impl.BaseXMLEventParser
      extended by net.sf.xolite.dom.DomXMLEventParser
All Implemented Interfaces:
NamespaceContext, XMLEventParser

public class DomXMLEventParser
extends BaseXMLEventParser

A XMLEventParser implementation using a DOM tree as input.


Constructor Summary
DomXMLEventParser()
          Build a DomEventParser.
 
Method Summary
protected  void addLocationInfo(XMLParseException xpe)
           
 Iterator<String> getAttributeNameIterator(String attrNamespaceURI)
          Get an iterator on names of all the attributes present in the current element and belonging to the given namespace.
 Iterator<String> getAttributeNamespaceIterator()
          Get an iterator on namespaces of all the attributes present in the current element.
 String getAttributeValue(String attrName)
          Get an attribute value.
 String getAttributeValueNS(String attrNamespaceURI, String attrName)
          Get value of an attribute with namespace.
 NamespaceContext getCurrentDefinedNamespaces()
          Get NamespacePrefixResolver mapping the prefix to the namespace URI.
 String getElementText()
          Get the content of the text buffer.
 String getNamespaceURI(String prefix)
          Get namespace URI corresponding to the given prefix.
 String getPrefix(String namespaceURI)
          Get the first perfix mapped to the given namespace.
 Iterator<String> getPrefixes(String namespaceURI)
          Get all the prefix mapped to the given namespace.
 String getSourceDescription()
           
 XMLSerializable parse(Document src)
          'Parse' the given DOM Document to java objects.
 void parse(Document src, XMLSerializable rootHandler)
          'Parse' the given DOM Document using the given XMLSerializable as root handler.
 XMLSerializable parseElement(String uri, String localName)
          Create the XMLSerializable object corresponding to the given XML element, delegates the parsing to it and return the created object.
protected  void tearDown()
          Clean state and avoid keeping dangling references to internal objects.
 
Methods inherited from class net.sf.xolite.impl.BaseXMLEventParser
delegateParsingTo, endElementImpl, getCurrentElementName, getCustomObject, getFactory, getLastParsedObject, getQualifiedName, isFirstEvent, isLastEvent, pushPrefixMappingInNextLevel, putCustomObject, setFactory, setup, startElementImpl, throwParseException, throwUnexpectedElementException, throwUnexpectedNamespaceException, transformAndThrowException
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DomXMLEventParser

public DomXMLEventParser()
Build a DomEventParser.

Method Detail

parse

public XMLSerializable parse(Document src)
                      throws XMLParseException
'Parse' the given DOM Document to java objects.
This method will succeed only if a factory knowing the class of the root element is defined.

Parameters:
src - source DOM Document.
Throws:
XMLParseException - if the source contains an invalid XML document.

parse

public void parse(Document src,
                  XMLSerializable rootHandler)
           throws XMLParseException
'Parse' the given DOM Document using the given XMLSerializable as root handler.

Parameters:
src - source DOM Document.
rootHandler - the root handler.
Throws:
XMLParseException - if the source contains an invalid DOM document.

tearDown

protected void tearDown()
Clean state and avoid keeping dangling references to internal objects.

Overrides:
tearDown in class BaseXMLEventParser

getNamespaceURI

public String getNamespaceURI(String prefix)
Get namespace URI corresponding to the given prefix. Note: the mapped namespace set depends on the current parsed node.

Specified by:
getNamespaceURI in interface NamespaceContext
Overrides:
getNamespaceURI in class BaseXMLEventParser
See Also:
NamespaceContext.getPrefix(java.lang.String)

getPrefix

public String getPrefix(String namespaceURI)
Get the first perfix mapped to the given namespace.

Specified by:
getPrefix in interface NamespaceContext
Overrides:
getPrefix in class BaseXMLEventParser
See Also:
NamespaceContext.getPrefix(java.lang.String)

getPrefixes

public Iterator<String> getPrefixes(String namespaceURI)
Get all the prefix mapped to the given namespace.

Specified by:
getPrefixes in interface NamespaceContext
Overrides:
getPrefixes in class BaseXMLEventParser
See Also:
NamespaceContext.getPrefixes(java.lang.String)

getCurrentDefinedNamespaces

public NamespaceContext getCurrentDefinedNamespaces()
Description copied from interface: XMLEventParser
Get NamespacePrefixResolver mapping the prefix to the namespace URI. A copy of the current mapping object of this parser at the moment of the call is returned.

Specified by:
getCurrentDefinedNamespaces in interface XMLEventParser
Overrides:
getCurrentDefinedNamespaces in class BaseXMLEventParser

parseElement

public XMLSerializable parseElement(String uri,
                                    String localName)
                             throws XMLParseException
Description copied from interface: XMLEventParser
Create the XMLSerializable object corresponding to the given XML element, delegates the parsing to it and return the created object.
Note: when returned the created object has not yet finished it's parsing. Only the first startElement(..) method has been called on it.
This method will work only if there is a factory defined and this factory knows the given element. It is equivalent to:
 XMLSerializable child = parser.getFactory().createObject(uri, localName, parser);
 parser.delegateParsingTo(child, uri, localName);
 return child;
 

Specified by:
parseElement in interface XMLEventParser
Overrides:
parseElement in class BaseXMLEventParser
Throws:
XMLParseException

getElementText

public String getElementText()
Description copied from interface: XMLEventParser
Get the content of the text buffer. Usually, this method is called when the end of the element (containing the text) is notified by a SAX event.

Use the ElementText helper class to get, parse, validate and format easily the element text.

Calling this method from a startElement notification is useful only when parsing XML with mixed content. In this case you got the text just before the started element.

Returns:
the text data of the current XML element.

addLocationInfo

protected void addLocationInfo(XMLParseException xpe)
Specified by:
addLocationInfo in class BaseXMLEventParser

getSourceDescription

public String getSourceDescription()

getAttributeValue

public String getAttributeValue(String attrName)
                         throws XMLParseException
Description copied from interface: XMLEventParser
Get an attribute value. If the requested attribute is not defined (because it is optional), null is returned.

Parameters:
attrName - the name of the attribute.
Returns:
the requested attribute value.
Throws:
XMLParseException

getAttributeValueNS

public String getAttributeValueNS(String attrNamespaceURI,
                                  String attrName)
                           throws XMLParseException
Description copied from interface: XMLEventParser
Get value of an attribute with namespace. If the requested attribute is not defined (because it is optional), the null is returned.

This method allows to specify the namespace of the attribute. In most of the case attributes are not associated to namespaces. It is not necessary because attributes definitions are, in most of the case, local to the definition of the element containing it. So this method should be rarely used (use the corresponding method without namespace parameter). Examples of attributes using namespaces are: 'xml:lang' or 'xmlns:prefix'. To get values of those attributes you must provide the namespace URI.

Parameters:
attrNamespaceURI - the namespace URI of the attribute.
attrName - the name of the attribute.
Returns:
the requested attribute value.
Throws:
XMLParseException

getAttributeNamespaceIterator

public Iterator<String> getAttributeNamespaceIterator()
                                               throws XMLParseException
Description copied from interface: XMLEventParser
Get an iterator on namespaces of all the attributes present in the current element.

Returns:
Iterator on namespaces of all the attributes present in the current element.
Throws:
XMLParseException

getAttributeNameIterator

public Iterator<String> getAttributeNameIterator(String attrNamespaceURI)
                                          throws XMLParseException
Description copied from interface: XMLEventParser
Get an iterator on names of all the attributes present in the current element and belonging to the given namespace.
Use null as namespace for attributes not bound to a namespace (i.e. most of the attributes).

Parameters:
attrNamespaceURI - namespace of the attributes or null for attributes without namespaces.
Returns:
Iterator on names of all the attributes present in the current element and belonging to the given namespace.
Throws:
XMLParseException


Copyright © 2012. All Rights Reserved.