cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blorit...@apache.org
Subject cvs commit: xml-cocoon/src/org/apache/cocoon/servlet CocoonServlet.java
Date Wed, 14 Feb 2001 03:58:37 GMT
bloritsch    01/02/13 19:58:37

  Modified:    src/org/apache/cocoon Tag: xml-cocoon2 Cocoon.java
                        Constants.java Main.java
               src/org/apache/cocoon/servlet Tag: xml-cocoon2
                        CocoonServlet.java
  Log:
  Made Cocoon live in the Repository ClassLoader.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.4.2.49  +21 -43    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.48
  retrieving revision 1.4.2.49
  diff -u -r1.4.2.48 -r1.4.2.49
  --- Cocoon.java	2001/02/12 13:30:42	1.4.2.48
  +++ Cocoon.java	2001/02/14 03:58:36	1.4.2.49
  @@ -40,8 +40,7 @@
   import org.apache.cocoon.util.NetUtils;
   import org.apache.cocoon.DefaultComponentManager;
   
  -import org.apache.log.Logger;
  -import org.apache.avalon.Loggable;
  +import org.apache.avalon.AbstractLoggable;
   
   import org.xml.sax.SAXException;
   import org.xml.sax.InputSource;
  @@ -50,13 +49,11 @@
    * @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.48 $ $Date: 2001/02/12 13:30:42 $
  + * @version CVS $Revision: 1.4.2.49 $ $Date: 2001/02/14 03:58:36 $
    */
  -public class Cocoon
  -  implements Component, Configurable, ComponentManager, Modifiable, Processor, Constants,
