cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Davanum Srinivas <d...@yahoo.com>
Subject Re: [patch] RequestParamAction
Date Wed, 11 Jul 2001 15:17:31 GMT
Torsten,

Checked in your patch. Please cross-check.

Thanks,
dims

--- Torsten Curdt <tcurdt@dff.st> wrote:
> Ok, guys,
> 
> I modified the RequestParamAction so the
>  - request URI
>  - request Query
>  - servlet context
> becomes available in the sitemap.
> 
> I also made the populating of the parameters to
> the substitution map configurable (true/false)
> 
> Maybe we should rename the action to RequestDetailsAction
> or something since now it make request detail available
> to the sitemap.
> 
> Hope all this is fine with you Marcus?
> --
> Torsten
> > Index: RequestParamAction.java
> ===================================================================
> RCS file: /home/cvspublic/xml-cocoon2/src/org/apache/cocoon/acting/RequestParamAction.java,v
> retrieving revision 1.2
> diff -u -r1.2 RequestParamAction.java
> --- RequestParamAction.java	2001/07/06 21:35:01	1.2
> +++ RequestParamAction.java	2001/07/11 12:26:40
> @@ -25,10 +25,18 @@
>  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.
> + * 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)
> + *
>   * Sitemap definition:
>   *
>   * <pre>
> @@ -42,7 +50,8 @@
>   * <pre>
>   * &lt;map:match pattern="some-resource"&gt;
>   *  &lt;map:act type="request"&gt;
> - *     &lt;map:redirect-to uri="{dest}"/&gt;
> + *     &lt;map:parameter name="parameters" value="true"/&gt;
> + *     &lt;map:redirect-to uri="{context}/somewhereelse/{dest}"/&gt;
>   *  &lt;/map:act&gt;
>   * &lt;/map:match&gt;
>   * </pre>
> @@ -52,6 +61,7 @@
>   * <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;
> @@ -62,43 +72,52 @@
>   * etc, etc.
>   *
>   * @author <a href="mailto:Marcus.Crafter@osa.de">Marcus Crafter</a>
> + * @author <a href="mailto:tcurdt@dff.st">Torsten Curdt</a>
>   * @version CVS $Revision: 1.2 $
>   */
>  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);
> +    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 Map act( Redirector redirector, SourceResolver resolver, Map objectModel,
String
> source, Parameters param )
> +        throws Exception
> +    {
> + 
> +        Request request = (Request) objectModel.get(Constants.REQUEST_OBJECT);
> +        if (request == null) {
> +          getLogger().error("RequestInfoAction: no request object!");
> +          return(null);
> +        }
> + 
> +        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);
>              }
> -
> -            return map;
> +          }
>          }
> -
> -        return null;
> + 
> +        return(map);
>      }
>  }
> > ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
> For additional commands, email: cocoon-dev-help@xml.apache.org


=====
Davanum Srinivas, JNI-FAQ Manager
http://www.jGuru.com/faq/JNI

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/

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


Mime
View raw message