cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r164180 - in /cocoon/blocks/supported/portal/trunk/java/org/apache/cocoon/portlet: CocoonPortlet.java SettingsHelper.java
Date Fri, 22 Apr 2005 07:02:36 GMT
Author: cziegeler
Date: Fri Apr 22 00:02:35 2005
New Revision: 164180

URL: http://svn.apache.org/viewcvs?rev=164180&view=rev
Log:
Add missing class

Added:
    cocoon/blocks/supported/portal/trunk/java/org/apache/cocoon/portlet/SettingsHelper.java
  (with props)
Modified:
    cocoon/blocks/supported/portal/trunk/java/org/apache/cocoon/portlet/CocoonPortlet.java

Modified: cocoon/blocks/supported/portal/trunk/java/org/apache/cocoon/portlet/CocoonPortlet.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/supported/portal/trunk/java/org/apache/cocoon/portlet/CocoonPortlet.java?rev=164180&r1=164179&r2=164180&view=diff
==============================================================================
--- cocoon/blocks/supported/portal/trunk/java/org/apache/cocoon/portlet/CocoonPortlet.java
(original)
+++ cocoon/blocks/supported/portal/trunk/java/org/apache/cocoon/portlet/CocoonPortlet.java
Fri Apr 22 00:02:35 2005
@@ -53,9 +53,9 @@
 import org.apache.cocoon.components.notification.DefaultNotifyingBuilder;
 import org.apache.cocoon.components.notification.Notifier;
 import org.apache.cocoon.components.notification.Notifying;
-import org.apache.cocoon.configuration.Settings;
 import org.apache.cocoon.core.BootstrapEnvironment;
 import org.apache.cocoon.core.CoreUtil;
+import org.apache.cocoon.core.Settings;
 import org.apache.cocoon.environment.Context;
 import org.apache.cocoon.environment.Environment;
 import org.apache.cocoon.environment.portlet.PortletContext;
@@ -64,7 +64,6 @@
 import org.apache.cocoon.portlet.multipart.RequestFactory;
 import org.apache.cocoon.util.IOUtils;
 import org.apache.cocoon.util.log.CocoonLogFormatter;
-import org.apache.commons.lang.BooleanUtils;
 import org.apache.commons.lang.SystemUtils;
 import org.apache.log.ContextMap;
 import org.apache.log.LogTarget;
@@ -836,35 +835,9 @@
             if (getLogger() != null && getLogger().isDebugEnabled()) {
                 getLogger().debug(name + " was not set - defaulting to '" + defaultValue
+ "'");
             }
