01: /*
02: * Copyright 2005-2006 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.php
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package edu.iu.uis.eden.web;
18:
19: import org.apache.commons.beanutils.Converter;
20:
21: /**
22: * A BeanUtils Converter which delegates to an original convertor or a KEW converter depending on
23: * what the current {@link ModuleContext} is. This allows for the KEW struts module to run inside
24: * of an ActionServlet that has the "convertNull" init-param set to null. The KEW module
25: * depends on this being set to true in order for the form processing to work properly.
26: * When KEW is embedded in a web application where this is not the case, we need to work
27: * around the issue by registering custom converters to convert the values properly when inside
28: * the context of the KEW struts module but preserve the conversion behavior of the parent
29: * struts module.
30: *
31: * @author ewestfal
32: */
33: public class ContextSensitiveConverter implements Converter {
34:
35: private Converter originalConverter;
36: private Converter kewConverter;
37:
38: public ContextSensitiveConverter(Converter originalConverter,
39: Converter kewConverter) {
40: this .originalConverter = originalConverter;
41: this .kewConverter = kewConverter;
42: }
43:
44: public Object convert(Class type, Object object) {
45: if (ModuleContext.isKew()) {
46: return kewConverter.convert(type, object);
47: } else {
48: return originalConverter.convert(type, object);
49: }
50: }
51:
52: }
|