Loggable, Contextualizable {
  +public class Cocoon extends AbstractLoggable
  +  implements Component, Configurable, ComponentManager, Modifiable, Processor, Constants,
Contextualizable {
   
  -    private Logger log;
  -
       /** The application context */
       private Context context;
   
  @@ -95,55 +92,36 @@
           setSystemProperties();
       }
   
  -    /**
  -     * Create a new <code>Cocoon</code> object, parsing configuration from
  -     * the specified file.
  -     */
  -    public Cocoon(final URL configurationFile, final String classpath, File workDir)
  -    throws SAXException,
  -           IOException,
  -       ConfigurationException,
  -           ComponentManagerException {
  -        this();
  -
  -        this.classpath = classpath;
  -        this.workDir = workDir;
  -        this.configurationFile = configurationFile;
  -    }
  -
  -    public void setLogger(Logger logger) {
  -        if (this.log == null) {
  -            this.log = logger;
  -            this.componentManager.setLogger(this.log);
  -        }
  -    }
  -
       public void contextualize(Context context) {
           if (this.context == null) {
               this.context = context;
               this.componentManager.contextualize(this.context);
  +
  +            this.classpath = (String) context.get(Constants.CONTEXT_CLASSPATH);
  +            this.workDir = (File) context.get(Constants.CONTEXT_WORK_DIR);
  +            this.configurationFile = (URL) context.get(Constants.CONTEXT_CONFIG_URL);
           }
       }
   
       public void init() throws Exception {
  -        log.debug("New Cocoon object.");
  +        getLogger().debug("New Cocoon object.");
   
           // Setup the default parser, for parsing configuration.
           // If one need to use a different parser, set the given system property
           String parser = System.getProperty(PARSER_PROPERTY, DEFAULT_PARSER);
  -        log.debug("Using parser: " + parser);
  +        getLogger().debug("Using parser: " + parser);
   
           try {
               this.componentManager.addComponent(Roles.PARSER, ClassUtils.loadClass(parser),null);
           } catch ( Exception e ) {
  -            log.error("Could not load parser, Cocoon object not created.", e);
  +            getLogger().error("Could not load parser, Cocoon object not created.", e);
               throw new ConfigurationException("Could not load parser " + parser, e);
           }
           this.componentManager.addComponentInstance(Roles.COCOON, this);
   
  -        log.debug("Classpath = " + classpath);
  +        getLogger().debug("Classpath = " + classpath);
   
  -        log.debug("Work directory = " + workDir.getCanonicalPath());
  +        getLogger().debug("Work directory = " + workDir.getCanonicalPath());
   
           Parser p = (Parser) this.lookup(Roles.PARSER);
           SAXConfigurationHandler b = new SAXConfigurationHandler();
  @@ -180,35 +158,35 @@
   
           this.configuration = conf;
   
  -        log.debug("Root configuration: " + conf.getName());
  +        getLogger().debug("Root configuration: " + conf.getName());
           if (!"cocoon".equals(conf.getName())) {
               throw new ConfigurationException("Invalid configuration file\n" + conf.toString());
           }
   
  -        log.debug("Configuration version: " + conf.getAttribute("version"));
  +        getLogger().debug("Configuration version: " + conf.getAttribute("version"));
           if (!CONF_VERSION.equals(conf.getAttribute("version"))) {
               throw new ConfigurationException("Invalid configuration schema version. Must
be '"
                   + CONF_VERSION + "'.");
           }
   
  -        log.debug("Setting up components...");
  +        getLogger().debug("Setting up components...");
           this.componentManager.configure(conf);
   
  -        log.debug("Setting up the sitemap.");
  +        getLogger().debug("Setting up the sitemap.");
           // Create the sitemap
           Configuration sconf = conf.getChild("sitemap");
   
           this.sitemapManager = new Manager(null);
  -        this.sitemapManager.setLogger(this.log);
  +        this.sitemapManager.setLogger(getLogger());
           this.sitemapManager.compose(this);
           this.sitemapManager.configure(conf);
           this.sitemapFileName = sconf.getAttribute("file");
           if (this.sitemapFileName == null) {
  -            log.error("No sitemap file name");
  +            getLogger().error("No sitemap file name");
               throw new ConfigurationException("No sitemap file name\n" + conf.toString());
           }
   
  -        log.debug("Sitemap location = " + this.sitemapFileName);
  +        getLogger().debug("Sitemap location = " + this.sitemapFileName);
       }
   
       /**
  @@ -228,7 +206,7 @@
           try {
               answer = date < this.configurationFile.openConnection().getLastModified();
           } catch (IOException ioe) {
  -            log.warn("Problem checking the date on the Configuration File.", ioe);
  +            getLogger().warn("Problem checking the date on the Configuration File.", ioe);
               answer = false;
           }
   
  
  
  
  1.1.2.16  +4 -1      xml-cocoon/src/org/apache/cocoon/Attic/Constants.java
  
  Index: Constants.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/Attic/Constants.java,v
  retrieving revision 1.1.2.15
  retrieving revision 1.1.2.16
  diff -u -r1.1.2.15 -r1.1.2.16
  --- Constants.java	2001/02/12 13:30:42	1.1.2.15
  +++ Constants.java	2001/02/14 03:58:37	1.1.2.16
  @@ -10,7 +10,7 @@
   
   /**
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  - * @version CVS $Revision: 1.1.2.15 $ $Date: 2001/02/12 13:30:42 $
  + * @version CVS $Revision: 1.1.2.16 $ $Date: 2001/02/14 03:58:37 $
    */
   
   public interface Constants {
  @@ -59,4 +59,7 @@
       String CONTEXT_SERVLET_CONTEXT = "servlet-context";
       String CONTEXT_ROOT_PATH       = "root-path";
       String CONTEXT_CLASS_LOADER    = "class-loader";
  +    String CONTEXT_WORK_DIR        = "work-directory";
  +    String CONTEXT_CLASSPATH       = "classpath";
  +    String CONTEXT_CONFIG_URL      = "config-url";
   }
  
  
  
  1.1.4.21  +4 -2      xml-cocoon/src/org/apache/cocoon/Attic/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/Attic/Main.java,v
  retrieving revision 1.1.4.20
  retrieving revision 1.1.4.21
  diff -u -r1.1.4.20 -r1.1.4.21
  --- Main.java	2001/02/12 13:30:42	1.1.4.20
  +++ Main.java	2001/02/14 03:58:37	1.1.4.21
  @@ -49,7 +49,7 @@
    * Command line entry point.
    *
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  - * @version CVS $Revision: 1.1.4.20 $ $Date: 2001/02/12 13:30:42 $
  + * @version CVS $Revision: 1.1.4.21 $ $Date: 2001/02/14 03:58:37 $
    */
   
   public class Main {
  @@ -196,7 +196,9 @@
               //appContext.put(Constants.CONTEXT_SERVLET_CONTEXT, contextDir);
               appContext.put(Constants.CONTEXT_ROOT_PATH, contextDir);
               appContext.put(Constants.CONTEXT_CLASS_LOADER, Main.class.getClassLoader());
  -            Cocoon c = new Cocoon(conf.toURL(), null, work);
  +            appContext.put(Constants.CONTEXT_CONFIG_URL, conf.toURL());
  +            appContext.put(Constants.CONTEXT_WORK_DIR, work);
  +            Cocoon c = new Cocoon();
               c.setLogger(log);
               c.contextualize(appContext);
               c.init();
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.4.53  +28 -29    xml-cocoon/src/org/apache/cocoon/servlet/Attic/CocoonServlet.java
  
  Index: CocoonServlet.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/servlet/Attic/CocoonServlet.java,v
  retrieving revision 1.1.4.52
  retrieving revision 1.1.4.53
  diff -u -r1.1.4.52 -r1.1.4.53
  --- CocoonServlet.java	2001/02/12 13:30:45	1.1.4.52
  +++ CocoonServlet.java	2001/02/14 03:58:37	1.1.4.53
  @@ -59,7 +59,7 @@
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
    * @author <a href="mailto:nicolaken@supereva.it">Nicola Ken Barozzi</a> Aisa
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision: 1.1.4.52 $ $Date: 2001/02/12 13:30:45 $
  + * @version CVS $Revision: 1.1.4.53 $ $Date: 2001/02/14 03:58:37 $
    */
   
   public class CocoonServlet extends HttpServlet {
  @@ -72,13 +72,8 @@
   
       private long creationTime = 0;
       private Cocoon cocoon;
  -    private URL configFile;
       private Exception exception;
  -    private ServletContext servletContext;
       private DefaultContext appContext = new DefaultContext();
  -    private String classpath;
  -    private File workDir;
  -    private RepositoryClassLoader classloader = new RepositoryClassLoader(new URL[] {},
this.getClass().getClassLoader());
   
       /**
        * Initialize this <code>CocoonServlet</code> instance.  You will
  @@ -96,24 +91,27 @@
       throws ServletException {
   
           super.init(conf);
  +        RepositoryClassLoader classloader = new RepositoryClassLoader(new URL[] {}, this.getClass().getClassLoader());
  +        ServletContext context = conf.getServletContext();
   
  -        this.servletContext = conf.getServletContext();
  -        this.appContext.put(Constants.CONTEXT_SERVLET_CONTEXT, this.servletContext);
  +        ClassUtils.setClassLoader(classloader);
  +        this.appContext.put(Constants.CONTEXT_CLASS_LOADER, classloader);
   
  -        this.initLogger(conf.getInitParameter("log-level"), this.servletContext);
  +        this.appContext.put(Constants.CONTEXT_SERVLET_CONTEXT, context);
   
  -        this.setClassPath(this.servletContext);
  +        this.initLogger(conf.getInitParameter("log-level"), context, classloader);
   
  -        this.forceLoad(conf.getInitParameter("load-class"));
  +        this.appContext.put(Constants.CONTEXT_CLASSPATH, this.getClassPath(context, classloader));
   
  -        this.workDir = (File) this.servletContext.getAttribute("javax.servlet.context.tempdir");
  +        this.forceLoad(conf.getInitParameter("load-class"));
   
  -        this.setConfigFile(conf.getInitParameter("configurations"), this.servletContext);
  +        this.appContext.put(Constants.CONTEXT_WORK_DIR,
  +                context.getAttribute("javax.servlet.context.tempdir"));
   
  -        this.appContext.put(Constants.CONTEXT_ROOT_PATH, this.servletContext.getRealPath("/"));
  +        this.appContext.put(Constants.CONTEXT_CONFIG_URL,
  +                this.getConfigFile(conf.getInitParameter("configurations"), context));
   
  -        ClassUtils.setClassLoader(this.classloader);
  -        this.appContext.put(Constants.CONTEXT_CLASS_LOADER, this.classloader);
  +        this.appContext.put(Constants.CONTEXT_ROOT_PATH, context.getRealPath("/"));
   
           this.createCocoon();
       }
  @@ -134,14 +132,14 @@
        *
        * @throws ServletException
        */
  -     private void setClassPath(final ServletContext context)
  +     private String getClassPath(final ServletContext context, RepositoryClassLoader classloader)
        throws ServletException {
           StringBuffer buildClassPath = new StringBuffer();
           String classDir = context.getRealPath("/WEB-INF/classes");
           File root = new File(context.getRealPath("/WEB-INF/lib"));
   
           try {
  -            this.classloader.addDirectory(new File(classDir));
  +            classloader.addDirectory(new File(classDir));
           } catch (Exception e) {
               log.debug("Could not add directory" + classDir, e);
           }
  @@ -156,7 +154,7 @@
                                 .append(IOUtils.getFullFilename(libraries[i]));
   
                   try {
  -                    this.classloader.addDirectory(libraries[i]);
  +                    classloader.addDirectory(libraries[i]);
                   } catch (Exception e) {
                       log.debug("Could not add file" + IOUtils.getFullFilename(libraries[i]));
                   }
  @@ -166,7 +164,7 @@
           buildClassPath.append(File.pathSeparatorChar)
                         .append(System.getProperty("java.class.path"));
   
  -        this.classpath = buildClassPath.toString();
  +        return buildClassPath.toString();
        }
   
       /**
  @@ -184,7 +182,7 @@
        *
        * @throws ServletException
        */
  -    private void initLogger(final String logLevel, final ServletContext context)
  +    private void initLogger(final String logLevel, final ServletContext context, final
RepositoryClassLoader classloader)
       throws ServletException {
           final Priority.Enum logPriority;
   
  @@ -204,7 +202,7 @@
                          new ServletLogTarget(context, Priority.ERROR)
                   });
   
  -            this.classloader.setLogger(this.log);
  +            classloader.setLogger(this.log);
           } catch (Exception e) {
               LogKit.log("Could not set up Cocoon Logger, will use screen instead", e);
           }
  @@ -220,13 +218,13 @@
        *
        * @throws ServletException
        */
  -    private void setConfigFile(final String configFileName, final ServletContext context)
  +    private URL getConfigFile(final String configFileName, final ServletContext context)
       throws ServletException {
           final String usedFileName;
  +
           if (configFileName == null) {
               log.warn("Servlet initialization argument 'configurations' not specified, attempting
to use '/cocoon.xconf'");
               usedFileName = "/cocoon.xconf";
  -            // throw new ServletException("Servlet initialization argument 'configurations'
not specified");
           } else {
               usedFileName = configFileName;
           }
  @@ -234,7 +232,7 @@
           log.debug("Using configuration file: " + usedFileName);
   
           try {
  -            this.configFile = this.servletContext.getResource(usedFileName);
  +            return context.getResource(usedFileName);
           } catch (Exception mue) {
               log.error("Servlet initialization argument 'configurations' not found at "
+ usedFileName, mue);
               throw new ServletException("Servlet initialization argument 'configurations'
not found at " + usedFileName);
  @@ -328,7 +326,7 @@
                   uri = uri.substring(1);
               }
   
  -            HttpEnvironment env = new HttpEnvironment(uri, req, res, this.servletContext);
  +            HttpEnvironment env = new HttpEnvironment(uri, req, res, (ServletContext) this.appContext.get(Constants.CONTEXT_SERVLET_CONTEXT));
               env.setLogger(this.log);
   
               if (!this.cocoon.process(env)) {
  @@ -401,10 +399,11 @@
        */
       private void createCocoon() {
           try {
  -            log.info("Reloading from: " + this.configFile.toExternalForm());
  -            Cocoon c = new Cocoon(this.configFile, this.classpath, this.workDir);
  -            c.setLogger(this.log);
  +            URL configFile = (URL) this.appContext.get(Constants.CONTEXT_CONFIG_URL);
  +            log.info("Reloading from: " + configFile.toExternalForm());
  +            Cocoon c = (Cocoon) ClassUtils.newInstance("org.apache.cocoon.Cocoon");
               c.contextualize(this.appContext);
  +            c.setLogger(this.log);
               c.init();
               this.creationTime = new Date().getTime();
               this.cocoon = c;
  
  
  

Mime
View raw message