Clover coverage report - Code Coverage for tapestry release 4.0.2
Coverage timestamp: Thu Apr 13 2006 10:52:06 EDT
file stats: LOC: 90   Methods: 7
NCLOC: 57   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
MinLength.java 100% 100% 100% 100%
coverage
 1    // Copyright 2005 The Apache Software Foundation
 2    //
 3    // Licensed under the Apache License, Version 2.0 (the "License");
 4    // you may not use this file except in compliance with the License.
 5    // You may obtain a copy of the License at
 6    //
 7    // http://www.apache.org/licenses/LICENSE-2.0
 8    //
 9    // Unless required by applicable law or agreed to in writing, software
 10    // distributed under the License is distributed on an "AS IS" BASIS,
 11    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12    // See the License for the specific language governing permissions and
 13    // limitations under the License.
 14   
 15    package org.apache.tapestry.form.validator;
 16   
 17    import org.apache.tapestry.IMarkupWriter;
 18    import org.apache.tapestry.IRequestCycle;
 19    import org.apache.tapestry.TapestryUtils;
 20    import org.apache.tapestry.form.FormComponentContributorContext;
 21    import org.apache.tapestry.form.IFormComponent;
 22    import org.apache.tapestry.form.ValidationMessages;
 23    import org.apache.tapestry.valid.ValidationConstraint;
 24    import org.apache.tapestry.valid.ValidationStrings;
 25    import org.apache.tapestry.valid.ValidatorException;
 26   
 27    /**
 28    * Validates that the value, a string, is of a minimum length.
 29    *
 30    * @author Howard Lewis Ship
 31    * @since 4.0
 32    */
 33    public class MinLength extends BaseValidator
 34    {
 35    private int _minLength;
 36   
 37  2 public MinLength()
 38    {
 39    }
 40   
 41  5 public MinLength(String initializer)
 42    {
 43  5 super(initializer);
 44    }
 45   
 46  6 public void setMinLength(int minLength)
 47    {
 48  6 _minLength = minLength;
 49    }
 50   
 51  1 public int getMinLength()
 52    {
 53  1 return _minLength;
 54    }
 55   
 56  3 public void validate(IFormComponent field, ValidationMessages messages, Object object)
 57    throws ValidatorException
 58    {
 59  3 String string = (String) object;
 60   
 61  3 if (string.length() < _minLength)
 62  2 throw new ValidatorException(buildMessage(messages, field),
 63    ValidationConstraint.MINIMUM_WIDTH);
 64    }
 65   
 66  4 protected String buildMessage(ValidationMessages messages, IFormComponent field)
 67    {
 68  4 return messages.formatValidationMessage(
 69    getMessage(),
 70    ValidationStrings.VALUE_TOO_SHORT,
 71    new Object[]
 72    { new Integer(_minLength), field.getDisplayName() });
 73    }
 74   
 75  2 public void renderContribution(IMarkupWriter writer, IRequestCycle cycle,
 76    FormComponentContributorContext context, IFormComponent field)
 77    {
 78  2 context.includeClasspathScript("/org/apache/tapestry/form/validator/StringValidator.js");
 79   
 80  2 StringBuffer buffer = new StringBuffer("function(event) { Tapestry.validate_min_length(event, '");
 81  2 buffer.append(field.getClientId());
 82  2 buffer.append("', ");
 83  2 buffer.append(_minLength);
 84  2 buffer.append(", ");
 85  2 buffer.append(TapestryUtils.enquote(buildMessage(context, field)));
 86  2 buffer.append("); }");
 87   
 88  2 context.addSubmitHandler(buffer.toString());
 89    }
 90    }