1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.struts2.views.jsp;
19
20 import java.util.HashMap;
21 import java.util.Map;
22
23 import javax.servlet.ServletResponse;
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpSession;
26
27 import com.mockobjects.servlet.MockPageContext;
28
29
30 /***
31 */
32 public class StrutsMockPageContext extends MockPageContext {
33
34 private Map attributes = new HashMap();
35 private ServletResponse response;
36
37
38 public void setAttribute(String s, Object o) {
39 if ((s == null) || (o == null)) {
40 throw new NullPointerException("PageContext does not accept null attributes");
41 }
42
43 this.attributes.put(s, o);
44 }
45
46 public Object getAttribute(String key) {
47 return attributes.get(key);
48 }
49
50 public Object getAttributes(String key) {
51 return this.attributes.get(key);
52 }
53
54 public void setResponse(ServletResponse response) {
55 this.response = response;
56 }
57
58 public ServletResponse getResponse() {
59 return response;
60 }
61
62 public HttpSession getSession() {
63 HttpSession session = super.getSession();
64
65 if (session == null) {
66 session = ((HttpServletRequest) getRequest()).getSession(true);
67 }
68
69 return session;
70 }
71
72 public Object findAttribute(String s) {
73 return attributes.get(s);
74 }
75
76 public void removeAttribute(String key) {
77 this.attributes.remove(key);
78 }
79 }