-            return defaultValue;
-        } else {
-            return result;
-        }
-    }
-
-    /** Convenience method to access boolean portlet parameters */
-    private boolean getInitParameterAsBoolean(String name, boolean defaultValue) {
-        String value = getInitParameter(name);
-        if (value == null) {
-            if (getLogger() != null && getLogger().isDebugEnabled()) {
-                getLogger().debug(name + " was not set - defaulting to '" + defaultValue
+ "'");
-            }
-            return defaultValue;
-        }
-
-        return BooleanUtils.toBoolean(value);
-    }
-
-    private int getInitParameterAsInteger(String name, int defaultValue) {
-        String value = getInitParameter(name);
-        if (value == null) {
-            if (getLogger() != null && getLogger().isDebugEnabled()) {
-                getLogger().debug(name + " was not set - defaulting to '" + defaultValue
+ "'");
-            }
-            return defaultValue;
-        } else {
-            return Integer.parseInt(value);
+            result = defaultValue;
         }
+        return result;
     }
 
     protected Logger getLogger() {

Added: cocoon/blocks/supported/portal/trunk/java/org/apache/cocoon/portlet/SettingsHelper.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/supported/portal/trunk/java/org/apache/cocoon/portlet/SettingsHelper.java?rev=164180&view=auto
==============================================================================
--- cocoon/blocks/supported/portal/trunk/java/org/apache/cocoon/portlet/SettingsHelper.java
(added)
+++ cocoon/blocks/supported/portal/trunk/java/org/apache/cocoon/portlet/SettingsHelper.java
Fri Apr 22 00:02:35 2005
@@ -0,0 +1,226 @@
+/*
+ * Copyright 2005 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.portlet;
+
+import java.util.StringTokenizer;
+
+import javax.portlet.PortletConfig;
+
+import org.apache.cocoon.core.Settings;
+import org.apache.cocoon.util.StringUtils;
+import org.apache.commons.lang.BooleanUtils;
+import org.apache.commons.lang.SystemUtils;
+
+/**
+ * This helper class initializes the {@link Settings} object from the servlet
+ * configuration.
+ * 
+ * @version SVN $Id$
+ */
+public class SettingsHelper {
+
+    private SettingsHelper() {
+        //  no instantiation
+    }
+    
+    public static void fill(Settings s, PortletConfig config) {
+        String value;
+
+        s.setInitClassloader(getInitParameterAsBoolean(config, "init-classloader", s.isInitClassloader()));
+
+        handleForceProperty(getInitParameter(config, "force-property"), s);
+
+        value = getInitParameter(config, "configurations");
+        if ( value != null ) {
+            s.setConfiguration(value);
+        } else if ( s.getConfiguration() == null ) {
+            s.setConfiguration("/WEB-INF/cocoon.xconf");
+        }
+
+        value = getInitParameter(config, "logkit-config");
+        if ( value != null ) {
+            s.setLoggingConfiguration("context:/" + value);
+        }
+
+        value = getInitParameter(config, "servlet-logger");
+        if ( value != null ) {
+            s.setAccessLogger(value);
+        }
+
+        value = getInitParameter(config, "cocoon-logger");
+        if ( value != null ) {
+            s.setCocoonLogger(value);
+        }
+
+        value = getInitParameter(config, "log-level");
+        if ( value != null ) {
+            s.setBootstrapLogLevel(value);
+        }
+
+        value = getInitParameter(config, "logger-class");
+        if ( value != null ) {
+            s.setLoggerClassName(value);
+        }
+
+        value = getInitParameter(config, "log4j-config");
+        if ( value != null ) {
+            s.setLog4jConfiguration("context:/" + value);
+        }
+
+        s.setAllowReload(getInitParameterAsBoolean(config, "allow-reload", s.isAllowReload()));
+
+        handleLoadClass(getInitParameter(config, "load-class"), s);
+
+        s.setEnableUploads(getInitParameterAsBoolean(config, "enable-uploads", s.isEnableUploads()));
+
+        value = getInitParameter(config, "upload-directory");
+        if ( value != null ) {
+            s.setUploadDirectory(value);
+        }
+
+        s.setAutosaveUploads(getInitParameterAsBoolean(config, "autosave-uploads", s.isAutosaveUploads()));
+
+        value = getInitParameter(config, "overwrite-uploads");
+        if ( value != null ) {
+            s.setOverwriteUploads(config.getInitParameter(value));
+        }
+
+        s.setMaxUploadSize(getInitParameterAsInteger(config, "upload-max-size", s.getMaxUploadSize()));
+        
+        value = getInitParameter(config, "cache-directory");
+        if ( value != null ) {
+            s.setCacheDirectory(value);
+        }
+
+        value = getInitParameter(config, "work-directory");
+        if ( value != null ) {
+            s.setWorkDirectory(value);
+        }
+
+        handleExtraClassPath(config.getInitParameter("extra-classpath"), s);
+
+        value = getInitParameter(config, "parent-service-manager");
+        if ( value != null ) {
+            s.setParentServiceManagerClassName(value);
+        }
+
+        value = getInitParameter(config, "show-time");
+        if ( value != null && value.equalsIgnoreCase("hide") ) {
+            s.setShowTime(true);
+            s.setHideShowTime(true);
+        } else {
+            s.setShowTime(getInitParameterAsBoolean(config, "show-time", false));
+            s.setHideShowTime(false);
+        }
+
+        s.setManageExceptions(getInitParameterAsBoolean(config, "manage-exceptions", s.isManageExceptions()));
+
+        value = getInitParameter(config, "form-encoding");
+        if ( value != null ) {
+            s.setFormEncoding(value);
+        }
+    }
+    
+    /** Convenience method to access boolean servlet parameters */
+    protected static boolean getInitParameterAsBoolean(PortletConfig config, String name,
boolean defaultValue) {
+        String value = getInitParameter(config, name);
+        if (value == null) {
+            return defaultValue;
+        }
+
+        return BooleanUtils.toBoolean(value);
+    }
+
+    protected static int getInitParameterAsInteger(PortletConfig config, String name, int
defaultValue) {
+        String value = getInitParameter(config, name);
+        if (value == null) {
+            return defaultValue;
+        }
+        return Integer.parseInt(value);
+    }
+    
+    private static void handleLoadClass(String param, Settings s) {
+        if ( param == null ) {
+            return;
+        }
+        StringTokenizer tokenizer = new StringTokenizer(param, " \t\r\n\f;,", false);
+        while (tokenizer.hasMoreTokens()) {
+            final String value = tokenizer.nextToken().trim();
+            s.addToLoadClasses(value);
+        }
+    }
+
+    /**
+     * Handle the "force-property" parameter.
+     *
+     * If you need to force more than one property to load, then
+     * separate each entry with whitespace, a comma, or a semi-colon.
+     * Cocoon will strip any whitespace from the entry.
+     */
+    private static void handleForceProperty(String forceSystemProperty, Settings s) {
+        if (forceSystemProperty != null) {
+            StringTokenizer tokenizer = new StringTokenizer(forceSystemProperty, " \t\r\n\f;,",
false);
+
+            while (tokenizer.hasMoreTokens()) {
+                final String property = tokenizer.nextToken().trim();
+                if (property.indexOf('=') == -1) {
+                    continue;
+                }
+                try {
+                    String key = property.substring(0, property.indexOf('='));
+                    String value = property.substring(property.indexOf('=') + 1);
+                    if (value.indexOf("${") != -1) {
+                        value = StringUtils.replaceToken(value);
+                    }
+                    s.addToForceProperties(key, value);
+                } catch (Exception e) {
+                    // Do not throw an exception, because it is not a fatal error.
+                }
+            }
+        }
+    }
+
+    /**
+     * Retreives the "extra-classpath" attribute, that needs to be
+     * added to the class path.
+     */
+    private static void handleExtraClassPath(String extraClassPath, Settings settings) {
+        if (extraClassPath != null) {
+            StringTokenizer st = new StringTokenizer(extraClassPath, SystemUtils.PATH_SEPARATOR,
false);
+            while (st.hasMoreTokens()) {
+                String s = st.nextToken();
+                settings.addToExtraClasspaths(s);
+            }
+        }
+    }
+
+    /**
+     * Get an initialisation parameter. The value is trimmed, and null is returned if the
trimmed value
+     * is empty.
+     */
+    private static String getInitParameter(PortletConfig config, String name) {
+        String result = config.getInitParameter(name);
+        if (result != null) {
+            result = result.trim();
+            if (result.length() == 0) {
+                result = null;
+            }
+        }
+
+        return result;
+    }
+    
+}

Propchange: cocoon/blocks/supported/portal/trunk/java/org/apache/cocoon/portlet/SettingsHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/supported/portal/trunk/java/org/apache/cocoon/portlet/SettingsHelper.java
------------------------------------------------------------------------------
    svn:keywords = Id



Mime
View raw message