diva.compat.xml
Class XmlReader.Handler

java.lang.Object
  extended by diva.compat.xml.XmlReader.Handler
All Implemented Interfaces:
XmlHandler
Enclosing class:
XmlReader

public class XmlReader.Handler
extends Object
implements XmlHandler

Handler is an inner class that implements the Aelfred XmlHandler interface. It constructs XmlElements and also initializes the current XmlDocument from things like the doctype declaration. In verbose mode, it prints out lots of additional info during the parse.


Constructor Summary
XmlReader.Handler()
           
 
Method Summary
protected  String _currentExternalEntity()
           
 void attribute(String name, String value, boolean specified)
          Handle an attribute assignment that is part of an XML element.
 void charData(char[] c, int offset, int length)
          Append the given character bytes to the character data of the current XML element.
 void doctypeDecl(String name, String publicId, String systemId)
          Handle a document type declaration.
 void endDocument()
          End the document.
 void endElement(String name)
          Move up one level in the parse tree.
 void endExternalEntity(String URI)
          Move up one level in the external entity tree.
 void error(String message, String sysid, int line, int column)
          Print an error message to the error stream.
 void ignorableWhitespace(char[] ch, int start, int length)
          Handle ignorable whitespace.
 void processingInstruction(String target, String data)
          Handle a processing instruction.
 Object resolveEntity(String pubID, String sysID)
          Attempt resolve the public ID representing an XML external entity into a valid string url.
 void startDocument()
          Start a document.
 void startElement(String name)
          Start an element.
 void startExternalEntity(String URI)
          Move down one level in the entity tree.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlReader.Handler

public XmlReader.Handler()
Method Detail

attribute

public void attribute(String name,
                      String value,
                      boolean specified)
               throws Exception
Handle an attribute assignment that is part of an XML element. This method is called prior to the corresponding startElement() call, so it simply accumulates attributes in a hashtable for use by startElement().

Specified by:
attribute in interface XmlHandler
Parameters:
name - The name of the attribute.
value - The value of the attribute, or null if the attribute is #IMPLIED and not specified.
specified - True if the value is specified, false if the value comes from the default value in the DTD rather than from the XML file.
Throws:
XmlException - If the name or value is null.
Exception - The handler may throw any exception.
See Also:
XmlHandler.startElement(java.lang.String), XmlParser.declaredAttributes(java.lang.String), XmlParser.getAttributeType(java.lang.String, java.lang.String), XmlParser.getAttributeDefaultValue(java.lang.String, java.lang.String)

charData

public void charData(char[] c,
                     int offset,
                     int length)
              throws Exception
Append the given character bytes to the character data of the current XML element.

Specified by:
charData in interface XmlHandler
Parameters:
c - The character data.
offset - The starting position in the array.
length - The number of characters available.
Throws:
Exception - The handler may throw any exception.

doctypeDecl

public void doctypeDecl(String name,
                        String publicId,
                        String systemId)
                 throws Exception
Handle a document type declaration. This sets the DTD external identifiers in the XmlDocument.

Specified by:
doctypeDecl in interface XmlHandler
Parameters:
name - The document type name.
publicId - The public identifier, or null if unspecified.
systemId - The system identifier, or null if unspecified.
Throws:
Exception - The handler may throw any exception.

endDocument

public void endDocument()
                 throws Exception
End the document. If we've finished the parse and didn't get back to the root of the parse tree, generate an error.

Specified by:
endDocument in interface XmlHandler
Throws:
Exception - The handler may throw any exception.
See Also:
XmlHandler.startDocument()

endElement

public void endElement(String name)
                throws Exception
Move up one level in the parse tree.

Specified by:
endElement in interface XmlHandler
Parameters:
name - The element type name.
Throws:
Exception - The handler may throw any exception.
See Also:
XmlHandler.startElement(java.lang.String), XmlParser.declaredElements(), XmlParser.getElementContentType(java.lang.String)

endExternalEntity

