001: /*
002: * Copyright (c) JForum Team
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms,
006: * with or without modification, are permitted provided
007: * that the following conditions are met:
008: *
009: * 1) Redistributions of source code must retain the above
010: * copyright notice, this list of conditions and the
011: * following disclaimer.
012: * 2) Redistributions in binary form must reproduce the
013: * above copyright notice, this list of conditions and
014: * the following disclaimer in the documentation and/or
015: * other materials provided with the distribution.
016: * 3) Neither the name of "Rafael Steil" nor
017: * the names of its contributors may be used to endorse
018: * or promote products derived from this software without
019: * specific prior written permission.
020: *
021: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
022: * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
023: * EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
024: * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
025: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR
026: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
027: * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
028: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
029: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES
030: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
031: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
032: * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
033: * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
034: * IN CONTRACT, STRICT LIABILITY, OR TORT
035: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
036: * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
037: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
038: *
039: * Created on 26/08/2006 21:56:05
040: * The JForum Project
041: * http://www.jforum.net
042: */
043: package net.jforum.context.standard;
044:
045: import java.io.UnsupportedEncodingException;
046: import java.util.Enumeration;
047: import java.util.Hashtable;
048: import java.util.Locale;
049:
050: import javax.servlet.http.Cookie;
051:
052: import net.jforum.context.RequestContext;
053: import net.jforum.context.SessionContext;
054:
055: /**
056: * Request context non-dependent of HTTP
057: * @author Rafael Steil
058: * @version $Id: StandardRequestContext.java,v 1.6 2007/09/20 16:07:09 rafaelsteil Exp $
059: */
060: public class StandardRequestContext implements RequestContext {
061: private Hashtable data;
062: private SessionContext sessionContext;
063:
064: public StandardRequestContext() {
065: this .data = new Hashtable();
066: this .sessionContext = new StandardSessionContext();
067: }
068:
069: /**
070: * @see net.jforum.context.RequestContext#addParameter(java.lang.String, java.lang.Object)
071: */
072: public void addParameter(String name, Object value) {
073: if (this .data.contains(name)) {
074: this .data.remove(name);
075: }
076:
077: this .data.put(name, value);
078: }
079:
080: /**
081: * @see net.jforum.context.RequestContext#addOrReplaceParameter(java.lang.String, java.lang.Object)
082: */
083: public void addOrReplaceParameter(String name, Object value) {
084: this .addParameter(name, value);
085: }
086:
087: /**
088: * @see net.jforum.context.RequestContext#getAction()
089: */
090: public String getAction() {
091:
092: return null;
093: }
094:
095: /**
096: * @see net.jforum.context.RequestContext#getAttribute(java.lang.String)
097: */
098: public Object getAttribute(String name) {
099: return this .getParameter(name);
100: }
101:
102: /**
103: * This method will always return null
104: */
105: public String getContextPath() {
106: return null;
107: }
108:
109: /**
110: * This method will always return null
111: */
112: public Cookie[] getCookies() {
113: return null;
114: }
115:
116: /**
117: * This method will always return null
118: */
119: public String getHeader(String name) {
120: return null;
121: }
122:
123: /**
124: * @see net.jforum.context.RequestContext#getIntParameter(java.lang.String)
125: */
126: public int getIntParameter(String parameter) {
127: return Integer.parseInt(this .getParameter(parameter));
128: }
129:
130: /**
131: * @see net.jforum.context.RequestContext#getModule()
132: */
133: public String getModule() {
134:
135: return null;
136: }
137:
138: /**
139: * @see net.jforum.context.RequestContext#getObjectParameter(java.lang.String)
140: */
141: public Object getObjectParameter(String parameter) {
142: return this .data.get(parameter);
143: }
144:
145: /**
146: * @see net.jforum.context.RequestContext#getParameter(java.lang.String)
147: */
148: public String getParameter(String name) {
149: Object value = this .data.get(name);
150: return value != null ? value.toString() : null;
151: }
152:
153: /**
154: * @see net.jforum.context.RequestContext#getParameterNames()
155: */
156: public Enumeration getParameterNames() {
157: return this .data.elements();
158: }
159:
160: /**
161: * This method will always return null;
162: */
163: public String[] getParameterValues(String name) {
164: return null;
165: }
166:
167: /**
168: * This method will always return null
169: */
170: public String getQueryString() {
171: return null;
172: }
173:
174: /**
175: * @see net.jforum.context.RequestContext#getRemoteAddr()
176: */
177: public String getRemoteAddr() {
178:
179: return null;
180: }
181:
182: /**
183: * This method will always return null
184: */
185: public String getRemoteUser() {
186: return null;
187: }
188:
189: /**
190: * This method will always return null
191: */
192: public String getRequestURI() {
193: return null;
194: }
195:
196: /**
197: * This method will always return null
198: */
199: public String getScheme() {
200: return null;
201: }
202:
203: /**
204: * This method will always return null
205: */
206: public String getServerName() {
207: return null;
208: }
209:
210: /**
211: * This method will always return 0
212: */
213: public int getServerPort() {
214: return 0;
215: }
216:
217: /**
218: * @see net.jforum.context.RequestContext#getSessionContext()
219: */
220: public SessionContext getSessionContext() {
221: return this .sessionContext;
222: }
223:
224: /**
225: * This method is equal to {@link #getSessionContext()}
226: */
227: public SessionContext getSessionContext(boolean create) {
228: return this .getSessionContext();
229: }
230:
231: /**
232: * @see net.jforum.context.RequestContext#removeAttribute(java.lang.String)
233: */
234: public void removeAttribute(String name) {
235: this .data.remove(name);
236: }
237:
238: /**
239: * This method is equal to {@link #addParameter(String, Object)}
240: */
241: public void setAttribute(String name, Object o) {
242: this .addParameter(name, o);
243: }
244:
245: /**
246: * This method does nothing
247: */
248: public void setCharacterEncoding(String env)
249: throws UnsupportedEncodingException {
250: }
251:
252: public Locale getLocale() {
253:
254: return null;
255: }
256: }
|