Coverage Report - org.seasar.teeda.core.taglib.core.ValidateLengthTag
 
Classes in this File Line Coverage Branch Coverage Complexity
ValidateLengthTag
100%
27/27
100%
12/12
3
 
 1  
 /*
 2  
  * Copyright 2004-2011 the Seasar Foundation and the Others.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package org.seasar.teeda.core.taglib.core;
 17  
 
 18  
 import javax.faces.context.FacesContext;
 19  
 import javax.faces.el.ValueBinding;
 20  
 import javax.faces.internal.ValueBindingUtil;
 21  
 import javax.faces.validator.LengthValidator;
 22  
 import javax.faces.validator.Validator;
 23  
 import javax.servlet.jsp.JspException;
 24  
 
 25  
 import org.seasar.framework.util.AssertionUtil;
 26  
 import org.seasar.teeda.core.util.BindingUtil;
 27  
 import org.seasar.teeda.core.util.ConverterUtil;
 28  
 
 29  
 /**
 30  
  * @author yone
 31  
  * @author shot
 32  
  */
 33  
 public class ValidateLengthTag extends MaxMinValidatorTag {
 34  
 
 35  
     private static final long serialVersionUID = 1L;
 36  
 
 37  
     private static final String VALIDATOR_ID = LengthValidator.VALIDATOR_ID;
 38  
 
 39  7
     protected int minimum = 0;
 40  
 
 41  7
     protected int maximum = 0;
 42  
 
 43  
     public ValidateLengthTag() {
 44  7
         super();
 45  7
     }
 46  
 
 47  
     protected Validator createValidator() throws JspException {
 48  7
         super.setValidatorId(VALIDATOR_ID);
 49  7
         LengthValidator validator = (LengthValidator) super.createValidator();
 50  7
         AssertionUtil.assertNotNull("LengthValidator", validator);
 51  
 
 52  6
         evaluateExpressions();
 53  6
         if (isMinimumSet()) {
 54  2
             validator.setMinimum(minimum);
 55  
         }
 56  6
         if (isMaximumSet()) {
 57  2
             validator.setMaximum(maximum);
 58  
         }
 59  6
         return validator;
 60  
     }
 61  
 
 62  
     private void evaluateExpressions() throws JspException {
 63  6
         FacesContext context = FacesContext.getCurrentInstance();
 64  6
         final String min = getMinimum();
 65  6
         if (min != null) {
 66  2
             if (BindingUtil.isValueReference(min)) {
 67  1
                 ValueBinding vb = ValueBindingUtil.createValueBinding(context,
 68  
                         min);
 69  1
                 minimum = ConverterUtil.convertToInt(vb.getValue(context));
 70  
             } else {
 71  1
                 minimum = ConverterUtil.convertToInt(min);
 72  
             }
 73  
         }
 74  6
         final String max = getMaximum();
 75  6
         if (max != null) {
 76  2
             if (BindingUtil.isValueReference(max)) {
 77  1
                 ValueBinding vb = context.getApplication().createValueBinding(
 78  
                         max);
 79  1
                 maximum = ConverterUtil.convertToInt(vb.getValue(context));
 80  
             } else {
 81  1
                 maximum = ConverterUtil.convertToInt(max);
 82  
             }
 83  
         }
 84  6
     }
 85  
 
 86  
 }