StandardRequestContext.java
Upload User: gdxydsw
Upload Date: 2019-01-29
Package Size: 16721k
Code Size: 6k
Category:

Java Develop

Development Platform:

Java

  1. /*
  2.  * Copyright (c) JForum Team
  3.  * All rights reserved.
  4.  * 
  5.  * Redistribution and use in source and binary forms, 
  6.  * with or without modification, are permitted provided 
  7.  * that the following conditions are met:
  8.  * 
  9.  * 1) Redistributions of source code must retain the above 
  10.  * copyright notice, this list of conditions and the 
  11.  * following  disclaimer.
  12.  * 2)  Redistributions in binary form must reproduce the 
  13.  * above copyright notice, this list of conditions and 
  14.  * the following disclaimer in the documentation and/or 
  15.  * other materials provided with the distribution.
  16.  * 3) Neither the name of "Rafael Steil" nor 
  17.  * the names of its contributors may be used to endorse 
  18.  * or promote products derived from this software without 
  19.  * specific prior written permission.
  20.  * 
  21.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT 
  22.  * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
  23.  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 
  24.  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
  25.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
  26.  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
  27.  * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 
  28.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
  29.  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
  30.  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
  31.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
  32.  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
  33.  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 
  34.  * IN CONTRACT, STRICT LIABILITY, OR TORT 
  35.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
  36.  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
  37.  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
  38.  * 
  39.  * Created on 26/08/2006 21:56:05
  40.  * The JForum Project
  41.  * http://www.jforum.net
  42.  */
  43. package net.jforum.context.standard;
  44. import java.io.UnsupportedEncodingException;
  45. import java.util.Enumeration;
  46. import java.util.Hashtable;
  47. import java.util.Locale;
  48. import javax.servlet.http.Cookie;
  49. import net.jforum.context.RequestContext;
  50. import net.jforum.context.SessionContext;
  51. /**
  52.  * Request context non-dependent of HTTP 
  53.  * @author Rafael Steil
  54.  * @version $Id: StandardRequestContext.java,v 1.6 2007/09/20 16:07:09 rafaelsteil Exp $
  55.  */
  56. public class StandardRequestContext implements RequestContext
  57. {
  58. private Hashtable data;
  59. private SessionContext sessionContext;
  60. public StandardRequestContext()
  61. {
  62. this.data = new Hashtable();
  63. this.sessionContext = new StandardSessionContext();
  64. }
  65. /**
  66.  * @see net.jforum.context.RequestContext#addParameter(java.lang.String, java.lang.Object)
  67.  */
  68. public void addParameter(String name, Object value)
  69. {
  70. if (this.data.contains(name)) {
  71. this.data.remove(name);
  72. }
  73. this.data.put(name, value);
  74. }
  75. /**
  76.  * @see net.jforum.context.RequestContext#addOrReplaceParameter(java.lang.String, java.lang.Object)
  77.  */
  78. public void addOrReplaceParameter(String name, Object value) 
  79. {
  80. this.addParameter(name, value);
  81. }
  82. /**
  83.  * @see net.jforum.context.RequestContext#getAction()
  84.  */
  85. public String getAction()
  86. {
  87. return null;
  88. }
  89. /**
  90.  * @see net.jforum.context.RequestContext#getAttribute(java.lang.String)
  91.  */
  92. public Object getAttribute(String name)
  93. {
  94. return this.getParameter(name);
  95. }
  96. /**
  97.  * This method will always return null
  98.  */
  99. public String getContextPath()
  100. {
  101. return null;
  102. }
  103. /**
  104.  * This method will always return null
  105.  */
  106. public Cookie[] getCookies()
  107. {
  108. return null;
  109. }
  110. /**
  111.  * This method will always return null
  112.  */
  113. public String getHeader(String name)
  114. {
  115. return null;
  116. }
  117. /**
  118.  * @see net.jforum.context.RequestContext#getIntParameter(java.lang.String)
  119.  */
  120. public int getIntParameter(String parameter)
  121. {
  122. return Integer.parseInt(this.getParameter(parameter));
  123. }
  124. /**
  125.  * @see net.jforum.context.RequestContext#getModule()
  126.  */
  127. public String getModule()
  128. {
  129. return null;
  130. }
  131. /**
  132.  * @see net.jforum.context.RequestContext#getObjectParameter(java.lang.String)
  133.  */
  134. public Object getObjectParameter(String parameter)
  135. {
  136. return this.data.get(parameter);
  137. }
  138. /**
  139.  * @see net.jforum.context.RequestContext#getParameter(java.lang.String)
  140.  */
  141. public String getParameter(String name)
  142. {
  143. Object value = this.data.get(name);
  144. return value != null ? value.toString() : null;
  145. }
  146. /**
  147.  * @see net.jforum.context.RequestContext#getParameterNames()
  148.  */
  149. public Enumeration getParameterNames()
  150. {
  151. return this.data.elements();
  152. }
  153. /**
  154.  * This method will always return null;
  155.  */
  156. public String[] getParameterValues(String name)
  157. {
  158. return null;
  159. }
  160. /**
  161.  * This method will always return null
  162.  */
  163. public String getQueryString()
  164. {
  165. return null;
  166. }
  167. /**
  168.  * @see net.jforum.context.RequestContext#getRemoteAddr()
  169.  */
  170. public String getRemoteAddr()
  171. {
  172. return null;
  173. }
  174. /**
  175.  * This method will always return null
  176.  */
  177. public String getRemoteUser()
  178. {
  179. return null;
  180. }
  181. /**
  182.  * This method will always return null
  183.  */
  184. public String getRequestURI()
  185. {
  186. return null;
  187. }
  188. /**
  189.  * This method will always return null
  190.  */
  191. public String getScheme()
  192. {
  193. return null;
  194. }
  195. /**
  196.  * This method will always return null
  197.  */
  198. public String getServerName()
  199. {
  200. return null;
  201. }
  202. /**
  203.  * This method will always return 0
  204.  */
  205. public int getServerPort()
  206. {
  207. return 0;
  208. }
  209. /**
  210.  * @see net.jforum.context.RequestContext#getSessionContext()
  211.  */
  212. public SessionContext getSessionContext()
  213. {
  214. return this.sessionContext;
  215. }
  216. /**
  217.  * This method is equal to {@link #getSessionContext()}
  218.  */
  219. public SessionContext getSessionContext(boolean create)
  220. {
  221. return this.getSessionContext();
  222. }
  223. /**
  224.  * @see net.jforum.context.RequestContext#removeAttribute(java.lang.String)
  225.  */
  226. public void removeAttribute(String name)
  227. {
  228. this.data.remove(name);
  229. }
  230. /**
  231.  * This method is equal to {@link #addParameter(String, Object)}
  232.  */
  233. public void setAttribute(String name, Object o)
  234. {
  235. this.addParameter(name, o);
  236. }
  237. /**
  238.  * This method does nothing 
  239.  */
  240. public void setCharacterEncoding(String env) throws UnsupportedEncodingException {}
  241. public Locale getLocale() {
  242. return null;
  243. }
  244. }