Coverage report

  %line %branch
org.apache.turbine.services.intake.model.StringField
0% 
0% 

 1  
 package org.apache.turbine.services.intake.model;
 2  
 
 3  
 /*
 4  
  * Copyright 2001-2005 The Apache Software Foundation.
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License")
 7  
  * you may not use this file except in compliance with the License.
 8  
  * 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, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 import org.apache.commons.lang.StringUtils;
 20  
 
 21  
 import org.apache.turbine.services.intake.IntakeException;
 22  
 import org.apache.turbine.services.intake.validator.StringValidator;
 23  
 import org.apache.turbine.services.intake.xmlmodel.XmlField;
 24  
 
 25  
 /**
 26  
  * Text field.
 27  
  *
 28  
  * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
 29  
  * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
 30  
  * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
 31  
  * @version $Id: StringField.java 264148 2005-08-29 14:21:04Z henning $
 32  
  */
 33  
 public class StringField
 34  
         extends Field
 35  
 {
 36  
 
 37  
     /**
 38  
      * Constructor.
 39  
      *
 40  
      * @param field xml field definition object
 41  
      * @param group xml group definition object
 42  
      * @throws IntakeException thrown by superclass
 43  
      */
 44  
     public StringField(XmlField field, Group group)
 45  
             throws IntakeException
 46  
     {
 47  0
         super(field, group);
 48  0
     }
 49  
 
 50  
     /**
 51  
      * Produces the fully qualified class name of the default validator.
 52  
      *
 53  
      * @return class name of the default validator
 54  
      */
 55  
     protected String getDefaultValidator()
 56  
     {
 57  0
         return StringValidator.class.getName();
 58  
     }
 59  
 
 60  
     /**
 61  
      * Sets the default value for a String field
 62  
      *
 63  
      * @param prop Parameter for the default values
 64  
      */
 65  
     public void setDefaultValue(String prop)
 66  
     {
 67  0
         defaultValue = prop;
 68  0
     }
 69  
 
 70  
     /**
 71  
      * Set the empty Value. This value is used if Intake
 72  
      * maps a field to a parameter returned by the user and
 73  
      * the corresponding field is either empty (empty string)
 74  
      * or non-existant.
 75  
      *
 76  
      * @param prop The value to use if the field is empty.
 77  
      */
 78  
     public void setEmptyValue(String prop)
 79  
     {
 80  0
         emptyValue = prop;
 81  0
     }
 82  
 
 83  
     /**
 84  
      * Sets the value of the field from data in the parser.
 85  
      */
 86  
     protected void doSetValue()
 87  
     {
 88  0
         if (isMultiValued)
 89  
         {
 90  0
             String[] ss = parser.getStrings(getKey());
 91  0
             String[] sval = new String[ss.length];
 92  0
             for (int i = 0; i < ss.length; i++)
 93  
             {
 94  0
                 sval[i] = (StringUtils.isNotEmpty(ss[i])) ? ss[i] : (String) getEmptyValue();
 95  
             }
 96  0
             setTestValue(sval);
 97  
         }
 98  
         else
 99  
         {
 100  0
             String val = parser.getString(getKey());
 101  0
             setTestValue(StringUtils.isNotEmpty(val) ? val : (String) getEmptyValue());
 102  
         }
 103  0
     }
 104  
 
 105  
     /**
 106  
      * Set the value of required.
 107  
      *
 108  
      * @param v  Value to assign to required.
 109  
      * @param message an error message
 110  
      */
 111  
     public void setRequired(boolean v, String message)
 112  
     {
 113  0
         this.required = v;
 114  0
         if (v)
 115  
         {
 116  0
             if (isMultiValued)
 117  
             {
 118  0
                 String[] ss = (String[]) getTestValue();
 119  0
                 if (ss == null || ss.length == 0)
 120  
                 {
 121  0
                     validFlag = false;
 122  0
                     this.message = message;
 123  
                 }
 124  
                 else
 125  
                 {
 126  0
                     boolean set = false;
 127  0
                     for (int i = 0; i < ss.length; i++)
 128  
                     {
 129  0
                         set |= StringUtils.isNotEmpty(ss[i]);
 130  0
                         if (set)
 131  
                         {
 132  0
                             break;
 133  
                         }
 134  
                     }
 135  0
                     if (!set)
 136  
                     {
 137  0
                         validFlag = false;
 138  0
                         this.message = message;
 139  
                     }
 140  
                 }
 141  
             }
 142  
             else
 143  
             {
 144  0
                 if (!setFlag || StringUtils.isEmpty((String) getTestValue()))
 145  
                 {
 146  0
                     validFlag = false;
 147  0
                     this.message = message;
 148  
                 }
 149  
             }
 150  
         }
 151  0
     }
 152  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.