public static class

XmlParser.ElementHandler

extends Object
java.lang.Object
   ↳ com.google.gdata.util.XmlParser.ElementHandler
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

Base class for custom element handlers.

To implement a new element handler, one must create a new class extending this class, override getChildHandler(String, String, String, Attributes, List) if nested elements need to be parsed, override processAttribute(String, String, String) if attributes need to be parsed, and override processEndElement() to receive the text() value and post-process the element.

If the handler wishes to store unrecognized XML contents in an XmlBlob value, it must call initializeXmlBlob(XmlBlob, boolean, boolean) either in the constructor, in parent's getChildHandler(String, String, String, Attributes, List), or in processAttribute(String, String, String). The resulting XmlBlob value is available following the invocation of processEndElement() through the object passed to initializeXmlBlob(XmlBlob, boolean, boolean).

This class implements overridable methods to support unrecognized XML parsing if desired.

Summary

Fields
Set<String> blobNamespaces Namespaces used by this blob.
private StringBuilder buffer Temporary buffer for building up the text() value.
boolean fullTextIndex Flag indicating whether unrecognized XML should be processed for full-text indexing.
StringWriter fullTextIndexWriter String writer underlying the full-text index string.
XmlWriter innerXml This element's inner XML writer.
StringWriter innerXmlStringWriter String writer underlying innerXml.
boolean mixedContent Flag indicating whether mixed content unrecognized XML is allowed.
boolean okToInitializeXmlBlob Flag indicating whether it's still OK to call initializeXmlBlob(XmlBlob, boolean, boolean).
XmlParser.ElementHandler parent Keeps track of the element stack.
public String qName This element's QName.
public String value This element's text() value.
public String xmlBase The current state of xml:base.
XmlBlob xmlBlob If the handler is parsing unrecognized XML, this object stores the output.
public String xmlLang The current state of xml:lang.
Public Constructors
XmlParser.ElementHandler()
Public Methods
String getAbsoluteUri(String uriValue)
Utility routine that combines the current state of xml:base with the specified URI to obtain an absolute URI.
Boolean getBooleanAttribute(Attributes attrs, String attrName)
Utility method to return the value of an xsd:boolean attribute.
XmlParser.ElementHandler getChildHandler(String namespace, String localName, Attributes attrs)
Determines a handler for a child element.
XmlParser.ElementHandler getChildHandler(String namespace, String qualifiedName, String localName, Attributes attrs, List<XmlNamespace> namespaces)
Determines a handler for a child element.
void initializeXmlBlob(XmlBlob xmlBlob, boolean mixedContent, boolean fullTextIndex)
If a derived class wishes to retrieve all unrecognized XML in a blob, it calls this method.
void processAttribute(String namespace, String localName, String value)
Called to process an attribute.
void processAttribute(String namespace, String qualifiedName, String localName, String attrValue)
Called to process an attribute.
void processEndElement()
Called to process this element when the closing tag is encountered.
Protected Methods
Boolean parseBooleanValue(String value)
Utility method to parse provided xsd:boolean value.
[Expand]
Inherited Methods
From class java.lang.Object

Fields

Set<String> blobNamespaces

Namespaces used by this blob.

private StringBuilder buffer

Temporary buffer for building up the text() value.

boolean fullTextIndex

Flag indicating whether unrecognized XML should be processed for full-text indexing. If set, the resulting string ready for indexing is stored in fullText. Non-contiguous strings within this index are separated by '\n'.

StringWriter fullTextIndexWriter

String writer underlying the full-text index string.

XmlWriter innerXml

This element's inner XML writer. Used internally by XmlParser.

StringWriter innerXmlStringWriter

String writer underlying innerXml.

boolean mixedContent

Flag indicating whether mixed content unrecognized XML is allowed.

boolean okToInitializeXmlBlob

Flag indicating whether it's still OK to call initializeXmlBlob(XmlBlob, boolean, boolean).

XmlParser.ElementHandler parent

Keeps track of the element stack.

public String qName

This element's QName. Used for error reporting.

public String value

This element's text() value.

public String xmlBase

The current state of xml:base. See http://www.cafeconleche.org/books/xmljava/chapters/ch03s03.html for more information.

