org.mycore.common.xml
Class MCRParserXerces

java.lang.Object
  extended by org.mycore.common.xml.MCRParserXerces
All Implemented Interfaces:
MCRParserInterface, ErrorHandler

public class MCRParserXerces
extends Object
implements MCRParserInterface, ErrorHandler

Implements the MCRParserInterface using the Xerces XML to parse XML streams to a DOM document.

Version:
$Revision: 15270 $ $Date: 2009-05-25 17:27:57 +0200 (Mon, 25 May 2009) $
Author:
Jens Kupferschmidt, Frank Lützenkirchen, Thomas Scheffler (yagee)

Field Summary
(package private)  SAXBuilder builder
          A xerces parser instance that will not validate
(package private)  SAXBuilder builderValid
          A xerces parser instance that will validate
 
Constructor Summary
MCRParserXerces()
          Constructor for the Xerces parser.
 
Method Summary
 void error(SAXParseException ex)
          Handles parse errors
 void fatalError(SAXParseException ex)
          Handles fatal parse errors
 Document parseURI(URI uri)
          Parses the XML byte stream with xerces parser and returns a DOM document.
 Document parseURI(URI uri, boolean validate)
          Parses the XML byte stream with xerces parser and returns a DOM document.
 Document parseXML(byte[] xml)
          Parses the XML byte stream with xerces parser and returns a DOM document.
 Document parseXML(byte[] xml, boolean validate)
          Parses the XML byte stream with xerces parser and returns a DOM document.
 Document parseXML(InputStream input)
          Parses an Byte Array and returns it as DOM.
 Document parseXML(InputStream input, boolean validate)
          Parses an Byte Array and returns it as DOM.
 Document parseXML(String xml)
          Parses the XML byte stream with xerces parser and returns a DOM document.
 Document parseXML(String xml, boolean validate)
          Parses the XML byte stream with xerces parser and returns a DOM document.
 void warning(SAXParseException ex)
          Handles parser warnings
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

builderValid

SAXBuilder builderValid
A xerces parser instance that will validate


builder

SAXBuilder builder
A xerces parser instance that will not validate

Constructor Detail

MCRParserXerces

public MCRParserXerces()
Constructor for the Xerces parser. Sets default validation flag as specified by the property MCR.XMLParser.ValidateSchema in mycore.properties

Method Detail

parseURI

public Document parseURI(URI uri)
Parses the XML byte stream with xerces parser and returns a DOM document. Uses the validation flag from mycore.properties.

Specified by:
parseURI in interface MCRParserInterface
Parameters:
uri - the URI of the XML input stream
Returns:
the parsed XML stream as a DOM document
Throws:
MCRException - if XML could not be parsed

parseURI

public Document parseURI(URI uri,
                         boolean validate)
Parses the XML byte stream with xerces parser and returns a DOM document. Uses the validation flag given.

Specified by:
parseURI in interface MCRParserInterface
Parameters:
uri - the URI of the XML input stream
validate - if true, will validate against XML Schema
Returns:
the parsed XML stream as a DOM document
Throws:
MCRException - if XML could not be parsed
IOException
SAXException

parseXML

public Document parseXML(String xml)
Parses the XML byte stream with xerces parser and returns a DOM document. Uses the validation flag from mycore.properties

Specified by:
parseXML in interface MCRParserInterface
Parameters:
xml - the XML byte stream
Returns:
the parsed XML stream as a DOM document
Throws:
MCRException - if XML could not be parsed

parseXML

public Document parseXML(String xml,
                         boolean validate)
Parses the XML byte stream with xerces parser and returns a DOM document. Uses the validation flag given.

Specified by:
parseXML in interface MCRParserInterface
Parameters:
xml - the XML byte stream
validate - if true, will validate against XML Schema
Returns:
the parsed XML stream as a DOM document
Throws:
MCRException - if XML could not be parsed

parseXML

public Document parseXML(byte[] xml)
Parses the XML byte stream with xerces parser and returns a DOM document. Uses the validation flag from mycore.properties

Specified by:
parseXML in interface MCRParserInterface
Parameters:
xml - the XML byte stream
Returns:
the parsed XML stream as a DOM document
Throws:
MCRException - if XML could not be parsed

parseXML

public Document parseXML(byte[] xml,
                         boolean validate)
Parses the XML byte stream with xerces parser and returns a DOM document. Uses the given validation flag.

Specified by:
parseXML in interface MCRParserInterface
Parameters:
xml - the XML byte stream
validate - if true, will validate against XML Schema
Returns:
the parsed XML stream as a DOM document
Throws:
MCRException - if XML could not be parsed

parseXML

public Document parseXML(InputStream input)
                  throws MCRException
Description copied from interface: MCRParserInterface
Parses an Byte Array and returns it as DOM. Use the validation value from mycore.properties.

Specified by:
parseXML in interface MCRParserInterface
Parameters:
input - the InputStream to be parsed
Returns:
the XML file as a DOM object
Throws:
MCRException - if XML could not be parsed

parseXML

public Document parseXML(InputStream input,
                         boolean validate)
                  throws MCRException
Description copied from interface: MCRParserInterface
Parses an Byte Array and returns it as DOM. Use the given validation flag.

Specified by:
parseXML in interface MCRParserInterface
Parameters:
input - the InputStream to be parsed
validate - the validation flag
Returns:
the XML file as a DOM object
Throws:
MCRException - if XML could not be parsed

warning

public void warning(SAXParseException ex)
Handles parser warnings

Specified by:
warning in interface ErrorHandler

error

public void error(SAXParseException ex)
Handles parse errors

Specified by:
error in interface ErrorHandler

fatalError

public void fatalError(SAXParseException ex)
Handles fatal parse errors

Specified by:
fatalError in interface ErrorHandler