You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by bl...@locus.apache.org on 2000/11/01 16:52:44 UTC

cvs commit: xml-cocoon/src/org/apache/cocoon/xml SAXConfigurationBuilder.java

bloritsch    00/11/01 07:52:42

  Modified:    src/org/apache/cocoon Tag: xml-cocoon2 Cocoon.java
               src/org/apache/cocoon/components/parser Tag: xml-cocoon2
                        Parser.java XercesParser.java
  Removed:     src/org/apache/cocoon/xml Tag: xml-cocoon2
                        SAXConfigurationBuilder.java
  Log:
  Made changes to use the official Avalon ConfigurationBuilder.  I had to make
  changes to both Avalon and Cocoon.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.4.2.34  +33 -34    xml-cocoon/src/org/apache/cocoon/Cocoon.java
  
  Index: Cocoon.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/Cocoon.java,v
  retrieving revision 1.4.2.33
  retrieving revision 1.4.2.34
  diff -u -r1.4.2.33 -r1.4.2.34
  --- Cocoon.java	2000/10/19 16:39:05	1.4.2.33
  +++ Cocoon.java	2000/11/01 15:52:29	1.4.2.34
  @@ -5,14 +5,14 @@
    * version 1.1, a copy of which has been included  with this distribution in *
    * the LICENSE file.                                                         *
    *****************************************************************************/
  - 
  +
   package org.apache.cocoon;
   
   import java.io.File;
  +import java.io.FileReader;
   import java.io.FileNotFoundException;
   import java.io.IOException;
   import java.io.OutputStream;
  -import java.io.FileReader;
   import java.net.URL;
   import java.util.HashMap;
   import java.util.Enumeration;
  @@ -26,6 +26,7 @@
   import org.apache.avalon.Modifiable;
   import org.apache.avalon.Configurable;
   import org.apache.avalon.Configuration;
  +import org.apache.avalon.ConfigurationBuilder;
   import org.apache.avalon.ConfigurationException;
   
   import org.apache.cocoon.components.parser.Parser;
  @@ -34,38 +35,37 @@
   import org.apache.cocoon.sitemap.Manager;
   import org.apache.cocoon.util.ClassUtils;
   import org.apache.cocoon.DefaultComponentManager;
  -import org.apache.cocoon.xml.SAXConfigurationBuilder;
   
  -import org.xml.sax.InputSource;
   import org.xml.sax.SAXException;
  +import org.xml.sax.InputSource;
   
   /**
    * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
    *         (Apache Software Foundation, Exoffice Technologies)
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  - * @version CVS $Revision: 1.4.2.33 $ $Date: 2000/10/19 16:39:05 $
  + * @version CVS $Revision: 1.4.2.34 $ $Date: 2000/11/01 15:52:29 $
    */
   public class Cocoon
     implements Component, Configurable, ComponentManager, Modifiable, Processor, Constants {
   
       /** The table of role-class */
       private HashMap components = new HashMap();
  -    
  +
       /** The table of role-configuration */
       private HashMap configurations = new HashMap();
  -    
  -    /** The configuration file */ 
  -    private File configurationFile; 
  -    
  -    /** The sitemap file */ 
  -    private String sitemapFileName; 
  -    
  +
  +    /** The configuration file */
  +    private File configurationFile;
  +
  +    /** The sitemap file */
  +    private String sitemapFileName;
  +
       /** The configuration tree */
       private Configuration configuration;
  -    
  +
       /** The sitemap manager */
       private Manager sitemapManager;
  -    
  +
       /** The root uri/path */
       private URL root;
   
  @@ -94,7 +94,7 @@
               throw new ConfigurationException("Could not load parser " + parser + ": " + e.getMessage());
           }
           this.componentManager.addComponentInstance(Roles.COCOON, this);
  -         
  +
           String processor = System.getProperty(PROCESSOR_PROPERTY, DEFAULT_PROCESSOR);
           try {
           org.apache.trax.Processor.setPlatformDefaultProcessor(processor);
  @@ -103,7 +103,7 @@
               throw new ConfigurationException("Error creating processor (" + processor + ")");
           }
       }
  -    
  +
       /**
        * Create a new <code>Cocoon</code> object, parsing configuration from
        * the specified file.
  @@ -113,22 +113,21 @@
           this();
   
           this.classpath = classpath;
  -        
  +
           this.workDir = workDir;
  -                
  +
           this.configurationFile = configurationFile;
           if (!configurationFile.isFile()) {
               throw new FileNotFoundException(configurationFile.toString());
           }
  -            
  +
           Parser p = (Parser) this.lookup(Roles.PARSER);
  -        SAXConfigurationBuilder b = new SAXConfigurationBuilder();
  -        p.setContentHandler(b);
  -        String path = this.configurationFile.getPath();
  +        ConfigurationBuilder b = new ConfigurationBuilder();
  +	String path = this.configurationFile.getPath();
           InputSource is = new InputSource(new FileReader(path));
  -        is.setSystemId(path);
  -        p.parse(is);
  -        this.configure(b.getConfiguration());
  +	is.setSystemId(path);
  +	b.setXMLReader(p.getXMLReader());
  +        this.configure(b.build(is));
           this.root = this.configurationFile.getParentFile().toURL();
       }
   
  @@ -161,17 +160,17 @@
        */
       public void configure(Configuration conf)
       throws ConfigurationException {
  -    
  +
           this.configuration = conf;
  -        
  +
           if (!"cocoon".equals(conf.getName())) {
               throw new ConfigurationException("Invalid configuration file\n" + conf.toString());
           }
           if (!CONF_VERSION.equals(conf.getAttribute("version"))) {
  -            throw new ConfigurationException("Invalid configuration schema version. Must be '" 
  +            throw new ConfigurationException("Invalid configuration schema version. Must be '"
                   + CONF_VERSION + "'."/*, conf*/);
           }
  -            
  +
           // Set components
           Iterator e = conf.getChildren("component");
           while (e.hasNext()) {
  @@ -209,7 +208,7 @@
       throws ComponentNotFoundException, ComponentNotAccessibleException {
           return this.componentManager.lookup(role);
       }
  -    
  +
       /**
        * Queries the class to estimate its ergodic period termination.
        */
  @@ -220,7 +219,7 @@
       /**
        * Process the given <code>Environment</code> to produce the output.
        */
  -    public boolean process(Environment environment) 
  +    public boolean process(Environment environment)
       throws Exception {
           String file = new URL(environment.resolveEntity(null, this.sitemapFileName).getSystemId()).getFile();
           return this.sitemapManager.invoke(environment, "", file, true);
  @@ -228,7 +227,7 @@
   
     /**
      * Sets required system properties .
  -   */    
  +   */
       protected void setSystemProperties()
       {
         java.util.Properties props = new java.util.Properties();
  @@ -236,7 +235,7 @@
         // This is needed by Xalan2, it is used by org.xml.sax.helpers.XMLReaderFactory
         // to locate the SAX2 driver.
         props.put("org.xml.sax.driver", "org.apache.xerces.parsers.SAXParser");
  -      
  +
         java.util.Properties systemProps = System.getProperties();
         Enumeration propEnum = props.propertyNames();
         while(propEnum.hasMoreElements())
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.9   +5 -1      xml-cocoon/src/org/apache/cocoon/components/parser/Attic/Parser.java
  
  Index: Parser.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/components/parser/Attic/Parser.java,v
  retrieving revision 1.1.2.8
  retrieving revision 1.1.2.9
  diff -u -r1.1.2.8 -r1.1.2.9
  --- Parser.java	2000/09/05 17:27:50	1.1.2.8
  +++ Parser.java	2000/11/01 15:52:36	1.1.2.9
  @@ -13,15 +13,19 @@
   import org.apache.cocoon.xml.dom.DOMFactory;
   import org.xml.sax.InputSource;
   import org.xml.sax.SAXException;
  +import org.xml.sax.XMLReader;
   
   /**
    *
    * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
    *         (Apache Software Foundation, Exoffice Technologies)
  - * @version CVS $Revision: 1.1.2.8 $ $Date: 2000/09/05 17:27:50 $
  + * @version CVS $Revision: 1.1.2.9 $ $Date: 2000/11/01 15:52:36 $
    */
   public interface Parser extends Component, XMLProducer, DOMFactory {
       
       public void parse(InputSource in) throws SAXException, IOException;
  +
  +    /** This is required to use this with configurations. */
  +    public XMLReader getXMLReader();
       
   }
  
  
  
  1.1.2.7   +21 -9     xml-cocoon/src/org/apache/cocoon/components/parser/Attic/XercesParser.java
  
  Index: XercesParser.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/components/parser/Attic/XercesParser.java,v
  retrieving revision 1.1.2.6
  retrieving revision 1.1.2.7
  diff -u -r1.1.2.6 -r1.1.2.7
  --- XercesParser.java	2000/09/05 17:27:50	1.1.2.6
  +++ XercesParser.java	2000/11/01 15:52:37	1.1.2.7
  @@ -17,27 +17,39 @@
   import org.xml.sax.InputSource;
   import org.xml.sax.SAXException;
   import org.xml.sax.SAXParseException;
  +import org.xml.sax.XMLReader;
   import org.w3c.dom.Document;
   
   /**
    *
    * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
    *         (Apache Software Foundation, Exoffice Technologies)
  - * @version CVS $Revision: 1.1.2.6 $ $Date: 2000/09/05 17:27:50 $
  + * @version CVS $Revision: 1.1.2.7 $ $Date: 2000/11/01 15:52:37 $
    */
   public class XercesParser extends AbstractXMLProducer
   implements Parser, ErrorHandler, DOMFactory {
  +
  +    final SAXParser parser;
  +
  +    public XercesParser ()
  +    throws SAXException {
  +        this.parser = new SAXParser();
  +
  +	this.parser.setFeature("http://xml.org/sax/features/validation",false);
  +	this.parser.setFeature("http://xml.org/sax/features/namespaces",true);
  +	this.parser.setProperty("http://xml.org/sax/properties/lexical-handler",
  +	              super.lexicalHandler);
  +    }
       
       public void parse(InputSource in)
       throws SAXException, IOException {
  -        SAXParser p=new SAXParser();
  -        p.setFeature("http://xml.org/sax/features/validation",false);
  -        p.setFeature("http://xml.org/sax/features/namespaces",true);
  -        p.setProperty("http://xml.org/sax/properties/lexical-handler",
  -                      super.lexicalHandler);
  -        p.setErrorHandler(this);
  -        p.setContentHandler(super.contentHandler);
  -        p.parse(in);
  +        this.parser.setErrorHandler(this);
  +        this.parser.setContentHandler(super.contentHandler);
  +        this.parser.parse(in);
  +    }
  +
  +    public XMLReader getXMLReader() {
  +        return this.parser;
       }
           
       /**