Author: vgritsenko
Date: Wed Oct 27 13:25:23 2004
New Revision: 55730

Modified:
   
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portlet/CocoonPortlet.java
   
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portlet/ManagedCocoonPortlet.java
   
cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/java/org/apache/cocoon/ant/CocoonTask.java
   
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/bean/CocoonWrapper.java
   
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/servlet/CocoonServlet.java
Log:
Make sure work directory present in context before initializing logger.


Modified: 
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portlet/CocoonPortlet.java
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portlet/CocoonPortlet.java
    (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portlet/CocoonPortlet.java
    Wed Oct 27 13:25:23 2004
@@ -331,8 +331,11 @@
             this.workDir = new File(workDir, "cocoon-files");
         }
         this.workDir.mkdirs();
+        this.appContext.put(Constants.CONTEXT_WORK_DIR, workDir);
 
+        // Init logger
         initLogger();
+
         String path = this.portletContextPath;
         if (getLogger().isDebugEnabled()) {
             getLogger().debug("getRealPath for /: " + path);
@@ -369,25 +372,19 @@
                 throw new PortletException("Unable to determine portlet 
context URL.", me);
             }
         }
-        if (getLogger().isDebugEnabled()) {
-            getLogger().debug("URL for Root: " + this.portletContextURL);
-        }
 
         this.forceLoadParameter = getInitParameter("load-class", null);
-
         this.forceSystemProperty = getInitParameter("force-property", null);
 
