org.ceryle.xtm
Class XtmHandler

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by org.ceryle.xtm.XtmHandler
All Implemented Interfaces:
Constants, ContentHandler, DTDHandler, EntityResolver, ErrorHandler, LexicalHandler

public class XtmHandler
extends DefaultHandler
implements Constants, ContentHandler, ErrorHandler, LexicalHandler

Receives SAX events to process an XTM format document.

WARNINGS

This Handler has some known deficiencies, namely, it does not support all attributes on all elements (specifically, it doesn't support id attributes on elements unlikely to need them, ignores all XLink attributes except xlink:href). When the feature is active, XML Namespaces are processed correctly (according to the XTM 1.0 Specification's use of features in the W3C XML Namespaces Recommendation).

This processor does perform some structural checks on elements and attributes, but is non-validating, so invalid source documents may create incorrect in-memory representations and therefore invalid XTM serializations. The SAX parser should be operated in validation mode if there is some question as to the validity of the source documents it may process.

Since:
JDK1.3
Version:
$Id: XtmHandler.java,v 3.6 2007-06-15 12:10:35 altheim Exp $
Author:
Murray Altheim

Field Summary
protected  Stack elementStack
          Stack container for element names (Strings), which will precisely reflect the XTM syntax.
protected  Locator locator
          Document Locator.
protected  MessageHandler mh
           
protected  XtmNode node
          The current XtmNode object (a topic, association or mergeMap object).
protected  Stack nodeStack
          Stack container for nodes (XtmNode objects), which may not reflect the XTM syntax nesting.
protected  XtmNode parent
          The current XtmNode's parent object.
static String XMLNS_xlink
          A String containing the XML Namespace URI for XLink.
protected  XtmProcessor xtmp
          An XtmProcessor that receives events in the creation of an XTM document.
 
Fields inherited from interface org.ceryle.util.Constants
Amp, AMP, Apos, APOS, APP_NAME, APP_VERSION_NAME, APP_VERSION_NUMBER, AT, BANG, BAR, BIT_dev, BIT_http, BIT_ignoreCom, BIT_merge, BIT_none, BIT_noPreload, BIT_simple, BIT_ui, BIT_unused1, BIT_unused2, BIT_unused3, BIT_validating, BIT_verbose, BIT_xcatalog, BIT_xlink, BIT_xmlnsAware, BIT_xsd, BROKB, BSlash, BSLASH, CERYLE_CREDITS_FILE, CERYLE_DATA_DIR, CERYLE_HIST_FILE, CERYLE_LICENSE_FILE, CERYLE_PREF_FILE, CERYLE_PROP, CERYLE_PROP_BASE, CERYLE_PROP_FILE, CERYLE_RSRC_DIR, CERYLE_THANKS_FILE, CFLEX, Colon, COLON, Comma, COMMA, CR, CRet, Dash, DASH, DEFAULT_DIRECTORY, DEVELOPER, DOLR, Dot, DOT, EIGHT, Ellip, EOF, EqQuot, EQUAL, Equals, False, FALSE, FileProt, Filesep, FileURL, Five, FIVE, FONTSIZES, Four, FOUR, FSchar, GCOL_PROP, GRAPH_PROP, GRAVE, GT, Hash, HASH, HOME_DIRECTORY, HOME_DIRECTORY_PATH, HOME_DIRECTORY_URL, HTML, HttpProt, HttpURL, INDENT, INDENT_0, INDENT_1, INDENT_10, INDENT_2, INDENT_3, INDENT_4, INDENT_5, INDENT_6, INDENT_7, INDENT_8, INDENT_9, INIT, LCURL, LCurly, LF, LFS, Localhost, LPAR, LParen, LS, LSBrkt, LSBrkt2, LSQB, LT, MT, NBSP, NEL, NINE, NL, NL20x, NLchar, No, Null, NULL, NULL_STATE, NumParams, One, ONE, Pathsep, Percent, PERO, PLUS, Prcnt, PS, QMark, QMARK, Quot, QUOT, RCURL, RCurly, RESOURCE_BUNDLE, RPAR, RParen, RSBrkt, RSBrkt2, RSQB, Semi, SEMI, SEVEN, SIX, Slash, SLASH, SP, SPACE, Stago, Star, STAR, Tab, TAB, Tee, Three, THREE, Tilde, TILDE, TM_PROP, True, TRUE, Two, TWO, Under, UNDER, URI, URL, VBar, WIKI_PROP, XNodePfx, XNodeURL, XtmExt, Yes, Zero, ZERO
 
Constructor Summary
XtmHandler(Services services, XtmProcessor xtmp)
          Constructor provided with Services and an XtmProcessor.
 
Method Summary
 void characters(char[] ch, int offset, int length)
          Receive an event indicating the presence of character data.
 void comment(char[] ch, int offset, int length)
          Receive an event indicating the presence of an XML comment.
 void endCDATA()
           
 void endDocument()
          Receive an event indicating the end of the document has been reached.
 void endDTD()
           
 void endElement(String uri, String localpart, String name)
          Receive an event indicating the end tag of an element.
 void endEntity(String name)
           
 void error(SAXParseException spe)
          Error.
 void fatalError(SAXParseException spe)
          Fatal error.
 void ignorableWhitespace(char[] ch, int offset, int length)
           
