craigmcc    01/02/02 19:23:25

  Modified:    src/doc  struts-bean.xml
               src/share/org/apache/struts/taglib/bean CookieTag.java
                        HeaderTag.java ParameterTag.java
               web/test bean-cookie.jsp bean-header.jsp bean-parameter.jsp
  Log:
  Implement a default "value" attribute on <bean:cookie>, <bean:header>, and
  <bean:parameter> that specify what is returned, instead of a runtime
  exception, if the specified cookie, header, or parameter is not included
  on this request.
  
  PR: BugZilla Bug #493
  Submitted by:  [EMAIL PROTECTED] (Rusty Knabe)
  
  Revision  Changes    Path
  1.18      +36 -6     jakarta-struts/src/doc/struts-bean.xml
  
  Index: struts-bean.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/doc/struts-bean.xml,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- struts-bean.xml   2001/01/26 20:12:32     1.17
  +++ struts-bean.xml   2001/02/03 03:23:24     1.18
  @@ -50,8 +50,8 @@
       (if <code>multiple</code> is not specified) or <code>Cookie[]</code>
       (if <code>multiple</code> is specified).</p>
   
  -    <p>If no cookie with the specified name can be located, a request time
  -    exception will be thrown.</p>
  +    <p>If no cookie with the specified name can be located, and no default
  +    value is specified, a request time exception will be thrown.</p>
       </info>
   
       <attribute>
  @@ -88,6 +88,16 @@
         </info>
       </attribute>
   
  +    <attribute>
  +      <name>value</name>
  +      <required>false</required>
  +      <rtexprvalue>true</rtexprvalue>
  +      <info>
  +      <p>The default cookie value to return if no cookie with the
  +      specified name was included in this request.</p>
  +      </info>
  +    </attribute>
  +
     </tag>
   
   
  @@ -241,8 +251,8 @@
       (if <code>multiple</code> is not specified) or <code>String[]</code>
       (if <code>multiple</code> is specified).</p>
   
  -    <p>If no header with the specified name can be located, a request time
  -    exception will be thrown.</p>
  +    <p>If no header with the specified name can be located, and no default
  +    value is specified, a request time exception will be thrown.</p>
       </info>
   
       <attribute>
  @@ -280,6 +290,16 @@
         </info>
       </attribute>
   
  +    <attribute>
  +      <name>value</name>
  +      <required>false</required>
  +      <rtexprvalue>true</rtexprvalue>
  +      <info>
  +      <p>The default header value to return if no header with the
  +      specified name was included in this request.</p>
  +      </info>
  +    </attribute>
  +
     </tag>
   
   
  @@ -534,8 +554,8 @@
       (if <code>multiple</code> is not specified) or <code>String[]</code>
       (if <code>multiple</code> is specified).</p>
   
  -    <p>If no request parameter with the specified name can be located, a
  -    request time exception will be thrown.</p>
  +    <p>If no request parameter with the specified name can be located, and
  +    no default value is specified, a request time exception will be thrown.</p>
       </info>
   
       <attribute>
  @@ -570,6 +590,16 @@
         <info>
         <p>Specifies the name of the request parameter whose value, or values,
         is to be retrieved.</p>
  +      </info>
  +    </attribute>
  +
  +    <attribute>
  +      <name>value</name>
  +      <required>false</required>
  +      <rtexprvalue>true</rtexprvalue>
  +      <info>
  +      <p>The default parameter value to return if no parameter with the
  +      specified name was included in this request.</p>
         </info>
       </attribute>
   
  
  
  
  1.7       +21 -4     
jakarta-struts/src/share/org/apache/struts/taglib/bean/CookieTag.java
  
  Index: CookieTag.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/bean/CookieTag.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- CookieTag.java    2000/12/28 02:09:08     1.6
  +++ CookieTag.java    2001/02/03 03:23:24     1.7
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/bean/CookieTag.java,v 1.6 
2000/12/28 02:09:08 craigmcc Exp $
  - * $Revision: 1.6 $
  - * $Date: 2000/12/28 02:09:08 $
  + * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/bean/CookieTag.java,v 1.7 
