cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r125937 - /cocoon/trunk/src/core/java/org/apache/cocoon/configuration/Settings.java /cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java /cocoon/trunk/src/java/org/apache/cocoon/servlet/SettingsHelper.java
Date Fri, 21 Jan 2005 15:58:06 GMT
Author: cziegeler
Date: Fri Jan 21 07:58:04 2005
New Revision: 125937

URL: http://svn.apache.org/viewcvs?view=rev&rev=125937
Log:
Fill settings
Modified:
   cocoon/trunk/src/core/java/org/apache/cocoon/configuration/Settings.java
   cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java
   cocoon/trunk/src/java/org/apache/cocoon/servlet/SettingsHelper.java

Modified: cocoon/trunk/src/core/java/org/apache/cocoon/configuration/Settings.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/core/java/org/apache/cocoon/configuration/Settings.java?view=diff&rev=125937&p1=cocoon/trunk/src/core/java/org/apache/cocoon/configuration/Settings.java&r1=125936&p2=cocoon/trunk/src/core/java/org/apache/cocoon/configuration/Settings.java&r2=125937
==============================================================================
--- cocoon/trunk/src/core/java/org/apache/cocoon/configuration/Settings.java	(original)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/configuration/Settings.java	Fri Jan 21 07:58:04
2005
@@ -40,8 +40,8 @@
     protected boolean enableUploads;
     protected String uploadDirectory;    
     protected boolean autosaveUploads;
-    protected boolean overwriteUploads;
-    protected long maxUploadSize;
+    protected String overwriteUploads;
+    protected int maxUploadSize;
     protected String cacheDirectory;
     protected String workDirectory;
     protected String[] extraClasspaths;
@@ -273,25 +273,25 @@
     /**
      * @return Returns the maxUploadSize.
      */
