Devsphere.com


com.devsphere.xml.taglib.support.builder
Class BuilderSupport

java.lang.Object
  |
  +--org.xml.sax.helpers.DefaultHandler
        |
        +--com.devsphere.xml.saxdomix.SDXBuilder
              |
              +--com.devsphere.xml.taglib.support.builder.BuilderSupport
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler, org.xml.sax.ext.LexicalHandler
Direct Known Subclasses:
Builder, Main, Main

public class BuilderSupport
extends SDXBuilder

This helper class extends com.devsphere.xml.saxdomix.SDXBuilder with methods for parsing an input source and logging parsing errors.


Field Summary
 
Fields inherited from class com.devsphere.xml.saxdomix.SDXBuilder
controller, handler, helper, inCDATA, lexicalHandler, newCDATA, stack, wantDOM
 
Constructor Summary
BuilderSupport(org.xml.sax.helpers.DefaultHandler handler, SDXController controller, AbstractLogger logger)
          Initializes the builder
 
Method Summary
 void error(org.xml.sax.SAXParseException e)
          Logs a parse error.
 void fatalError(org.xml.sax.SAXParseException e)
          Throws a fatal parse error.
protected  javax.xml.parsers.SAXParser getSAXParser(boolean validating)
          Creates a SAX parser object.
protected static javax.xml.parsers.SAXParserFactory getSAXParserFactory(boolean validating)
          Creates a factory for SAX parsers.
protected  void log(java.lang.String message, org.xml.sax.SAXParseException e)
          Logs a SAX warning or error.
 void parse(org.xml.sax.InputSource source, boolean validating)
          Parses an input source using SAXDOMIX.
 void warning(org.xml.sax.SAXParseException e)
          Logs a parse warning.
 
Methods inherited from class com.devsphere.xml.saxdomix.SDXBuilder
characters, comment, endCDATA, endDocument, endDTD, endElement, endEntity, processingInstruction, setDocumentLocator, startCDATA, startDocument, startDTD, startElement, startEntity
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, ignorableWhitespace, notationDecl, resolveEntity, skippedEntity, startPrefixMapping, unparsedEntityDecl
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BuilderSupport

public BuilderSupport(org.xml.sax.helpers.DefaultHandler handler,
                      SDXController controller,
                      AbstractLogger logger)
Initializes the builder

Parameters:
handler - org.xml.sax.helpers.DefaultHandler instance that will handle the SAX events
controller - com.devsphere.xml.saxdomix.SDXController instance that will handle the DOM sub-trees and control the switches between SAX and DOM
logger - com.devsphere.logging.AbstractLogger instance that will be used to log the parsing errors, if any
Method Detail

parse

public void parse(org.xml.sax.InputSource source,
                  boolean validating)
           throws javax.xml.parsers.ParserConfigurationException,
                  org.xml.sax.SAXException,
                  java.io.IOException
Parses an input source using SAXDOMIX. It creates a SAX parser and passes this to its parse() method. Therefore this builder object will act as SAX handler and forward the SAX events or create DOM sub-trees as indicated by the controller object.

Parameters:
source - the XML input source that must be parsed
validating - a flag indicating if the XML content should be validated by the XML parser
Throws:
org.xml.sax.SAXException - to signal a SAX error
java.io.IOException - to signal an I/O error
javax.xml.parsers.ParserConfigurationException - to signal a configuration error

warning

public void warning(org.xml.sax.SAXParseException e)
             throws org.xml.sax.SAXException
Logs a parse warning.

Specified by:
warning in interface org.xml.sax.ErrorHandler
Overrides:
warning in class org.xml.sax.helpers.DefaultHandler
Parameters:
e - the SAX warning
Throws:
org.xml.sax.SAXException - no exception is thrown

error

public void error(org.xml.sax.SAXParseException e)
           throws org.xml.sax.SAXException
Logs a parse error.

Specified by:
error in interface org.xml.sax.ErrorHandler
Overrides:
error in class org.xml.sax.helpers.DefaultHandler
Parameters:
e - the SAX error
Throws:
org.xml.sax.SAXException - no exception is thrown

fatalError

public void fatalError(org.xml.sax.SAXParseException e)
                throws org.xml.sax.SAXException
Throws a fatal parse error. The exception isn't logged. The catcher of the exception should log it.

Specified by:
fatalError in interface org.xml.sax.ErrorHandler
Overrides:
fatalError in class org.xml.sax.helpers.DefaultHandler
Parameters:
e - the SAX fatal error
Throws:
org.xml.sax.SAXException - the SAX fatal error

log

protected void log(java.lang.String message,
                   org.xml.sax.SAXParseException e)
Logs a SAX warning or error.

Parameters:
message - the message that must be logged
e - the exception that must be logged

getSAXParser

protected javax.xml.parsers.SAXParser getSAXParser(boolean validating)
                                            throws org.xml.sax.SAXException,
                                                   javax.xml.parsers.ParserConfigurationException
Creates a SAX parser object.

Parameters:
validating - flag indicating if validation should be performed during the parsing of an XML source
Returns:
a SAX parser object
Throws:
org.xml.sax.SAXException - to signal a SAX error
javax.xml.parsers.ParserConfigurationException - to signal a configuration error

getSAXParserFactory

protected static javax.xml.parsers.SAXParserFactory getSAXParserFactory(boolean validating)
Creates a factory for SAX parsers.

Parameters:
validating - flag indicating if validation should be performed during the parsing of an XML source
Returns:
a factory for SAX parsers

 Devsphere.com