You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by SAXESS - Hussayn Dabbous <da...@saxess.com> on 2003/02/11 12:16:18 UTC

enhancement of RequestParamAction

Hy, all;

i had a problem with RequestParamAction (cocoon-2.0.4). I enclose
the Source of a slightly modified version of RequestParamAction
that solves my problem. The class is named ExtendedRequestParamAction,
i did a little of refactoring and a bit on the documentation
of the class. In case it makes sense, i would be glad if someone
could replace the body of RequestParamAction with the body of my
modified class, which is fully compatible to the original.
(I don't know how to apply a patch myself ...)

In the following i explain, why i made the modifications:

The problem:
------------

I want to use the requestQuery of an incoming request in my sitemap
as follows:

<map:match pattern="*/canvas/search_mask">
   <map:act type="request" >
     <map:parameter name="default.fieldtype" value="required"/>
     <map:generate src="http:/hmyserver/result{requestQuery}"/>
   </map:act>
   <map:serialize type = "xml"/>
</map:match>

This would forward the GET parameters of the original request to the 
HTTP call for the src in map:generate.
In addition i want to forward the parameter fieldtype. How would i do
this with RequestParamAction ?

The RequestParamAction can't help me there because:

1.) It won't add the fieldtype to the requestQuery automatically.
     so i must add it myself, e.g. like this:

     <map:generate
      src="http:/hmyserver/result{requestQuery}&fieldtype={fieldtype}"/>

     This fails, if {requestQuery} happens to be empty. Due to the
     treatment of requestQuery in the code i would miss the
     beginning "?" of my querylist in that case.

     <map:generate
      src="http:/hmyserver/result?fieldtype={fieldtype}&{requestQuery}"/>

     wouldn't work either. In this case i would end with duplicate "?",
     if requestQuery is NOT empty.

2.) I could use the parameters="true":

     <map:act type="request" >
       <map:parameter name="default.fieldtype" value="required"/>
       <map:parameter name="parameters" value="true"/>
       <map:generate ...

      Then i need to know exactly, which parameters are given in the
      original request and i would need to specify each parameter
      in the sitemap, which i don't want (i even don't know, which
      parameters are enclosed in the list).


the solution
------------

In order to get around this problem i added a new parameter named
"usedefaults". If this parameter is given in the sitemap, then
all default parameters, which are not allready set in the query are
automatically added to the requestQuery string.

By this i can now setup my sitemap as follows:

<map:match pattern="*/canvas/search_mask">
   <map:act type="request" >
     <map:parameter name="usedefault" value="true"/>
     <map:parameter name="default.fieldtype" value="required"/>
     <map:generate src="http:/hmyserver/result.jsp{requestQuery}"/>
   </map:act>
   <map:serialize type = "xml"/>
</map:match>

and i am shure, fieldtype is enclosed in the requestQuery, either
from the request itself, or added by the action.

limitations
-----------

default parameters are always added after the original queryString,
hence i have no control of the insertion place in the queryList. This
may be necessary in some pathological cases.


regards, Hussayn

Re: enhancement of RequestParamAction

Posted by Konstantin Piroumian <kp...@apache.org>.
From: "SAXESS - Hussayn Dabbous" <da...@saxess.com>

> hy, Konstantin;
>
> thanks for the input. i was not aware of these possibilities.
> Where could i learn something more about this ?
> I only use 2.0.4 Maybe this is something newer ?
> Also i heard rumours, that input modules should not yet
> be used in production, because they are under discussion ?

There were under discussion, but it seems that it's settled a little. And
also they were ported to 2.0 branch, so you can use them even now.

Where could you learn about them? Hm... There were a short document
somewhere in User docs/Concepts and a sample in 2.1 version. Not sure that
the samples were ported too. So it's worth looking at 2.1 from CVS or
nightly build. You'll find the sample at /src/webapp/samples/modules.

>
> Just two points i don't understand:
>
> 1.)
>
> src="http:/hmyserver/result?fieldtype=aFieldType&{request.queryString}"
>
> Does this imply, that i could access also the request-parameters
> using this very same syntax ?, e.g. could i write down:
>
> src="http:/hmyserver/result?fieldtype=aFieldType&{request.mycgiparam}"
>
> Would this also imply that RequestParamAction is obsolete ?

Not exact, but something like this should work:
src="http:/hmyserver/result?fieldtype=aFieldType&{request-param.mycgiparam}"

