jcreek.cke.importexport.xml
Class XercesParserWrapper

java.lang.Object
  extended byjcreek.cke.importexport.xml.XercesParserWrapper
All Implemented Interfaces:
DOMparserWrapper, org.xml.sax.ErrorHandler

public class XercesParserWrapper
extends java.lang.Object
implements DOMparserWrapper, org.xml.sax.ErrorHandler

Wraps the Xerces DOM parser.

This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation and was originally based on software copyright (c) 1999, International Business Machines, Inc., http://www.apache.org. For more information on the Apache Software Foundation, please see www.apache.org.

Author:
Stein L. Tomassen, NTNU 2002, Apache org.

Constructor Summary
XercesParserWrapper()
          The constructor that initializes the parser and sets the basic features.
 
Method Summary
 void error(org.xml.sax.SAXParseException ex)
          In case the parser encounters an error while parsing the document, then the error should be logged.
 void fatalError(org.xml.sax.SAXParseException ex)
          In case the parser encounters a fatal error while parsing the document, then the fatal error should be logged.
 java.lang.String getErrorsMsg()
          Returns a string with all the error messages the parser reports when parsing.
 java.lang.String getFatalErrorsMsg()
          Returns a string with all the fatal error messages the parser reports when parsing.
protected  java.lang.String getLocationString(org.xml.sax.SAXParseException ex)
          Finds the location of an error in the DOM document and returns this location as a string.
 int getNumberOfErrors()
          Returns the number of error messages the parser reports when parsing
 int getNumberOfFatalErrors()
          Returns the number of fatal error messages the parser reports when parsing
 int getNumberOfWarnings()
          Returns the number of warning messages the parser reports when parsing
 java.lang.String getWarningsMsg()
          Returns a string with all the warning messages the parser reports when parsing.
 org.w3c.dom.Document parse(org.w3c.dom.Document document)
          Parses the specified Document and returns it as a DOM document.
 org.w3c.dom.Document parse(java.io.InputStream istream)
          Parses the specified InputStream and returns the document.
 org.w3c.dom.Document parse(java.io.Reader reader)
          Parses the specified Reader and returns it as a DOM document.
 org.w3c.dom.Document parse(java.lang.String url)
          Parses the specified URL and returns it as a DOM document.
 void setFeature(java.lang.String featureId, boolean state)
          Set the state of a feature.
 void warning(org.xml.sax.SAXParseException ex)
          In case the parser encounters a warning while parsing the document, then the warning should be logged.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XercesParserWrapper

public XercesParserWrapper()
The constructor that initializes the parser and sets the basic features. In case of an initialization fault, a fatal error message will be created, and must therefore be checked for after intialization.

Method Detail

parse

public org.w3c.dom.Document parse(java.lang.String url)
                           throws java.lang.Exception
Description copied from interface: DOMparserWrapper
Parses the specified URL and returns it as a DOM document.

Specified by:
parse in interface DOMparserWrapper
Parameters:
url - the URL of the document to parse
Returns:
the parsed document as a DOM object
Throws:
java.lang.Exception - an expection if an parser error occurs
See Also:
DOMparserWrapper.parse(String)

parse

public org.w3c.dom.Document parse(java.io.InputStream istream)
                           throws java.lang.Exception
Description copied from interface: DOMparserWrapper
Parses the specified InputStream and returns the document.

Specified by:
parse in interface DOMparserWrapper
Parameters:
istream - the input stream being the source of the document to parse
Returns:
the parsed document as a DOM object
Throws:
java.lang.Exception - an expection if an parser error occurs
See Also:
DOMparserWrapper.parse(InputStream)

parse

public org.w3c.dom.Document parse(java.io.Reader reader)
                           throws java.lang.Exception
Description copied from interface: DOMparserWrapper
Parses the specified Reader and returns it as a DOM document.

Specified by:
parse in interface DOMparserWrapper
Parameters:
reader - the input reader being the source of the document to parse
Returns:
the parsed document as a DOM object
Throws:
java.lang.Exception - an expection if an parser error occurs
See Also:
DOMparserWrapper.parse(Reader)

parse

public org.w3c.dom.Document parse(org.w3c.dom.Document document)
                           throws java.lang.Exception
Description copied from interface: DOMparserWrapper
Parses the specified Document and returns it as a DOM document. This method makes it easier to revalidate a document. In a future version of Xerces, maybe revalidation will a feature...

