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