1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.core.web.format; |
17 | |
|
18 | |
import org.kuali.rice.core.api.util.RiceKeyConstants; |
19 | |
import org.kuali.rice.core.api.util.Truth; |
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | 0 | public class LittleBooleanFormatter extends Formatter { |
25 | |
|
26 | |
private static final long serialVersionUID = -1800859871401901842L; |
27 | |
|
28 | |
protected Object convertToObject(String target) { |
29 | 0 | if (Formatter.isEmptyValue(target)) |
30 | 0 | return Boolean.FALSE; |
31 | |
|
32 | 0 | String stringValue = target.getClass().isArray() ? unwrapString(target) : (String) target; |
33 | 0 | stringValue = stringValue.trim().toLowerCase(); |
34 | |
|
35 | 0 | Boolean b = Truth.strToBooleanIgnoreCase(stringValue); |
36 | 0 | if (b == null) { |
37 | 0 | throw new FormatException("converting", RiceKeyConstants.ERROR_BOOLEAN, stringValue); |
38 | |
} |
39 | 0 | return b; |
40 | |
} |
41 | |
|
42 | |
public Object format(Object target) { |
43 | 0 | if (target == null) |
44 | 0 | return "No"; |
45 | 0 | if (target instanceof String) { |
46 | 0 | return target; |
47 | |
} |
48 | |
|
49 | 0 | boolean isTrue = ((Boolean) target).booleanValue(); |
50 | |
|
51 | 0 | return isTrue ? "Yes" : "No"; |
52 | |
} |
53 | |
|
54 | |
protected Object getNullObjectValue() { |
55 | 0 | return Boolean.FALSE; |
56 | |
} |
57 | |
|
58 | |
} |