01: /*
02: * Copyright 2006-2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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.module.financial.web.struts.form;
17:
18: import org.apache.commons.lang.StringUtils;
19: import org.kuali.core.service.KualiConfigurationService;
20: import org.kuali.core.web.format.Formatter;
21: import org.kuali.kfs.KFSConstants;
22: import org.kuali.kfs.KFSKeyConstants;
23: import org.kuali.kfs.context.SpringContext;
24:
25: public class CashDrawerStatusCodeFormatter extends Formatter {
26: private final String CLOSED_CD;
27: private final String CLOSED_MSG;
28:
29: private final String OPEN_CD;
30: private final String OPEN_MSG;
31:
32: private final String LOCKED_CD;
33: private final String LOCKED_MSG;
34:
35: public CashDrawerStatusCodeFormatter() {
36: CLOSED_CD = KFSConstants.CashDrawerConstants.STATUS_CLOSED;
37: CLOSED_MSG = SpringContext.getBean(
38: KualiConfigurationService.class).getPropertyString(
39: KFSKeyConstants.CashDrawer.CASH_DRAWER_STATUS_CLOSED);
40:
41: OPEN_CD = KFSConstants.CashDrawerConstants.STATUS_OPEN;
42: OPEN_MSG = SpringContext.getBean(
43: KualiConfigurationService.class).getPropertyString(
44: KFSKeyConstants.CashDrawer.CASH_DRAWER_STATUS_OPEN);
45:
46: LOCKED_CD = KFSConstants.CashDrawerConstants.STATUS_LOCKED;
47: LOCKED_MSG = SpringContext.getBean(
48: KualiConfigurationService.class).getPropertyString(
49: KFSKeyConstants.CashDrawer.CASH_DRAWER_STATUS_LOCKED);
50: }
51:
52: /**
53: * Converts the given statusCode into a status message.
54: */
55: protected Object convertToObject(String target) {
56: Object result = target;
57:
58: if (target instanceof String) {
59: String message = (String) target;
60:
61: if (StringUtils.equals(message, OPEN_MSG)) {
62: result = OPEN_CD;
63: } else if (StringUtils.equals(message, CLOSED_MSG)) {
64: result = CLOSED_CD;
65: } else if (StringUtils.equals(message, LOCKED_MSG)) {
66: result = LOCKED_CD;
67: }
68: }
69:
70: return result;
71: }
72:
73: /**
74: * Converts the given status message into a status code.
75: */
76: public Object format(Object value) {
77: Object formatted = value;
78:
79: if (value instanceof String) {
80: String statusCode = (String) value;
81:
82: if (StringUtils.equals(statusCode, CLOSED_CD)) {
83: formatted = CLOSED_MSG;
84: } else if (StringUtils.equals(statusCode, OPEN_CD)) {
85: formatted = OPEN_MSG;
86: } else if (StringUtils.equals(statusCode, LOCKED_CD)) {
87: formatted = LOCKED_MSG;
88: }
89: }
90:
91: return formatted;
92: }
93:
94: }
|