1 20 package org.apache.cactus.server; 21 22 import java.io.InputStream ; 23 24 import java.net.MalformedURLException ; 25 import java.net.URL ; 26 27 import java.util.Enumeration ; 28 import java.util.Hashtable ; 29 import java.util.Vector ; 30 31 import javax.servlet.RequestDispatcher ; 32 import javax.servlet.Servlet ; 33 import javax.servlet.ServletContext ; 34 import javax.servlet.ServletException ; 35 36 48 public abstract class AbstractServletContextWrapper implements ServletContext 49 { 50 53 protected ServletContext originalContext; 54 55 58 protected Hashtable initParameters; 59 60 63 private Vector logs = new Vector (); 64 65 67 70 public AbstractServletContextWrapper(ServletContext theOriginalContext) 71 { 72 this.originalContext = theOriginalContext; 73 this.initParameters = new Hashtable (); 74 } 75 76 78 82 public ServletContext getOriginalContext() 83 { 84 return this.originalContext; 85 } 86 87 94 public void setInitParameter(String theName, String theValue) 95 { 96 this.initParameters.put(theName, theValue); 97 } 98 99 108 public Vector getLogs() 109 { 110 return this.logs; 111 } 112 113 115 118 public void setAttribute(String theName, Object theAttribute) 119 { 120 this.originalContext.setAttribute(theName, theAttribute); 121 } 122 123 126 public void removeAttribute(String theName) 127 { 128 this.originalContext.removeAttribute(theName); 129 } 130 131 143 public void log(String theMessage, Throwable theCause) 144 { 145 if (theMessage != null) 146 { 147 this.logs.addElement(theMessage); 148 } 149 150 this.originalContext.log(theMessage, theCause); 151 } 152 153 164 public void log(String theMessage) 165 { 166 if (theMessage != null) 167 { 168 this.logs.addElement(theMessage); 169 } 170 171 this.originalContext.log(theMessage); 172 } 173 174 192 public void log(Exception theException, String theMessage) 193 { 194 if (theMessage != null) 195 { 196 this.logs.addElement(theMessage); 197 } 198 199 this.originalContext.log(theException, theMessage); 200 } 201 202 205 public Enumeration getServlets() 206 { 207 return this.originalContext.getServlets(); 208 } 209 210 213 public Enumeration getServletNames() 214 { 215 return this.originalContext.getServletNames(); 216 } 217 218 221 public Servlet getServlet(String theName) throws ServletException 222 { 223 return this.originalContext.getServlet(theName); 224 } 225 226 229 public String getServerInfo() 230 { 231 return this.originalContext.getServerInfo(); 232 } 233 234 237 public InputStream getResourceAsStream(String thePath) 238 { 239 return this.originalContext.getResourceAsStream(thePath); 240 } 241 242 245 public URL getResource(String thePath) throws MalformedURLException 246 { 247 return this.originalContext.getResource(thePath); 248 } 249 250 255 public RequestDispatcher getRequestDispatcher(String thePath) 256 { 257 RequestDispatcher wrappedDispatcher = null; 258 259 RequestDispatcher originalDispatcher = 260 this.originalContext.getRequestDispatcher(thePath); 261 262 if (originalDispatcher != null) 263 { 264 wrappedDispatcher = 265 new RequestDispatcherWrapper(originalDispatcher); 266 } 267 268 return wrappedDispatcher; 269 } 270 271 277 public RequestDispatcher getNamedDispatcher(String theName) 278 { 279 RequestDispatcher wrappedDispatcher = null; 280 281 RequestDispatcher originalDispatcher = 282 this.originalContext.getNamedDispatcher(theName); 283 284 if (originalDispatcher != null) 285 { 286 wrappedDispatcher = 287 new RequestDispatcherWrapper(originalDispatcher); 288 } 289 290 return wrappedDispatcher; 291 } 292 293 296 public String getRealPath(String thePath) 297 { 298 return this.originalContext.getRealPath(thePath); 299 } 300 301 304 public int getMinorVersion() 305 { 306 return this.originalContext.getMinorVersion(); 307 } 308 309 312 public String getMimeType(String theFilename) 313 { 314 return this.originalContext.getMimeType(theFilename); 315 } 316 317 320 public int getMajorVersion() 321 { 322 return this.originalContext.getMajorVersion(); 323 } 324 325 330 public Enumeration getInitParameterNames() 331 { 332 Vector names = new Vector (); 333 334 Enumeration en = this.initParameters.keys(); 336 337 while (en.hasMoreElements()) 338 { 339 String value = (String ) en.nextElement(); 340 341 names.add(value); 342 } 343 344 en = this.originalContext.getInitParameterNames(); 346 347 while (en.hasMoreElements()) 348 { 349 String value = (String ) en.nextElement(); 350 351 if (!names.contains(value)) 354 { 355 names.add(value); 356 } 357 } 358 359 return names.elements(); 360 } 361 362 368 public String getInitParameter(String theName) 369 { 370 String value = (String ) this.initParameters.get(theName); 373 374 if (value == null) 375 { 376 value = this.originalContext.getInitParameter(theName); 377 } 378 379 return value; 380 } 381 382 388 public ServletContext getContext(String theUripath) 389 { 390 ServletContext context = new ServletContextWrapper( 391 this.originalContext.getContext(theUripath)); 392 393 return context; 394 } 395 396 399 public Enumeration getAttributeNames() 400 { 401 return this.originalContext.getAttributeNames(); 402 } 403 404 407 public Object getAttribute(String theName) 408 { 409 return this.originalContext.getAttribute(theName); 410 } 411 } 412 | Popular Tags |