Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
DelegationTypeFormatter |
|
| 7.0;7 |
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.kns.web.format; | |
19 | // end Kuali Foundation modification | |
20 | ||
21 | import org.kuali.rice.core.web.format.Formatter; | |
22 | import org.kuali.rice.kew.api.action.DelegationType; | |
23 | import org.kuali.rice.kew.util.KEWConstants; | |
24 | ||
25 | /** | |
26 | * begin Kuali Foundation modification | |
27 | * This class is used to format boolean values. | |
28 | * end Kuali Foundation modification | |
29 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
30 | */ | |
31 | 0 | public class DelegationTypeFormatter extends Formatter { |
32 | private static final long serialVersionUID = -4109390572922205211L; | |
33 | /* | |
34 | protected Object convertToObject(String target) { | |
35 | if (Formatter.isEmptyValue(target)) | |
36 | return null; | |
37 | ||
38 | String stringValue = target.getClass().isArray() ? unwrapString(target) : (String) target; | |
39 | stringValue = stringValue.trim().toUpperCase(); | |
40 | ||
41 | return KEWConstants.DELEGATION_TYPES.get(stringValue); | |
42 | if (TRUE_VALUES.contains(stringValue)) | |
43 | return Boolean.TRUE; | |
44 | if (FALSE_VALUES.contains(stringValue)) | |
45 | return Boolean.FALSE; | |
46 | ||
47 | // begin Kuali Foundation modification | |
48 | // was: throw new FormatException(CONVERT_MSG + stringValue); | |
49 | throw new FormatException("converting", RiceKeyConstants.ERROR_BOOLEAN, stringValue); | |
50 | // end Kuali Foundation modification | |
51 | } | |
52 | */ | |
53 | public Object format(Object target) { | |
54 | 0 | if (target == null) { |
55 | 0 | return null; |
56 | } | |
57 | // begin Kuali Foundation modification | |
58 | 0 | if (target instanceof String) { |
59 | 0 | DelegationType delegationType = DelegationType.fromCode(((String)target).trim().toUpperCase()); |
60 | 0 | if (delegationType != null) { |
61 | 0 | return delegationType.getLabel(); |
62 | } else { | |
63 | 0 | return KEWConstants.DELEGATION_BOTH_LABEL; |
64 | } | |
65 | } else { | |
66 | 0 | return ""; |
67 | } | |
68 | } | |
69 | } |