| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| BooleanFormatter |
|
| 6.0;6 |
| 1 | /* | |
| 2 | * Copyright 2004 Jonathan M. Lehr | |
| 3 | * | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. | |
| 5 | * You may obtain a copy of the License at | |
| 6 | * | |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 | * | |
| 9 | * Unless required by applicable law or agreed to in writing, software | |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 | * See the License for the specific language governing permissions and | |
| 13 | * limitations under the License. | |
| 14 | * | |
| 15 | * MODIFIED BY THE KUALI FOUNDATION | |
| 16 | */ | |
| 17 | // begin Kuali Foundation modification | |
| 18 | package org.kuali.rice.core.web.format; | |
| 19 | // end Kuali Foundation modification | |
| 20 | ||
| 21 | import org.kuali.rice.core.api.util.RiceKeyConstants; | |
| 22 | import org.kuali.rice.core.api.util.Truth; | |
| 23 | ||
| 24 | /** | |
| 25 | * begin Kuali Foundation modification | |
| 26 | * This class is used to format boolean values. | |
| 27 | * end Kuali Foundation modification | |
| 28 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
| 29 | */ | |
| 30 | 0 | public class BooleanFormatter extends Formatter { |
| 31 | // begin Kuali Foundation modification | |
| 32 | // deleted line: public static final String BOOLEAN_ERROR_KEY = "error.boolean"; | |
| 33 | private static final long serialVersionUID = -4109390572922205211L; | |
| 34 | ||
| 35 | // deleted line: static final String CONVERT_MSG = "Unable to create Boolean object from "; | |
| 36 | // end Kuali Foundation modification | |
| 37 | ||
| 38 | /* begin Kuali Foundation modification | |
| 39 | deleted following method */ | |
| 40 | // /** | |
| 41 | // * Returns the error key for this Formatter. | |
| 42 | // * | |
| 43 | // * @see Formatter#getErrorKey() | |
| 44 | // */ | |
| 45 | // public String getErrorKey() { | |
| 46 | // return BOOLEAN_ERROR_KEY; | |
| 47 | // } | |
| 48 | // end Kuali Foundation modification | |
| 49 | ||
| 50 | protected Object convertToObject(String target) { | |
| 51 | 0 | if (Formatter.isEmptyValue(target)) |
| 52 | 0 | return null; |
| 53 | ||
| 54 | 0 | String stringValue = target.getClass().isArray() ? unwrapString(target) : (String) target; |
| 55 | 0 | stringValue = stringValue.trim().toLowerCase(); |
| 56 | ||
| 57 | 0 | Boolean b = Truth.strToBooleanIgnoreCase(stringValue); |
| 58 | 0 | if (b == null) { |
| 59 | 0 | throw new FormatException("converting", RiceKeyConstants.ERROR_BOOLEAN, stringValue); |
| 60 | } | |
| 61 | ||
| 62 | 0 | return b; |
| 63 | } | |
| 64 | ||
| 65 | public Object format(Object target) { | |
| 66 | 0 | if (target == null) |
| 67 | 0 | return null; |
| 68 | // begin Kuali Foundation modification | |
| 69 | 0 | if (target instanceof String) { |
| 70 | 0 | return target; |
| 71 | } | |
| 72 | // end Kuali Foundation modification | |
| 73 | ||
| 74 | 0 | boolean isTrue = ((Boolean) target).booleanValue(); |
| 75 | ||
| 76 | 0 | return isTrue ? "Yes" : "No"; |
| 77 | } | |
| 78 | } |