and yes. One of the main advantages of input modules is that you can avoid
action usage with their innatural nesting syntax.

Btw, if Cocoon's request implemented getParameterMap() then it'd be possible
to use this syntax:
{request:parameterMap[@name='mycgiparam']}
and even
{request:parameterMap[@name='mycgiparam'][1]}

>
> 2.)
>
> Could anyone point me to an example snippet where the XPath
> functionality is explained in little more detail ?
> I am very interested in this, but it would help to get
> an initial push ...
> i.e. where in the sitemap would i place the
> {request:translate(queryString, '&', ';')} to get this
> transformation done ?

It's worth to take a look at the underlying JXPath project docs at
http://jakarta.apache.org/commons/jxpath and the declaration of input
modules in cocoon.xconf. Also, a very good start is the mentioned above
modules sample, just take a look at its sitemap and you'll get the idea.

Hope my English was understandable ;)

Konstantin

>
>
> regards, Hussayn
>
>
> Konstantin Piroumian wrote:
> > Btw, why don't you use input modules instead?
> > You could do something like this:
> >
> > <map:generate
> >
src="http:/hmyserver/result?fieldtype=aFieldType&{request.queryString}"/>
> >
> > You can also use XPath functions to perform some special handling, e.g.:
> >
> > {request:translate(queryString, '&', ';')} - this will replace all
> > ampersands by a semicolon.
> >
> > Konstantin
> >
> > ----- Original Message -----
> > From: "SAXESS - Hussayn Dabbous" <da...@saxess.com>
> > To: <co...@xml.apache.org>
> > Sent: Tuesday, February 11, 2003 14:16
> > Subject: enhancement of RequestParamAction
> >
> >
> >
> >>Hy, all;
> >>
> >>i had a problem with RequestParamAction (cocoon-2.0.4). I enclose
> >>the Source of a slightly modified version of RequestParamAction
> >>that solves my problem. The class is named ExtendedRequestParamAction,
> >>i did a little of refactoring and a bit on the documentation
> >>of the class. In case it makes sense, i would be glad if someone
> >>could replace the body of RequestParamAction with the body of my
> >>modified class, which is fully compatible to the original.
> >>(I don't know how to apply a patch myself ...)
> >>
> >>In the following i explain, why i made the modifications:
> >>
> >>The problem:
> >>------------
> >>
> >>I want to use the requestQuery of an incoming request in my sitemap
> >>as follows:
> >>
> >><map:match pattern="*/canvas/search_mask">
> >>   <map:act type="request" >
> >>     <map:parameter name="default.fieldtype" value="required"/>
> >>     <map:generate src="http:/hmyserver/result{requestQuery}"/>
> >>   </map:act>
> >>   <map:serialize type = "xml"/>
> >></map:match>
> >>
> >>This would forward the GET parameters of the original request to the
> >>HTTP call for the src in map:generate.
> >>In addition i want to forward the parameter fieldtype. How would i do
> >>this with RequestParamAction ?
> >>
> >>The RequestParamAction can't help me there because:
> >>
> >>1.) It won't add the fieldtype to the requestQuery automatically.
> >>     so i must add it myself, e.g. like this:
> >>
> >>     <map:generate
> >>      src="http:/hmyserver/result{requestQuery}&fieldtype={fieldtype}"/>
> >>
> >>     This fails, if {requestQuery} happens to be empty. Due to the
> >>     treatment of requestQuery in the code i would miss the
> >>     beginning "?" of my querylist in that case.
> >>
> >>     <map:generate
> >>
src="http:/hmyserver/result?fieldtype={fieldtype}&{requestQuery}"/>
> >>
> >>     wouldn't work either. In this case i would end with duplicate "?",
> >>     if requestQuery is NOT empty.
> >>
> >>2.) I could use the parameters="true":
> >>
> >>     <map:act type="request" >
> >>       <map:parameter name="default.fieldtype" value="required"/>
> >>       <map:parameter name="parameters" value="true"/>
> >>       <map:generate ...
> >>
> >>      Then i need to know exactly, which parameters are given in the
> >>      original request and i would need to specify each parameter
> >>      in the sitemap, which i don't want (i even don't know, which
> >>      parameters are enclosed in the list).
> >>
> >>
> >>the solution
> >>------------
> >>
> >>In order to get around this problem i added a new parameter named
> >>"usedefaults". If this parameter is given in the sitemap, then
> >>all default parameters, which are not allready set in the query are
> >>automatically added to the requestQuery string.
> >>
> >>By this i can now setup my sitemap as follows:
> >>
> >><map:match pattern="*/canvas/search_mask">
> >>   <map:act type="request" >
> >>     <map:parameter name="usedefault" value="true"/>
> >>     <map:parameter name="default.fieldtype" value="required"/>
> >>     <map:generate src="http:/hmyserver/result.jsp{requestQuery}"/>
> >>   </map:act>
> >>   <map:serialize type = "xml"/>
> >></map:match>
> >>
> >>and i am shure, fieldtype is enclosed in the requestQuery, either
> >>from the request itself, or added by the action.
> >>
> >>limitations
> >>-----------
> >>
> >>default parameters are always added after the original queryString,
> >>hence i have no control of the insertion place in the queryList. This
> >>may be necessary in some pathological cases.
> >>
> >>
> >>regards, Hussayn
> >>
> >
> >
> >
>
> --------------------------------------------------------------------------
--
> > ----
> >
> >
> >
> >>/*
> >>
> >>
> >
> >
============================================================================
> >
> >>                   The Apache Software License, Version 1.1
> >>
> >
> >
============================================================================
> >
> >> Copyright (C) 1999-2002 The Apache Software Foundation. All rights
> >
> > reserved.
> >
> >> Redistribution and use in source and binary forms, with or without
> >
> > modifica-
> >
> >> tion, are permitted provided that the following conditions are met:
> >>
> >> 1. Redistributions of  source code must  retain the above copyright
> >
> > notice,
> >
> >>    this list of conditions and the following disclaimer.
> >>
> >> 2. Redistributions in binary form must reproduce the above copyright
> >
> > notice,
> >
> >>    this list of conditions and the following disclaimer in the
> >
> > documentation
> >
> >>    and/or other materials provided with the distribution.
> >>
> >> 3. The end-user documentation included with the redistribution, if any,
> >
> > must
> >
> >>    include  the following  acknowledgment:  "This product includes
> >
> > software
> >
> >>    developed  by the  Apache Software Foundation
> >
> > (http://www.apache.org/)."
> >
> >>    Alternately, this  acknowledgment may  appear in the software
itself,
> >
> > if
> >
> >>    and wherever such third-party acknowledgments normally appear.
> >>
> >> 4. The names "Apache Cocoon" and  "Apache Software Foundation" must
not
> >
> > be
> >
> >>    used to  endorse or promote  products derived from  this software
> >
> > without
> >
> >>    prior written permission. For written permission, please contact
> >>    apache@apache.org.
> >>
> >> 5. Products  derived from this software may not  be called "Apache",
nor
> >
> > may
> >
> >>    "Apache" appear  in their name,  without prior written permission
of
> >
> > the
> >
> >>    Apache Software Foundation.
> >>
> >> THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
> >
> > WARRANTIES,
> >
> >> INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY
> >
> > AND
> >
> >> FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL
> >
> > THE
> >
> >> APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY
> >
> > DIRECT,
> >
> >> INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES
> >
> > (INCLU-
> >
> >> DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES;
> >
> > LOSS
> >
> >> OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED
AND
> >
> > ON
> >
> >> ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR
> >
> > TORT
> >
> >> (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE
USE
> >
> > OF
> >
> >> THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> >>
> >> This software  consists of voluntary contributions made  by many
> >
> > individuals
> >
> >> on  behalf of the Apache Software  Foundation and was  originally
created
> >
> > by
> >
> >> Stefano Mazzocchi  <st...@apache.org>. For more  information on the
> >
> > Apache
> >
> >> Software Foundation, please see <http://www.apache.org/>.
> >>
> >>*/
> >>package org.apache.cocoon.acting;
> >>
> >>/*
> >> * Standard imports
> >> */
> >>import org.apache.avalon.framework.parameters.Parameters;
> >>import org.apache.avalon.framework.thread.ThreadSafe;
> >>import org.apache.cocoon.Constants;
> >>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.Enumeration;
> >>import java.util.HashMap;
> >>import java.util.Map;
> >>
> >>/**
> >> * This action makes some request details available to the sitemap via
> >
> > parameter
> >
> >> * substitution. Within this action context following parameters get
> >
> > available:
> >
> >> *
> >> *
> >> * OUPTUT PARAMETERS
> >> * =================
> >> * output parameters available within the action context:
> >> *
> >> * {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 are
> >> *                  GET params available
> >> *
> >> * These parameters are always available.
> >> *
> >> *
> >> * CONTROL PARAMETERS
> >> * ==================
> >> * The action can be further controlled via sitemap arameters:
> >> *
> >> * sitemap parameters:
> >> *
> >> * parameters="true"  - all request parameters are made available as
> >> *                      sitemap params using their names.
> >> * usedefaults="true" - default values (see below) will be added to
> >> *                      requestQuery if not allready exisiting in
> >
> > requestQuery
> >
> >> *
> >> * All control parameters can be used in parallel.
> >> *
> >> *
> >> * CREATING DEFAULT VALUES
> >> * =======================
> >> * Default values can be set for request parameters, by including
> >> * sitemap parameters following the syntax "default.<parameter-name>".
> >> *
> >> *
> >> * Sitemap definition:
> >> *
> >> * <pre>
> >> * &lt;map:action name="request"
> >
> > src="org.apache.cocoon.acting.ExtendedRequestParamAction"/&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>
> >> * @author <a href="mailto:hussayn.dabbous@saxess.com">Hussayn
Dabbous</a>
> >> */
> >>public class ExtendedRequestParamAction extends ComposerAction
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_USEDEFAULTS    = "usedefaults";
> >>    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);
> >>        if (request == null) {
> >>          getLogger().error("RequestInfoAction: no request object!");
> >>          return(null);
> >>        }
> >>
> >>        Map map = new HashMap();
> >>
> >>        map.put(MAP_URI, request.getRequestURI());
> >>        map.put(MAP_CONTEXTPATH, request.getContextPath());
> >>
> >>String query = request.getQueryString();
> >>
> >>boolean usedefaults =
> >
> > ("true".equalsIgnoreCase(param.getParameter(PARAM_USEDEFAULTS, null)));
> >
> >>        boolean setparams   =
> >
> > ("true".equalsIgnoreCase(param.getParameter(PARAM_PARAMETERS, null)));
> >
> >>        if (setparams){
> >>          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);
> >>            }
> >>          }
> >>        }
> >>
> >>        if(setparams || usedefaults) {
> >>        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)) {
> >
> >>          String name =
> >
> > paramNames[i].substring(PARAM_DEFAULT_PREFIX.length());
> >
> >>          String value= param.getParameter(paramNames[i]);
> >>          if(setparams) map.put(name, value);
> >>          if(usedefaults){
> >>          if(query==null) query=""; else query +="&";
> >>          query += name+"="+value;
> >>          }
> >>          }
> >>          }
> >>        }
> >>
> >>        if (query != null && query.length() > 0){
> >>          map.put(MAP_QUERY, "?" + query);
> >>        }
> >>        else{
> >>          map.put(MAP_QUERY, "");
> >>        }
> >>        return(map);
> >>    }
> >>}
> >>
> >>
> >
> >
> >
>
> --------------------------------------------------------------------------
--
> > ----
> >
> >
> >
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
> >>For additional commands, email: cocoon-dev-help@xml.apache.org
> >
> >
>
> --
> Dr. Hussayn Dabbous
> SAXESS Software Design GmbH
> Neuenhöfer Allee 125
> 50935 Köln
> Telefon: +49-221-56011-0
> Fax:     +49-221-56011-20
> E-Mail:  dabbous@saxess.com
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Re: enhancement of RequestParamAction