public void endExternalEntity(String URI)
                       throws Exception
Move up one level in the external entity tree.

Specified by:
endExternalEntity in interface XmlHandler
Parameters:
URI - The URI of the external entity that is ending.
Throws:
XmlException - If given URI was not the URI that was expected, based on the external entity tree.
Exception - The handler may throw any exception.
See Also:
XmlHandler.startExternalEntity(java.lang.String), XmlHandler.resolveEntity(java.lang.String, java.lang.String)

error

public void error(String message,
                  String sysid,
                  int line,
                  int column)
           throws Exception
Print an error message to the error stream.

Specified by:
error in interface XmlHandler
Parameters:
message - The error message.
sysid - The system identifier of the entity that contains the error.
line - The approximate line number of the error.
column - The approximate column number of the error.
Throws:
Exception - The handler may throw any exception.
See Also:
XmlException

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws Exception
Handle ignorable whitespace.

The default implementation does nothing.

Specified by:
ignorableWhitespace in interface XmlHandler
Parameters:
ch - The literal whitespace characters.
start - The starting position in the array.
length - The number of whitespace characters available.
Throws:
Exception - Derived methods may throw exceptions.
See Also:
com.microstar.xml.XmlHandler#ignorableWhitespace

processingInstruction

public void processingInstruction(String target,
                                  String data)
                           throws Exception
Handle a processing instruction.

The default implementation does nothing.

Specified by:
processingInstruction in interface XmlHandler
Parameters:
target - The target (the name at the start of the PI).
data - The data, if any (the rest of the PI).
Throws:
Exception - Derived methods may throw exceptions.
See Also:
com.microstar.xml.XmlHandler#processingInstruction

resolveEntity

public Object resolveEntity(String pubID,
                            String sysID)
                     throws Exception
Attempt resolve the public ID representing an XML external entity into a valid string url. If the public ID is non-null and matches the public ID of the document and the document has a DTD specified, return that DTD in a reader. Otherwise, non-null public DTD's are looked up in the default resource bundle, diva/resource/Defaults.properties.

Specified by:
resolveEntity in interface XmlHandler
Parameters:
pubID - The public identifier, or null if none was supplied.
sysID - The system identifier.
Returns:
The replacement system identifier, or null to use the default.
Throws:
Exception - The handler may throw any exception.
See Also:
XmlHandler.startExternalEntity(java.lang.String), XmlHandler.endExternalEntity(java.lang.String)

startDocument

public void startDocument()
Start a document. This method is called just before the parser attempts to read the first entity (the root of the document). It is guaranteed that this will be the first method called. Initialize the parse tree to contain no elements.

Specified by:
startDocument in interface XmlHandler
See Also:
XmlHandler.endDocument()

startElement

public void startElement(String name)
Start an element. This is called at the beginning of each XML element. By the time it is called, all of the attributes for the element will already have been reported using the attribute() method. Create a new XmlElement to represent the element. Set the attributes of the new XmlElement equal to the attributes that have been accumulated since the last call to this method. If this is the first element encountered during this parse, set the root of the parse tree equal to the newly created element. Descend the parse tree into the new element

Specified by:
startElement in interface XmlHandler
Parameters:
name - the element type of the element that is beginning.
See Also:
XmlHandler.attribute(java.lang.String, java.lang.String, boolean), XmlHandler.endElement(java.lang.String), XmlParser.declaredElements(), XmlParser.getElementContentType(java.lang.String)

startExternalEntity

public void startExternalEntity(String URI)
                         throws Exception
Move down one level in the entity tree.

Specified by:
startExternalEntity in interface XmlHandler
Parameters:
URI - The URI of the external entity that is starting.
Throws:
Exception - The handler may throw any exception.
See Also:
XmlHandler.endExternalEntity(java.lang.String), XmlHandler.resolveEntity(java.lang.String, java.lang.String)

_currentExternalEntity

protected String _currentExternalEntity()


Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.