Return-Path: Delivered-To: apmail-jakarta-avalon-cvs-archive@apache.org Received: (qmail 71189 invoked from network); 14 Feb 2002 08:04:25 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 14 Feb 2002 08:04:25 -0000 Received: (qmail 11538 invoked by uid 97); 14 Feb 2002 08:04:38 -0000 Delivered-To: qmlist-jakarta-archive-avalon-cvs@jakarta.apache.org Received: (qmail 11510 invoked by uid 97); 14 Feb 2002 08:04:37 -0000 Mailing-List: contact avalon-cvs-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Avalon CVS List" Reply-To: "Avalon Developers List" Delivered-To: mailing list avalon-cvs@jakarta.apache.org Received: (qmail 11499 invoked by uid 97); 14 Feb 2002 08:04:36 -0000 Date: 14 Feb 2002 08:04:21 -0000 Message-ID: <20020214080421.38809.qmail@icarus.apache.org> From: cziegeler@apache.org To: jakarta-avalon-excalibur-cvs@apache.org Subject: cvs commit: jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/xml JaxpParser.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N cziegeler 02/02/14 00:04:21 Modified: src/scratchpad/org/apache/avalon/excalibur/xml JaxpParser.java Log: Added missing configuration for sax parser factory and document builder factory Revision Changes Path 1.11 +64 -6 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/xml/JaxpParser.java Index: JaxpParser.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/xml/JaxpParser.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- JaxpParser.java 13 Feb 2002 13:24:16 -0000 1.10 +++ JaxpParser.java 14 Feb 2002 08:04:21 -0000 1.11 @@ -14,6 +14,7 @@ import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.parameters.Parameterizable; import org.apache.avalon.framework.parameters.Parameters; +import org.apache.avalon.framework.parameters.ParameterException; import org.w3c.dom.Document; import org.xml.sax.*; import org.xml.sax.ext.LexicalHandler; @@ -46,17 +47,28 @@ * recycled in case of parsing errors : some parsers (e.g. Xerces) don't like * to be reused after failure. * + *
  • sax-parser-factory (string, optional) : the name of the SAXParserFactory + * implementation class to be used instead of using the standard JAXP mechanism + * (SAXParserFactory.newInstance()). This allows to choose + * unambiguously the JAXP implementation to be used when several of them are + * available in the classpath. + *
  • + *
  • document-builder-factory (string, optional) : the name of the + * DocumentBuilderFactory implementation to be used (similar to + * sax-parser-factory for DOM). + *
  • * * * @author Berin Loritsch * @author Carsten Ziegeler * @author Sylvain Wallez - * @version CVS $Revision: 1.10 $ $Date: 2002/02/13 13:24:16 $ + * @version CVS $Revision: 1.11 $ $Date: 2002/02/14 08:04:21 $ */ public class JaxpParser extends AbstractLogEnabled implements Parser, ErrorHandler, Composable, Parameterizable, Poolable { + /** the SAX Parser factory */ protected SAXParserFactory factory; @@ -111,6 +123,7 @@ * Configure */ public void parameterize( Parameters params ) + throws ParameterException { // Validation and namespace prefixes parameters boolean validate = params.getParameterAsBoolean("validate", false); @@ -119,23 +132,68 @@ this.stopOnWarning = params.getParameterAsBoolean("stop-on-warning", true); this.stopOnRecoverableError = params.getParameterAsBoolean("stop-on-recoverable-error", true); - this.factory = SAXParserFactory.newInstance(); + // Get the SAXFactory + final String saxParserFactoryName = params.getParameter("sax-parser-factory", + "javax.xml.parsers.SAXParserFactory"); + try + { + final Class factoryClass = this.loadClass( saxParserFactoryName ); + this.factory = (SAXParserFactory)factoryClass.newInstance(); + } + catch(Exception e) + { + throw new ParameterException("Cannot load SAXParserFactory class " + saxParserFactoryName, e); + } this.factory.setNamespaceAware(true); this.factory.setValidating(validate); - this.docFactory = DocumentBuilderFactory.newInstance(); - docFactory.setNamespaceAware(true); - docFactory.setValidating(validate); + // Get the DocumentFactory + final String documentBuilderFactoryName = params.getParameter("document-builder-factory", + "javax.xml.parsers.DocumentBuilderFactory"); + try + { + final Class factoryClass = this.loadClass( documentBuilderFactoryName ); + this.docFactory = (DocumentBuilderFactory)factoryClass.newInstance(); + } + catch(Exception e) + { + throw new ParameterException("Cannot load DocumentBuilderFactory class " + documentBuilderFactoryName, e); + } + this.docFactory.setNamespaceAware(true); + this.docFactory.setValidating(validate); + if ( this.getLogger().isDebugEnabled() ) { this.getLogger().debug("JaxpParser: validating: " + validate + ", namespace-prefixes: " + this.nsPrefixes + ", reuse parser: " + this.reuseParsers + ", stop on warning: " + this.stopOnWarning + - ", stop on recoverable-error: " + this.stopOnRecoverableError); + ", stop on recoverable-error: " + this.stopOnRecoverableError + + ", saxParserFactory: " + saxParserFactoryName + + ", documentBuilderFactory: " + documentBuilderFactoryName); + } + } + + /** + * Load a class + */ + protected Class loadClass( String name ) throws Exception + { + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + if (loader == null) + { + loader = this.getClass().getClassLoader(); } + return loader.loadClass( name ); } + /** + * Parse the InputSource and send + * SAX events to the consumer. + * Attention: the consumer can either be an XMLConsumer + * or implement the LexicalHandler as well. + * The parse should take care of this. + */ public void parse(InputSource in, ContentHandler consumer) throws SAXException, IOException { -- To unsubscribe, e-mail: For additional commands, e-mail: