cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: xml-cocoon2/src/org/apache/cocoon/acting RequestParamAction.java
Date Wed, 11 Jul 2001 15:17:00 GMT
dims        01/07/11 08:16:59

  Modified:    src/org/apache/cocoon/acting Tag: cocoon_20_branch
                        RequestParamAction.java
  Log:
  Patch from Torsten for populating Request Details into the sitemap.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.2   +56 -37    xml-cocoon2/src/org/apache/cocoon/acting/RequestParamAction.java
  
  Index: RequestParamAction.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/acting/RequestParamAction.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- RequestParamAction.java	2001/07/06 21:32:27	1.1.2.1
  +++ RequestParamAction.java	2001/07/11 15:16:54	1.1.2.2
  @@ -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>
  - * @version CVS $Revision: 1.1.2.1 $
  + * @author <a href="mailto:tcurdt@dff.st">Torsten Curdt</a>
  + * @version CVS $Revision: 1.1.2.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);
       }
   }
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org


Mime
View raw message