-        // add work directory
-        if (workDirParam != null) {
-            if (getLogger().isDebugEnabled()) {
+        // Output some debug info
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("Portlet Context URL: " + 
this.portletContextURL);
+            if (workDirParam != null) {
                 getLogger().debug("Using work-directory " + this.workDir);
-            }
-        } else {
-            if (getLogger().isDebugEnabled()) {
-                getLogger().debug("work-directory was not set - defaulting to 
" + this.workDir);
+            } else {
+                getLogger().debug("Using default work-directory " + 
this.workDir);
             }
         }
-        this.appContext.put(Constants.CONTEXT_WORK_DIR, workDir);
 
         final String uploadDirParam = 
conf.getInitParameter("upload-directory");
         if (uploadDirParam != null) {
@@ -410,7 +407,7 @@
         } else {
             this.uploadDir = new File(workDir, "upload-dir" + File.separator);
             if (getLogger().isDebugEnabled()) {
-                getLogger().debug("upload-directory was not set - defaulting 
to " + this.uploadDir);
+                getLogger().debug("Using default upload-directory " + 
this.uploadDir);
             }
         }
         this.uploadDir.mkdirs();
@@ -842,8 +839,8 @@
         if (this.portletContextPath == null) {
             File logSCDir = new File(this.workDir, "log");
             logSCDir.mkdirs();
-            if (logger.isWarnEnabled()) {
-                logger.warn("Setting servlet-context for LogKit to " + 
logSCDir);
+            if (getLogger().isWarnEnabled()) {
+                getLogger().warn("Setting context-root for LogKit to " + 
logSCDir);
             }
             subcontext.put("context-root", logSCDir.toString());
         } else {

Modified: 
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portlet/ManagedCocoonPortlet.java
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portlet/ManagedCocoonPortlet.java
     (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portlet/ManagedCocoonPortlet.java
     Wed Oct 27 13:25:23 2004
@@ -200,8 +200,6 @@
         this.envPortletContext = new PortletContext(this.portletContext);
         this.portletContextPath = this.portletContext.getRealPath("/");
 
-        initLogger();
-
         // first init the work-directory for the logger.
         // this is required if we are running inside a war file!
         final String workDirParam = getInitParameter("work-directory");
@@ -230,6 +228,9 @@
         }
         this.workDir.mkdirs();
 
+        // Init logger
+        initLogger();
+
         String path = this.portletContextPath;
         if (getLogger().isDebugEnabled()) {
             getLogger().debug("getRealPath for /: " + path);
@@ -903,12 +904,13 @@
         logKitLoggerManager.enableLogging(logger);
 
         final DefaultContext subcontext = new DefaultContext();
+        subcontext.put(Constants.CONTEXT_WORK_DIR, workDir);
         subcontext.put("portlet-context", this.portletContext);
         if (this.portletContextPath == null) {
             File logSCDir = new File(this.workDir, "log");
             logSCDir.mkdirs();
             if (getLogger().isWarnEnabled()) {
-                getLogger().warn("Setting servlet-context for LogKit to " + 
logSCDir);
+                getLogger().warn("Setting context-root for LogKit to " + 
logSCDir);
             }
             subcontext.put("context-root", logSCDir.toString());
         } else {

Modified: 
cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/java/org/apache/cocoon/ant/CocoonTask.java
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/java/org/apache/cocoon/ant/CocoonTask.java
       (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/java/org/apache/cocoon/ant/CocoonTask.java
       Wed Oct 27 13:25:23 2004
@@ -1,12 +1,12 @@
 /*
  * Copyright 1999-2004 The Apache Software Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -620,8 +620,6 @@
                         this.logKitLoggerManager = new 
LogKitLoggerManager(Hierarchy.getDefaultHierarchy());
 
                         final DefaultContext subcontext = new 
DefaultContext(this.ctx);
-                        File contextDir = (File) this.ctx.get("context-root");
-                        subcontext.put("context-root", contextDir);
                         this.logKitLoggerManager.contextualize(subcontext);
                         this.logKitLoggerManager.configure(logKitConf);
                         logger = 
this.logKitLoggerManager.getLoggerForCategory(logKitLogCategory);

Modified: 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/bean/CocoonWrapper.java
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/bean/CocoonWrapper.java 
    (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/bean/CocoonWrapper.java 
    Wed Oct 27 13:25:23 2004
@@ -1,12 +1,12 @@
 /*
  * Copyright 1999-2004 The Apache Software Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -56,7 +56,7 @@
 import org.apache.log.Priority;
 
 /**
- * The Cocoon Wrapper simplifies usage of the Cocoon object. Allows to create, 
+ * The Cocoon Wrapper simplifies usage of the Cocoon object. Allows to create,
  * configure Cocoon instance and process single requests.
  *
  * @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
@@ -80,7 +80,7 @@
     private String userAgent = DEFAULT_USER_AGENT;
     private String accept = DEFAULT_ACCEPT;
     private List classList = new ArrayList();
- 
+
     // Objects used alongside User Supplied Parameters
     private File context;
     private File work;
@@ -110,12 +110,13 @@
 
         try {
             DefaultContext appContext = new DefaultContext();
-            appContext.put(
-                Constants.CONTEXT_CLASS_LOADER,
-                CocoonWrapper.class.getClassLoader());
+            appContext.put(Constants.CONTEXT_CLASS_LOADER,
+                           CocoonWrapper.class.getClassLoader());
             cliContext = new CommandLineContext(contextDir);
             cliContext.enableLogging(log);
             appContext.put(Constants.CONTEXT_ENVIRONMENT_CONTEXT, cliContext);
+            appContext.put(Constants.CONTEXT_WORK_DIR, work);
+
             LogKitLoggerManager logKitLoggerManager =
                     new LogKitLoggerManager(Hierarchy.getDefaultHierarchy());
             logKitLoggerManager.enableLogging(log);
@@ -126,7 +127,7 @@
                     new DefaultConfigurationBuilder();
                 final Configuration logKitConf = builder.build(fis);
                 final DefaultContext subcontext = new 
DefaultContext(appContext);
-                subcontext.put("context-root", contextDir);
+                subcontext.put("context-root", this.contextDir);
                 logKitLoggerManager.contextualize(subcontext);
                 logKitLoggerManager.configure(logKitConf);
                 if (logger != null) {
@@ -137,13 +138,12 @@
             }
 
             appContext.put(Constants.CONTEXT_CLASSPATH, 
getClassPath(contextDir));
-            appContext.put(Constants.CONTEXT_WORK_DIR, work);
             appContext.put(Constants.CONTEXT_UPLOAD_DIR, contextDir + 
"upload-dir");
             File cacheDir = getDir(workDir + File.separator + "cache-dir", 
"cache");
             appContext.put(Constants.CONTEXT_CACHE_DIR, cacheDir);
             appContext.put(Constants.CONTEXT_CONFIG_URL, conf.toURL());
             appContext.put(Constants.CONTEXT_DEFAULT_ENCODING, "ISO-8859-1");
-            
+
             loadClasses(classList);
 
             cocoon = new Cocoon();
@@ -158,7 +158,7 @@
         }
         initialized = true;
     }
-    
+
     protected ExcaliburComponentManager getComponentManager() {
         return cocoon.getComponentManager();
     }
@@ -313,7 +313,7 @@
     public String getLoggerName() {
         return logger;
     }
-    
+
     /**
      * Set context directory
      * @param contextDir context directory
@@ -467,7 +467,7 @@
      */
     protected String getType(String deparameterizedURI, Map parameters)
         throws Exception {
-        
+
         parameters.put("user-agent", userAgent);
         parameters.put("accept", accept);
 

Modified: 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/servlet/CocoonServlet.java
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/servlet/CocoonServlet.java
  (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/servlet/CocoonServlet.java
  Wed Oct 27 13:25:23 2004
@@ -304,8 +304,11 @@
             this.workDir = new File(workDir, "cocoon-files");
         }
         this.workDir.mkdirs();
+        this.appContext.put(Constants.CONTEXT_WORK_DIR, workDir);
 
+        // Init logger
         initLogger();
+
         String path = this.servletContextPath;
         if (getLogger().isDebugEnabled()) {
             getLogger().debug("getRealPath for /: " + path);
@@ -342,25 +345,19 @@
                 throw new ServletException("Unable to determine servlet 
context URL.", me);
             }
         }
-        if (getLogger().isDebugEnabled()) {
-            getLogger().debug("URL for Root: " + this.servletContextURL);
-        }
 
         this.forceLoadParameter = getInitParameter("load-class", null);
-
         this.forceSystemProperty = getInitParameter("force-property", null);
 
-        // add work directory
-        if (workDirParam != null) {
-            if (getLogger().isDebugEnabled()) {
+        // Output some debug info
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("Servlet Context URL: " + 
this.servletContextURL);
+            if (workDirParam != null) {
                 getLogger().debug("Using work-directory " + this.workDir);
-            }
-        } else {
-            if (getLogger().isDebugEnabled()) {
-                getLogger().debug("work-directory was not set - defaulting to 
" + this.workDir);
+            } else {
+                getLogger().debug("Using default work-directory " + 
this.workDir);
             }
         }
-        this.appContext.put(Constants.CONTEXT_WORK_DIR, workDir);
 
         final String uploadDirParam = 
conf.getInitParameter("upload-directory");
         if (uploadDirParam != null) {
@@ -383,7 +380,7 @@
         } else {
             this.uploadDir = new File(workDir, "upload-dir" + File.separator);
             if (getLogger().isDebugEnabled()) {
-                getLogger().debug("upload-directory was not set - defaulting 
to " + this.uploadDir);
+                getLogger().debug("Using default upload-directory " + 
this.uploadDir);
             }
         }
         this.uploadDir.mkdirs();
@@ -794,11 +791,12 @@
 
         final DefaultContext subcontext = new DefaultContext(this.appContext);
         subcontext.put("servlet-context", this.servletContext);
+        subcontext.put("context-work", this.workDir);
         if (this.servletContextPath == null) {
             File logSCDir = new File(this.workDir, "log");
             logSCDir.mkdirs();
             if (logger.isWarnEnabled()) {
-                logger.warn("Setting servlet-context for LogKit to " + 
logSCDir);
+                logger.warn("Setting context-root for LogKit to " + logSCDir);
             }
             subcontext.put("context-root", logSCDir.toString());
         } else {

Reply via email to