cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stef...@locus.apache.org
Subject cvs commit: xml-cocoon/src/org/apache/cocoon/processor/xsp XSPProcessor.java
Date Fri, 17 Mar 2000 00:02:02 GMT
stefano     00/03/16 16:02:02

  Modified:    src/org/apache/cocoon/framework Factory.java Manager.java
               src/org/apache/cocoon/processor/xsp XSPProcessor.java
  Log:
  added createResource method in factories to allow better classloader abstraction... still
doesn't work if the resources are not in the classpath, damn It!!! If you can help me, please
do so!
  
  Revision  Changes    Path
  1.5       +22 -16    xml-cocoon/src/org/apache/cocoon/framework/Factory.java
  
  Index: Factory.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/framework/Factory.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Factory.java	2000/02/13 18:29:22	1.4
  +++ Factory.java	2000/03/17 00:02:01	1.5
  @@ -1,36 +1,36 @@
  -/*-- $Id: Factory.java,v 1.4 2000/02/13 18:29:22 stefano Exp $ -- 
  +/*-- $Id: Factory.java,v 1.5 2000/03/17 00:02:01 stefano Exp $ --
   
    ============================================================================
                      The Apache Software License, Version 1.1
    ============================================================================
  - 
  +
    Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  - 
  +
    Redistribution and use in source and binary forms, with or without modifica-
    tion, are permitted provided that the following conditions are met:
  - 
  +
    1. Redistributions of  source code must  retain the above copyright  notice,
       this list of conditions and the following disclaimer.
  - 
  +
    2. Redistributions in binary form must reproduce the above copyright notice,
       this list of conditions and the following disclaimer in the documentation
       and/or other materials provided with the distribution.
  - 
  +
    3. The end-user documentation included with the redistribution, if any, must
       include  the following  acknowledgment:  "This product includes  software
       developed  by the  Apache Software Foundation  (http://www.apache.org/)."
       Alternately, this  acknowledgment may  appear in the software itself,  if
       and wherever such third-party acknowledgments normally appear.
  - 
  +
    4. The names "Cocoon" and  "Apache Software Foundation"  must not be used to
       endorse  or promote  products derived  from this  software without  prior
       written permission. For written permission, please contact
       apache@apache.org.
  - 
  +
    5. Products  derived from this software may not  be called "Apache", nor may
       "Apache" appear  in their name,  without prior written permission  of the
       Apache Software Foundation.
  - 
  +
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
    FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  @@ -41,25 +41,26 @@
    ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
    (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  - 
  +
    This software  consists of voluntary contributions made  by many individuals
    on  behalf of the Apache Software  Foundation and was  originally created by
  - Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache 
  + Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
    Software Foundation, please see <http://www.apache.org/>.
  - 
  +
    */
   package org.apache.cocoon.framework;
   
   import java.util.*;
  +import java.io.*;
   
   /**
  - * A factory is responsible to create and properly initialize 
  + * A factory is responsible to create and properly initialize
    * dynamically loaded classes. The use of dynamic linking allows
    * simpler management and stronger decoupling between the core
    * classes and the actors.
    *
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  - * @version $Revision: 1.4 $ $Date: 2000/02/13 18:29:22 $
  + * @version $Revision: 1.5 $ $Date: 2000/03/17 00:02:01 $
    */
   
   public interface Factory extends Actor {
  @@ -70,7 +71,7 @@
       Object create(String name);
   
       /**
  -     * Create the instance of a class and, if configurable, use 
  +     * Create the instance of a class and, if configurable, use
        * the given configurations to configure it.
        */
       Object create(String name, Configurations conf);
  @@ -80,10 +81,15 @@
        * of strings indicating their respective names.
        */
       Vector create(Vector names);
  -    
  +
       /**
        * Create a vector of instances with given configurations.
        */
       Vector create(Vector names, Configurations conf);
  +
  +    /**
  +     * Creates a resource.
  +     */
  +    InputStream createResource(String resource);
   
   }
  
  
  
  1.7       +42 -21    xml-cocoon/src/org/apache/cocoon/framework/Manager.java
  
  Index: Manager.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/framework/Manager.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Manager.java	2000/02/13 18:29:22	1.6
  +++ Manager.java	2000/03/17 00:02:01	1.7
  @@ -1,36 +1,36 @@
  -/*-- $Id: Manager.java,v 1.6 2000/02/13 18:29:22 stefano Exp $ -- 
  +/*-- $Id: Manager.java,v 1.7 2000/03/17 00:02:01 stefano Exp $ --
   
    ============================================================================
                      The Apache Software License, Version 1.1
    ============================================================================
  - 
  +
    Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  - 
  +
    Redistribution and use in source and binary forms, with or without modifica-
    tion, are permitted provided that the following conditions are met:
  - 
  +
    1. Redistributions of  source code must  retain the above copyright  notice,
       this list of conditions and the following disclaimer.
  - 
  +
    2. Redistributions in binary form must reproduce the above copyright notice,
       this list of conditions and the following disclaimer in the documentation
       and/or other materials provided with the distribution.
  - 
  +
    3. The end-user documentation included with the redistribution, if any, must
       include  the following  acknowledgment:  "This product includes  software
       developed  by the  Apache Software Foundation  (http://www.apache.org/)."
       Alternately, this  acknowledgment may  appear in the software itself,  if
       and wherever such third-party acknowledgments normally appear.
  - 
  +
    4. The names "Cocoon" and  "Apache Software Foundation"  must not be used to
       endorse  or promote  products derived  from this  software without  prior
       written permission. For written permission, please contact
       apache@apache.org.
  - 
  +
    5. Products  derived from this software may not  be called "Apache", nor may
       "Apache" appear  in their name,  without prior written permission  of the
       Apache Software Foundation.
  - 
  +
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
    FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  @@ -41,30 +41,35 @@
    ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
    (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  - 
  +
    This software  consists of voluntary contributions made  by many individuals
    on  behalf of the Apache Software  Foundation and was  originally created by
  - Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache 
  + Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
    Software Foundation, please see <http://www.apache.org/>.
  - 
  +
    */
   package org.apache.cocoon.framework;
   
   import java.util.*;
  +import java.io.*;
   
   /**
  - * This class is used to create and control software actors.
  + * This class is used to create and control software actors and resources.
    *
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  - * @version $Revision: 1.6 $ $Date: 2000/02/13 18:29:22 $
  + * @version $Revision: 1.7 $ $Date: 2000/03/17 00:02:01 $
    */
   
   public class Manager extends Hashtable implements Actor, Factory, Director {
   
  +    private ClassLoader classloader;
  +
       /**
        * Initialize the actor by indicating their director.
        */
  -    public void init(Director director) {}
  +    public void init(Director director) {
  +        this.classloader = this.getClass().getClassLoader();
  +    }
   
       /**
        * Create the instance of a class given its name.
  @@ -74,7 +79,7 @@
       }
   
       /**
  -     * Create the instance of a class and, if configurable, use 
  +     * Create the instance of a class and, if configurable, use
        * the given configurations to configure it.
        */
       public Object create(String name, Configurations conf) throws RuntimeException {
  @@ -84,11 +89,11 @@
               if (object instanceof Actor) {
                   ((Actor) object).init((Director) this);
               }
  -            
  +
               if ((object instanceof Configurable) && (conf != null)) {
                   ((Configurable) object).init(conf);
               }
  -            
  +
               return object;
           } catch (ClassNotFoundException e) {
               throw new RuntimeException("Error creating " + name + ": class is not found");
  @@ -111,7 +116,7 @@
       public Vector create(Vector names) {
           return create(names, null);
       }
  -    
  +
       /**
        * Create a vector of instances with given configurations.
        */
  @@ -123,7 +128,7 @@
            }
            return v;
        }
  -     
  +
       /**
        * Get the actor currently playing the given role.
        */
  @@ -136,8 +141,24 @@
        */
       public void setRole(String role, Object actor) {
           this.put(role, actor);
  +    }
  +
  +    /**
  +     * Creates the requested resource.
  +     */
  +    public InputStream createResource(String resource) {
  +        InputStream is = null;
  +
  +        if (this.classloader != null) {
  +            is = this.classloader.getResourceAsStream(resource);
  +        } else {
  +            is = ClassLoader.getSystemResourceAsStream(resource);
  +        }
  +
  +        if (is == null) throw new RuntimeException("resource " + resource + " was not found.");
  +        else return is;
       }
  -    
  +
       /**
        * Get the roles currently set.
        */
  
  
  
  1.13      +13 -8     xml-cocoon/src/org/apache/cocoon/processor/xsp/XSPProcessor.java
  
  Index: XSPProcessor.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/processor/xsp/XSPProcessor.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- XSPProcessor.java	2000/03/13 21:26:27	1.12
  +++ XSPProcessor.java	2000/03/17 00:02:01	1.13
  @@ -1,4 +1,4 @@
  -/*-- $Id: XSPProcessor.java,v 1.12 2000/03/13 21:26:27 ricardo Exp $ --
  +/*-- $Id: XSPProcessor.java,v 1.13 2000/03/17 00:02:01 stefano Exp $ --
   
    ============================================================================
                      The Apache Software License, Version 1.1
  @@ -73,14 +73,16 @@
    * This class implements the XSP engine.
    *
    * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
  - * @version $Revision: 1.12 $ $Date: 2000/03/13 21:26:27 $
  + * @version $Revision: 1.13 $ $Date: 2000/03/17 00:02:01 $
    */
   public class XSPProcessor extends AbstractActor
     implements Processor, Configurable, Status
   {
     public static final String DEFAULT_LANGUAGE = "java";
     public static final String LOGICSHEET_PI = "xml-logicsheet";
  +  public static final String XSP_ROOT = "org/apache/cocoon/processor/xsp/";
   
  +  protected Factory factory;
     protected Parser parser;
     protected Transformer transformer;
   
  @@ -101,6 +103,9 @@
     public void init(Director director) {
       super.init(director);
   
  +    // Initialize Cocoon factory
  +    this.factory = (Factory) director.getActor("factory");
  +
       // Initialize Cocoon cache
       this.store = (Store) director.getActor("store");
   
  @@ -124,7 +129,7 @@
         Document document = this.parser.parse(
           new InputSource(
             new InputStreamReader(
  -            this.getClass().getResourceAsStream("xsp.xml")
  +            this.factory.createResource(XSP_ROOT + "xsp.xml")
             )
           ), false
         );
  @@ -167,9 +172,9 @@
   
           String logicsheetName = languageElement.getAttribute("template");
           Document logicsheetStylesheet = this.parser.parse(
  -          new InputSource(  
  +          new InputSource(
               new InputStreamReader(
  -              this.getClass().getResourceAsStream(logicsheetName)
  +              this.factory.createResource(XSP_ROOT + logicsheetName)
               )
             ), false
           );
  @@ -190,7 +195,7 @@
             // Add to namespace logicsheet list
         this.byNamespace.put("xsp", xspLogicsheets);
       } catch (Exception e) {
  -      throw new RuntimeException("Error during initialization: " + e);
  +      throw new RuntimeException("Error during initialization: " + e.getMessage());
       }
     }
   
  @@ -493,7 +498,7 @@
   
       logicsheet.setStylesheet(getDocument(resource));
       logicsheet.setPreprocessor(preprocessor);
  - 
  +
       // Hold logicsheet in store
       this.store.hold(name, logicsheet);
       this.monitor.invalidate(name);
  @@ -619,7 +624,7 @@
           int logicsheetCount = this.logicsheets.size();
           for (int i = 0; i < logicsheetCount; i++) {
             Object resource = this.logicsheets.elementAt(i);
  -  
  +
             if (
               monitor.hasChanged(resource.toString()) ||
               this.target.lastModified() < monitor.timestamp(resource)
  
  
  

Mime
View raw message