com.microstar.xml
Class SAXDriver

java.lang.Object
  |
  +--com.microstar.xml.SAXDriver
All Implemented Interfaces:
AttributeList, Locator, Parser, XmlHandler

public class SAXDriver
extends java.lang.Object
implements XmlHandler, Locator, AttributeList, Parser

A SAX driver for Microstar's Ælfred XML parser.

This driver acts as a front-end for Ælfred, and translates Ælfred's events into SAX events. It implements the SAX parser interface, and you can use it without directly calling Ælfred at all:

 org.xml.sax.Parser parser = new com.microstar.xml.SAXDriver();
 

When you are using SAX, you do not need to use the XmlParser or XmlHandler classes at all: this class is your entry point.

This driver is based on the 1.0gamma version of SAX, available from http://www.megginson.com/SAX/

See Also:
Parser, XmlParser

Constructor Summary
SAXDriver()
           
 
Method Summary
 void attribute(java.lang.String aname, java.lang.String value, boolean isSpecified)
          Implement com.microstar.xml.XmlHandler#attribute.
 void charData(char[] ch, int start, int length)
          Implement com.microstar.xml.XmlHandler#charData.
 void doctypeDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
          Implement com.microstar.xml.XmlHandler#doctypeDecl.
 void endDocument()
          Implement com.microstar.xml.XmlHandler#endDocument.
 void endElement(java.lang.String elname)
          Implement com.microstar.xml.XmlHandler#endElement.
 void endExternalEntity(java.lang.String systemId)
          Implement com.microstar.xml.XmlHandler#endExternalEntity.
 void error(java.lang.String message, java.lang.String url, int line, int column)
          Implement com.microstar.xml.XmlHandler#error.
 int getColumnNumber()
          Return the column number where the current document event ends.
 int getLength()
          Return the number of attributes in this list.
 int getLineNumber()
          Return the line number where the current document event ends.
 java.lang.String getName(int i)
          Return the name of an attribute in this list (by position).
 java.lang.String getPublicId()
          Return the public identifier for the current document event.
 java.lang.String getSystemId()
          Return the system identifier for the current document event.
 java.lang.String getType(int i)
          Return the type of an attribute in the list (by position).
 java.lang.String getType(java.lang.String name)
          Return the type of an attribute in the list (by name).
 java.lang.String getValue(int i)
          Return the value of an attribute in the list (by position).
 java.lang.String getValue(java.lang.String name)
          Return the value of an attribute in the list (by name).
 void ignorableWhitespace(char[] ch, int start, int length)
          Implement com.microstar.xml.XmlHandler#ignorableWhitespace.
 void parse(InputSource source)
          Parse a document.
 void parse(java.lang.String systemId)
          Parse an XML document from a system identifier (URI).
 void processingInstruction(java.lang.String target, java.lang.String data)
          Implement com.microstar.xml.XmlHandler#processingInstruction.
 java.lang.Object resolveEntity(java.lang.String publicId, java.lang.String systemId)
          Implement com.microstar.xml.XmlHandler.resolveSystemId
 void setDocumentHandler(DocumentHandler handler)
          Set the document handler for this parser.
 void setDTDHandler(DTDHandler handler)
          Set the DTD handler for this parser.
 void setEntityResolver(EntityResolver resolver)
          Set the entity resolver for this parser.
 void setErrorHandler(ErrorHandler handler)
          Set the error handler for this parser.
 void setLocale(java.util.Locale locale)
          Set the locale.
 void startDocument()
          Implement com.microstar.xml.XmlHandler#startDocument.
 void startElement(java.lang.String elname)
          Implement com.microstar.xml.XmlHandler#startElement.
 void startExternalEntity(java.lang.String systemId)
          Implement com.microstar.xml.XmlHandler#startExternalEntity.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SAXDriver

public SAXDriver()
Method Detail

setLocale

public void setLocale(java.util.Locale locale)
               throws SAXException
Set the locale.

