org.objectweb.jorm.xml2mi.lib
Class SAXParserHelper

java.lang.Object
  extended byorg.objectweb.jorm.xml2mi.lib.SAXParserHelper
All Implemented Interfaces:
org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public class SAXParserHelper
extends java.lang.Object
implements org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

This class is an helper for the use of SAX Parser. It manages the entity resolving public id, and handling errors.

Author:
S.Chassande-Barrioz

Constructor Summary
SAXParserHelper(java.util.Properties publicid2location, Logger logger)
          Creates and initializes a SAX parser with the classLoader of the current class.
SAXParserHelper(java.util.Properties publicid2location, Logger logger, java.lang.ClassLoader cl, boolean dtdverify)
          Creates and initializes a SAX parser.
 
Method Summary
 void error(org.xml.sax.SAXParseException e)
           
 void fatalError(org.xml.sax.SAXParseException e)
           
 org.w3c.dom.Document parse(java.io.InputStream is)
          Parses a stream as an xml file.
 org.w3c.dom.Document parse(java.lang.String xmlFileName)
          Parses a xml file.
 org.xml.sax.InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId)
          Resolves the entity according to the associaition contained in #publicid2location.
 void warning(org.xml.sax.SAXParseException e)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SAXParserHelper

public SAXParserHelper(java.util.Properties publicid2location,
                       Logger logger)
                throws org.xml.sax.SAXException
Creates and initializes a SAX parser with the classLoader of the current class. The DTD checking is done.

Parameters:
publicid2location - contains the association between public id and location

SAXParserHelper

public SAXParserHelper(java.util.Properties publicid2location,
                       Logger logger,
                       java.lang.ClassLoader cl,
                       boolean dtdverify)
                throws org.xml.sax.SAXException
Creates and initializes a SAX parser.

Parameters:
publicid2location - contains the association between public id and location
cl - is the classLoader used to try to load entities and xml files
dtdverify - indicates if the DTD checking must be done
Method Detail

parse

public org.w3c.dom.Document parse(java.lang.String xmlFileName)
                           throws org.xml.sax.SAXException
Parses a xml file. Firstly this method try to found the xml file from the file system or the classpath. Then the method delegates the parsing to the parse(InputStream) method.

Parameters:
xmlFileName - is the path to the xml file. This path can be valid from the file system or the classpath/classloader. The path can be an URL.
Returns:
the Document representing the XML file.
Throws:
org.xml.sax.SAXException - is thrown if the file cannot be found or if the file is malformed.

parse

public org.w3c.dom.Document parse(java.io.InputStream is)
                           throws org.xml.sax.SAXException
Parses a stream as an xml file. Errors are logged.

Parameters:
is - an inputStream contains the XML xml content
Returns:
the Document representing the XML file.
Throws:
org.xml.sax.SAXException - is thrown if the file cannot be found or if the file is malformed.

error

public void error(org.xml.sax.SAXParseException e)
           throws org.xml.sax.SAXException
Specified by:
error in interface org.xml.sax.ErrorHandler
Throws:
org.xml.sax.SAXException

fatalError

public void fatalError(org.xml.sax.SAXParseException e)
                throws org.xml.sax.SAXException
Specified by:
fatalError in interface org.xml.sax.ErrorHandler
Throws:
org.xml.sax.SAXException

warning

public void warning(org.xml.sax.SAXParseException e)
             throws org.xml.sax.SAXException
Specified by:
warning in interface org.xml.sax.ErrorHandler
Throws:
org.xml.sax.SAXException

resolveEntity

public org.xml.sax.InputSource resolveEntity(java.lang.String publicId,
                                             java.lang.String systemId)
                                      throws org.xml.sax.SAXException
Resolves the entity according to the associaition contained in #publicid2location. The entity are searched in the file system and in the classpath.

Specified by:
resolveEntity in interface org.xml.sax.EntityResolver
Throws:
org.xml.sax.SAXException