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 javax.servlet.http.HttpServletRequest;
18:
19: import org.strecks.constants.InfrastructureKeys;
20: import org.strecks.context.ActionContext;
21: import org.strecks.web.RedirectHelper;
22: import org.strecks.web.RedirectHelperImpl;
23:
24: /**
25: * Injection handler to find a <code>RedirectHelper</code> instance from the
26: * <code>HttpServletRequest</code> by using the
27: * <code>HttpServletRequest.getAttribute(InfrastructureKeys.REDIRECT_HELPER)</code>. If this is
28: * <code>null</code>, it is added to the <code>HttpServletRequest</code> as an attribute under
29: * this key method, before being returned
30: * @author Phil Zoio
31: */
32: public class RedirectHelperInjectionHandler implements InjectionHandler {
33:
34: public Object getValue(ActionContext injectionContext) {
35: HttpServletRequest request = injectionContext.getRequest();
36: RedirectHelper redirectHelper = (RedirectHelper) request
37: .getAttribute(InfrastructureKeys.REDIRECT_HELPER);
38:
39: if (redirectHelper == null) {
40: redirectHelper = new RedirectHelperImpl();
41: request.setAttribute(InfrastructureKeys.REDIRECT_HELPER,
42: redirectHelper);
43: }
44: return redirectHelper;
45: }
46:
47: }
|