protected  String listNodeStack()
          Return a String indicating the node stack contents.
 void processingInstruction(String target, String data)
          Receive an event indicating that a processing instruction has been parsed.
 void setDocumentLocator(Locator locator)
           
 void skippedEntity(String name)
           
 void startCDATA()
           
 void startDocument()
          Receive an event indicating the start of the document.
 void startDTD(String name, String publicId, String systemId)
          Receive an event indicating the presence of a DOCTYPE declaration.
 void startElement(String uri, String localpart, String name, Attributes attributes)
          Receive an event indicating the start tag of an element and process accordingly.
 void startEntity(String name)
           
 void warning(SAXParseException spe)
          Warning.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, notationDecl, resolveEntity, startPrefixMapping, unparsedEntityDecl
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.xml.sax.ContentHandler
endPrefixMapping, startPrefixMapping
 

Field Detail

XMLNS_xlink

public static final String XMLNS_xlink
A String containing the XML Namespace URI for XLink.

See Also:
Constant Field Values

mh

protected MessageHandler mh

xtmp

protected XtmProcessor xtmp
An XtmProcessor that receives events in the creation of an XTM document.


locator

protected Locator locator
Document Locator.


elementStack

protected Stack elementStack
Stack container for element names (Strings), which will precisely reflect the XTM syntax.


nodeStack

protected Stack nodeStack
Stack container for nodes (XtmNode objects), which may not reflect the XTM syntax nesting.


node

protected XtmNode node
The current XtmNode object (a topic, association or mergeMap object).


parent

protected XtmNode parent
The current XtmNode's parent object.

Constructor Detail

XtmHandler

public XtmHandler(Services services,
                  XtmProcessor xtmp)
Constructor provided with Services and an XtmProcessor. The XtmProcessor is assumed to have created the XtmDocument (and an internal XtmTopicMap object) already and is awaiting events to populate it.

Method Detail

startElement

public void startElement(String uri,
                         String localpart,
                         String name,
                         Attributes attributes)
Receive an event indicating the start tag of an element and process accordingly. This is where the bulk of this class's processing occurs.

Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class DefaultHandler

endElement

public void endElement(String uri,
                       String localpart,
                       String name)
                throws SAXException
Receive an event indicating the end tag of an element.

Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class DefaultHandler
Throws:
SAXException

characters

public void characters(char[] ch,
                       int offset,
                       int length)
                throws SAXException
Receive an event indicating the presence of character data. Only <resourceData> and <baseNameString> elements can contain character data.

Specified by:
characters in interface ContentHandler
Overrides:
characters in class DefaultHandler
Throws:
SAXException

comment

public void comment(char[] ch,
                    int offset,
                    int length)
             throws SAXException
Receive an event indicating the presence of an XML comment.

Specified by:
comment in interface LexicalHandler
Throws:
SAXException

startDTD

public void startDTD(String name,
                     String publicId,
                     String systemId)
              throws SAXException
Receive an event indicating the presence of a DOCTYPE declaration.

Specified by:
startDTD in interface LexicalHandler
Throws:
SAXException

startEntity

public void startEntity(String name)
                 throws SAXException
Specified by:
startEntity in interface LexicalHandler
Throws:
SAXException

startCDATA

public void startCDATA()
                throws SAXException
Specified by:
startCDATA in interface LexicalHandler
Throws:
SAXException

endCDATA

public void endCDATA()
              throws SAXException
Specified by:
endCDATA in interface LexicalHandler
Throws:
SAXException

endEntity

public void endEntity(String name)
               throws SAXException
Specified by:
endEntity in interface LexicalHandler
Throws:
SAXException

endDTD

public void endDTD()
            throws SAXException
Specified by:
endDTD in interface LexicalHandler
Throws:
SAXException

listNodeStack

protected String listNodeStack()
Return a String indicating the node stack contents.


setDocumentLocator

public void setDocumentLocator(Locator locator)
Specified by:
setDocumentLocator in interface ContentHandler
Overrides:
setDocumentLocator in class DefaultHandler

startDocument

public void startDocument()
                   throws SAXException
Receive an event indicating the start of the document.

Specified by:
startDocument in interface ContentHandler
Overrides:
startDocument in class DefaultHandler
Throws:
SAXException

endDocument

public void endDocument()
                 throws SAXException
Receive an event indicating the end of the document has been reached.

Specified by:
endDocument in interface ContentHandler
Overrides:
endDocument in class DefaultHandler
Throws:
SAXException

processingInstruction

public void processingInstruction(String target,
                                  String data)
Receive an event indicating that a processing instruction has been parsed.

Specified by:
processingInstruction in interface ContentHandler
Overrides:
processingInstruction in class DefaultHandler

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int offset,
                                int length)
Specified by:
ignorableWhitespace in interface ContentHandler
Overrides:
ignorableWhitespace in class DefaultHandler

skippedEntity

public void skippedEntity(String name)
Specified by:
skippedEntity in interface ContentHandler
Overrides:
skippedEntity in class DefaultHandler

warning

public void warning(SAXParseException spe)
Warning.

Specified by:
warning in interface ErrorHandler
Overrides:
warning in class DefaultHandler

error

public void error(SAXParseException spe)
Error.

Specified by:
error in interface ErrorHandler
Overrides:
error in class DefaultHandler

fatalError

public void fatalError(SAXParseException spe)
Fatal error.

Specified by:
fatalError in interface ErrorHandler
Overrides:
fatalError in class DefaultHandler


The Ceryle Project. Copyright ©2001-2007 Murray Altheim, All Rights Reserved. See LICENSE included with distribution.