Specified by:
setLocale in interface Parser
Parameters:
locale - A Java Locale object.
Throws:
SAXException - Throws an exception (using the previous or default locale) if the requested locale is not supported.
See Also:
Parser.setLocale(java.util.Locale)

setEntityResolver

public void setEntityResolver(EntityResolver resolver)
Set the entity resolver for this parser.

Specified by:
setEntityResolver in interface Parser
Parameters:
resolver - The object for resolving entities.
See Also:
Parser.setEntityResolver(org.xml.sax.EntityResolver)

setDTDHandler

public void setDTDHandler(DTDHandler handler)
Set the DTD handler for this parser.

Specified by:
setDTDHandler in interface Parser
Parameters:
handler - The object to receive DTD events.
See Also:
Parser.setDTDHandler(org.xml.sax.DTDHandler)

setDocumentHandler

public void setDocumentHandler(DocumentHandler handler)
Set the document handler for this parser.

Specified by:
setDocumentHandler in interface Parser
Parameters:
handler - The object to receive document events.
See Also:
Parser.setDocumentHandler(org.xml.sax.DocumentHandler)

setErrorHandler

public void setErrorHandler(ErrorHandler handler)
Set the error handler for this parser.

Specified by:
setErrorHandler in interface Parser
Parameters:
handler - The object to receive error events.
See Also:
Parser.setErrorHandler(org.xml.sax.ErrorHandler)

parse

public void parse(InputSource source)
           throws SAXException
Parse a document.

If you want anything useful to happen, you should set at least one type of handler.

Specified by:
parse in interface Parser
Parameters:
source - The XML input source.
Throws:
SAXException - The handlers may throw any exception.
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
Parser.parse(InputSource), setEntityResolver(org.xml.sax.EntityResolver), setDTDHandler(org.xml.sax.DTDHandler), setDocumentHandler(org.xml.sax.DocumentHandler), setErrorHandler(org.xml.sax.ErrorHandler)

parse

public void parse(java.lang.String systemId)
           throws SAXException
Parse an XML document from a system identifier (URI).

Specified by:
parse in interface Parser
Parameters:
systemId - The system identifier (URI).
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
Parser.parse(String)

startDocument

public void startDocument()
                   throws SAXException
Implement com.microstar.xml.XmlHandler#startDocument.

Translate to the SAX interface.

Users should never invoke this method directly.

Specified by:
startDocument in interface XmlHandler
Throws:
SAXException - May throw any exception.
See Also:
XmlHandler.startDocument()

endDocument

public void endDocument()
                 throws SAXException
Implement com.microstar.xml.XmlHandler#endDocument.

Translate to the SAX interface.

Users should never invoke this method directly.

Specified by:
endDocument in interface XmlHandler
Throws:
SAXException - May throw any exception.
See Also:
XmlHandler.endDocument()

resolveEntity

public java.lang.Object resolveEntity(java.lang.String publicId,
                                      java.lang.String systemId)
                               throws SAXException,
                                      java.io.IOException
Implement com.microstar.xml.XmlHandler.resolveSystemId

Translate to the SAX interface.

Users should never invoke this method directly.

Specified by:
resolveEntity in interface XmlHandler
Parameters:
publicId - The public identifier, or null if none was supplied.
systemId - The system identifier.
Returns:
The replacement system identifier, or null to use the default.
Throws:
SAXException - May throw any exception.
java.io.IOException
See Also:
XmlHandler.resolveEntity(java.lang.String, java.lang.String)

startExternalEntity

public void startExternalEntity(java.lang.String systemId)
                         throws SAXException
Implement com.microstar.xml.XmlHandler#startExternalEntity.

Translate to the SAX interface.

Users should never invoke this method directly.

Specified by:
startExternalEntity in interface XmlHandler
Parameters:
systemId - The URI of the external entity that is starting.
Throws:
SAXException - May throw any exception.
See Also:
XmlHandler.startExternalEntity(java.lang.String)

endExternalEntity

public void endExternalEntity(java.lang.String systemId)
                       throws SAXException
