01: /*
02: * Copyright 2005-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
05: * in compliance with the License. You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software distributed under the License
10: * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11: * or implied. See the License for the specific language governing permissions and limitations under
12: * the License.
13: */
14:
15: package org.strecks.injection.handler;
16:
17: import java.util.Map;
18:
19: import javax.servlet.http.HttpServletRequest;
20: import javax.servlet.http.HttpSession;
21:
22: import org.strecks.constants.InfrastructureKeys;
23: import org.strecks.context.ActionContext;
24: import org.strecks.util.Assert;
25:
26: /**
27: * Injection handler to find redirect parameter from the <code>HttpServletRequest</code> by using the
28: * <code>HttpServletRequest.getAttribute(InfrastructureKeys.REDIRECT_PARAMETERS)</code> method. No type conversion is
29: * necessary
30: * @author Phil Zoio
31: */
32: public class RedirectParameterInjectionHandler implements
33: InjectionHandler {
34:
35: private String parameterName;
36:
37: public RedirectParameterInjectionHandler(String parameterName) {
38:
39: super ();
40:
41: Assert.notNull(parameterName);
42: this .parameterName = parameterName;
43:
44: }
45:
46: public String getParameterName() {
47: return parameterName;
48: }
49:
50: public Object getValue(ActionContext injectionContext) {
51:
52: HttpServletRequest request = injectionContext.getRequest();
53:
54: HttpSession session = request.getSession(false);
55:
56: if (session == null) {
57: return null;
58: } else {
59: Map map = (Map) session
60: .getAttribute(InfrastructureKeys.REDIRECT_PARAMETERS);
61: if (map != null) {
62: return map.get(parameterName);
63: }
64: return null;
65: }
66: }
67:
68: }
|