You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Mauricio Nuñez <mn...@maxmedia.cl> on 2003/04/10 01:56:55 UTC

Endorsed XML parser : possible solution

Hi,

May be Off-topic, but the avalon cornerstone project had a 
DocumentBuilderFactory and a SaxParserFactory capable to map to a crimson 
parser or a xerces parser based on the configuration passed to it.

If that configuration object is part of the specific webapp classloader, may 
be posible to get distincts parser inside the same JVM. (I'm guessing)

Someone can clarified me this alternative?

TIA

Mauricio Nuñez
mauricio at chile dot com






---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Endorsed XML parser : possible solution

Posted by Jacob Kjome <ho...@visi.com>.
Keep in mind that the endorsed stuff mostly only has to do with libraries 
such as java.*, javax.*, org.w3c.*, and org.xml.*.  Basically, anything 
that the JDK comes with can only be overridden via the endorsed standards 
override mechanism.  Most XML parsers contain these libraries because they 
are the foundation upon which the XML parser is based.  Xerces tries to 
split these up into xercesImpl.jar and xmlParserAPIs.jar but both end up 
having org.w3c.dom.* packages and the latter also has org.xml.* and 
javax.*.   So, it isn't the xerces library itself that is important here, 
but the libraries that the JDK already has which Xerces provides updated 
versions of.

2 libraries that you'd have to override that don't fall in the normal 
categories above are the XML parser Crimson (if you had a newer version 
than comes with j2sdk1.4.x) and Xalan (j2sdk1.4.x comes with an old buggy 
version of Xalan).  This is why I always put the latest Xalan in 
JAVA_HOME/jre/lib/endorsed.  It makes sure that any java program I run sees 
the latest Xalan instead of the buggy version.

Now, as far as choosing your SAX parser, here is a technique for choosing 
the one you want with fallback for other possible parsers if the one you 
want doesn't exist in the classpath....

     /**
      * create SAX2 Parser (XMLReader) instance.  Attempts to load the 
passed-in
      * preferred parser first. If that fails, it falls back to loading the
      * parser set by the org.xml.sax.driver property. Failing that, other 
known
      * parsers are explicitly attempted for loading. If that fails, you are
      * trying really hard to defeat this method!
      *
      * @param preferred the preferred parser name, may be null
      * @return an XMLReader, guaranteed non-null
      * @throws SAXException when no SAX2 Parser is available
      */
     private XMLReader getXMLReader(String preferred) throws SAXException {
         XMLReader parser = null;
         try { // Preferred
             if (preferred != null) {
                 parser = XMLReaderFactory.createXMLReader(preferred);
             } else {
                 throw new SAXException("Preferred SAX parser unavailable!");
             }
         }
         catch (SAXException e1) {
             try { // default
                 // obtain parser via system property...
                 // loads whatever parser was set in the system property
                 // org.xml.sax.driver and will also fall back to the SAX1
                 // system property org.xml.sax.parser
                 parser = XMLReaderFactory.createXMLReader();
             }
             catch (SAXException e2) {
                 try { // Piccolo (speed demon: 
http://piccolo.sourceforge.net/bench.html -- non-validating, but can be 
wrapped by a validating parser)
                     parser = 
XMLReaderFactory.createXMLReader("com.bluecast.xml.Piccolo");
                 }
                 catch (SAXException e3) {
                     try { // Xerces (the standard)
                         parser = 
XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
                     }
                     catch (SAXException e4) {
                         try { // Crimson (exists in j2sdk1.4.x)
                             parser = 
XMLReaderFactory.createXMLReader("org.apache.crimson.parser.XMLReaderImpl");
                         }
                         catch (SAXException e5) {
                             try { // Ælfred (optionally validating)
                                 parser = 
XMLReaderFactory.createXMLReader("gnu.xml.aelfred2.XmlReader");
                             }
                             catch (SAXException e6) {
                                 try { // older Ælfred (non-validating)
                                 parser = 
XMLReaderFactory.createXMLReader("net.sf.saxon.aelfred.SAXDriver");
                                 }
                                 catch (SAXException e7) {
                                     // Oracle (well, why not?) ...last 
ditch attempt, let the exception go after this
                                     parser = 
XMLReaderFactory.createXMLReader("oracle.xml.parser.v2.SAXParser");
                                 }
                             }
                         }
                     }
                 }
             }
         }
         return parser;
     }


Hope that helps.

Jake



At 07:56 PM 4/9/2003 -0400, you wrote:
>Hi,
>
>May be Off-topic, but the avalon cornerstone project had a
>DocumentBuilderFactory and a SaxParserFactory capable to map to a crimson
>parser or a xerces parser based on the configuration passed to it.
>
>If that configuration object is part of the specific webapp classloader, may
>be posible to get distincts parser inside the same JVM. (I'm guessing)
>
>Someone can clarified me this alternative?
>
>TIA
>
>Mauricio Nuñez
>mauricio at chile dot com
>
>
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org