org.jboss.dna.graph.xml
Class XmlHandler

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by org.xml.sax.ext.DefaultHandler2
          extended by org.jboss.dna.graph.xml.XmlHandler
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler, DeclHandler, EntityResolver2, LexicalHandler

@NotThreadSafe
public class XmlHandler
extends DefaultHandler2

A DefaultHandler2 specialization that responds to XML content events by creating the corresponding content in the supplied graph. This implementation ignores DTD entities, XML contents, and other XML processing instructions. If other behavior is required, the appropriate methods can be overridden. (Which is why this class extends DefaultHandler2, which has support for processing all the different parts of XML.

This class can be passed to the SAXParser's parse(..,DefaultHandler) methods.


Nested Class Summary
static class XmlHandler.AttributeScoping
          The choices for how attributes that have no namespace prefix should be assigned a namespace.
 
Field Summary
static XmlHandler.AttributeScoping DEFAULT_ATTRIBUTE_SCOPING
          The default XmlHandler.AttributeScoping.
static TextDecoder DEFAULT_DECODER
          Decoder for XML names, to turn '_xHHHH_' sequences in the XML element and attribute names into the corresponding UTF-16 characters.
 
Constructor Summary
XmlHandler(Destination destination, boolean skipRootElement, Path parent, TextDecoder textDecoder, Name nameAttribute, Name typeAttribute, Name typeAttributeValue, XmlHandler.AttributeScoping scoping)
          Create a handler that creates content in the supplied graph
 
Method Summary
 void characters(char[] ch, int start, int length)
          
 void endDocument()
          
 void endElement(String uri, String localName, String name)
          
 void endPrefixMapping(String prefix)
          
 void startElement(String uri, String localName, String name, Attributes attributes)
          
 void startPrefixMapping(String prefix, String uri)
           This method ensures that the namespace is registered with the registry, using the supplied prefix to register the namespace if required.
 
Methods inherited from class org.xml.sax.ext.DefaultHandler2
attributeDecl, comment, elementDecl, endCDATA, endDTD, endEntity, externalEntityDecl, getExternalSubset, internalEntityDecl, resolveEntity, resolveEntity, startCDATA, startDTD, startEntity
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, setDocumentLocator, skippedEntity, startDocument, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_DECODER

public static TextDecoder DEFAULT_DECODER
Decoder for XML names, to turn '_xHHHH_' sequences in the XML element and attribute names into the corresponding UTF-16 characters.


DEFAULT_ATTRIBUTE_SCOPING

public static XmlHandler.AttributeScoping DEFAULT_ATTRIBUTE_SCOPING
The default XmlHandler.AttributeScoping.

Constructor Detail

XmlHandler

public XmlHandler(Destination destination,
                  boolean skipRootElement,
                  Path parent,
                  TextDecoder textDecoder,
                  Name nameAttribute,
                  Name typeAttribute,
                  Name typeAttributeValue,
                  XmlHandler.AttributeScoping scoping)
Create a handler that creates content in the supplied graph

Parameters:
destination - the destination where the content should be sent.graph in which the content should be placed
skipRootElement - true if the root element of the document should be skipped, or false if the root element should be converted to the top-level node of the content
parent - the path to the node in the graph under which the content should be placed; if null, the root node is assumed
textDecoder - the text decoder that should be used to decode the XML element names and XML attribute names, prior to using those values to create names; or null if the default encoder should be used
nameAttribute - the name of the property whose value should be used for the names of the nodes (typically, this is "jcr:name" or something equivalent); or null if the XML element name should always be used as the node name
typeAttribute - the name of the property that should be set with the type of the XML element, or null if there is no such property
typeAttributeValue - the value of the type property that should be used if the node has no nameAttribute, or null if the value should be set to the type of the XML element
scoping - defines how to choose the namespace of attributes that do not have a namespace prefix; if null, the DEFAULT_ATTRIBUTE_SCOPING value is used
Throws:
IllegalArgumentException - if the destination reference is null
Method Detail

startPrefixMapping

public void startPrefixMapping(String prefix,
                               String uri)

This method ensures that the namespace is registered with the registry, using the supplied prefix to register the namespace if required. Note that because this class does not really use the namespace prefixes to create Name objects, no attempt is made to match the XML namespace prefixes.

Specified by:
startPrefixMapping in interface ContentHandler
Overrides:
startPrefixMapping in class DefaultHandler
See Also:
DefaultHandler.startPrefixMapping(java.lang.String, java.lang.String)

endPrefixMapping

public void endPrefixMapping(String prefix)

Specified by:
endPrefixMapping in interface ContentHandler
Overrides:
endPrefixMapping in class DefaultHandler
See Also:
DefaultHandler.endPrefixMapping(java.lang.String)

startElement

public void startElement(String uri,
                         String localName,
                         String name,
                         Attributes attributes)

Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class DefaultHandler
See Also:
DefaultHandler.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)

endElement

public void endElement(String uri,
                       String localName,
                       String name)

Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class DefaultHandler
See Also:
DefaultHandler.endElement(java.lang.String, java.lang.String, java.lang.String)

characters

public void characters(char[] ch,
                       int start,
                       int length)

Specified by:
characters in interface ContentHandler
Overrides:
characters in class DefaultHandler
See Also:
DefaultHandler.characters(char[], int, int)

endDocument

public void endDocument()

Specified by:
endDocument in interface ContentHandler
Overrides:
endDocument in class DefaultHandler
See Also:
DefaultHandler.endDocument()


Copyright © 2008-2009 JBoss, a division of Red Hat. All Rights Reserved.