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.
    * </li>
  + * <li>sax-parser-factory (string, optional) : the name of the 
<code>SAXParserFactory</code>
  + *     implementation class to be used instead of using the standard JAXP 
mechanism
  + *     (<code>SAXParserFactory.newInstance()</code>). This allows to choose
  + *     unambiguously the JAXP implementation to be used when several of them 
are
  + *     available in the classpath.
  + * </li>
  + * <li>document-builder-factory (string, optional) : the name of the
  + *     <code>DocumentBuilderFactory</code> implementation to be used 
(similar to
  + *     <code>sax-parser-factory</code> for DOM).
  + * </li>
    * </ul>
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Sylvain Wallez</a>
  - * @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 <code>InputSource</code> and send
  +     * SAX events to the consumer.
  +     * Attention: the consumer can either be an XMLConsumer
  +     * or implement the <code>LexicalHandler</code> as well.
  +     * The parse should take care of this.
  +     */
       public void parse(InputSource in, ContentHandler consumer)
       throws SAXException, IOException
       {
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to