-    public long getMaxUploadSize() {
+    public int getMaxUploadSize() {
         return this.maxUploadSize;
     }
     /**
      * @param maxUploadSize The maxUploadSize to set.
      */
-    public void setMaxUploadSize(long maxUploadSize) {
+    public void setMaxUploadSize(int maxUploadSize) {
         this.maxUploadSize = maxUploadSize;
     }
     /**
      * @return Returns the overwriteUploads.
      */
-    public boolean isOverwriteUploads() {
+    public String getOverwriteUploads() {
         return this.overwriteUploads;
     }
     /**
      * @param overwriteUploads The overwriteUploads to set.
      */
-    public void setOverwriteUploads(boolean overwriteUploads) {
+    public void setOverwriteUploads(String overwriteUploads) {
         this.overwriteUploads = overwriteUploads;
     }
     /**
@@ -388,5 +388,38 @@
      */
     public void setOverrideLogLevel(String overrideLogLevel) {
         this.overrideLogLevel = overrideLogLevel;
+    }
+    
+    /* (non-Javadoc)
+     * @see java.lang.Object#toString()
+     */
+    public String toString() {
+        return "Settings:\n"+
+               "- Configuration: " + this.configuration + "\n" + 
+               "- Classloader: " + ( this.classloaderClassName == null ? "-" : this.classloaderClassName
) + "\n" + 
+               "- InitClassloader: " + this.initClassloader + "\n" + 
+               "- ForceProperties: " + ( this.forceProperties == null ? "-" : this.forceProperties.toString()
) + "\n" +
+               "- Logging-Configuration: " + this.loggingConfiguration + "\n" +
+               "- Cocoon-Logger: " + this.cocoonLogger + "\n" + 
+               "- Access-Logger: " + this.accessLogger + "\n" +
+               "- Logger-Classname: " + this.loggerClassName + "\n" + 
+               "- Bootstrap-Loglevel: " + this.bootstrapLogLevel + "\n" +
+               "- Allow-Reload: " + this.allowReload + "\n" +
+               "- Enable-Uploads: " + this.enableUploads + "\n" +
+               "- Upload-Directory: " + this.uploadDirectory + "\n" +
+               "- Autosave-Uploads: " + this.autosaveUploads + "\n" +
+               "- Overwrite-Uploads: " + this.overwriteUploads + "\n" +
+               "- Max.Uploadsize: " + this.maxUploadSize + "\n" +
+               "- Cache-Directory: " + this.cacheDirectory + "\n" + 
+               "- Work-Directory: " + this.workDirectory + "\n" +
+               "- Load Classes: " + this.loadClasses + "\n" + 
+               "- Extra Classpath: " + this.extraClasspaths + "\n" +
+               "- Parent ServiceManager: " + this.parentServiceManagerClassName + "\n" +
+               "- Show Time: " + this.showTime + "\n" + 
+               "- Manage Exceptions: " + this.manageExceptions + "\n" +
+               "- Form-Encoding: " + this.formEncoding + "\n" + 
+               "- Log4J Configuration: " + this.log4jConfiguration + "\n" +
+               "- Override Loglevel: " + this.overrideLogLevel + "\n";
+
     }
 }

Modified: cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java?view=diff&rev=125937&p1=cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java&r1=125936&p2=cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java&r2=125937
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java	(original)
+++ cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java	Fri Jan 21 07:58:04
2005
@@ -206,6 +206,9 @@
      */
     protected RequestFactory requestFactory;
 
+    /** Settings */
+    protected Settings settings;
+    
     /**
      * Initialize this <code>CocoonServlet</code> instance.  You will
      * notice that I have broken the init into sub methods to make it
@@ -236,6 +239,7 @@
             try {
                 Thread.currentThread().setContextClassLoader(this.classLoader);
             } catch (Exception e) {
+                // ignore this
             }
         }
 
@@ -280,9 +284,9 @@
         this.appContext.put(Constants.CONTEXT_WORK_DIR, workDir);
 
         String path = this.servletContextPath;
-/*        if (getLogger().isDebugEnabled()) {
-            getLogger().debug("getRealPath for /: " + path);
-        }*/
+        // these two variables are just for debugging. We can't log at this point
+        // as the logger isn't initialized yet.
+        String debugPathOne = null, debugPathTwo = null;
         if (path == null) {
             // Try to figure out the path of the root from that of WEB-INF
             try {
@@ -290,13 +294,9 @@
             } catch (MalformedURLException me) {
                 throw new ServletException("Unable to get resource 'WEB-INF'.", me);
             }
-           /* if (getLogger().isDebugEnabled()) {
-                getLogger().debug("getResource for /WEB-INF: " + path);
-            }*/
+            debugPathOne = path;
             path = path.substring(0, path.length() - "WEB-INF".length());
-            /*if (getLogger().isDebugEnabled()) {
-                getLogger().debug("Path for Root: " + path);
-            }*/
+            debugPathTwo = path;
         }
         try {
             if (path.indexOf(':') > 1) {
@@ -317,8 +317,17 @@
         this.appContext.put(ContextHelper.CONTEXT_ROOT_URL, this.servletContextURL);
 
         // Init logger
+        this.settings = SettingsHelper.getSettings(this.getServletConfig());
+        
         initLogger();
-
+        if (this.getLogger().isDebugEnabled()) {
+            this.getLogger().debug(this.settings.toString());
+            this.getLogger().debug("getRealPath for /: " + this.servletContextPath);
+            if ( this.servletContextPath == null ) {                
+                this.getLogger().debug("getResource for /WEB-INF: " + debugPathOne);
+                this.getLogger().debug("Path for Root: " + debugPathTwo);
+            }
+        }
         this.forceLoadParameter = getInitParameter("load-class", null);
         this.forceSystemProperty = getInitParameter("force-property", null);
 
@@ -718,9 +727,6 @@
     }
 
     protected void initLogger() {
-        // get settings - TODO we will move this to a better place soon
-        final Settings settings = SettingsHelper.getSettings(this.getServletConfig());
-
         final CocoonLogFormatter formatter = new CocoonLogFormatter();
         formatter.setFormat("%7.7{priority} %{time}   [%8.8{category}] " +
                             "(%{uri}) %{thread}/%{class:short}: %{message}\\n%{throwable}");
@@ -737,7 +743,7 @@
             subcontext.put("context-root", this.servletContextPath);
         }
 
-        LoggingHelper lh = new LoggingHelper(settings, servTarget, subcontext);
+        LoggingHelper lh = new LoggingHelper(this.settings, servTarget, subcontext);
         this.loggerManager = lh.getLoggerManager();
         this.log = lh.getLogger();
     }

Modified: cocoon/trunk/src/java/org/apache/cocoon/servlet/SettingsHelper.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/servlet/SettingsHelper.java?view=diff&rev=125937&p1=cocoon/trunk/src/java/org/apache/cocoon/servlet/SettingsHelper.java&r1=125936&p2=cocoon/trunk/src/java/org/apache/cocoon/servlet/SettingsHelper.java&r2=125937
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/servlet/SettingsHelper.java	(original)
+++ cocoon/trunk/src/java/org/apache/cocoon/servlet/SettingsHelper.java	Fri Jan 21 07:58:04
2005
@@ -15,9 +15,12 @@
  */
 package org.apache.cocoon.servlet;
 
+import java.util.StringTokenizer;
+
 import javax.servlet.ServletConfig;
 
 import org.apache.cocoon.configuration.Settings;
+import org.apache.commons.lang.BooleanUtils;
 
 /**
  * This helper class initializes the {@link Settings} object from the servlet
@@ -49,6 +52,66 @@
             s.setLog4jConfiguration("context:/" + value);
         }
         
+        s.setClassloaderClassName(config.getInitParameter("classloader-class"));
+        s.setInitClassloader(getInitParameterAsBoolean(config, "init-classloader", false));
+        s.setForceProperties(getInitParameterAsArray(config, "force-property"));
+        s.setConfiguration(config.getInitParameter("configurations"));
+        s.setInitClassloader(getInitParameterAsBoolean(config, "allow-reload", false));
+        s.setLoadClasses(getInitParameterAsArray(config, "load-class"));
+        s.setEnableUploads(getInitParameterAsBoolean(config, "init-classloader", false));
+        s.setUploadDirectory(config.getInitParameter("upload-directory"));
+        s.setAutosaveUploads(getInitParameterAsBoolean(config, "autosave-uploads", true));
+        s.setOverwriteUploads(config.getInitParameter("overwrite-uploads"));
+        s.setMaxUploadSize(getInitParameterAsInteger(config, "upload-max-size", 10000000));
+        s.setCacheDirectory(config.getInitParameter("cache-directory"));
+        s.setWorkDirectory(config.getInitParameter("work-directory"));
+        s.setParentServiceManagerClassName(config.getInitParameter("parent-service-manager"));
+        s.setShowTime(getInitParameterAsBoolean(config, "show-time", false));
+        s.setManageExceptions(getInitParameterAsBoolean(config, "manage-exceptions", true));
+        s.setFormEncoding(config.getInitParameter("form-encoding"));
+        
+        // TODO extra classpath
+        
         return s;
     }
+    
+    /** Convenience method to access boolean servlet parameters */
+    protected static boolean getInitParameterAsBoolean(ServletConfig config, String name,
boolean defaultValue) {
+        String value = config.getInitParameter(name);
+        if (value == null) {
+            return defaultValue;
+        }
+
+        return BooleanUtils.toBoolean(value);
+    }
+
+    protected static int getInitParameterAsInteger(ServletConfig config, String name, int
defaultValue) {
+        String value = config.getInitParameter(name);
+        if (value == null) {
+            return defaultValue;
+        }
+        return Integer.parseInt(value);
+    }
+    
+    protected static String[] getInitParameterAsArray(ServletConfig config, String name)
{
+        final String param = config.getInitParameter(name);
+        if ( param == null ) {
+            return null;
+        }
+        StringTokenizer tokenizer = new StringTokenizer(param, " \t\r\n\f;,", false);
+        String[] array = null;    
+        while (tokenizer.hasMoreTokens()) {
+            final String value = tokenizer.nextToken().trim();
+            if ( array == null ) {
+                array = new String[1];
+            } else {
+                String[] ca = new String[array.length+1];
+                System.arraycopy(array, 0, ca, 0, array.length);
+                array = ca;
+            }
+            array[array.length-1] = value;
+        }
+        return array;
+    }
+    
 }

Mime
View raw message