Implement com.microstar.xml.XmlHandler#endExternalEntity.

Translate to the SAX interface.

Users should never invoke this method directly.

Specified by:
endExternalEntity in interface XmlHandler
Parameters:
systemId - The URI of the external entity that is ending.
Throws:
SAXException - May throw any exception.
See Also:
XmlHandler.endExternalEntity(java.lang.String)

doctypeDecl

public void doctypeDecl(java.lang.String name,
                        java.lang.String publicId,
                        java.lang.String systemId)
                 throws SAXException
Implement com.microstar.xml.XmlHandler#doctypeDecl.

Translate to the SAX interface.

Users should never invoke this method directly.

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:
SAXException - May throw any exception.
See Also:
XmlHandler.doctypeDecl(java.lang.String, java.lang.String, java.lang.String)

attribute

public void attribute(java.lang.String aname,
                      java.lang.String value,
                      boolean isSpecified)
               throws SAXException
Implement com.microstar.xml.XmlHandler#attribute.

Translate to the SAX interface.

Users should never invoke this method directly.

Specified by:
attribute in interface XmlHandler
Parameters:
value - The value of the attribute, or null if the attribute is #IMPLIED.
isSpecified - True if the value was specified, false if it was defaulted from the DTD.
Throws:
SAXException - May throw any exception.
See Also:
XmlHandler.attribute(java.lang.String, java.lang.String, boolean)

startElement

public void startElement(java.lang.String elname)
                  throws SAXException
Implement com.microstar.xml.XmlHandler#startElement.

Translate to the SAX interface.

Users should never invoke this method directly.

Specified by:
startElement in interface XmlHandler
Parameters:
elname - The element type name.
Throws:
SAXException - May throw any exception.
See Also:
XmlHandler.startElement(java.lang.String)

endElement

public void endElement(java.lang.String elname)
                throws SAXException
Implement com.microstar.xml.XmlHandler#endElement.

Translate to the SAX interface.

Users should never invoke this method directly.

Specified by:
endElement in interface XmlHandler
Parameters:
elname - The element type name.
Throws:
SAXException - May throw any exception.
See Also:
XmlHandler.endElement(java.lang.String)

charData

public void charData(char[] ch,
                     int start,
                     int length)
              throws SAXException
Implement com.microstar.xml.XmlHandler#charData.

Translate to the SAX interface.

Users should never invoke this method directly.

Specified by:
charData in interface XmlHandler
Parameters:
ch - The character data.
start - The starting position in the array.
length - The number of characters available.
Throws:
SAXException - May throw any exception.
See Also:
XmlHandler.charData(char[], int, int)

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws SAXException
Implement com.microstar.xml.XmlHandler#ignorableWhitespace.

Translate to the SAX interface.

Users should never invoke this method directly.

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:
SAXException - May throw any exception.
See Also:
XmlHandler.ignorableWhitespace(char[], int, int)

processingInstruction

public void processingInstruction(java.lang.String target,
                                  java.lang.String data)
                           throws SAXException
Implement com.microstar.xml.XmlHandler#processingInstruction.

Translate to the SAX interface.

Users should never invoke this method directly.

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:
SAXException - May throw any exception.
See Also:
XmlHandler.processingInstruction(java.lang.String, java.lang.String)

error

public void error(java.lang.String message,
                  java.lang.String url,
                  int line,
                  int column)
           throws SAXException
Implement com.microstar.xml.XmlHandler#error.

Translate to the SAX interface.

Users should never invoke this method directly.

Specified by:
error in interface XmlHandler
Parameters:
message - The error message.
url - 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:
SAXException - May throw any exception.
See Also:
XmlHandler.error(java.lang.String, java.lang.String, int, int)

getLength

public int getLength()
Description copied from interface: AttributeList
Return the number of attributes in this list.

The SAX parser may provide attributes in any arbitrary order, regardless of the order in which they were declared or specified. The number of attributes may be zero.

Specified by:
getLength in interface AttributeList
Returns:
The number of attributes in the list.