2001/02/03 03:23:24 craigmcc Exp $
  + * $Revision: 1.7 $
  + * $Date: 2001/02/03 03:23:24 $
    *
    * ====================================================================
    *
  @@ -82,7 +82,7 @@
    * cookie received with this request.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.6 $ $Date: 2000/12/28 02:09:08 $
  + * @version $Revision: 1.7 $ $Date: 2001/02/03 03:23:24 $
    */
   
   public class CookieTag extends TagSupport {
  @@ -142,6 +142,20 @@
       }
   
   
  +    /**
  +     * The default value to return if no cookie of the specified name is found.
  +     */
  +    protected String value = null;
  +
  +    public String getValue() {
  +        return (this.value);
  +    }
  +
  +    public void setValue(String value) {
  +        this.value = value;
  +    }
  +
  +
       // --------------------------------------------------------- Public Methods
   
   
  @@ -163,6 +177,8 @@
               if (name.equals(cookies[i].getName()))
                   values.add(cookies[i]);
           }
  +        if ((values.size() < 1) && (value != null))
  +            values.add(new Cookie(name, value));
           if (values.size() < 1) {
               JspException e = new JspException
                   (messages.getMessage("getter.cookie", name));
  @@ -193,6 +209,7 @@
           id = null;
           multiple = null;
           name = null;
  +        value = null;
   
       }
   
  
  
  
  1.6       +23 -4     
jakarta-struts/src/share/org/apache/struts/taglib/bean/HeaderTag.java
  
  Index: HeaderTag.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/bean/HeaderTag.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- HeaderTag.java    2000/12/28 02:09:09     1.5
  +++ HeaderTag.java    2001/02/03 03:23:24     1.6
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/bean/HeaderTag.java,v 1.5 
2000/12/28 02:09:09 craigmcc Exp $
  - * $Revision: 1.5 $
  - * $Date: 2000/12/28 02:09:09 $
  + * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/bean/HeaderTag.java,v 1.6 
