2009/05/20 - Apache Shale has been retired.

For more information, please explore the Attic.

Coverage Report - org.apache.shale.validator.faces.ValidatorTag
 
Classes in this File Line Coverage Branch Coverage Complexity
ValidatorTag
0% 
0% 
1.529
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to you under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 
 18  
 package org.apache.shale.validator.faces;
 19  
 
 20  
 import java.util.Iterator;
 21  
 import java.util.LinkedHashMap;
 22  
 import java.util.Map;
 23  
 
 24  
 import javax.faces.validator.Validator;
 25  
 import javax.servlet.jsp.JspException;
 26  
 
 27  
 import org.apache.shale.util.Tags;
 28  
 import org.apache.shale.validator.CommonsValidator;
 29  
 
 30  
 /**
 31  
  * The tag class for the <code>s:commonsValidator</code> tag.
 32  
  *
 33  
  * $Id: ValidatorTag.java 481413 2006-12-01 21:48:06Z rahul $
 34  
  */
 35  
 public class ValidatorTag extends javax.faces.webapp.ValidatorTag  {
 36  
 
 37  
     /**
 38  
      * Serial version UID.
 39  
      */
 40  
     private static final long serialVersionUID = -5007063635477571688L;
 41  
 
 42  
 
 43  
     /**
 44  
      * <p>The <code>type</code> attribute.
 45  
      */
 46  
    private String type;
 47  
 
 48  
 
 49  
     /**
 50  
      * <p>The <code>min</code> attribute.
 51  
      */
 52  
    private String min;
 53  
 
 54  
 
 55  
     /**
 56  
      * <p>The <code>max</code> attribute.
 57  
      */
 58  
    private String max;
 59  
 
 60  
 
 61  
     /**
 62  
      * <p>The <code>minlength</code> attribute.
 63  
      */
 64  
    private String minlength;
 65  
 
 66  
 
 67  
     /**
 68  
      * <p>The <code>maxlength</code> attribute.
 69  
      */
 70  
    private String maxlength;
 71  
 
 72  
 
 73  
     /**
 74  
      * <p>The <code>datePatternStrict</code> attribute.
 75  
      */
 76  
    private String datePatternStrict;
 77  
 
 78  
 
 79  
     /**
 80  
      * <p>The <code>mask</code> attribute.
 81  
      */
 82  
    private String mask;
 83  
 
 84  
 
 85  
     /**
 86  
      * <p>The <code>message</code> attribute.
 87  
      */
 88  
    private String message;
 89  
 
 90  
 
 91  
     /**
 92  
      * <p>The <code>arg</code> attribute.
 93  
      */
 94  
    private String arg;
 95  
 
 96  
 
 97  
     /**
 98  
      * <p>The <code>client</code> attribute.
 99  
      */
 100  
    private String client;
 101  
 
 102  
 
 103  
     /**
 104  
      * <p>The <code>server</code> attribute.
 105  
      */
 106  
    private String server;
 107  
 
 108  
 
 109  
    /**
 110  
     * <p>The parameters to pass to the validator.</p>
 111  
     */
 112  
    private LinkedHashMap params;
 113  
 
 114  
 
 115  
     /**
 116  
      * <p>This constructor obtains a reference to the
 117  
      *    tag utility object, which is a JSF managed bean.
 118  
      */
 119  0
    public ValidatorTag() {
 120  0
       setValidatorId("org.apache.shale.CommonsValidator");
 121  0
    }
 122  
 
 123  
 
 124  
     /**
 125  
      * <p>Setter method for the <code>type</code> attribute.
 126  
      *
 127  
      * @param newValue the new attribute value
 128  
      */
 129  
    public void setType(String newValue) {
 130  0
       type = newValue;
 131  0
    }
 132  
 
 133  
 
 134  
     /**
 135  
      * <p>Setter method for the <code>min</code> attribute.
 136  
      *
 137  
      * @param newValue the new attribute value
 138  
      */
 139  
    public void setMin(String newValue) {
 140  0
       min = newValue;
 141  0
    }
 142  
 
 143  
 
 144  
     /**
 145  
      * <p>Setter method for the <code>max</code> attribute.
 146  
      *
 147  
      * @param newValue the new attribute value
 148  
      */
 149  
    public void setMax(String newValue) {
 150  0
       max = newValue;
 151  0
    }
 152  
 
 153  
 
 154  
     /**
 155  
      * <p>Setter method for the <code>minlength</code> attribute.
 156  
      *
 157  
      * @param newValue the new attribute value
 158  
      */
 159  
    public void setMinlength(String newValue) {
 160  0
       minlength = newValue;
 161  0
    }
 162  
 
 163  
 
 164  
     /**
 165  
      * <p>Setter method for the <code>maxlength</code> attribute.
 166  
      *
 167  
      * @param newValue the new attribute value
 168  
      */
 169  
    public void setMaxlength(String newValue) {
 170  0
       maxlength = newValue;
 171  0
    }
 172  
 
 173  
 
 174  
     /**
 175  
      * <p>Setter method for the <code>setDatePatternStrict</code> attribute.
 176  
      *
 177  
      * @param newValue the new attribute value
 178  
      */
 179  
    public void setDatePatternStrict(String newValue) {
 180  0
       datePatternStrict = newValue;
 181  0
    }
 182  
 
 183  
 
 184  
     /**
 185  
      * <p>Setter method for the <code>mask</code> attribute.
 186  
      *
 187  
      * @param newValue the new attribute value
 188  
      */
 189  
    public void setMask(String newValue) {
 190  0
       mask = newValue;
 191  0
    }
 192  
 
 193  
 
 194  
     /**
 195  
      * <p>Setter method for the <code>message</code> attribute.
 196  
      *
 197  
      * @param newValue the new attribute value
 198  
      */
 199  
    public void setMessage(String newValue) {
 200  0
       message = newValue;
 201  0
    }
 202  
 
 203  
 
 204  
     /**
 205  
      * <p>Setter method for the <code>arg</code> attribute.
 206  
      *
 207  
      * @param newValue the new attribute value
 208  
      */
 209  
    public void setArg(String newValue) {
 210  0
       arg = newValue;
 211  0
    }
 212  
 
 213  
 
 214  
     /**
 215  
      * <p>Setter method for the <code>client</code> attribute.
 216  
      *
 217  
      * @param newValue the new attribute value
 218  
      */
 219  
    public void setClient(String newValue) {
 220  0
       client = newValue;
 221  0
    }
 222  
 
 223  
 
 224  
     /**
 225  
      * <p>Setter method for the <code>server</code> attribute.
 226  
      *
 227  
      * @param newValue the new attribute value
 228  
      */
 229  
    public void setServer(String newValue) {
 230  0
       server = newValue;
 231  0
    }
 232  
 
 233  
 
 234  
    /**
 235  
     * <p>Adds a parameter to pass to the Commons Validator that will be
 236  
     * used.</p>
 237  
     *
 238  
     * @param name    the name of the parameter to pass to the validator.
 239  
     * @param value   the value of the parameter to pass to the validator.
 240  
     */
 241  
    public void addParam(String name, String value) {
 242  0
       params.put(name, value);
 243  0
    }
 244  
 
 245  
    /**
 246  
     * <p>Overridden to prevent the call to {@link #createValidator} from
 247  
     * occurring here.</p>
 248  
     *
 249  
     * @return EVAL_BODY_INCLUDE
 250  
     */
 251  
    public int doStartTag() throws JspException {
 252  
       // reset the params for each use of this tag
 253  0
       params = new LinkedHashMap();
 254  0
       return EVAL_BODY_INCLUDE;
 255  
    }
 256  
 
 257  
 
 258  
    /**
 259  
     * <p>Executes the code that was skipped in the <code>doStartTag()</code>
 260  
     * override.</p>
 261  
     *
 262  
     * @exception JspException if a JSP processing error occurs
 263  
     */
 264  
    public int doEndTag() throws JspException {
 265  0
       super.doStartTag();
 266  0
       return super.doEndTag();
 267  
    }
 268  
 
 269  
 
 270  
    /**
 271  
      * <p>Create a validator by calling <code>super.createValidator()</code>.
 272  
      *    This method initializes that validator with the tag's attribute
 273  
      *    values.
 274  
      *
 275  
      * @exception JspException if a JSP processing error occurs
 276  
      */
 277  
    public Validator createValidator() throws JspException {
 278  0
       CommonsValidator validator = (CommonsValidator) super.createValidator();
 279  
 
 280  
       // parameters for specific validators
 281  0
       if (min != null) {
 282  0
           validator.setMin(min);
 283  
       }
 284  0
       if (max != null) {
 285  0
           validator.setMax(max);
 286  
       }
 287  0
       if (minlength != null) {
 288  0
           validator.setMinLength(minlength);
 289  
       }
 290  0
       if (maxlength != null) {
 291  0
           validator.setMaxLength(maxlength);
 292  
       }
 293  0
       if (datePatternStrict != null) {
 294  0
           validator.setDatePatternStrict(datePatternStrict);
 295  
       }
 296  0
       if (mask != null) {
 297  0
           validator.setMask(mask);
 298  
       }
 299  0
       if (arg != null) {
 300  0
           validator.setArg(arg);
 301  
       }
 302  
 
 303  0
       Tags tagUtils = new Tags();
 304  
 
 305  
       // these properties require early binding
 306  0
       validator.setType(tagUtils.evalString(type));
 307  0
       validator.setMessage(tagUtils.evalString(message));
 308  0
       validator.setClient(tagUtils.evalBoolean(client));
 309  0
       validator.setServer(tagUtils.evalBoolean(server));
 310  
 
 311  0
       tagUtils = null;
 312  
 
 313  
       // pass the parameters specified through <s:validatorVar>
 314  
       // if these vars contain binding expressions, they are
 315  
       // evaluated late
 316  0
       if (params != null) {
 317  0
          for (Iterator iterator = params.entrySet().iterator(); iterator.hasNext();) {
 318  0
             Map.Entry e = (Map.Entry) iterator.next();
 319  0
             Object key = e.getKey();
 320  0
             Object value = e.getValue();
 321  0
             validator.getVars().put(key, value);
 322  0
          }
 323  
       }
 324  
 
 325  0
       return validator;
 326  
    }
 327  
 
 328  
 
 329  
     /**
 330  
      * <p>Sets all instance objects representing tag attribute values
 331  
       *    to <code>null</code>.
 332  
      */
 333  
    public void release() {
 334  0
       type = null;
 335  0
       params = null;
 336  0
       min = null;
 337  0
       max = null;
 338  0
       minlength = null;
 339  0
       maxlength = null;
 340  0
       datePatternStrict = null;
 341  0
       mask = null;
 342  0
       message = null;
 343  0
       arg = null;
 344  0
       client = null;
 345  0
       server = null;
 346  0
    }
 347  
 
 348  
 }