Coverage Report - org.kuali.rice.kns.web.format.KualiIntegerCurrencyFormatter
 
Classes in this File Line Coverage Branch Coverage Complexity
KualiIntegerCurrencyFormatter
0%
0/15
0%
0/4
4.5
 
 1  
 /*
 2  
  * Copyright 2006-2007 The Kuali Foundation
 3  
  * 
 4  
  * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
 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, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.kns.web.format;
 17  
 
 18  
 import java.text.NumberFormat;
 19  
 
 20  
 import org.kuali.rice.kns.util.KualiDecimal;
 21  
 import org.kuali.rice.kns.util.KualiInteger;
 22  
 import org.kuali.rice.kns.util.RiceKeyConstants;
 23  
 
 24  0
 public class KualiIntegerCurrencyFormatter extends CurrencyFormatter {
 25  
 
 26  
     protected Object convertToObject(String target) {
 27  0
         KualiDecimal value = (KualiDecimal) (super.convertToObject(target));
 28  0
         return new KualiInteger(value.longValue());
 29  
     }
 30  
 
 31  
     /**
 32  
      * Returns a string representation of its argument formatted as a currency value.
 33  
      */
 34  
     public Object format(Object obj) {
 35  0
         if (obj == null)
 36  0
             return null;
 37  
 
 38  0
         NumberFormat formatter = NumberFormat.getNumberInstance();
 39  0
         String string = null;
 40  
 
 41  
         try {
 42  0
             KualiInteger number = (KualiInteger) obj;
 43  0
             string = formatter.format(number.doubleValue());
 44  
         }
 45  0
         catch (IllegalArgumentException e) {
 46  0
             throw new FormatException("formatting", RiceKeyConstants.ERROR_CURRENCY, obj.toString(), e);
 47  
         }
 48  0
         catch (ClassCastException e) {
 49  0
             throw new FormatException("formatting", RiceKeyConstants.ERROR_CURRENCY, obj.toString(), e);
 50  0
         }
 51  
 
 52  0
         return showSymbol() ? string : removeSymbol(string);
 53  
     }
 54  
 }