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.web;
16:
17: import javax.servlet.ServletContext;
18: import javax.servlet.http.HttpServletRequest;
19: import javax.servlet.http.HttpSession;
20:
21: import org.strecks.util.Assert;
22:
23: /**
24: * Basic implementation of <code>WebHelper</code>
25: * @author Phil Zoio
26: */
27: public class WebHelperImpl implements WebHelper {
28:
29: private HttpServletRequest request;
30:
31: private ServletContext context;
32:
33: public WebHelperImpl(HttpServletRequest request,
34: ServletContext context) {
35: super ();
36: Assert.notNull(request);
37: Assert.notNull(context);
38:
39: this .request = request;
40: this .context = context;
41: }
42:
43: public void setRequestAttribute(String name, Object value) {
44: request.setAttribute(name, value);
45: }
46:
47: public void setSessionAttribute(String name, Object value) {
48: request.getSession().setAttribute(name, value);
49: }
50:
51: public void setContextAttribute(String name, Object value) {
52: context.setAttribute(name, value);
53: }
54:
55: public void removeRequestAttribute(String name) {
56: request.removeAttribute(name);
57: }
58:
59: public void removeSessionAttribute(String name) {
60: // don't create a session unless you need to!
61: HttpSession session = request.getSession(false);
62: if (session != null)
63: session.removeAttribute(name);
64: }
65:
66: public void removeContextAttribute(String name) {
67: context.removeAttribute(name);
68: }
69:
70: }
|