Coverage Report - org.kuali.rice.core.web.format.BooleanFormatter
 
Classes in this File Line Coverage Branch Coverage Complexity
BooleanFormatter
0%
0/15
0%
0/12
6
 
 1  
 /**
 2  
  * Copyright 2005-2011 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  
 // begin Kuali Foundation modification
 17  
 package org.kuali.rice.core.web.format;
 18  
 // end Kuali Foundation modification
 19  
 
 20  
 import org.kuali.rice.core.api.util.RiceKeyConstants;
 21  
 import org.kuali.rice.core.api.util.Truth;
 22  
 
 23  
 /**
 24  
  * begin Kuali Foundation modification
 25  
  * This class is used to format boolean values.
 26  
  * end Kuali Foundation modification
 27  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 28  
  */
 29  0
 public class BooleanFormatter extends Formatter {
 30  
     // begin Kuali Foundation modification
 31  
     // deleted line: public static final String BOOLEAN_ERROR_KEY = "error.boolean";
 32  
     private static final long serialVersionUID = -4109390572922205211L;
 33  
 
 34  
     // deleted line: static final String CONVERT_MSG = "Unable to create Boolean object from ";
 35  
     // end Kuali Foundation modification
 36  
 
 37  
         /* begin Kuali Foundation modification
 38  
            deleted following method */
 39  
     // /**
 40  
         //  * Returns the error key for this Formatter.
 41  
         //  * 
 42  
         //  * @see Formatter#getErrorKey()
 43  
         //  */
 44  
         // public String getErrorKey() {
 45  
         //         return BOOLEAN_ERROR_KEY;
 46  
         // }
 47  
         // end Kuali Foundation modification
 48  
         
 49  
     protected Object convertToObject(String target) {
 50  0
         if (Formatter.isEmptyValue(target))
 51  0
             return null;
 52  
 
 53  0
         String stringValue = target.getClass().isArray() ? unwrapString(target) : (String) target;
 54  0
         stringValue = stringValue.trim().toLowerCase();
 55  
 
 56  0
         Boolean b = Truth.strToBooleanIgnoreCase(stringValue);
 57  0
         if (b == null) {
 58  0
             throw new FormatException("converting", RiceKeyConstants.ERROR_BOOLEAN, stringValue);
 59  
         }
 60  
 
 61  0
         return b;
 62  
     }
 63  
 
 64  
     public Object format(Object target) {
 65  0
         if (target == null)
 66  0
             return null;
 67  
         // begin Kuali Foundation modification
 68  0
         if (target instanceof String) {
 69  0
             return target;
 70  
         }
 71  
         // end Kuali Foundation modification
 72  
 
 73  0
         boolean isTrue = ((Boolean) target).booleanValue();
 74  
 
 75  0
         return isTrue ? "Yes" : "No";
 76  
     }
 77  
 }