Posted by Konstantin Piroumian <kp...@apache.org>.
Btw, why don't you use input modules instead?
You could do something like this:

<map:generate
src="http:/hmyserver/result?fieldtype=aFieldType&{request.queryString}"/>

You can also use XPath functions to perform some special handling, e.g.:

{request:translate(queryString, '&', ';')} - this will replace all
ampersands by a semicolon.

Konstantin

----- Original Message -----
From: "SAXESS - Hussayn Dabbous" <da...@saxess.com>
To: <co...@xml.apache.org>
Sent: Tuesday, February 11, 2003 14:16
Subject: enhancement of RequestParamAction


> Hy, all;
>
> i had a problem with RequestParamAction (cocoon-2.0.4). I enclose
> the Source of a slightly modified version of RequestParamAction
> that solves my problem. The class is named ExtendedRequestParamAction,
> i did a little of refactoring and a bit on the documentation
> of the class. In case it makes sense, i would be glad if someone
> could replace the body of RequestParamAction with the body of my
> modified class, which is fully compatible to the original.
> (I don't know how to apply a patch myself ...)
>
> In the following i explain, why i made the modifications:
>
> The problem:
> ------------
>
> I want to use the requestQuery of an incoming request in my sitemap
> as follows:
>
> <map:match pattern="*/canvas/search_mask">
>    <map:act type="request" >
>      <map:parameter name="default.fieldtype" value="required"/>
>      <map:generate src="http:/hmyserver/result{requestQuery}"/>
>    </map:act>
>    <map:serialize type = "xml"/>
> </map:match>
>
> This would forward the GET parameters of the original request to the
> HTTP call for the src in map:generate.
> In addition i want to forward the parameter fieldtype. How would i do
> this with RequestParamAction ?
>
> The RequestParamAction can't help me there because:
>
> 1.) It won't add the fieldtype to the requestQuery automatically.
>      so i must add it myself, e.g. like this:
>
>      <map:generate
>       src="http:/hmyserver/result{requestQuery}&fieldtype={fieldtype}"/>
>
>      This fails, if {requestQuery} happens to be empty. Due to the
>      treatment of requestQuery in the code i would miss the
>      beginning "?" of my querylist in that case.
>
>      <map:generate
>       src="http:/hmyserver/result?fieldtype={fieldtype}&{requestQuery}"/>
>
>      wouldn't work either. In this case i would end with duplicate "?",
>      if requestQuery is NOT empty.
>
> 2.) I could use the parameters="true":
>
>      <map:act type="request" >
>        <map:parameter name="default.fieldtype" value="required"/>
>        <map:parameter name="parameters" value="true"/>
>        <map:generate ...
>
>       Then i need to know exactly, which parameters are given in the
>       original request and i would need to specify each parameter
>       in the sitemap, which i don't want (i even don't know, which
>       parameters are enclosed in the list).
>
>
> the solution
> ------------
>
> In order to get around this problem i added a new parameter named
> "usedefaults". If this parameter is given in the sitemap, then
> all default parameters, which are not allready set in the query are
> automatically added to the requestQuery string.
>
> By this i can now setup my sitemap as follows:
>
> <map:match pattern="*/canvas/search_mask">
>    <map:act type="request" >
>      <map:parameter name="usedefault" value="true"/>
>      <map:parameter name="default.fieldtype" value="required"/>
>      <map:generate src="http:/hmyserver/result.jsp{requestQuery}"/>
>    </map:act>
>    <map:serialize type = "xml"/>
> </map:match>
>
> and i am shure, fieldtype is enclosed in the requestQuery, either
> from the request itself, or added by the action.
>
> limitations
> -----------
>
> default parameters are always added after the original queryString,
> hence i have no control of the insertion place in the queryList. This
> may be necessary in some pathological cases.
>
>
> regards, Hussayn
>