2001/02/03 03:23:24 craigmcc Exp $
  + * $Revision: 1.6 $
  + * $Date: 2001/02/03 03:23:24 $
    *
    * ====================================================================
    *
  @@ -82,7 +82,7 @@
    * header received with this request.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.5 $ $Date: 2000/12/28 02:09:09 $
  + * @version $Revision: 1.6 $ $Date: 2001/02/03 03:23:24 $
    */
   
   public class HeaderTag extends TagSupport {
  @@ -142,6 +142,20 @@
       }
   
   
  +    /**
  +     * The default value to return if no header of the specified name is found.
  +     */
  +    protected String value = null;
  +
  +    public String getValue() {
  +        return (this.value);
  +    }
  +
  +    public void setValue(String value) {
  +        this.value = value;
  +    }
  +
  +
       // --------------------------------------------------------- Public Methods
   
   
  @@ -156,6 +170,8 @@
           if (multiple == null) {
            String value =
              ((HttpServletRequest) pageContext.getRequest()).getHeader(name);
  +            if ((value == null) && (this.value != null))
  +                value = this.value;
            if (value == null) {
                JspException e = new JspException
                  (messages.getMessage("getter.header", name));
  @@ -173,6 +189,8 @@
          ((HttpServletRequest) pageContext.getRequest()).getHeaders(name);
        while (items.hasMoreElements())
            values.add(items.nextElement());
  +        if ((values.size() == 0) && (this.value != null))
  +            values.add(this.value);
        String headers[] = new String[values.size()];
        if (headers.length == 0) {
            JspException e = new JspException
  @@ -196,6 +214,7 @@
           id = null;
           multiple = null;
           name = null;
  +        value = null;
   
       }
   
  
  
  
  1.5       +28 -4     
jakarta-struts/src/share/org/apache/struts/taglib/bean/ParameterTag.java
  
  Index: ParameterTag.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/bean/ParameterTag.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ParameterTag.java 2000/10/30 06:02:13     1.4
  +++ ParameterTag.java 2001/02/03 03:23:24     1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/bean/ParameterTag.java,v 
1.4 2000/10/30 06:02:13 craigmcc Exp $
  - * $Revision: 1.4 $
  - * $Date: 2000/10/30 06:02:13 $
  + * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/bean/ParameterTag.java,v 
1.5 2001/02/03 03:23:24 craigmcc Exp $
  + * $Revision: 1.5 $
  + * $Date: 2001/02/03 03:23:24 $
    *
    * ====================================================================
    *
  @@ -79,7 +79,7 @@
    * parameter received with this request.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.4 $ $Date: 2000/10/30 06:02:13 $
  + * @version $Revision: 1.5 $ $Date: 2001/02/03 03:23:24 $
    */
   
   public class ParameterTag extends TagSupport {
  @@ -140,6 +140,21 @@
       }
   
   
  +    /**
  +     * The default value to return if no parameter of the specified name is
  +     * found.
  +     */
  +    protected String value = null;
  +
  +    public String getValue() {
  +        return (this.value);
  +    }
  +
  +    public void setValue(String value) {
  +        this.value = value;
  +    }
  +
  +
       // --------------------------------------------------------- Public Methods
   
   
  @@ -154,6 +169,8 @@
           if (multiple == null) {
            String value =
              pageContext.getRequest().getParameter(name);
  +            if ((value == null) && (this.value != null))
  +                value = this.value;
            if (value == null) {
                JspException e = new JspException
                  (messages.getMessage("getter.parameter", name));
  @@ -168,6 +185,12 @@
        // Deal with multiple parameter values
        String values[] =
          pageContext.getRequest().getParameterValues(name);
  +        if ((values == null) || (values.length == 0)) {
  +            if (this.value != null) {
  +                values = new String[1];
  +                values[0] = this.value;
  +            }
  +        }
        if ((values == null) || (values.length == 0)) {
            JspException e = new JspException
              (messages.getMessage("getter.parameter", name));
  @@ -190,6 +213,7 @@
           id = null;
           multiple = null;
           name = null;
  +        value = null;
   
       }
   
  
  
  
  1.2       +50 -0     jakarta-struts/web/test/bean-cookie.jsp
  
  Index: bean-cookie.jsp
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/web/test/bean-cookie.jsp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- bean-cookie.jsp   2000/09/05 21:28:04     1.1
  +++ bean-cookie.jsp   2001/02/03 03:23:25     1.2
  @@ -62,5 +62,55 @@
     </tr>
   </table>
   
  +<bean:cookie id="dummy" name="UNKNOWN_COOKIE" value="UNKNOWN_VALUE"/>
  +
  +<table border="1">
  +  <tr>
  +    <th>Property Name</th>
  +    <th>Correct Value</th>
  +    <th>Test Result</th>
  +  </tr>
  +  <tr>
  +    <td>comment</td>
  +    <td><jsp:getProperty name="dummy" property="comment"/></td>
  +    <td><bean:write name="dummy" property="comment"/></td>
  +  </tr>
  +  <tr>
  +    <td>domain</td>
  +    <td><jsp:getProperty name="dummy" property="domain"/></td>
  +    <td><bean:write name="dummy" property="domain"/></td>
  +  </tr>
  +  <tr>
  +    <td>maxAge</td>
  +    <td><jsp:getProperty name="dummy" property="maxAge"/></td>
  +    <td><bean:write name="dummy" property="maxAge"/></td>
  +  </tr>
  +  <tr>
  +    <td>name</td>
  +    <td><jsp:getProperty name="dummy" property="name"/></td>
  +    <td><bean:write name="dummy" property="name"/></td>
  +  </tr>
  +  <tr>
  +    <td>path</td>
  +    <td><jsp:getProperty name="dummy" property="path"/></td>
  +    <td><bean:write name="dummy" property="path"/></td>
  +  </tr>
  +  <tr>
  +    <td>secure</td>
  +    <td><jsp:getProperty name="dummy" property="secure"/></td>
  +    <td><bean:write name="dummy" property="secure"/></td>
  +  </tr>
  +  <tr>
  +    <td>value</td>
  +    <td><jsp:getProperty name="dummy" property="value"/></td>
  +    <td><bean:write name="dummy" property="value"/></td>
  +  </tr>
  +  <tr>
  +    <td>version</td>
  +    <td><jsp:getProperty name="dummy" property="version"/></td>
  +    <td><bean:write name="dummy" property="version"/></td>
  +  </tr>
  +</table>
  +
   </body>
   </html>
  
  
  
  1.2       +5 -0      jakarta-struts/web/test/bean-header.jsp
  
  Index: bean-header.jsp
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/web/test/bean-header.jsp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- bean-header.jsp   2000/09/05 21:28:05     1.1
  +++ bean-header.jsp   2001/02/03 03:23:25     1.2
  @@ -33,6 +33,11 @@
   <%
     }
   %>
  +  <bean:header id="dummy" name="UNKNOWN-HEADER" value="UNKNOWN VALUE"/>
  +  <tr>
  +    <td>UNKNOWN HEADER</td>
  +    <td><bean:write name="dummy"/></td>
  +  </tr>
   </table>
   
   </body>
  
  
  
  1.2       +6 -0      jakarta-struts/web/test/bean-parameter.jsp
  
  Index: bean-parameter.jsp
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/web/test/bean-parameter.jsp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- bean-parameter.jsp        2000/09/05 21:28:05     1.1
  +++ bean-parameter.jsp        2001/02/03 03:23:25     1.2
  @@ -17,6 +17,7 @@
   
   <bean:parameter id="param1" name="param1"/>
   <bean:parameter id="param2" name="param2"/>
  +<bean:parameter id="param3" name="param3" value="UNKNOWN VALUE"/>
   
   <table border="1">
     <tr>
  @@ -33,6 +34,11 @@
       <td>param2</td>
       <td>value2</td>
       <td><%= param2 %></td>
  +  </tr>
  +  <tr>
  +    <td>param3</td>
  +    <td>UNKNOWN VALUE</td>
  +    <td><%= param3 %></td>
     </tr>
   </table>
   
  
  
  

Reply via email to