cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jheym...@apache.org
Subject svn commit: r330548 [9/132] - in /cocoon/whiteboard/maven2/cocoon-flat-layout: ./ cocoon-ajax-block/ cocoon-ajax-block/api/ cocoon-ajax-block/api/src/ cocoon-ajax-block/api/src/main/ cocoon-ajax-block/api/src/main/java/ cocoon-ajax-block/api/src/main/r...
Date Thu, 03 Nov 2005 14:00:48 GMT
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/LocaleAction.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/LocaleAction.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/LocaleAction.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/LocaleAction.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,292 @@
+/*
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.acting;
+
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.thread.ThreadSafe;
+
+import org.apache.cocoon.environment.Redirector;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.i18n.I18nUtils;
+
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+
+/**
+ * An action that locates and provides to the pipeline locale information
+ * looked up in a range of ways.
+ *
+ * <h1>Configuration</h1>
+ * <p>A sample configuration (given in the &lt;map:matchers&gt; section of the
+ * sitemap) is given below. This configuration shows default values.
+ * </p>
+ * <pre>
+ *   &lt;map:action name="locale" src="org.apache.cocoon.acting.LocaleAction"&gt;
+ *     &lt;locale-attribute&gt;locale&lt;/locale-attribute&gt;
+ *     &lt;use-locale&gt;true&lt;/use-locale&gt;
+ *     &lt;default-locale language="en" country="US"/&gt;
+ *     &lt;store-in-request&gt;false&lt;store-in-request&gt;
+ *     &lt;create-session&gt;false&lt;create-session&gt;
+ *     &lt;store-in-session&gt;false&lt;store-in-session&gt;
+ *     &lt;store-in-cookie&gt;false&lt;store-in-cookie&gt;
+ *   &lt;/map:action&gt;
+ * </pre>
+ *
+ * <p>Above configuration parameters mean:
+ *   <ul>
+ *     <li><b>locale-attribute</b> specifies the name of the request
+ *     parameter / session attribute / cookie that is to be used as a locale
+ *     (defaults to <code>locale</code>)</li>
+ *     <li><b>use-locale</b> specifies whether the primary locale provided
+ *     by the user agent (or server default, is no locale passed by the agent)
+ *     is to be used</li>
+ *     <li><b>default-locale</b> specifies the default locale to be used when
+ *     none found.</li>
+ *     <li><b>store-in-request</b> specifies whether found locale should be
+ *     stored as request attribute.</li>
+ *     <li><b>create-session</b> specifies whether session should be created
+ *     when storing found locale as session attribute.</li>
+ *     <li><b>store-in-session</b> specifies whether found locale should be
+ *     stored as session attribute.</li>
+ *     <li><b>store-in-cookie</b> specifies whether found locale should be
+ *     stored as cookie.</li>
+ *   </ul>
+ * </p>
+ *
+ * <h1>Usage</h1>
+ * <p>This action will be used in a pipeline like so:</p>
+ * <pre>
+ *   &lt;map:act type="locale"&gt;
+ *     &lt;map:generate src="file_{language}_{country}_{variant}.xml"/&gt;
+ *     ...
+ *   &lt;/map:match&gt;
+ * </pre>
+ * <p>or</p>
+ * <pre>
+ *   &lt;map:act type="locale"&gt;
+ *     &lt;map:generate src="file_{locale}.xml"/&gt;
+ *     ...
+ *   &lt;/map:match&gt;
+ * </pre>
+ *
+ * <h1>Locale Identification</h1>
+ * <p>Locales will be tested in following order:</p>
+ * <ul>
+ *   <li>Locale provided as a request parameter</li>
+ *   <li>Locale provided as a session attribute</li>
+ *   <li>Locale provided as a cookie</li>
+ *   <li>Locale provided using a sitemap parameter<br>
+ *   (&lt;map:parameter name="locale" value="{1}"/&gt; style parameter within
+ *   the &lt;map:match&gt; node)</li>
+ *   <li>Locale provided by the user agent, or server default,
+ *   if <code>use-locale</code> is set to <code>true</code></li>
+ *   <li>The default locale, if specified in the matcher's configuration</li>
+ * </ul>
+ * <p>First found locale will be returned.</p>
+ *
+ * <h1>Sitemap Variables</h1>
+ * <p>Once locale has been found, the following sitemap variables
+ * will be available to sitemap elements contained within the action:</p>
+ * <ul>
+ *   <li>{locale}: The locale string</li>
+ *   <li>{language}: The language of the found locale</li>
+ *   <li>{country}: The country of the found locale</li>
+ *   <li>{variant}: The variant of the found locale</li>
+ * </ul>
+ *
+ * @author <a href="mailto:Marcus.Crafter@osa.de">Marcus Crafter</a>
+ * @author <a href="mailto:kpiroumian@flagship.ru">Konstantin Piroumian</a>
+ * @author <a href="mailto:lassi.immonen@valkeus.com">Lassi Immonen</a>
+ * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
+ * @version CVS $Id: LocaleAction.java 36371 2004-08-14 00:48:04Z vgritsenko $
+ */
+public class LocaleAction extends ServiceableAction implements ThreadSafe, Configurable {
+
+    private static final String DEFAULT_DEFAULT_LANG = "en";
+    private static final String DEFAULT_DEFAULT_COUNTRY = "US";
+    private static final String DEFAULT_DEFAULT_VARIANT = "";
+
+    /**
+      * Default locale attribute name.
+     */
+    public static final String LOCALE = "locale";
+
+    /**
+     * Configuration element name for locale attribute name.
+     */
+    public static final String LOCALE_ATTR = "locale-attribute";
+
+
+    /**
+     * Constant representing the request storage configuration attribute
+     */
+    public static final String STORE_REQUEST = "store-in-request";
+
+    /**
+     * Constant representing the session creation configuration attribute
+     */
+    public static final String CREATE_SESSION = "create-session";
+
+    /**
+     * Constant representing the session storage configuration attribute
+     */
+    public static final String STORE_SESSION = "store-in-session";
+
+    /**
+     * Constant representing the cookie storage configuration attribute
+     */
+    public static final String STORE_COOKIE = "store-in-cookie";
+
+
+    /**
+     * Name of the locale request parameter, session attribute, cookie.
+     */
+    private String localeAttribute;
+
+    /**
+     * Whether to query locale provided by the user agent or not.
+     */
+    private boolean useLocale;
+
+    /**
+     * Default locale if no other found and {@link #useLocale} is false.
+     */
+    private Locale defaultLocale;
+
+    /**
+     * Store the locale in request. Default is not to do this.
+     */
+    private boolean storeInRequest;
+
+    /**
+     * Store the locale in session, if available. Default is not to do this.
+     */
+    private boolean storeInSession;
+
+    /**
+     * Should we create a session if needed. Default is not to do this.
+     */
+    private boolean createSession;
+
+    /**
+     * Should we add a cookie with the locale. Default is not to do this.
+     */
+    private boolean storeInCookie;
+
+    /**
+     * Configure this action.
+     *
+     * @param config configuration information (if any)
+     */
+    public void configure(Configuration config)
+    throws ConfigurationException {
+        this.storeInRequest = config.getChild(STORE_REQUEST).getValueAsBoolean(false);
+        this.createSession = config.getChild(CREATE_SESSION).getValueAsBoolean(false);
+        this.storeInSession = config.getChild(STORE_SESSION).getValueAsBoolean(false);
+        this.storeInCookie = config.getChild(STORE_COOKIE).getValueAsBoolean(false);
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug((this.storeInRequest ? "will" : "won't") + " set values in request");
+            getLogger().debug((this.createSession ? "will" : "won't") + " create session");
+            getLogger().debug((this.storeInSession ? "will" : "won't") + " set values in session");
+            getLogger().debug((this.storeInCookie ? "will" : "won't") + " set values in cookies");
+        }
+
+        this.localeAttribute = config.getChild(LOCALE_ATTR).getValue(LOCALE);
+        this.useLocale = config.getChild("use-locale").getValueAsBoolean(true);
+
+        Configuration child = config.getChild("default-locale", false);
+        if (child != null) {
+            this.defaultLocale = new Locale(child.getAttribute("language", DEFAULT_DEFAULT_LANG),
+                                            child.getAttribute("country", DEFAULT_DEFAULT_COUNTRY),
+                                            child.getAttribute("variant", DEFAULT_DEFAULT_VARIANT));
+        }
+
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("Locale attribute name is " + this.localeAttribute);
+            getLogger().debug((this.useLocale ? "will" : "won't") + " use request locale");
+            getLogger().debug("default locale " + this.defaultLocale);
+        }
+    }
+
+    /**
+     * Action which obtains the current environments locale information, and
+     * places it in the objectModel (and optionally in a session/cookie).
+     */
+    public Map act(Redirector redirector,
+                   SourceResolver resolver,
+                   Map objectModel,
+                   String source,
+                   Parameters params)
+    throws Exception {
+        // Obtain locale information from request, session, cookies, or params
+        Locale locale = I18nUtils.findLocale(objectModel,
+                                             localeAttribute,
+                                             params,
+                                             defaultLocale,
+                                             useLocale);
+
+        if (locale == null) {
+            if (getLogger().isDebugEnabled()) {
+                getLogger().debug("No locale found.");
+            }
+
+            return null;
+        }
+
+        String localeStr = locale.toString();
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("Found locale: " + localeStr);
+        }
+
+        I18nUtils.storeLocale(objectModel,
+                              localeAttribute,
+                              localeStr,
+                              storeInRequest,
+                              storeInSession,
+                              storeInCookie,
+                              createSession);
+
+        // Set up a map for sitemap parameters
+        Map map = new HashMap();
+        map.put("language", locale.getLanguage());
+        map.put("country", locale.getCountry());
+        map.put("variant", locale.getVariant());
+        map.put("locale", localeStr);
+        return map;
+    }
+
+    /**
+     * Helper method to retreive the attribute value containing locale
+     * information. See class documentation for locale determination algorythm.
+     *
+     * @deprecated See I18nUtils.findLocale
+     * @param objectModel requesting object's environment
+     * @return locale value or <code>null</null> if no locale was found
+     */
+    public static String getLocaleAttribute(Map objectModel,
+                                            String localeAttrName) {
+        Locale locale = I18nUtils.findLocale(objectModel,
+                                             localeAttrName,
+                                             null,
+                                             null,
+                                             true);
+        return locale.toString();
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/LocaleAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/PropagatorAction.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/PropagatorAction.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/PropagatorAction.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/PropagatorAction.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,265 @@
+/*
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.acting;
+
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.service.ServiceSelector;
+import org.apache.avalon.framework.thread.ThreadSafe;
+
+import org.apache.cocoon.components.modules.output.OutputModule;
+import org.apache.cocoon.environment.Redirector;
+import org.apache.cocoon.environment.SourceResolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * This is the action used to propagate parameters into a store using an
+ * {@link org.apache.cocoon.components.modules.output.OutputModule}. It
+ * simply propagates given expression. Additionaly it will make all propagated values
+ * available via returned Map.
+ *
+ * <p>Example configuration:</p>
+ * <pre>
+ * &lt;map:action type="...." name="...." logger="..."&gt;
+ *   &lt;output-module name="session-attr"&gt;
+ *      &lt;!-- optional configuration for output module --&gt;
+ *   &lt;/output-module&gt;
+ *   &lt;store-empty-parameters&gt;true&lt;/store-empty-parameters&gt;
+ *   &lt;defaults&gt;
+ *     &lt;default name="..." value="...."/&gt;
+ *     &lt;default name="..." value="..."/&gt;
+ *   &lt;/defaults&gt;
+ * &lt;/map:action&gt;
+ * </pre>
+ *
+ * <p>Example use:</p>
+ * <pre>
+ * &lt;map:act type="session-propagator"&gt;
+ *      &lt;paramater name="example" value="{example}"/&gt;
+ *      &lt;paramater name="example1" value="xxx"/&gt;
+ *      &lt;parameter name="PropagatorAction:store-empty-parameters" value="true"/&gt;
+ *      &lt;parameter name="PropagatorAction:output-module" value="session-attr"/&gt;
+ * &lt;/map:act&gt;
+ * </pre>
+ *
+ * <h3>Configuration</h3>
+ * <table><tbody>
+ * <tr>
+ *  <th>output-module</th>
+ *  <td>Nested element configuring output to use. Name attribute holds
+ *      output module hint.</td>
+ *  <td></td><td>XML</td><td><code>request-attr</code></td>
+ * </tr>
+ * <tr>
+ *  <th>store-empty-parameters</th>
+ *  <td>Propagate parameters with empty values.</td>
+ *  <td></td><td>boolean</td><td><code>true</code></td>
+ * </tr>
+ * <tr>
+ *  <th>defaults</th>
+ *  <td>Parent for default parameters to propagate.</td>
+ *  <td></td><td>XML</td><td></td>
+ * </tr>
+ * <tr>
+ *  <th>defaults/default</th>
+ *  <td>Name attribute holds parameter name, value attribute holds
+ *      parameter value. Will be used when not set on use.</td>
+ *  <td></td><td>parameter</td><td></td>
+ * </tr>
+ * </tbody></table>
+ *
+ *<h3>Parameters</h3>
+ * <table><tbody>
+ * <tr>
+ *  <th>PropagatorAction:output-module</th>
+ *  <td>Alternative output module hint to use. A <code>null</code> configuration
+ *      will be passed to a module selected this way.</td>
+ *  <td></td><td>String</td><td>as determined by configuration</td>
+ * </tr>
+ * <tr>
+ *  <th>PropagatorAction:store-empty-parameters</th>
+ *  <td>Propagate parameters with empty values.</td>
+ *  <td></td><td>boolean</td><td>as determined by configuration</td>
+ * </tr>
+ * <tr>
+ *  <th>any other</th>
+ *  <td>Any other parameter will be propagated.</td>
+ *  <td></td><td>String</td><td></td>
+ * </tr>
+ * </tbody></table>
+ *
+ * @author <a href="mailto:haul@apache.org">Christian Haul</a>
+ * @author <a href="mailto:Martin.Man@seznam.cz">Martin Man</a>
+ * @version CVS $Id: PropagatorAction.java 126305 2005-01-24 18:42:30Z vgritsenko $
+ */
+public class PropagatorAction extends ServiceableAction
+                              implements Configurable, ThreadSafe {
+
+    /** Prefix for sitemap parameters targeted at this action. */
+    private static final String ACTION_PREFIX = "PropagatorAction:";
+
+    /** Configuration parameter name. */
+    private static final String CONFIG_STORE_EMPTY = "store-empty-parameters";
+
+    /** Configuration parameter name. */
+    private static final String CONFIG_OUTPUT_MODULE = "output-module";
+
+    /** Default output module name. */
+    private static final String OUTPUT_HINT = "request-attr"; // defaults to request attributes
+
+
+    /** Should empty parameter values be propagated? */
+    private boolean storeEmpty = true;
+
+    /** Configuration object for output module. */
+    private Configuration outputConf;
+
+    /** Name of output module to use. */
+    private String outputName;
+
+    /** List of {@link Entry}s holding default values. */
+    private List defaults;
+
+    /**
+     * A private helper holding default parameter entries.
+     *
+     */
+    private static class Entry {
+        public String key;
+        public String value;
+
+        public Entry(String key, String value) {
+            this.key = key;
+            this.value = value;
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
+     */
+    public void configure(Configuration config) throws ConfigurationException {
+        this.outputConf = config.getChild(CONFIG_OUTPUT_MODULE);
+        this.outputName = this.outputConf.getAttribute("name", OUTPUT_HINT);
+        this.storeEmpty =
+            config.getChild(CONFIG_STORE_EMPTY).getValueAsBoolean(this.storeEmpty);
+
+        Configuration[] dflts = config.getChild("defaults").getChildren("default");
+        if (dflts != null) {
+            this.defaults = new ArrayList(dflts.length);
+            for (int i = 0; i < dflts.length; i++) {
+                this.defaults.add(
+                        new Entry(dflts[i].getAttribute("name"),
+                                  dflts[i].getAttribute("value")));
+            }
+        } else {
+            this.defaults = new ArrayList(0);
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.acting.Action#act(Redirector, SourceResolver, Map, String, Parameters)
+     */
+    public Map act(Redirector redirector,
+                   SourceResolver resolver,
+                   Map objectModel,
+                   String source,
+                   Parameters parameters)
+    throws Exception {
+        // Read action parameters
+        String outputName = parameters.getParameter(ACTION_PREFIX + CONFIG_OUTPUT_MODULE,
+                                                    null);
+        boolean storeEmpty = parameters.getParameterAsBoolean(ACTION_PREFIX + CONFIG_STORE_EMPTY,
+                                                              this.storeEmpty);
+        parameters.removeParameter(ACTION_PREFIX + CONFIG_OUTPUT_MODULE);
+        parameters.removeParameter(ACTION_PREFIX + CONFIG_STORE_EMPTY);
+
+        Configuration outputConf = null;
+        if (outputName == null) {
+            outputName = this.outputName;
+            outputConf = this.outputConf;
+        }
+
+        // Action results map
+        final Map results = new HashMap();
+
+        OutputModule output = null;
+        ServiceSelector selector = null;
+        try {
+            selector = (ServiceSelector) this.manager.lookup(OutputModule.ROLE + "Selector");
+            if (outputName != null
+                && selector != null
+                && selector.isSelectable(outputName)) {
+
+                output = (OutputModule) selector.select(outputName);
+
+                String[] names = parameters.getNames();
+                for (int i = 0; i < names.length; i++) {
+                    String name = names[i];
+                    String value = parameters.getParameter(name);
+                    if (storeEmpty || (value != null && !value.equals(""))) {
+                        if (getLogger().isDebugEnabled()) {
+                            getLogger().debug("Propagating <" + name + "> value <" + value + ">");
+                        }
+                        output.setAttribute(outputConf,
+                                            objectModel,
+                                            name,
+                                            value);
+                        results.put(name, value);
+                    }
+                }
+
+                // Defaults, that are not overridden
+                for (Iterator i = defaults.iterator(); i.hasNext();) {
+                    Entry entry = (Entry) i.next();
+                    if (!results.containsKey(entry.key)) {
+                        if (getLogger().isDebugEnabled()) {
+                            getLogger().debug("Propagating default <" + entry.key + "> value <" + entry.value + ">");
+                        }
+                        output.setAttribute(outputConf,
+                                            objectModel,
+                                            entry.key,
+                                            entry.value);
+                        results.put(entry.key, entry.value);
+                    }
+                }
+
+                output.commit(outputConf, objectModel);
+            }
+        } catch (Exception e) {
+            if (output != null) {
+                output.rollback(outputConf, objectModel, e);
+            }
+            throw e;
+        } finally {
+            if (selector != null) {
+                if (output != null) {
+                    selector.release(output);
+                }
+                this.manager.release(selector);
+            }
+        }
+
+        return Collections.unmodifiableMap(results);
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/PropagatorAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/RequestParamAction.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/RequestParamAction.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/RequestParamAction.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/RequestParamAction.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,135 @@
+/*
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.acting;
+
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.thread.ThreadSafe;
+
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Redirector;
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.environment.SourceResolver;
+
+/**
+ * This action makes some request details available to the sitemap via parameter
+ * substitution.
+ *
+ * {context}      - is the context path of the servlet (usually "/cocoon")
+ * {requestURI}   - is the requested URI without parameters
+ * {requestQuery} - is the query string like "?param1=test" if there is one
+ *
+ * Additionlly all request parameters can be made available for use in the sitemap.
+ * if the parameter "parameters" is set to true.
+ * (A variable is created for each request parameter (only if it doesn't exist)
+ * with the same name as the parameter itself)
+ *
+ * Default values can be set for request parameters, by including sitemap parameters
+ * named "default.<parameter-name>".
+ *
+ * Sitemap definition:
+ *
+ * <pre>
+ * &lt;map:action name="request" src="org.apache.cocoon.acting.RequestParamAction"/&gt;
+ * </pre>
+ *
+ * <p>
+ *
+ * Example use:
+ *
+ * <pre>
+ * &lt;map:match pattern="some-resource"&gt;
+ *  &lt;map:act type="request"&gt;
+ *     &lt;map:parameter name="parameters" value="true"/&gt;
+ *     &lt;map:parameter name="default.dest" value="invalid-destination.html"/&gt;
+ *     &lt;map:redirect-to uri="{context}/somewhereelse/{dest}"/&gt;
+ *  &lt;/map:act&gt;
+ * &lt;/map:match&gt;
+ * </pre>
+ *
+ * Redirection is only one example, another use:
+ *
+ * <pre>
+ * &lt;map:match pattern="some-resource"&gt;
+ *  &lt;map:act type="request"&gt;
+ *     &lt;map:parameter name="parameters" value="true"/&gt;
+ *     &lt;map:generate src="users/menu-{id}.xml"/&gt;
+ *  &lt;/map:act&gt;
+ *  &lt;map:transform src="menus/personalisation.xsl"/&gt;
+ *  &lt;map:serialize/&gt;
+ * &lt;/map:match&gt;
+ * </pre>
+ *
+ * etc, etc.
+ *
+ * @author <a href="mailto:Marcus.Crafter@osa.de">Marcus Crafter</a>
+ * @author <a href="mailto:tcurdt@dff.st">Torsten Curdt</a>
+ * @version CVS $Id: RequestParamAction.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public class RequestParamAction extends ServiceableAction implements ThreadSafe {
+
+    public final static String MAP_URI         = "requestURI";
+    public final static String MAP_QUERY       = "requestQuery";
+    public final static String MAP_CONTEXTPATH = "context";
+
+    public final static String PARAM_PARAMETERS     = "parameters";
+    public final static String PARAM_DEFAULT_PREFIX = "default.";
+
+    public Map act(Redirector redirector, SourceResolver resolver, Map objectModel,
+                   String source, Parameters param) throws Exception {
+
+        Request request = ObjectModelHelper.getRequest(objectModel);
+
+        Map map = new HashMap();
+
+        map.put(MAP_URI, request.getRequestURI());
+
+        String query = request.getQueryString();
+        if (query != null && query.length() > 0) {
+            map.put(MAP_QUERY, "?" + query);
+        } else {
+            map.put(MAP_QUERY, "");
+        }
+
+        map.put(MAP_CONTEXTPATH, request.getContextPath());
+
+        if ("true".equalsIgnoreCase(param.getParameter(PARAM_PARAMETERS, null))) {
+            Enumeration e = request.getParameterNames();
+            while (e.hasMoreElements()) {
+                String name = (String)e.nextElement();
+                String value = request.getParameter(name);
+
+                if (value != null && !map.containsKey(name)) {
+                    map.put(name, value);
+                }
+            }
+
+            String[] paramNames = param.getNames();
+            for (int i = 0; i < paramNames.length; i++) {
+                if (paramNames[i].startsWith(PARAM_DEFAULT_PREFIX)
+                        && (request.getParameter(paramNames[i].substring(PARAM_DEFAULT_PREFIX.length())) == null)) {
+                    map.put(paramNames[i].substring(PARAM_DEFAULT_PREFIX.length()),
+                            param.getParameter(paramNames[i]));
+                }
+            }
+        }
+        return (map);
+    }
+
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/RequestParamAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/RequestParameterExistsAction.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/RequestParameterExistsAction.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/RequestParameterExistsAction.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/RequestParameterExistsAction.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,345 @@
+/*
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.acting;
+
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.StringTokenizer;
+import java.util.Iterator;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Redirector;
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.environment.SourceResolver;
+
+/**
+ * This action simply checks to see if a given request parameter
+ * exists. It takes an arbitrary number of default parameters to check
+ * named 'parameter-name'. Non-default parameters need to be separated
+ * by spaces and passed as value of a sitemap parameter named
+ * 'parameters'. The action returns a map with all parameters if all
+ * of them exist and null otherwise. Parameter names can only be added
+ * to this list but no default parameters can be overridden by
+ * specific ones.
+ *
+ * <p>This action is very closely related to @link{RequestParamAction}
+ * and {@link FormValidatorAction}. However this action is considerably
+ * simpler in that it tests only for existence of a parameter and it
+ * doesn't need a descriptor. Besides it doesn't propagate all request
+ * parameters to the sitemap but only those that are marked as
+ * required.</p> <p> One special feature is, however, that parameters
+ * can contain <strong>one</strong> wildcard ("*"). It will be
+ * checked, whether all parameters with a wildcard have the same
+ * matches. E.g. "id_* name_*" enforces, that if "id_1" exists,
+ * "name_1" must also exist and vice versa.</p>
+ *
+ * @author <a href="mailto:haul@apache.org">Christian Haul</a>
+ * @version CVS $Id: RequestParameterExistsAction.java 293457 2005-10-03 21:52:54Z danielf $
+ */
+public class RequestParameterExistsAction extends AbstractConfigurableAction implements ThreadSafe
+{
+
+    protected class StringParts {
+        String prefix = null;
+        String pstfix = null;
+        int count = 0;
+
+        public StringParts ( String pre, String post ) {
+            prefix = pre;
+            pstfix = post;
+        }
+    }
+
+
+
+    public Map act( Redirector redirector,
+            SourceResolver resolver,
+            Map objectModel,
+            String source,
+            Parameters parameters
+            )
+    throws Exception {
+        Request request = ObjectModelHelper.getRequest(objectModel);
+        HashMap results = new HashMap();
+        HashMap items = new HashMap();
+        int wildcards = 0;
+
+        // check default parameters for existence
+        if (this.getLogger().isDebugEnabled()) {
+            getLogger().debug("checking default parameters");
+        }
+        Iterator reqParams = settings.values().iterator();
+        while (reqParams.hasNext()) {
+            String paramName = (String) reqParams.next();
+            StringParts sp = splitParameter(paramName);
+            if (sp != null) {
+                // wildcard: special care required (deferred until later)
+                items.put(new Integer(wildcards++), sp);
+                if (this.getLogger().isDebugEnabled()) {
+                    getLogger().debug("(default) deferring " + paramName);
+                }
+            } else {
+                String paramValue = request.getParameter(paramName);
+                if (paramValue == null) {
+                    return null;
+                }
+                results.put(paramName, paramValue);
+            }
+        }
+
+        // check parameters for existence
+        if (this.getLogger().isDebugEnabled()) {
+            getLogger().debug("checking sitemap parameters");
+        }
+        String params = parameters.getParameter("parameters", null);
+        if (params != null) {
+            StringTokenizer st = new StringTokenizer(params);
+            while (st.hasMoreTokens()) {
+                String paramName = st.nextToken();
+                StringParts sp = splitParameter(paramName);
+                if (sp != null) {
+                    // wildcard: special care required (deferred until later)
+                    items.put(new Integer(wildcards++), sp);
+                    if (this.getLogger().isDebugEnabled()) {
+                        getLogger().debug("deferring " + paramName);
+                    }
+                } else {
+
+                    String paramValue = request.getParameter(paramName);
+                    if (paramValue == null) {
+                        return null;
+                    }
+                    results.put(paramName, paramValue);
+                }
+            }
+        }
+
+        if (wildcards != 0) {
+            // special care for parameters with wildcard
+            //
+            if (this.getLogger().isDebugEnabled()) {
+                getLogger().debug("deferred checking for parameters: " + wildcards);
+            }
+
+            // first one
+            //
+            if (this.getLogger().isDebugEnabled()) {
+                getLogger().debug(" checking first");
+            }
+            HashMap values = new HashMap();
+            StringParts sp1 = (StringParts) items.get(new Integer(0));
+            if (this.getLogger().isDebugEnabled()) {
+                getLogger().debug(
+                    "  Parameter is [" + sp1.prefix + " * " + sp1.pstfix + "] ");
+            }
+            Enumeration requestParams = request.getParameterNames();
+            Boolean dummy = Boolean.TRUE;
+            while (requestParams.hasMoreElements()) {
+                String paramName = (String) requestParams.nextElement();
+                String match = getMatch(paramName, sp1);
+                if (match != null) {
+                    if (this.getLogger().isDebugEnabled()) {
+                        getLogger().debug(
+                            "  value is >"
+                            + match
+                            + "< "
+                            + sp1.prefix.length()
+                            + " "
+                            + paramName.length()
+                            + " "
+                            + sp1.pstfix.length());
+                    }
+                    values.put(match, dummy);
+                    sp1.count++;
+                    if (this.getLogger().isDebugEnabled()) {
+                        getLogger().debug(
+                            "   Parameter "
+                            + sp1.prefix
+                            + "*"
+                            + sp1.pstfix
+                            + " matches "
+                            + paramName
+                            + " ("
+                            + sp1.count
+                            + " so far)");
+                    }
+                    String paramValue = request.getParameter(paramName);
+                    if (paramValue == null) {
+                        return null;
+                    }
+                    results.put(paramName, paramValue);
+                }
+            }
+
+            if (sp1.count == 0) {
+                if (this.getLogger().isDebugEnabled()) {
+                    getLogger().debug(
+                       "   Parameter "
+                        + sp1.prefix
+                        + "*"
+                        + sp1.pstfix
+                        + " matches "
+                        + sp1.count);
+                }
+                return null;
+            }
+
+            // all other ones
+            //
+            if (this.getLogger().isDebugEnabled()) {
+                getLogger().debug(" checking others");
+            }
+            requestParams = request.getParameterNames();
+            while (requestParams.hasMoreElements()) {
+                String paramName = (String) requestParams.nextElement();
+                if (this.getLogger().isDebugEnabled()) {
+                    getLogger().debug("  checking request parameter " + paramName);
+                }
+                for (int i = wildcards - 1; i > 0; i--) {
+                    if (this.getLogger().isDebugEnabled()) {
+                        getLogger().debug("   checking against " + i);
+                    }
+                    StringParts sp = (StringParts) items.get(new Integer(i));
+                    String match = getMatch(paramName, sp);
+                    if (this.getLogger().isDebugEnabled()) {
+                        getLogger().debug(
+                            "   Parameter is ["
+                            + sp.prefix
+                            + " * "
+                            + sp.pstfix
+                            + "] ");
+                    }
+                    if (match != null) {
+                        if (this.getLogger().isDebugEnabled()) {
+                            getLogger().debug(
+                                "   Parameter "
+                                    + sp.prefix
+                                    + "*"
+                                    + sp.pstfix
+                                    + " matches "
+                                    + paramName
+                                    + " ("
+                                    + sp.count
+                                    + " so far)");
+                        }
+                        if (values.containsKey(match)) {
+                            sp.count++;
+                            if (this.getLogger().isDebugEnabled()) {
+                                getLogger().debug(
+                                "   " + paramName + " (verified)");
+                            }
+                            String paramValue = request.getParameter(paramName);
+                            if (paramValue == null) {
+                                return null;
+                            }
+                            results.put(paramName, paramValue);
+
+                        } else {
+                            if (this.getLogger().isDebugEnabled()) {
+                                getLogger().debug(
+                                    "Match "
+                                    + match
+                                    + "not found for "
+                                    + sp1.prefix
+                                    + "*"
+                                    + sp1.pstfix
+                                    + " but for "
+                                    + sp.prefix
+                                    + "*"
+                                    + sp.pstfix);
+                            }
+                            return null;
+                        }
+                    }
+                }
+            }
+
+            // since we enforce that only matches are counted, that exist for
+            // the first parameter as well, check if every parameter has an
+            // equal number of matches.
+            //
+            if (this.getLogger().isDebugEnabled()) {
+                getLogger().debug("checking number of matches");
+            }
+            for (int i = wildcards - 1; i > 0; i--) {
+                StringParts sp = (StringParts) items.get(new Integer(i));
+                if (sp.count != sp1.count) {
+                    if (this.getLogger().isDebugEnabled()) {
+                        getLogger().debug(
+                            "Found "
+                            + sp.count
+                            + " matches for "
+                            + sp.prefix
+                            + "*"
+                            + sp.pstfix
+                            + " but expected "
+                            + sp1.count);
+                    }
+                    return null;
+                } else {
+                    if (this.getLogger().isDebugEnabled()) {
+                        getLogger().debug(
+                            "Found "
+                            + sp.count
+                            + " matches for "
+                            + sp.prefix
+                            + "*"
+                            + sp.pstfix
+                            + " as expected");
+                    }
+                }
+            }
+
+        }
+
+        return Collections.unmodifiableMap(results);
+    }
+
+
+    /**
+     * Find first "*" in a String and split it into the substring
+     * before and after the "*". Returns null if no "*" is present.
+     */
+    protected StringParts splitParameter( String paramName )
+    {
+    int idx = paramName.indexOf("*");
+    if ( idx != -1 ) {
+        return new StringParts(paramName.substring(0,idx), paramName.substring(idx+1));
+    } else {
+        return null;
+    }
+    }
+
+    /**
+     * If a String matches a StringPart spec, return the substring
+     * between the specified prefix and postfix. Returns null if it
+     * doesn't match.
+     */
+    protected String getMatch( String paramName,
+                   StringParts sp
+                   )
+    {
+    if ( paramName.startsWith( sp.prefix ) && paramName.endsWith( sp.pstfix ) ) {
+        return paramName.substring( sp.prefix.length(), ( paramName.length() - sp.pstfix.length() ) );
+    } else {
+        return null;
+    }
+    }
+
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/RequestParameterExistsAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/ResourceExistsAction.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/ResourceExistsAction.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/ResourceExistsAction.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/ResourceExistsAction.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,63 @@
+/*
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.acting;
+
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.environment.Redirector;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceNotFoundException;
+
+import java.util.Map;
+
+/**
+ * This action simply checks to see if a resource identified by the <code>src</code>
+ * sitemap attribute exists or not. The action returns empty <code>Map</code> if
+ * resource exists, <code>null</code> otherwise.
+ * 
+ * <p>Instead of src attribute, source can be specified using
+ * parameter named <code>url</code> (this is old syntax, should be removed soon).
+ * 
+ * <p><b>NOTE:</b> {@link org.apache.cocoon.selection.ResourceExistsSelector}
+ * should be preferred to this component, as the semantics of a Selector better
+ * matches the supplied functionality.
+ *
+ * @author <a href="mailto:balld@apache.org">Donald Ball</a>
+ * @version CVS $Id: ResourceExistsAction.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public class ResourceExistsAction extends ServiceableAction implements ThreadSafe {
+
+    public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String src, Parameters parameters) throws Exception {
+        String resourceURI = parameters.getParameter("url", src);
+        Source source = null;
+        try {
+            source = resolver.resolveURI(resourceURI);
+            if (source.exists()) {
+                return EMPTY_MAP;
+            }
+        } catch (SourceNotFoundException e) {
+            // Do not log
+        } catch (Exception e) {
+            getLogger().warn("Exception resolving resource " + resourceURI, e);
+        } finally {
+            if (source != null) {
+                resolver.release(source);
+            }
+        }
+        return null;
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/ResourceExistsAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/ServiceableAction.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/ServiceableAction.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/ServiceableAction.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/ServiceableAction.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.acting;
+
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+
+/**
+ * The <code>ServiceableAction</code> will allow any <code>Action</code>
+ * that extends this to access SitemapComponents.
+ *
+ * @author <a href="mailto:cziegeler@pwr.ch">Carsten Ziegeler</a>
+ * @version CVS $Id: ServiceableAction.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public abstract class ServiceableAction 
+    extends AbstractAction implements Serviceable {
+
+    /** The service manager instance */
+    protected ServiceManager manager;
+
+    /**
+     * Set the current <code>ServiceManager</code> instance used by this
+     * <code>Serviceable</code>.
+     */
+    public void service(ServiceManager manager) throws ServiceException {
+        this.manager = manager;
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/ServiceableAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/SessionInvalidatorAction.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/SessionInvalidatorAction.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/SessionInvalidatorAction.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/SessionInvalidatorAction.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,59 @@
+/*
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.acting;
+
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Redirector;
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.environment.Session;
+import org.apache.cocoon.environment.SourceResolver;
+
+import java.util.Map;
+
+/**
+ * This is the action used to invalidate an HTTP session. The action returns
+ * empty map if everything is ok, null otherwise.
+ *
+ * @author <a href="mailto:Martin.Man@seznam.cz">Martin Man</a>
+ * @version CVS $Id: SessionInvalidatorAction.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public class SessionInvalidatorAction extends AbstractAction implements ThreadSafe
+{
+    /**
+     * Main invocation routine.
+     */
+    public Map act (Redirector redirector, SourceResolver resolver, Map objectModel, String src,
+            Parameters parameters) throws Exception {
+        Request req = ObjectModelHelper.getRequest(objectModel);
+
+        /* check session validity */
+        Session session = req.getSession (false);
+        if (session != null) {
+            session.invalidate ();
+            if (this.getLogger().isDebugEnabled()) {
+                getLogger ().debug ("SESSIONINVALIDATOR: session invalidated");
+            }
+        } else {
+            if (this.getLogger().isDebugEnabled()) {
+                getLogger ().debug ("SESSIONINVALIDATOR: no session object");
+            }
+        }
+
+        return EMPTY_MAP; // cut down on object creation
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/SessionInvalidatorAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/SessionIsValidAction.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/SessionIsValidAction.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/SessionIsValidAction.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/SessionIsValidAction.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,62 @@
+/*
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.acting;
+
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Redirector;
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.environment.Session;
+import org.apache.cocoon.environment.SourceResolver;
+
+import java.util.Map;
+
+
+/**
+ * This action just checks if a session exists and whether the current
+ * seesion is still valid.
+ *
+ * @author <a href="mailto:haul@apache.org">Christian Haul</a>
+ * @version CVS $Id: SessionIsValidAction.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public class SessionIsValidAction extends AbstractAction implements ThreadSafe
+{
+    /**
+     * Main invocation routine.
+     */
+    public Map act (Redirector redirector, SourceResolver resolver, Map objectModel, String src,
+            Parameters parameters) throws Exception {
+        Request req = ObjectModelHelper.getRequest(objectModel);
+
+        /* check session validity */
+        Session session = req.getSession (false);
+        if (session == null) {
+            if (this.getLogger().isDebugEnabled()) {
+                getLogger().debug("No session object");
+            }
+            return null;
+        }
+        if (!req.isRequestedSessionIdValid()) {
+            if (this.getLogger().isDebugEnabled()) {
+                getLogger().debug("Requested session id is invalid");
+            }
+            return null;
+        }
+
+        return EMPTY_MAP;
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/SessionIsValidAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/SessionPropagatorAction.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/SessionPropagatorAction.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/SessionPropagatorAction.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/SessionPropagatorAction.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,143 @@
+/*
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.acting;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.thread.ThreadSafe;
+
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Redirector;
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.environment.Session;
+import org.apache.cocoon.environment.SourceResolver;
+
+/**
+ * This is the action used to propagate parameters into session. It
+ * simply propagates given expression to the session. If session does not
+ * exist, action fails. Additionaly it will make all propagated values
+ * available via returned Map.
+ *
+ * <pre>
+ * &lt;map:act type="session-propagator"&gt;
+ *      &lt;paramater name="example" value="{example}"&gt;
+ *      &lt;paramater name="example1" value="xxx"&gt;
+ * &lt;/map:act&gt;
+ * </pre>
+ *
+ * @author <a href="mailto:Martin.Man@seznam.cz">Martin Man</a>
+ * @version CVS $Id: SessionPropagatorAction.java 54551 2004-10-11 10:33:49Z cziegeler $
+ */
+public class SessionPropagatorAction extends AbstractConfigurableAction implements ThreadSafe {
+
+    /**
+     * A private helper holding default parameter entries.
+     * 
+     */
+    private static class Entry {
+        public String key = null;
+        public String value = null;
+
+        public Entry(String key, String value) {
+            this.key = key;
+            this.value = value;
+        }
+    }
+    
+    private List defaults;
+
+    public void configure(Configuration conf) throws ConfigurationException {
+        super.configure(conf);
+        Configuration[] dflts = conf.getChildren();
+        if (dflts != null) {
+            this.defaults = new ArrayList(dflts.length);
+            for (int i = 0; i < dflts.length; i++) {
+                this.defaults.add(
+                    new Entry(
+                        dflts[i].getName(),
+                        dflts[i].getValue()));
+            }
+        } else {
+            this.defaults = new ArrayList(0);
+        }
+    }
+
+    /**
+     * Main invocation routine.
+     */
+    public Map act (Redirector redirector, SourceResolver resolver, Map objectModel, String src,
+                    Parameters parameters) throws Exception {
+        Request req = ObjectModelHelper.getRequest(objectModel);
+        HashMap actionMap = new HashMap ();
+
+        /* check session validity */
+        Session session = req.getSession (false);
+        if (session == null) {
+            if (getLogger().isDebugEnabled()) {
+                getLogger().debug("No session object");
+            }
+            return null;
+        }
+
+        try {
+            String[] names = parameters.getNames();
+
+            // parameters
+            for (int i = 0; i < names.length; i++) {
+                String sessionParamName = names[i];
+                String value = parameters.getParameter(sessionParamName);
+                if (getLogger().isDebugEnabled()) {
+                    getLogger().debug("Propagating value "
+                                      + value
+                                      + " to session attribute "
+                                      + sessionParamName);
+                }
+                session.setAttribute(sessionParamName, value);
+                actionMap.put(sessionParamName, value);
+            }
+
+            // defaults, that are not overridden
+            for (int i = 0; i < defaults.size(); i++) {
+                final Entry entry = (Entry)defaults.get(i);
+                if (!actionMap.containsKey(entry.key)) {
+                    if (getLogger().isDebugEnabled()) {
+                        getLogger().debug("Propagating value "
+                                          + entry.value
+                                          + " to session attribute "
+                                          + entry.key);
+                    }  
+                    session.setAttribute(entry.key, entry.value);
+                    actionMap.put(entry.key, entry.value);
+                }
+            }
+            if (getLogger().isDebugEnabled()) {
+                getLogger().debug("All params propagated " + "to session");
+            }
+            return Collections.unmodifiableMap(actionMap);
+        } catch (Exception e) {
+            getLogger().warn("exception: ", e);
+        }
+        return null;
+    }
+}
+

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/SessionPropagatorAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/SessionStateAction.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/SessionStateAction.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/SessionStateAction.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/SessionStateAction.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,174 @@
+/*
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.acting;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Redirector;
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.environment.Session;
+import org.apache.cocoon.environment.SourceResolver;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Store the session's current state in a session attribute.
+ *
+ * <p> To keep track of the state of a user's session, a string is
+ * stored in a session attribute in order to allow to chose between
+ * different pipelines in the sitemap accordingly.</p>
+ *
+ * <p> For added flexibility it is possible to use sub states as
+ * well. For this declare your own name for the session state
+ * attribute and give the number of sublevels plus the level to
+ * modify. (This is <b>one</b> based!) Sub states below the current
+ * one are removed from the session so that the default sub state will
+ * be reentered when the user returns. If you don't like this
+ * behaviour and prefer independent sub states, use this action
+ * several times with different attribute names rather than sub
+ * levels. </p>
+ *
+ * <p><b>Global and local parameters:</b></p>
+ *
+ * <table border="1">
+ *   <tr>
+ *     <td><code>state-key-prefix</code></td>
+ *     <td>String that identifies the attribute that stores the session state in the
+ *     	 session object. When sublevels are used, this is a prefix ie. the
+ *     	 number of the level is appended to the prefix. Example prefix is
+ *     	 "<code>__sessionState</code>", sub-levels is 2, attributes
+ *     	 "<code>__sessionState1</code>", "<code>__sessionState2</code>", and
+ *     	 "<code>__sessionState3</code>" will be used to store the
+ *     	 information.
+ *     </td>
+ *   </tr>
+ *   <tr>
+ *     <td><code>new-state</code></td>
+ *     <td>String that identifies the current state</td>
+ *   </tr>
+ *   <tr>
+ *     <td><code>sub-levels</code></td>
+ *     <td>Number of sub levels to  use</td>
+ *   </tr>
+ *   <tr>
+ *     <td><code>state-level</code></td>
+ *     <td>Sub level to modify, this is <b>one</b> based</td>
+ *   </tr>
+ * </table>
+ *
+ * @see org.apache.cocoon.matching.WildcardSessionAttributeMatcher
+ * @see org.apache.cocoon.selection.SessionAttributeSelector
+ *
+ * @author <a href="mailto:haul@apache.org">Christian Haul</a>
+ * @version CVS $Id: SessionStateAction.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public class SessionStateAction
+    extends AbstractConfigurableAction
+    implements ThreadSafe {
+
+    protected String statekey = "org.apache.cocoon.SessionState";
+    protected String newstate = null;
+    protected int sublevels = 0;
+    protected int mylevel = 0;
+
+    /**
+     * Configures the Action.
+     */
+    public void configure(Configuration conf) throws ConfigurationException {
+        super.configure(conf);
+
+        if (settings.containsKey("state-key-prefix")) {
+            statekey = (String) settings.get("state-key-prefix");
+        }
+        if (settings.containsKey("new-state")) {
+            newstate = (String) settings.get("new-state");
+        }
+        if (settings.containsKey("sub-levels")) {
+            sublevels = Integer.parseInt((String) settings.get("sub-levels"));
+        }
+        if (settings.containsKey("state-level")) {
+            mylevel = Integer.parseInt((String) settings.get("state-level"));
+        }
+    }
+
+    public Map act(Redirector redirector,
+                   SourceResolver resolver,
+                   Map objectModel,
+                   String src,
+                   Parameters par) throws Exception {
+
+        Request request = ObjectModelHelper.getRequest(objectModel);
+
+        // read local settings
+        String newstate = par.getParameter("new-state", this.newstate);
+        String statekey = par.getParameter("state-key", this.statekey);
+        int sublevels = par.getParameterAsInteger("sublevels", this.sublevels);
+        int mylevel = par.getParameterAsInteger("state-level", this.mylevel);
+
+        if (newstate == null) {
+            if (this.getLogger().isDebugEnabled()) {
+                getLogger().error("new-state is null");
+            }
+            return null;
+        }
+
+        if (request != null) {
+            Session session = request.getSession(false);
+
+            if (session != null && request.isRequestedSessionIdValid()) {
+                String oldstate = null;
+                if (sublevels == 0) {
+                    oldstate = (String) session.getAttribute(statekey);
+                    session.setAttribute(statekey, newstate);
+                    if (this.getLogger().isDebugEnabled()) {
+                         getLogger().debug(statekey + "=" + newstate);
+                    }
+
+                } else { // sublevels != 0
+                    oldstate = (String)session.getAttribute(statekey + mylevel);
+                    for (int i = mylevel + 1; i <= sublevels; i++) {
+                        session.removeAttribute(statekey + i);
+                        if (this.getLogger().isDebugEnabled()) {
+                            getLogger().debug("Remove " + statekey + i);
+                        }
+                    }
+                    session.setAttribute(statekey + mylevel, newstate);
+                    if (this.getLogger().isDebugEnabled()) {
+                        getLogger().debug(statekey + mylevel + "=" + newstate);
+                    }
+                }
+                if (this.getLogger().isDebugEnabled()) {
+                    getLogger().debug("Transition " + oldstate + " -> " + newstate);
+                }
+
+                HashMap map = new HashMap(1);
+                map.put("newstate", newstate);
+                return map;
+            } else {
+                getLogger().warn(
+                    "A session object was not present or no longer valid");
+                return null;
+            }
+        } else {
+            getLogger().warn("No request object");
+            return null;
+        }
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/SessionStateAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/SessionValidatorAction.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/SessionValidatorAction.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/SessionValidatorAction.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/SessionValidatorAction.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,81 @@
+/*
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.acting;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.thread.ThreadSafe;
+
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Session;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * This is the action used to validate Session parameters (attributes).
+ * The parameters are described via the external xml
+ * file.
+ * 
+ * @see org.apache.cocoon.acting.AbstractValidatorAction
+ *
+ * @author <a href="mailto:Martin.Man@seznam.cz">Martin Man</a>
+ * @author <a href="mailto:haul@apache.org">Christian Haul</a>
+ * @version CVS $Id: SessionValidatorAction.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public class SessionValidatorAction extends AbstractValidatorAction implements ThreadSafe {
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.acting.AbstractValidatorAction#createMapOfParameters(java.util.Map, java.util.Collection)
+     */
+    protected HashMap createMapOfParameters(Map objectModel, Collection set) {
+        String name;
+        HashMap params = new HashMap(set.size());
+        // put required params into hash
+        Session session = ObjectModelHelper.getRequest(objectModel).getSession();
+        for (Iterator i = set.iterator(); i.hasNext();) {
+            name = ((Configuration) i.next()).getAttribute("name", "").trim();
+            Object value = session.getAttribute(name);
+            params.put(name, value);
+        }
+        return params;
+    }
+    
+    
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.acting.AbstractValidatorAction#setResult(java.util.Map, java.util.Map, java.util.Map, boolean)
+     */
+    protected Map setResult(Map objectModel, Map actionMap, Map resultMap, boolean allOK) {
+        if (allOK){
+            Session session = ObjectModelHelper.getRequest(objectModel).getSession();
+            for (Iterator i = actionMap.keySet().iterator(); i.hasNext(); ){
+                String name = (String) i.next();
+                session.setAttribute(name, actionMap.get(name));
+            }
+        }
+        return super.setResult(objectModel, actionMap, resultMap, allOK);
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.acting.AbstractValidatorAction#isStringEncoded()
+     */
+    boolean isStringEncoded() {
+        return false;
+    }
+
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/SessionValidatorAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/SetCharacterEncodingAction.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/SetCharacterEncodingAction.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/SetCharacterEncodingAction.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/SetCharacterEncodingAction.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,69 @@
+/*
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.acting;
+
+import org.apache.avalon.framework.parameters.ParameterException;
+import org.apache.avalon.framework.parameters.Parameterizable;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.thread.ThreadSafe;
+
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Redirector;
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.environment.SourceResolver;
+
+import java.util.Map;
+
+/**
+ * Sets the character encoding of parameters.
+ * Components use this encoding as default after the action.
+ * <p>
+ * <b>Configuration parameters:</b>
+ * <dl>
+ * <dt><i>form-encoding</i> (optional)
+ * <dd>The supposed encoding of the request parameter.
+ * </dl>
+ * These configuration options supported in both declaration and use time.
+ * <p>If no encoding specified, the action does nothing.
+ *
+ * @author <a href="mailto:miyabe@jzf.co.jp">MIYABE Tatsuhiko</a>
+ * @version CVS $Id: SetCharacterEncodingAction.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public class SetCharacterEncodingAction extends ServiceableAction implements ThreadSafe, Parameterizable {
+    private String global_form_encoding = null;
+
+    public void parameterize(Parameters parameters)
+    throws ParameterException {
+        // super.parameterize(parameters);
+
+        global_form_encoding = parameters.getParameter("form-encoding", null);
+    }
+
+    /**
+     * Set character encoding of current request.
+     */
+    public Map act (Redirector redirector, SourceResolver resolver, Map objectModel, String src, Parameters par) throws Exception {
+        Request request = ObjectModelHelper.getRequest(objectModel);
+        if (request != null) {
+            String form_encoding = par.getParameter("form-encoding", global_form_encoding);
+            if (form_encoding != null) {
+                request.setCharacterEncoding(form_encoding);
+            }
+        }
+
+        return null;
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/SetCharacterEncodingAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/SetterAction.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/SetterAction.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/SetterAction.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/SetterAction.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,93 @@
+/*
+ * 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.acting;
+
+import java.util.Map;
+
+import org.apache.avalon.framework.parameters.ParameterException;
+import org.apache.avalon.framework.parameters.Parameterizable;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Redirector;
+import org.apache.cocoon.environment.SourceResolver;
+
+/**
+ * This action can be used to set information in either the object model,
+ * the request or the session.
+ * All parameters set for this action are set in the according location
+ * whereas the parameter name is the key and the value of the parameter
+ * will be set as a string value for this key.
+ *
+ * @version SVN $Id: SetterAction.java 289177 2005-09-15 08:24:23Z cziegeler $
+ */
+public class SetterAction
+    extends AbstractAction
+    implements Parameterizable, ThreadSafe {
+
+    public static final int MODE_OBJECT_MODEL = 1;
+    public static final int MODE_REQUEST_ATTR = 2;
+    public static final int MODE_SESSION_ATTR = 3;
+    
+    public static final String MODEDEF_OBJECT_MODEL = "object-model";
+    public static final String MODEDEF_REQUEST_ATTR = "request-attribute";
+    public static final String MODEDEF_SESSION_ATTR = "session-attribute";
+
+    protected int mode = MODE_OBJECT_MODEL;
+
+    /**
+     * @see Parameterizable#parameterize(org.apache.avalon.framework.parameters.Parameters)
+     * @throws ParameterException
+     */
+    public void parameterize(Parameters params) 
+    throws ParameterException {
+        String modeDef = params.getParameter("mode", null);
+        if ( modeDef != null ) {
+            if ( MODEDEF_OBJECT_MODEL.equals(modeDef) ) {
+                this.mode = MODE_OBJECT_MODEL;
+            } else if ( MODEDEF_REQUEST_ATTR.equals(modeDef) ) {
+                this.mode = MODE_REQUEST_ATTR;
+            } else if ( MODEDEF_SESSION_ATTR.equals(modeDef) ) {
+                this.mode = MODE_SESSION_ATTR;
+            } else {
+                throw new ParameterException("Unknown mode: " + this.mode);
+            }
+        }
+    }
+
+    /**
+     * @see org.apache.cocoon.acting.Action#act(org.apache.cocoon.environment.Redirector, org.apache.cocoon.environment.SourceResolver, java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
+     */
+    public Map act(Redirector redirector,
+                   SourceResolver resolver,
+                   Map objectModel,
+                   String source,
+                   Parameters parameters)
+    throws Exception {
+        final String[] names = parameters.getNames();
+        for(int i = 0; i < names.length; i++) {
+            final String name = names[i];
+            if ( this.mode == MODE_OBJECT_MODEL ) {
+                objectModel.put(name, parameters.getParameter(name));                
+            } else if ( this.mode == MODE_REQUEST_ATTR ) {
+                ObjectModelHelper.getRequest(objectModel).setAttribute(name, parameters.getParameter(name));                
+            } else if ( this.mode == MODE_SESSION_ATTR ) {
+                ObjectModelHelper.getRequest(objectModel).getSession().setAttribute(name, parameters.getParameter(name));                
+            }
+        }
+        return EMPTY_MAP;
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/SetterAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/ValidatorActionHelper.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/ValidatorActionHelper.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/ValidatorActionHelper.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/ValidatorActionHelper.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,124 @@
+/*
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.acting;
+
+
+/**
+ * Helper class to pass the result of a validation back along with
+ * the validated object itself.
+ *
+ * @author <a href="mailto:haul@apache.org">Christian Haul</a>
+ * @version CVS $Id: ValidatorActionHelper.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public class ValidatorActionHelper
+{
+    protected ValidatorActionResult result = ValidatorActionResult.OK;
+    protected Object object = null;
+
+    /**
+     * Create a ValidatorActionHelper object that contains just the
+     * object. Defaults to <code>OK</code> as validation result.
+     *
+     * @param validatedObject object that has been validated
+     */
+    public ValidatorActionHelper ( Object validatedObject ) {
+        this.object = validatedObject;
+        this.result = ValidatorActionResult.OK;
+    }
+
+    /**
+     * Create a ValidatorActionHelper object that contains just the
+     * object. Defaults to <code>OK</code> as validation result.
+     *
+     * @param validatedObject object that has been validated
+     * @param validationResult result of the validation
+     */
+    public ValidatorActionHelper ( Object validatedObject, ValidatorActionResult validationResult ) {
+        this.object = validatedObject;
+        this.result = validationResult;
+    }
+
+    /**
+     * Tests if the validation result is <code>OK</code>
+     *
+     */
+    public boolean isOK() {
+        return (result.equals(ValidatorActionResult.OK));
+    }
+
+    /**
+     * Tests if the validation result is <code>NOTPRESENT</code>,
+     * e.g. when the value is null and is allowed to be null.
+     *
+     */
+    public boolean isNotPresent() {
+        return (result.equals(ValidatorActionResult.NOTPRESENT));
+    }
+
+    /**
+     * Tests if the validation result is <code>ISNULL</code>,
+     * e.g. when the value is null but is not supposed to be null.
+     *
+     */
+    public boolean isNull() {
+        return (result.equals(ValidatorActionResult.ISNULL));
+    }
+
+    /**
+     * Tests if the validation result is <code>TOOLARGE</code>,
+     * e.g. in case of a double or long the value is too large or in
+     * case of a string it is too long.
+     *
+     */
+    public boolean isTooLarge() {
+        return (result.equals(ValidatorActionResult.TOOLARGE));
+    }
+
+    /**
+     * Tests if the validation result is <code>TOOSMALL</code>,
+     * e.g. in case of a double or long the value is too small or in
+     * case of a string it is too short.
+     *
+     */
+    public boolean isTooSmall() {
+        return (result.equals(ValidatorActionResult.TOOSMALL));
+    }
+
+    /**
+     * Tests if the validation result is <code>NOMATCH</code>, can
+     * only occur when
+     *
+     */
+    public boolean doesNotMatch() {
+        return (result.equals(ValidatorActionResult.NOMATCH));
+    }
+
+    /**
+     * Returns the tested object.
+     *
+     */
+    public Object getObject() {
+        return object;
+    }
+
+    /**
+     * Returns the result.
+     *
+     */
+    public ValidatorActionResult getResult() {
+        return result;
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/ValidatorActionHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message