Coverage report

  %line %branch
org.apache.turbine.services.intake.model.BigDecimalField
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 java.math.BigDecimal;
 20  
 
 21  
 import java.text.DecimalFormatSymbols;
 22  
 
 23  
 import org.apache.commons.lang.StringUtils;
 24  
 
 25  
 import org.apache.turbine.services.intake.IntakeException;
 26  
 import org.apache.turbine.services.intake.validator.BigDecimalValidator;
 27  
 import org.apache.turbine.services.intake.xmlmodel.XmlField;
 28  
 
 29  
 /**
 30  
  * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
 31  
  * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
 32  
  * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
 33  
  * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
 34  
  * @version $Id: BigDecimalField.java 264148 2005-08-29 14:21:04Z henning $
 35  
  */
 36  
 public class BigDecimalField
 37  
         extends Field
 38  
 {
 39  
     /**
 40  
      * Constructor.
 41  
      *
 42  
      * @param field xml field definition object
 43  
      * @param group xml group definition object
 44  
      * @throws IntakeException thrown by superclass
 45  
      */
 46  
     public BigDecimalField(XmlField field, Group group)
 47  
             throws IntakeException
 48  
     {
 49  0
         super(field, group);
 50  0
     }
 51  
 
 52  
     /**
 53  
      * Sets the default value for a BigDecimal field
 54  
      *
 55  
      * @param prop Parameter for the default values
 56  
      */
 57  
     public void setDefaultValue(String prop)
 58  
     {
 59  0
         defaultValue = null;
 60  
 
 61  0
         if (prop == null)
 62  
         {
 63  0
             return;
 64  
         }
 65  
 
 66  0
         defaultValue = new BigDecimal(prop);
 67  0
     }
 68  
 
 69  
     /**
 70  
      * Set the empty Value. This value is used if Intake
 71  
      * maps a field to a parameter returned by the user and
 72  
      * the corresponding field is either empty (empty string)
 73  
      * or non-existant.
 74  
      *
 75  
      * @param prop The value to use if the field is empty.
 76  
      */
 77  
     public void setEmptyValue(String prop)
 78  
     {
 79  0
         emptyValue = null;
 80  
 
 81  0
         if (prop == null)
 82  
         {
 83  0
             return;
 84  
         }
 85  
 
 86  0
         emptyValue = new BigDecimal(prop);
 87  0
     }
 88  
 
 89  
     /**
 90  
      * A suitable validator.
 91  
      *
 92  
      * @return A suitable validator
 93  
      */
 94  
     protected String getDefaultValidator()
 95  
     {
 96  0
         return BigDecimalValidator.class.getName();
 97  
     }
 98  
 
 99  
     /**
 100  
      * Sets the value of the field from data in the parser.
 101  
      */
 102  
     protected void doSetValue()
 103  
     {
 104  0
         if (isMultiValued)
 105  
         {
 106  0
             String[] inputs = parser.getStrings(getKey());
 107  0
             BigDecimal[] values = new BigDecimal[inputs.length];
 108  0
             for (int i = 0; i < inputs.length; i++)
 109  
             {
 110  0
                 values[i] = StringUtils.isNotEmpty(inputs[i])
 111  
                         ? canonicalizeDecimalInput(inputs[i]) : (BigDecimal) getEmptyValue();
 112  
             }
 113  0
             setTestValue(values);
 114  
         }
 115  
         else
 116  
         {
 117  0
             String val = parser.getString(getKey());
 118  0
             setTestValue(StringUtils.isNotEmpty(val) ? canonicalizeDecimalInput(val) : (BigDecimal) getEmptyValue());
 119  
         }
 120  0
     }
 121  
 
 122  
     /**
 123  
      * Canonicalizes an user-inputted <code>BigDecimal</code> string
 124  
      * to the system's internal format.
 125  
      *
 126  
      * @param bigDecimal Text conforming to a <code>BigDecimal</code>
 127  
      * description for a set of <code>DecimalFormatSymbols</code>.
 128  
      * @return The canonicalized representation.
 129  
      */
 130  
     protected final BigDecimal canonicalizeDecimalInput(String bigDecimal)
 131  
     {
 132  0
         if (getLocale() != null)
 133  
         {
 134  0
             DecimalFormatSymbols internal = new DecimalFormatSymbols();
 135  0
             DecimalFormatSymbols user = new DecimalFormatSymbols(getLocale());
 136  
 
 137  0
             if (!internal.equals(user))
 138  
             {
 139  0
                 bigDecimal = bigDecimal.replace(user.getDecimalSeparator(),
 140  
                         internal.getDecimalSeparator());
 141  
             }
 142  
         }
 143  0
         return new BigDecimal(bigDecimal);
 144  
     }
 145  
 }

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