getName

public java.lang.String getName(int i)
Description copied from interface: AttributeList
Return the name of an attribute in this list (by position).

The names must be unique: the SAX parser shall not include the same attribute twice. Attributes without values (those declared #IMPLIED without a value specified in the start tag) will be omitted from the list.

If the attribute name has a namespace prefix, the prefix will still be attached.

Specified by:
getName in interface AttributeList
Parameters:
i - The index of the attribute in the list (starting at 0).
Returns:
The name of the indexed attribute, or null if the index is out of range.
See Also:
AttributeList.getLength()

getType

public java.lang.String getType(int i)
Description copied from interface: AttributeList
Return the type of an attribute in the list (by position).

The attribute type is one of the strings "CDATA", "ID", "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES", or "NOTATION" (always in upper case).

If the parser has not read a declaration for the attribute, or if the parser does not report attribute types, then it must return the value "CDATA" as stated in the XML 1.0 Recommentation (clause 3.3.3, "Attribute-Value Normalization").

For an enumerated attribute that is not a notation, the parser will report the type as "NMTOKEN".

Specified by:
getType in interface AttributeList
Parameters:
i - The index of the attribute in the list (starting at 0).
Returns:
The attribute type as a string, or null if the index is out of range.
See Also:
AttributeList.getLength(), AttributeList.getType(java.lang.String)

getValue

public java.lang.String getValue(int i)
Description copied from interface: AttributeList
Return the value of an attribute in the list (by position).

If the attribute value is a list of tokens (IDREFS, ENTITIES, or NMTOKENS), the tokens will be concatenated into a single string separated by whitespace.

Specified by:
getValue in interface AttributeList
Parameters:
i - The index of the attribute in the list (starting at 0).
Returns:
The attribute value as a string, or null if the index is out of range.
See Also:
AttributeList.getLength(), AttributeList.getValue(java.lang.String)

getType

public java.lang.String getType(java.lang.String name)
Description copied from interface: AttributeList
Return the type of an attribute in the list (by name).

The return value is the same as the return value for getType(int).

If the attribute name has a namespace prefix in the document, the application must include the prefix here.

Specified by:
getType in interface AttributeList
Parameters:
name - The name of the attribute.
Returns:
The attribute type as a string, or null if no such attribute exists.
See Also:
AttributeList.getType(int)

getValue

public java.lang.String getValue(java.lang.String name)
Description copied from interface: AttributeList
Return the value of an attribute in the list (by name).

The return value is the same as the return value for getValue(int).

If the attribute name has a namespace prefix in the document, the application must include the prefix here.

Specified by:
getValue in interface AttributeList
Returns:
The attribute value as a string, or null if no such attribute exists.
See Also:
AttributeList.getValue(int)

getPublicId

public java.lang.String getPublicId()
Description copied from interface: Locator
Return the public identifier for the current document event.

This will be the public identifier

Specified by:
getPublicId in interface Locator
Returns:
A string containing the public identifier, or null if none is available.
See Also:
Locator.getSystemId()

getSystemId

public java.lang.String getSystemId()
Description copied from interface: Locator
Return the system identifier for the current document event.

If the system identifier is a URL, the parser must resolve it fully before passing it to the application.

Specified by:
getSystemId in interface Locator
Returns:
A string containing the system identifier, or null if none is available.
See Also:
Locator.getPublicId()

getLineNumber

public int getLineNumber()
Description copied from interface: Locator
Return the line number where the current document event ends. Note that this is the line position of the first character after the text associated with the document event.

Specified by:
getLineNumber in interface Locator
Returns:
The line number, or -1 if none is available.
See Also:
Locator.getColumnNumber()

getColumnNumber

public int getColumnNumber()
Description copied from interface: Locator
Return the column number where the current document event ends. Note that this is the column number of the first character after the text associated with the document event. The first column in a line is position 1.

Specified by:
getColumnNumber in interface Locator
Returns:
The column number, or -1 if none is available.
See Also:
Locator.getLineNumber()