XmlBlob xmlBlob

If the handler is parsing unrecognized XML, this object stores the output.

public String xmlLang

The current state of xml:lang. See http://www.w3.org/TR/REC-xml/#sec-lang-tag for more information.

Public Constructors

public XmlParser.ElementHandler ()

Public Methods

public String getAbsoluteUri (String uriValue)

Utility routine that combines the current state of xml:base with the specified URI to obtain an absolute URI.

See http://www.cafeconleche.org/books/xmljava/chapters/ch03s03.html for more information.

Parameters
uriValue URI to be interpreted in the context of xml:base.
Returns
  • Corresponding absolute URI.
Throws
ParseException Invalid URI.

public Boolean getBooleanAttribute (Attributes attrs, String attrName)

Utility method to return the value of an xsd:boolean attribute.

Parameters
attrs Elements attributes to test against.
attrName Attribute name.
Returns
  • the Boolean value if the attribute is present, or null otherwise.
Throws
ParseException if attribute value is not valid xsd:boolean.

public XmlParser.ElementHandler getChildHandler (String namespace, String localName, Attributes attrs)

Determines a handler for a child element.

The default implementation doesn't recognize anything. The result is a schema error unless the parent handler accepts unrecognized XML. XmlParser. localname/namespace.

Parameters
namespace Child element namespace URI.
localName Child element name.
attrs Child element attributes. These attributes will be communicated to the child element handler through its processAttribute(String, String, String) method. They are passed here because sometimes the value of some attribute determines the element's content type, so different element handlers may be needed.
Returns
  • Child element handler, or null if the child is unrecognized.
Throws
ParseException Invalid child element.
IOException Internal I/O exception (e.g., thrown by XML blob writer).

public XmlParser.ElementHandler getChildHandler (String namespace, String qualifiedName, String localName, Attributes attrs, List<XmlNamespace> namespaces)

Determines a handler for a child element.

The default implementation doesn't recognize anything. The result is a schema error unless the parent handler accepts unrecognized XML. XmlParser. localname/namespace.

Parameters
namespace Child element's namespace URI.
qualifiedName Child element's qualified name.
localName Child element's local name.
attrs Child element's attributes. These attributes will be communicated to the child element handler through its processAttribute(String, String, String) method. They are passed here because sometimes the value of some attribute determines the element's content type, so different element handlers may be needed.
namespaces
Returns
  • Child element's handler, or null if the child is unrecognized.
Throws
ParseException Invalid child element.
IOException Internal I/O exception (e.g., thrown by XML blob writer).

public void initializeXmlBlob (XmlBlob xmlBlob, boolean mixedContent, boolean fullTextIndex)

If a derived class wishes to retrieve all unrecognized XML in a blob, it calls this method. It must be called in the constructor, in the parent element handler, or in processAttribute(String, String, String).

Parameters
xmlBlob Supplies the XML blob that stores the resulting XML.
mixedContent Specifies that the handler accepts mixed content XML.
fullTextIndex Flag indicating whether unrecognized XML should be processed for full-text indexing. If set, the resulting string ready for indexing is stored in fullText.

public void processAttribute (String namespace, String localName, String value)

Called to process an attribute. Designed to be overridden by derived classes.

Parameters
namespace Attribute namespace URI.
localName Attribute name.
value Attribute value.
Throws
ParseException Invalid attribute.

public void processAttribute (String namespace, String qualifiedName, String localName, String attrValue)

Called to process an attribute. Designed to be overridden by derived classes.

Parameters
namespace Attribute namespace URI.
qualifiedName Attribute's qualified name.
localName Attribute's local name.
attrValue Attribute value.
Throws
ParseException Invalid attribute.

public void processEndElement ()

Called to process this element when the closing tag is encountered. The default implementation refuses to accept text() content, unless the handler is configured to accept unrecognized XML with mixed content.

Protected Methods

protected Boolean parseBooleanValue (String value)

Utility method to parse provided xsd:boolean value.

Parameters
value Xsd:boolean value to parse
Returns
  • the Boolean value or null
Throws
ParseException if value is not valid xsd:boolean.