Package diva.util.xml
Class XmlReader.Handler
- java.lang.Object
-
- diva.util.xml.XmlReader.Handler
-
- All Implemented Interfaces:
XmlHandler
- Enclosing class:
- XmlReader
public class XmlReader.Handler extends java.lang.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
Constructors Constructor Description Handler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.String
_currentExternalEntity()
Return the current external entity.void
attribute(java.lang.String name, java.lang.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(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
Handle a document type declaration.void
endDocument()
End the document.void
endElement(java.lang.String name)
Move up one level in the parse tree.void
endExternalEntity(java.lang.String URI)
Move up one level in the external entity tree.void
error(java.lang.String message, java.lang.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(java.lang.String target, java.lang.String data)
Handle a processing instruction.java.lang.Object
resolveEntity(java.lang.String pubID, java.lang.String sysID)
Attempt resolve the public ID representing an XML external entity into a valid string url.void
startDocument()
Start a document.void
startElement(java.lang.String name)
Start an element.void
startExternalEntity(java.lang.String URI)
Move down one level in the entity tree.
-
-
-
Method Detail
-
attribute
public void attribute(java.lang.String name, java.lang.String value, boolean specified) throws java.lang.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 interfaceXmlHandler
- 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:
java.lang.Exception
- If the name or value is null.- 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 java.lang.Exception
Append the given character bytes to the character data of the current XML element.- Specified by:
charData
in interfaceXmlHandler
- Parameters:
c
- The character data.offset
- The starting position in the array.length
- The number of characters available.- Throws:
java.lang.Exception
- The handler may throw any exception.
-
doctypeDecl
public void doctypeDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId) throws java.lang.Exception
Handle a document type declaration. This sets the DTD external identifiers in the XmlDocument.- Specified by:
doctypeDecl
in interfaceXmlHandler
- Parameters:
name
- The document type name.publicId
- The public identifier, or null if unspecified.systemId
- The system identifier, or null if unspecified.- Throws:
java.lang.Exception
- The handler may throw any exception.
-
endDocument
public void endDocument() throws java.lang.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 interfaceXmlHandler
- Throws:
java.lang.Exception
- The handler may throw any exception.- See Also:
XmlHandler.startDocument()
-
endElement
public void endElement(java.lang.String name) throws java.lang.Exception
Move up one level in the parse tree.- Specified by:
endElement
in interfaceXmlHandler
- Parameters:
name
- The element type name.- Throws:
java.lang.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(java.lang.String URI) throws java.lang.Exception
Move up one level in the external entity tree.- Specified by:
endExternalEntity
in interfaceXmlHandler
- 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.java.lang.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(java.lang.String message, java.lang.String sysid, int line, int column) throws java.lang.Exception
Print an error message to the error stream.- Specified by:
error
in interfaceXmlHandler
- 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:
java.lang.Exception
- The handler may throw any exception.- See Also:
XmlException
-
ignorableWhitespace
public void ignorableWhitespace(char[] ch, int start, int length) throws java.lang.Exception
Handle ignorable whitespace.The default implementation does nothing.
- Specified by:
ignorableWhitespace
in interfaceXmlHandler
- Parameters:
ch
- The literal whitespace characters.start
- The starting position in the array.length
- The number of whitespace characters available.- Throws:
java.lang.Exception
- Derived methods may throw exceptions.- See Also:
XmlHandler.ignorableWhitespace(char[], int, int)
-
processingInstruction
public void processingInstruction(java.lang.String target, java.lang.String data) throws java.lang.Exception
Handle a processing instruction.The default implementation does nothing.
- Specified by:
processingInstruction
in interfaceXmlHandler
- Parameters:
target
- The target (the name at the start of the PI).data
- The data, if any (the rest of the PI).- Throws:
java.lang.Exception
- Derived methods may throw exceptions.- See Also:
XmlHandler.processingInstruction(java.lang.String, java.lang.String)
-
resolveEntity
public java.lang.Object resolveEntity(java.lang.String pubID, java.lang.String sysID) throws java.lang.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 interfaceXmlHandler
- 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:
java.lang.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 interfaceXmlHandler
- See Also:
XmlHandler.endDocument()
-
startElement
public void startElement(java.lang.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 interfaceXmlHandler
- 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(java.lang.String URI) throws java.lang.Exception
Move down one level in the entity tree.- Specified by:
startExternalEntity
in interfaceXmlHandler
- Parameters:
URI
- The URI of the external entity that is starting.- Throws:
java.lang.Exception
- The handler may throw any exception.- See Also:
XmlHandler.endExternalEntity(java.lang.String)
,XmlHandler.resolveEntity(java.lang.String, java.lang.String)
-
_currentExternalEntity
protected java.lang.String _currentExternalEntity()
Return the current external entity.- Returns:
- The current external entity.
-
-