----------------------------------------------------------------------------
----


> /*
>
>
============================================================================
>                    The Apache Software License, Version 1.1
>
============================================================================
>
>  Copyright (C) 1999-2002 The Apache Software Foundation. All rights
reserved.
>
>  Redistribution and use in source and binary forms, with or without
modifica-
>  tion, are permitted provided that the following conditions are met:
>
>  1. Redistributions of  source code must  retain the above copyright
notice,
>     this list of conditions and the following disclaimer.
>
>  2. Redistributions in binary form must reproduce the above copyright
notice,
>     this list of conditions and the following disclaimer in the
documentation
>     and/or other materials provided with the distribution.
>
>  3. The end-user documentation included with the redistribution, if any,
must
>     include  the following  acknowledgment:  "This product includes
software
>     developed  by the  Apache Software Foundation
(http://www.apache.org/)."
>     Alternately, this  acknowledgment may  appear in the software itself,
if
>     and wherever such third-party acknowledgments normally appear.
>
>  4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not
be
>     used to  endorse or promote  products derived from  this software
without
>     prior written permission. For written permission, please contact
>     apache@apache.org.
>
>  5. Products  derived from this software may not  be called "Apache", nor
may
>     "Apache" appear  in their name,  without prior written permission  of
the
>     Apache Software Foundation.
>
>  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES,
>  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND
>  FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL
THE
>  APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY
DIRECT,
>  INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES
(INCLU-
>  DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES;
LOSS
>  OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND
ON
>  ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR
TORT
>  (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE
OF
>  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
>
>  This software  consists of voluntary contributions made  by many
individuals
>  on  behalf of the Apache Software  Foundation and was  originally created
by
>  Stefano Mazzocchi  <st...@apache.org>. For more  information on the
Apache
>  Software Foundation, please see <http://www.apache.org/>.
>
> */
> package org.apache.cocoon.acting;
>
> /*
>  * Standard imports
>  */
> import org.apache.avalon.framework.parameters.Parameters;
> import org.apache.avalon.framework.thread.ThreadSafe;
> import org.apache.cocoon.Constants;
> 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.Enumeration;
> import java.util.HashMap;
> import java.util.Map;
>
> /**
>  * This action makes some request details available to the sitemap via
parameter
>  * substitution. Within this action context following parameters get
available:
>  *
>  *
>  * OUPTUT PARAMETERS
>  * =================
>  * output parameters available within the action context:
>  *
>  * {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 are
>  *                  GET params available
>  *
>  * These parameters are always available.
>  *
>  *
>  * CONTROL PARAMETERS
>  * ==================
>  * The action can be further controlled via sitemap arameters:
>  *
>  * sitemap parameters:
>  *
>  * parameters="true"  - all request parameters are made available as
>  *                      sitemap params using their names.
>  * usedefaults="true" - default values (see below) will be added to
>  *                      requestQuery if not allready exisiting in
requestQuery
>  *
>  * All control parameters can be used in parallel.
>  *
>  *
>  * CREATING DEFAULT VALUES
>  * =======================
>  * Default values can be set for request parameters, by including
>  * sitemap parameters following the syntax "default.<parameter-name>".
>  *
>  *
>  * Sitemap definition:
>  *
>  * <pre>
>  * &lt;map:action name="request"
src="org.apache.cocoon.acting.ExtendedRequestParamAction"/&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>
>  * @author <a href="mailto:hussayn.dabbous@saxess.com">Hussayn Dabbous</a>
>  */
> public class ExtendedRequestParamAction extends ComposerAction 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_USEDEFAULTS    = "usedefaults";
>     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);
>         if (request == null) {
>           getLogger().error("RequestInfoAction: no request object!");
>           return(null);
>         }
>
>         Map map = new HashMap();
>
>         map.put(MAP_URI, request.getRequestURI());
>         map.put(MAP_CONTEXTPATH, request.getContextPath());
>
> String query = request.getQueryString();
>
> boolean usedefaults =
("true".equalsIgnoreCase(param.getParameter(PARAM_USEDEFAULTS, null)));
>         boolean setparams   =
("true".equalsIgnoreCase(param.getParameter(PARAM_PARAMETERS, null)));
>         if (setparams){
>           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);
>             }
>           }
>         }
>
>         if(setparams || usedefaults) {
>         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)) {
>           String name =
paramNames[i].substring(PARAM_DEFAULT_PREFIX.length());
>           String value= param.getParameter(paramNames[i]);
>           if(setparams) map.put(name, value);
>           if(usedefaults){
>           if(query==null) query=""; else query +="&";
>           query += name+"="+value;
>           }
>           }
>           }
>         }
>
>         if (query != null && query.length() > 0){
>           map.put(MAP_QUERY, "?" + query);
>         }
>         else{
>           map.put(MAP_QUERY, "");
>         }
>         return(map);
>     }
> }
>
>


----------------------------------------------------------------------------
----


> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
> For additional commands, email: cocoon-dev-help@xml.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Re: enhancement of RequestParamAction

Posted by Vadim Gritsenko <va...@verizon.net>.
SAXESS - Hussayn Dabbous wrote:

> Hy, all;
>
> i had a problem with RequestParamAction (cocoon-2.0.4). I enclose
> the Source of a slightly modified version of RequestParamAction
> that solves my problem. The class is named ExtendedRequestParamAction,
> i did a little of refactoring and a bit on the documentation
> of the class. In case it makes sense, i would be glad if someone
> could replace the body of RequestParamAction with the body of my
> modified class, which is fully compatible to the original.
> (I don't know how to apply a patch myself ...)


It's simple:
$ cd xml-cocoon2/src/..../acting
$ cvs diff -u RequestParamAction.java > RequestParamAction.diff

If you don't have CVS checkout:
$ diff -u RequestParamAction.java ModifiedRequestParamAction.java > 
RequestParamAction.diff

If you don't have diff and you are using Win:
   www.cygwin.com


After that, you create a bug in bugzilla and attach diff to it.


Vadim

<snip/>



---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org