Hi All, I've just revamped my RequestParamMatcher by turning it into an action, and making it store all request parameters for use in the sitemap, as opposed to specifying the parameter as previously implemented. Attached is the new source file (which can replace the RequestParamMatcher completely, it's compatible with it), and a patch to the webapp showing an example. Limited docs are in the javadoc comments. I've also added the locale action definition to the webapp (forgot to do it in my previous email), and fixed up the locale action's author tags for the docs (sorry Lassi/Konstantin! :-) ) I've had thoughts about extending the RequestParamAction so that it can operate not just with request parameters, but also with session values, context values, etc. Is there be interest out there in having such functionality ? Cheers, hope everyone has a great weekend. Marcus -- ..... ,,$$$$$$$$$, Marcus Crafter ;$' '$$$$: Computer Systems Engineer $: $$$$: Open Software Associates GmbH $ o_)$$$: 82-84 Mainzer Landstrasse ;$, _/\ &&:' 60327 Frankfurt Germany ' /( &&& \_&&&&' Email : [EMAIL PROTECTED] &&&&. Business Hours : +49 69 9757 200 &&&&&&&: After Hours : +49 69 49086750
/***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * * ------------------------------------------------------------------------- * * This software is published under the terms of the Apache Software License * * version 1.1, a copy of which has been included with this distribution in * * the LICENSE file. * *****************************************************************************/ /* * Package definition */ package org.apache.cocoon.acting; /* * Standard imports */ import java.util.HashMap; import java.util.Map; import java.util.Enumeration; import org.apache.cocoon.acting.ComposerAction; import org.apache.cocoon.environment.Request; import org.apache.cocoon.environment.SourceResolver; import org.apache.cocoon.environment.Redirector; import org.apache.cocoon.Constants; import org.apache.avalon.framework.parameters.Parameters; /** * This action makes all request parameters available for use in the sitemap. * A variable is created for each request parameter (only if it doesn't exist) * with the same name as the parameter itself. * * Sitemap definition: * * <pre> * <map:action name="request" src="org.apache.cocoon.acting.RequestParamAction"/> * </pre> * * <p> * * Example use: * * <pre> * <map:match pattern="some-resource"> * <map:act type="request"> * <map:redirect-to uri="{dest}"/> * </map:act> * </map:match> * </pre> * * Redirection is only one example, another use: * * <pre> * <map:match pattern="some-resource"> * <map:act type="request"> * <map:generate src="users/menu-{id}.xml"/> * </map:act> * <map:transform src="menus/personalisation.xsl"/> * <map:serialize/> * </map:match> * </pre> * * etc, etc. * * @author <a href="mailto:[EMAIL PROTECTED]">Marcus Crafter</a> * @version CVS $Revision: 1.3 $ */ public class RequestParamAction extends ComposerAction { /** * Action which makes all request parameters available for xpath * substitution. */ public Map act( Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters par ) throws Exception { Request request = (Request) objectModel.get(Constants.REQUEST_OBJECT); Enumeration e = request.getParameterNames(); if (e.hasMoreElements()) { Map map = new HashMap(); while(e.hasMoreElements()) { String name = (String) e.nextElement(); String value = request.getParameter(name); if (value != null && !map.containsKey(name)) map.put(name, value); } return map; } return null; } }
Index: src/org/apache/cocoon/acting/LocaleAction.java =================================================================== RCS file: /home/cvspublic/xml-cocoon2/src/org/apache/cocoon/acting/LocaleAction.java,v retrieving revision 1.1 diff -u -r1.1 LocaleAction.java --- src/org/apache/cocoon/acting/LocaleAction.java 2001/07/02 19:38:55 1.1 +++ src/org/apache/cocoon/acting/LocaleAction.java 2001/07/06 16:18:27 @@ -107,9 +107,9 @@ * * <center>Code originated from org.apache.cocoon.acting.LangSelect</center> * - * @author: <a href="mailto:[EMAIL PROTECTED]">Marcus Crafter</a> - * @author: <a href="mailto:[EMAIL PROTECTED]">Konstantin Piroumian</a> - * @author: <a href="mailto:[EMAIL PROTECTED]">Lassi Immonen</a> + * @author <a href="mailto:[EMAIL PROTECTED]">Marcus Crafter</a> + * @author <a href="mailto:[EMAIL PROTECTED]">Konstantin Piroumian</a> + * @author <a href="mailto:[EMAIL PROTECTED]">Lassi Immonen</a> */ public class LocaleAction extends ComposerAction { Index: webapp/sitemap.xmap =================================================================== RCS file: /home/cvspublic/xml-cocoon2/webapp/sitemap.xmap,v retrieving revision 1.19 diff -u -r1.19 sitemap.xmap --- webapp/sitemap.xmap 2001/07/04 09:12:52 1.19 +++ webapp/sitemap.xmap 2001/07/06 16:18:39 @@ -29,7 +29,12 @@ <map:transformer name="log" src="org.apache.cocoon.transformation.LogTransformer"/> <map:transformer name="sql" src="org.apache.cocoon.transformation.SQLTransformer"/> <map:transformer name="extractor" src="org.apache.cocoon.transformation.FragmentExtractorTransformer"/> <map:transformer name="i18n" src="org.apache.cocoon.transformation.I18nTransformer"/> <map:transformer name="xinclude" src="org.apache.cocoon.transformation.XIncludeTransformer"/> <map:transformer name="cinclude" src="org.apache.cocoon.transformation.CIncludeTransformer"/> </map:transformers> @@ -89,14 +94,14 @@ <map:matchers default="wildcard"> <map:matcher name="wildcard" src="org.apache.cocoon.matching.WildcardURIMatcherFactory"/> <map:matcher name="regexp" src="org.apache.cocoon.matching.RegexpURIMatcherFactory"/> - <map:matcher name="request" src="org.apache.cocoon.matching.RequestParamMatcher"/> </map:matchers> <map:actions> <map:action name="add-employee" src="org.apache.cocoon.acting.DatabaseAddAction"/> <map:action name="del-employee" src="org.apache.cocoon.acting.DatabaseDeleteAction"/> <map:action name="upd-employee" src="org.apache.cocoon.acting.DatabaseUpdateAction"/> <map:action name="lang-select" src="org.apache.cocoon.acting.LangSelect"/> + <map:action name="locale" src="org.apache.cocoon.acting.LocaleAction"/> + <map:action name="request" src="org.apache.cocoon.acting.RequestParamAction"/> </map:actions> </map:components> @@ -230,6 +235,12 @@ <map:generate src="docs/samples/hello-page.xml"/> <map:transform src="stylesheets/page/simple-page2fo.xsl"/> <map:serialize type="fo2pdf"/> + </map:match> + + <map:match pattern="redirect"> + <map:act type="request"> + <map:redirect-to uri="{dest}"/> + </map:act> </map:match> <!-- ================ Sites =========================== --> Index: webapp/docs/samples/samples.xml =================================================================== RCS file: /home/cvspublic/xml-cocoon2/webapp/docs/samples/samples.xml,v retrieving revision 1.3 diff -u -r1.3 samples.xml --- webapp/docs/samples/samples.xml 2001/05/23 09:40:55 1.3 +++ webapp/docs/samples/samples.xml 2001/07/06 16:18:41 @@ -112,6 +112,9 @@ <sample name="Velocity Generator" href="templates/hello-page.vm"> An example of the VelocityGenerator producing XML out of a Velocity Template. </sample> + <sample name="Parameterised Redirecet" +href="redirect?dest=http://xml.apache.org/"> + An example of redirecting a client based on a request parameter. + </sample> </group> <group name="Web Applications">
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]