KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > views > jsp > WebWorkMockHttpServletRequest


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.webwork.views.jsp;
6
7 import com.mockobjects.servlet.MockHttpServletRequest;
8 import junit.framework.AssertionFailedError;
9
10 import javax.servlet.http.HttpSession JavaDoc;
11 import java.util.*;
12
13
14 /**
15  * WebWorkMockHttpServletRequest
16  *
17  * @author Jason Carreira
18  * Created Mar 28, 2003 10:28:50 PM
19  */

20 public class WebWorkMockHttpServletRequest extends MockHttpServletRequest {
21     //~ Instance fields ////////////////////////////////////////////////////////
22

23     Locale locale = Locale.US;
24     private Map attributes = new HashMap();
25     private Map parameterMap = new HashMap();
26     private String JavaDoc context = "";
27     private String JavaDoc pathInfo = "";
28     private String JavaDoc queryString;
29     private String JavaDoc requestURI;
30     private String JavaDoc scheme;
31     private String JavaDoc serverName;
32     private int serverPort;
33     private String JavaDoc encoding;
34
35     //~ Methods ////////////////////////////////////////////////////////////////
36

37     public void setAttribute(String JavaDoc s, Object JavaDoc o) {
38         attributes.put(s, o);
39     }
40
41     public Object JavaDoc getAttribute(String JavaDoc s) {
42         return attributes.get(s);
43     }
44
45     public Enumeration getAttributeNames() {
46         Vector v = new Vector();
47         v.addAll(attributes.keySet());
48
49         return v.elements();
50     }
51
52     public String JavaDoc getContextPath() {
53         return this.context;
54     }
55
56     public void setLocale(Locale locale) {
57         this.locale = locale;
58     }
59
60     public Locale getLocale() {
61         return locale;
62     }
63
64     public void setCharacterEncoding(String JavaDoc s) {
65         this.encoding = s;
66     }
67
68     public String JavaDoc getCharacterEncoding() {
69         return encoding;
70     }
71
72     public void setParameterMap(Map parameterMap) {
73         this.parameterMap = parameterMap;
74     }
75
76     public Map getParameterMap() {
77         return parameterMap;
78     }
79
80     public String JavaDoc getPathInfo() {
81         return pathInfo;
82     }
83
84     public void setQueryString(String JavaDoc queryString) {
85         this.queryString = queryString;
86     }
87
88     public String JavaDoc getQueryString() {
89         return queryString;
90     }
91
92     public void setRequestURI(String JavaDoc requestURI) {
93         this.requestURI = requestURI;
94     }
95
96     public String JavaDoc getRequestURI() {
97         return requestURI;
98     }
99
100     public void setScheme(String JavaDoc scheme) {
101         this.scheme = scheme;
102     }
103
104     public String JavaDoc getScheme() {
105         return scheme;
106     }
107
108     public void setServerName(String JavaDoc serverName) {
109         this.serverName = serverName;
110     }
111
112     public String JavaDoc getServerName() {
113         return serverName;
114     }
115
116     public void setServerPort(int serverPort) {
117         this.serverPort = serverPort;
118     }
119
120     public int getServerPort() {
121         return serverPort;
122     }
123
124     public HttpSession JavaDoc getSession() {
125         HttpSession JavaDoc session = null;
126
127         try {
128             session = super.getSession();
129         } catch (AssertionFailedError e) {
130             //ignore
131
}
132
133         if (session == null) {
134             session = new WebWorkMockHttpSession();
135             setSession(session);
136         }
137
138         return session;
139     }
140
141     public void setupGetContext(String JavaDoc context) {
142         this.context = context;
143     }
144
145     public void setupGetPathInfo(String JavaDoc pathInfo) {
146         this.pathInfo = pathInfo;
147     }
148 }
149
Popular Tags