cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject cvs commit: xml-cocoon2/src/org/apache/cocoon/acting RequestParamAction.java
Date Wed, 26 Sep 2001 13:15:59 GMT
cziegeler    01/09/26 06:15:59

  Modified:    src/org/apache/cocoon/acting RequestParamAction.java
  Log:
  Default value support for RequestParamAction
  Submitted by: Sergio Carvalho [sergio.carvalho@acm.org]
  
  Revision  Changes    Path
  1.6       +18 -1     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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- RequestParamAction.java	2001/08/22 12:03:32	1.5
  +++ RequestParamAction.java	2001/09/26 13:15:59	1.6
  @@ -38,6 +38,9 @@
    * (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.<parameter-name>".
  + *
    * Sitemap definition:
    *
    * <pre>
  @@ -52,6 +55,7 @@
    * &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;
  @@ -74,7 +78,7 @@
    *
    * @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.5 $
  + * @version CVS $Revision: 1.6 $
    */
   public class RequestParamAction extends ComposerAction implements ThreadSafe {
   
  @@ -83,6 +87,8 @@
       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
  @@ -113,10 +119,21 @@
             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);
  
  
  

----------------------------------------------------------------------
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