Coverage Report - org.apache.myfaces.taglib.core.ValidateRegexTag
 
Classes in this File Line Coverage Branch Coverage Complexity
ValidateRegexTag
0%
0/28
0%
0/8
2.5
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *   http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 18  
  */
 19  
 package org.apache.myfaces.taglib.core;
 20  
 
 21  
 import javax.el.ELContext;
 22  
 import javax.el.ValueExpression;
 23  
 import javax.faces.application.Application;
 24  
 import javax.faces.context.FacesContext;
 25  
 import javax.faces.validator.RegexValidator;
 26  
 import javax.faces.validator.Validator;
 27  
 import javax.faces.webapp.ValidatorELTag;
 28  
 import javax.servlet.jsp.JspException;
 29  
 
 30  
 /**
 31  
  * JSP Tag class for {@link javax.faces.validator.RegexValidator}.
 32  
  *
 33  
  * @author Jan-Kees van Andel
 34  
  * @since 2.0
 35  
  */
 36  0
 public class ValidateRegexTag extends ValidatorELTag
 37  
 {
 38  
     private static final long serialVersionUID = 8363913774859484811L;
 39  
 
 40  
     private ValueExpression _pattern;
 41  
 
 42  
     private ValueExpression _binding;
 43  
 
 44  
     @Override
 45  
     protected Validator createValidator() throws JspException
 46  
     {
 47  0
         FacesContext fc = FacesContext.getCurrentInstance();
 48  0
         ELContext elc = fc.getELContext();
 49  0
         if (_binding != null)
 50  
         {
 51  
             Object validator;
 52  
             try
 53  
             {
 54  0
                 validator = _binding.getValue(elc);
 55  
             }
 56  0
             catch (Exception e)
 57  
             {
 58  0
                 throw new JspException("Error while creating the Validator", e);
 59  0
             }
 60  0
             if (validator instanceof RegexValidator)
 61  
             {
 62  0
                 return (Validator)validator;
 63  
             }
 64  
         }
 65  0
         if (null != _pattern)
 66  
         {
 67  0
             Application appl = fc.getApplication();
 68  0
             RegexValidator validator = (RegexValidator) appl.createValidator(RegexValidator.VALIDATOR_ID);
 69  0
             String pattern = (String)_pattern.getValue(elc);
 70  0
             validator.setPattern(pattern);
 71  
 
 72  0
             if (_binding != null)
 73  
             {
 74  0
                 _binding.setValue(elc, validator);
 75  
             }
 76  
 
 77  0
             return validator;
 78  
         }
 79  
         else
 80  
         {
 81  0
             throw new AssertionError("pattern may not be null");
 82  
         }
 83  
     }
 84  
 
 85  
     public ValueExpression getBinding()
 86  
     {
 87  0
         return _binding;
 88  
     }
 89  
 
 90  
     public void setBinding(ValueExpression binding)
 91  
     {
 92  0
         _binding = binding;
 93  0
     }
 94  
 
 95  
     public ValueExpression getPattern()
 96  
     {
 97  0
         return _pattern;
 98  
     }
 99  
 
 100  
     public void setPattern(ValueExpression pattern)
 101  
     {
 102  0
         _pattern = pattern;
 103  0
     }
 104  
 
 105  
     @Override
 106  
     public void release()
 107  
     {
 108  0
         _pattern = null;
 109  0
         _binding = null;
 110  0
     }
 111  
 }