Return-Path:
A sample configuration (given in the <map:matchers> section of the
+ * sitemap) is given below. This configuration shows default values.
+ * Above configuration parameters mean:
+ * Configuration
+ *
+ * <map:action name="locale" src="org.apache.cocoon.acting.LocaleAction">
+ * <locale-attribute>locale</locale-attribute>
+ * <use-locale>true</use-locale>
+ * <default-locale language="en" country="US"/>
+ * <store-in-request>false<store-in-request>
+ * <create-session>false<create-session>
+ * <store-in-session>false<store-in-session>
+ * <store-in-cookie>false<store-in-cookie>
+ * </map:action>
+ *
+ *
+ *
+ *
+ * locale
)
This action will be used in a pipeline like so:
+ *+ * <map:act type="locale"> + * <map:generate src="file_{language}_{country}_{variant}.xml"/> + * ... + * </map:match> + *+ *
or
+ *+ * <map:act type="locale"> + * <map:generate src="file_{locale}.xml"/> + * ... + * </map:match> + *+ * + *
Locales will be tested in following order:
+ *use-locale
is set to true
First found locale will be returned.
+ * + *Once locale has been found, the following sitemap variables + * will be available to sitemap elements contained within the action:
+ *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.
+ *
+ * Example configuration:
+ *
+ * <map:action type="...." name="...." logger="...">
+ * <output-module name="session-attr">
+ * <!-- optional configuration for output module -->
+ * </output-module>
+ * <store-empty-parameters>true</store-empty-parameters>
+ * <defaults>
+ * <default name="..." value="...."/>
+ * <default name="..." value="..."/>
+ * </defaults>
+ * </map:action>
+ *
+ *
+ * Example use:
+ *
+ * <map:act type="session-propagator">
+ * <paramater name="example" value="{example}"/>
+ * <paramater name="example1" value="xxx"/>
+ * <parameter name="PropagatorAction:store-empty-parameters" value="true"/>
+ * <parameter name="PropagatorAction:output-module" value="session-attr"/>
+ * </map:act>
+ *
+ *
+ * Configuration
+ *
+ *
+ * output-module
+ * Nested element configuring output to use. Name attribute holds
+ * output module hint.
+ * XML request-attr
+ *
+ *
+ * store-empty-parameters
+ * Propagate parameters with empty values.
+ * boolean true
+ *
+ *
+ * defaults
+ * Parent for default parameters to propagate.
+ * XML
+ *
+ *
+ * defaults/default
+ * Name attribute holds parameter name, value attribute holds
+ * parameter value. Will be used when not set on use.
+ * parameter
+ *
+ *
+ *
+ *Parameters
+ *
+ *
+ * PropagatorAction:output-module
+ * Alternative output module hint to use. A null
configuration
+ * will be passed to a module selected this way.
+ * String as determined by configuration
+ *
+ *
+ * PropagatorAction:store-empty-parameters
+ * Propagate parameters with empty values.
+ * boolean as determined by configuration
+ *
+ *
+ * any other
+ * Any other parameter will be propagated.
+ * String
+ *
+ *
+ *
+ * @author Christian Haul
+ * @author Martin Man
+ * @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.".
+ *
+ * Sitemap definition:
+ *
+ *
+ * <map:action name="request" src="org.apache.cocoon.acting.RequestParamAction"/>
+ *
+ *
+ *
+ *
+ * Example use:
+ *
+ *
+ * <map:match pattern="some-resource">
+ * <map:act type="request">
+ * <map:parameter name="parameters" value="true"/>
+ * <map:parameter name="default.dest" value="invalid-destination.html"/>
+ * <map:redirect-to uri="{context}/somewhereelse/{dest}"/>
+ * </map:act>
+ * </map:match>
+ *
+ *
+ * Redirection is only one example, another use:
+ *
+ *
+ * <map:match pattern="some-resource">
+ * <map:act type="request">
+ * <map:parameter name="parameters" value="true"/>
+ * <map:generate src="users/menu-{id}.xml"/>
+ * </map:act>
+ * <map:transform src="menus/personalisation.xsl"/>
+ * <map:serialize/>
+ * </map:match>
+ *
+ *
+ * etc, etc.
+ *
+ * @author Marcus Crafter
+ * @author Torsten Curdt
+ * @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.
+ *
+ * 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.
One special feature is, however, that parameters
+ * can contain one 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.
+ *
+ * @author Christian Haul
+ * @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 src
+ * sitemap attribute exists or not. The action returns empty Map
if
+ * resource exists, null
otherwise.
+ *
+ * Instead of src attribute, source can be specified using
+ * parameter named url
(this is old syntax, should be removed soon).
+ *
+ *
NOTE: {@link org.apache.cocoon.selection.ResourceExistsSelector}
+ * should be preferred to this component, as the semantics of a Selector better
+ * matches the supplied functionality.
+ *
+ * @author Donald Ball
+ * @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 ServiceableAction
will allow any Action
+ * that extends this to access SitemapComponents.
+ *
+ * @author Carsten Ziegeler
+ * @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 ServiceManager
instance used by this
+ * Serviceable
.
+ */
+ 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 Martin Man
+ * @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 Christian Haul
+ * @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.
+ *
+ *
+ * <map:act type="session-propagator">
+ * <paramater name="example" value="{example}">
+ * <paramater name="example1" value="xxx">
+ * </map:act>
+ *
+ *
+ * @author Martin Man
+ * @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.
+ *
+ * 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.
+ *
+ * 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 one 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.
+ *
+ * Global and local parameters:
+ *
+ *
+ *
+ * state-key-prefix
+ * 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
+ * "__sessionState
", sub-levels is 2, attributes
+ * "__sessionState1
", "__sessionState2
", and
+ * "__sessionState3
" will be used to store the
+ * information.
+ *
+ *
+ *
+ * new-state
+ * String that identifies the current state
+ *
+ *
+ * sub-levels
+ * Number of sub levels to use
+ *
+ *
+ * state-level
+ * Sub level to modify, this is one based
+ *
+ *
+ *
+ * @see org.apache.cocoon.matching.WildcardSessionAttributeMatcher
+ * @see org.apache.cocoon.selection.SessionAttributeSelector
+ *
+ * @author Christian Haul
+ * @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 Martin Man
+ * @author Christian Haul
+ * @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.
+ *
+ * Configuration parameters:
+ *
+ * - form-encoding (optional)
+ *
- The supposed encoding of the request parameter.
+ *
+ * These configuration options supported in both declaration and use time.
+ * If no encoding specified, the action does nothing.
+ *
+ * @author MIYABE Tatsuhiko
+ * @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 Christian Haul
+ * @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 OK
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 OK
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 OK
+ *
+ */
+ public boolean isOK() {
+ return (result.equals(ValidatorActionResult.OK));
+ }
+
+ /**
+ * Tests if the validation result is NOTPRESENT
,
+ * 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 ISNULL
,
+ * 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 TOOLARGE
,
+ * 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 TOOSMALL
,
+ * 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 NOMATCH
, 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