Specified by:
parse in interface DOMparserWrapper
Parameters:
document - the DOM object to parse
Returns:
the parsed document as a DOM object
Throws:
java.lang.Exception - an expection if an parser error occurs
See Also:
DOMparserWrapper.parse(Document)

setFeature

public void setFeature(java.lang.String featureId,
                       boolean state)
                throws org.xml.sax.SAXNotRecognizedException,
                       org.xml.sax.SAXNotSupportedException
Description copied from interface: DOMparserWrapper
Set the state of a feature. Set the state of any feature in a SAX2 parser. The parser might not recognize the feature, and if it does recognize it, it might not be able to fulfill the request.

Specified by:
setFeature in interface DOMparserWrapper
Parameters:
featureId - The unique identifier (URI) of the feature.
state - The requested state of the feature (true or false).
Throws:
org.xml.sax.SAXNotSupportedException - If the requested feature is known, but the requested state is not supported.
org.xml.sax.SAXNotRecognizedException - If the requested feature is not known.
See Also:
DOMparserWrapper.setFeature(String, boolean)

getErrorsMsg

public java.lang.String getErrorsMsg()
Description copied from interface: DOMparserWrapper
Returns a string with all the error messages the parser reports when parsing. The messages is separeted with a new line character.

Specified by:
getErrorsMsg in interface DOMparserWrapper
Returns:
a string with all the error messages
See Also:
DOMparserWrapper.getErrorsMsg()

getWarningsMsg

public java.lang.String getWarningsMsg()
Description copied from interface: DOMparserWrapper
Returns a string with all the warning messages the parser reports when parsing. The messages is separeted with a new line character.

Specified by:
getWarningsMsg in interface DOMparserWrapper
Returns:
a string with all the warning messages
See Also:
DOMparserWrapper.getWarningsMsg()

getFatalErrorsMsg

public java.lang.String getFatalErrorsMsg()
Description copied from interface: DOMparserWrapper
Returns a string with all the fatal error messages the parser reports when parsing. The messages is separeted with a new line character.

Specified by:
getFatalErrorsMsg in interface DOMparserWrapper
Returns:
a string with all the fatal error messages
See Also:
DOMparserWrapper.getFatalErrorsMsg()

getNumberOfErrors

public int getNumberOfErrors()
Description copied from interface: DOMparserWrapper
Returns the number of error messages the parser reports when parsing

Specified by:
getNumberOfErrors in interface DOMparserWrapper
Returns:
the number of errors
See Also:
DOMparserWrapper.getNumberOfErrors()

getNumberOfWarnings

public int getNumberOfWarnings()
Description copied from interface: DOMparserWrapper
Returns the number of warning messages the parser reports when parsing

Specified by:
getNumberOfWarnings in interface DOMparserWrapper
Returns:
the number of warnings
See Also:
DOMparserWrapper.getNumberOfWarnings()

getNumberOfFatalErrors

public int getNumberOfFatalErrors()
Description copied from interface: DOMparserWrapper
Returns the number of fatal error messages the parser reports when parsing

Specified by:
getNumberOfFatalErrors in interface DOMparserWrapper
Returns:
the number of fatal errors
See Also:
DOMparserWrapper.getNumberOfFatalErrors()

warning

public void warning(org.xml.sax.SAXParseException ex)
In case the parser encounters a warning while parsing the document, then the warning should be logged.

Specified by:
warning in interface org.xml.sax.ErrorHandler
Parameters:
ex - the exception that occured
See Also:
ErrorHandler.warning(SAXParseException)

error

public void error(org.xml.sax.SAXParseException ex)
In case the parser encounters an error while parsing the document, then the error should be logged.

Specified by:
error in interface org.xml.sax.ErrorHandler
Parameters:
ex - the exception that occured
See Also:
ErrorHandler.error(SAXParseException)

fatalError

public void fatalError(org.xml.sax.SAXParseException ex)
                throws org.xml.sax.SAXException
In case the parser encounters a fatal error while parsing the document, then the fatal error should be logged. In addition an exception should be thrown, because in case of a fatal error the parsing cannot continue.

Specified by:
fatalError in interface org.xml.sax.ErrorHandler
Parameters:
ex - the exception that occured
Throws:
org.xml.sax.SAXException
See Also:
ErrorHandler.fatalError(SAXParseException)

getLocationString

protected java.lang.String getLocationString(org.xml.sax.SAXParseException ex)
Finds the location of an error in the DOM document and returns this location as a string.

Parameters:
ex - the exception that occured
Returns:
the location string


Created at IDI, NTNU by the Artificial Intelligence and Learning group