Google Data APIs Client Library (1.41.1)



com.google.gdata.util
Class XmlParser.ElementHandler

java.lang.Object
  extended by com.google.gdata.util.XmlParser.ElementHandler
Direct Known Subclasses:
AbstractExtension.AttributesHandler, Category.AtomHandler, ExtensionPoint.CumulativeBlobHandler, ExtensionProfile.ExtensionPointHandler, ExtensionProfile.Handler, Generator.AtomHandler, HtmlTextConstruct.AtomHandler, OtherContent.AtomHandler, OutOfLineContent.AtomHandler, PlainTextConstruct.AtomHandler, Rfc3339Handler, XhtmlTextConstruct.AtomHandler
Enclosing class:
XmlParser

public static class XmlParser.ElementHandler
extends java.lang.Object

Base class for custom element handlers.

To implement a new element handler, one must create a new class extending this class, override getChildHandler(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes, java.util.List) if nested elements need to be parsed, override processAttribute(java.lang.String, java.lang.String, java.lang.String, java.lang.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(com.google.gdata.util.XmlBlob, boolean, boolean) either in the constructor, in parent's getChildHandler(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes, java.util.List), or in processAttribute(java.lang.String, java.lang.String, java.lang.String, java.lang.String). The resulting XmlBlob value is available following the invocation of processEndElement() through the object passed to initializeXmlBlob(com.google.gdata.util.XmlBlob, boolean, boolean).

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


Field Summary
 java.lang.String qName
          This element's QName.
 java.lang.String value
          This element's text() value.
 java.lang.String xmlBase
          The current state of xml:base.
 java.lang.String xmlLang
          The current state of xml:lang.
 
Constructor Summary
XmlParser.ElementHandler()
           
 
Method Summary
 java.lang.String getAbsoluteUri(java.lang.String uriValue)
          Utility routine that combines the current state of xml:base with the specified URI to obtain an absolute URI.
 java.lang.Boolean getBooleanAttribute(org.xml.sax.Attributes attrs, java.lang.String attrName)
          Utility method to return the value of an xsd:boolean attribute.
 XmlParser.ElementHandler getChildHandler(java.lang.String namespace, java.lang.String localName, org.xml.sax.Attributes attrs)
          Determines a handler for a child element.
 XmlParser.ElementHandler getChildHandler(java.lang.String namespace, java.lang.String qualifiedName, java.lang.String localName, org.xml.sax.Attributes attrs, java.util.List<com.google.gdata.util.common.xml.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.
protected  java.lang.Boolean parseBooleanValue(java.lang.String value)
          Utility method to parse provided xsd:boolean value.
 void processAttribute(java.lang.String namespace, java.lang.String localName, java.lang.String value)
          Called to process an attribute.
 void processAttribute(java.lang.String namespace, java.lang.String qualifiedName, java.lang.String localName, java.lang.String attrValue)
          Called to process an attribute.
 void processEndElement()
          Called to process this element when the closing tag is encountered.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

qName

public java.lang.String qName
This element's QName. Used for error reporting.


value

public java.lang.String value
This element's text() value.


xmlLang

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


xmlBase

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

Constructor Detail

XmlParser.ElementHandler

public XmlParser.ElementHandler()
Method Detail

getChildHandler

public XmlParser.ElementHandler getChildHandler(java.lang.String namespace,
                                                java.lang.String qualifiedName,
                                                java.lang.String localName,
                                                org.xml.sax.Attributes attrs,
                                                java.util.List<com.google.gdata.util.common.xml.XmlNamespace> namespaces)
                                         throws ParseException,
                                                java.io.IOException
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(java.lang.String, java.lang.String, java.lang.String, java.lang.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's handler, or null if the child is unrecognized.
Throws:
ParseException - Invalid child element.
java.io.IOException - Internal I/O exception (e.g., thrown by XML blob writer).

getChildHandler

public XmlParser.ElementHandler getChildHandler(java.lang.String namespace,
                                                java.lang.String localName,
                                                org.xml.sax.Attributes attrs)
                                         throws ParseException,
                                                java.io.IOException
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(java.lang.String, java.lang.String, java.lang.String, java.lang.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.
java.io.IOException - Internal I/O exception (e.g., thrown by XML blob writer).

processAttribute

public void processAttribute(java.lang.String namespace,
                             java.lang.String qualifiedName,
                             java.lang.String localName,
                             java.lang.String attrValue)
                      throws ParseException
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.

processAttribute

public void processAttribute(java.lang.String namespace,
                             java.lang.String localName,
                             java.lang.String value)
                      throws ParseException
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.

processEndElement

public void processEndElement()
                       throws ParseException
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.

Throws:
ParseException

initializeXmlBlob

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(java.lang.String, java.lang.String, java.lang.String, java.lang.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 XmlBlob.fullText.

getAbsoluteUri

public java.lang.String getAbsoluteUri(java.lang.String uriValue)
                                throws ParseException
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.

getBooleanAttribute

public java.lang.Boolean getBooleanAttribute(org.xml.sax.Attributes attrs,
                                             java.lang.String attrName)
                                      throws ParseException
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.

parseBooleanValue

protected java.lang.Boolean parseBooleanValue(java.lang.String value)
                                       throws ParseException
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.