1 10 11 package mondrian.tui; 12 13 import java.io.InputStream ; 14 import java.util.HashMap ; 15 import java.util.Set ; 16 import java.util.Map ; 17 import java.util.Properties ; 18 import java.util.Enumeration ; 19 import java.util.Collections ; 20 import java.net.URL ; 21 import java.net.MalformedURLException ; 22 import javax.servlet.Servlet ; 23 import javax.servlet.ServletException ; 24 import javax.servlet.ServletContext ; 25 import javax.servlet.RequestDispatcher ; 26 27 38 public class MockServletContext implements ServletContext { 39 40 public static final String PARAM_DATASOURCES_CONFIG = "DataSourcesConfig"; 41 public static final String PARAM_CHAR_ENCODING = "CharacterEncoding"; 42 public static final String PARAM_CALLBACKS = "Callbacks"; 43 44 private Map <String , URL > resources; 45 private Map <String , Object > attributes; 46 private int majorVersion; 47 private int minorVersion; 48 private Properties parameters; 49 50 public MockServletContext() { 51 this.majorVersion = 1; 52 this.minorVersion = 1; 53 this.resources = Collections.emptyMap(); 54 this.attributes = Collections.emptyMap(); 55 this.parameters = new Properties (); 56 } 57 58 59 64 public ServletContext getContext(String s) { 65 return null; 67 } 68 69 74 public int getMajorVersion() { 75 return this.majorVersion; 76 } 77 78 83 public int getMinorVersion() { 84 return this.minorVersion; 85 } 86 87 92 public String getMimeType(String s) { 93 return null; 95 } 96 97 101 public Set getResourcePaths(String s) { 102 return null; 104 } 105 106 110 public URL getResource(String name) throws MalformedURLException { 111 return resources.get(name); 112 } 113 114 118 public InputStream getResourceAsStream(String s) { 119 return null; 121 } 122 123 128 public RequestDispatcher getRequestDispatcher(String s) { 129 return null; 131 } 132 133 138 public RequestDispatcher getNamedDispatcher(String s) { 139 return null; 141 } 142 143 157 158 public Servlet getServlet(String s) throws ServletException { 159 return null; 161 } 162 163 175 public Enumeration getServlets() { 176 return null; 178 } 179 180 192 public Enumeration getServletNames() { 193 return null; 195 } 196 197 201 public void log(String s) { 202 } 204 205 214 public void log(Exception exception, String s) { 215 log(s, exception); 216 } 217 218 223 public void log(String s, Throwable throwable) { 224 } 226 227 231 public String getRealPath(String path) { 232 return path; 233 } 234 235 240 public String getServerInfo() { 241 return null; 243 } 244 245 250 public String getInitParameter(String name) { 251 return parameters.getProperty(name); 252 } 253 254 260 public Enumeration getInitParameterNames() { 261 return parameters.propertyNames(); 262 } 263 264 268 public Object getAttribute(String s) { 269 return this.attributes.get(s); 270 } 271 272 277 public Enumeration getAttributeNames() { 278 return Collections.enumeration(this.attributes.keySet()); 280 } 281 282 286 public void setAttribute(String s, Object obj) { 287 if (this.attributes == Collections.EMPTY_MAP) { 288 this.attributes = new HashMap <String , Object >(); 289 } 290 this.attributes.put(s, obj); 291 } 292 293 297 public void removeAttribute(String s) { 298 this.attributes.remove(s); 299 } 300 301 305 public String getServletContextName() { 306 return null; 308 } 309 310 311 312 313 public void setMajorVersion(int majorVersion) { 319 this.majorVersion = majorVersion; 320 } 321 public void setMinorVersion(int minorVersion) { 322 this.minorVersion = minorVersion; 323 } 324 public void addResource(String name, URL url) { 325 if (this.resources == Collections.EMPTY_MAP) { 326 this.resources = new HashMap <String , URL >(); 327 } 328 this.resources.put(name, url); 329 } 330 public void addInitParameter(String name, String value) { 331 if (value != null) { 332 this.parameters.setProperty(name, value); 333 } 334 } 335 } 336 | Popular Tags |