KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > webman > template > jsp > WebManServletContext


1 package de.webman.template.jsp;
2
3 import javax.servlet.*;
4
5 import java.io.InputStream JavaDoc;
6 import java.io.IOException JavaDoc;
7 import java.net.URL JavaDoc;
8 import java.net.MalformedURLException JavaDoc;
9 import java.util.Enumeration JavaDoc;
10
11
12 /**
13  *
14  * Defines a set of methods that a servlet uses to communicate
15  * with a servlet engine, for example, to get the MIME type of a file,
16  * locate other servlets running on the server, or
17  * write to a servlet log file.
18  *
19  * <p>The servlet engine talks to the servlet by returning
20  * a <code>ServletContext</code> object (defined by this interface)
21  * that gives servlets information about their environment. Servlets use the
22  * {@link ServletConfig#getServletContext} method to get
23  * the <code>ServletContext</code> object.
24  *
25  * <p>If the server supports
26  * multiple or virtual hosts, the <code>ServletContext</code> object
27  * must be at least as unique as the host. Servlet engines can also
28  * create <code>ServletContext</code> objects
29  * that are unique to a group of servlets
30  * and are tied to a specific part of the host's URL namespace.
31  * You can assign this grouping administratively or define it in
32  * a deployment descriptor file.
33  *
34  * <p>The <code>ServletContext</code> object is contained within
35  * the {@link ServletConfig} object, which the
36  * Web server provides the
37  * servlet when the servlet is initialized. You can access
38  * the <code>ServletConfig</code> object by using the
39  * {@link Servlet#getServletConfig} method.
40  *
41  * @author Various
42  * @version $Version$
43  *
44  * @see Servlet#getServletConfig
45  * @see ServletConfig#getServletContext
46  *
47  */

48
49 public class WebManServletContext implements ServletContext {
50
51     /** Document Root */
52     private String JavaDoc docRoot;
53
54     /**
55      * Returns a <code>ServletContext</code> object that
56      * corresponds to a specified URL on the server.
57      *
58      * <p>This method allows servlets to gain
59      * access to the resources located at a specified URL and obtain
60      * {@link RequestDispatcher} objects from it.
61      *
62      * <p>In security conscious environments, the servlet engine can
63      * return <code>null</code> for a given URL.
64      *
65      * @param uripath a <code>String</code> specifying the URL for
66      * which you are requesting a <code>ServletContext</code>
67      * object
68      *
69      * @return the <code>ServletContext</code> object that
70      * corresponds to the named URL
71      *
72      * @see RequestDispatcher
73      *
74      */

75
76     public ServletContext getContext(String JavaDoc uripath)
77     {
78         return this;
79     }
80     
81     
82     public void setDocRoot(String JavaDoc root)
83     {
84         docRoot = root;
85     }
86     
87     /**
88      * Returns the major version of the Java Servlet API that this
89      * Web server supports. All implementations that comply
90      * with Version 2.1 must have this method
91      * return the integer 2.
92      *
93      * @return 2
94      *
95      */

96     
97     public int getMajorVersion()
98     {
99         return 2;
100     }
101     
102     /**
103         2.3
104         Returns a directory-like listing of all the paths to resources within the web application
105         whose longest sub-path matches the supplied path argument.
106         Paths indicating subdirectory paths end with a '/'.
107         The returned paths are all relative to the root of the web application and have a leading '/'.
108     */

109     public java.util.Set JavaDoc getResourcePaths(java.lang.String JavaDoc path)
110     {
111         return null;
112     }
113
114     
115     /**
116         2.3
117         Returns the name of this web application correponding to this ServletContext
118         as specified in the deployment descriptor for this web application
119         by the display-name element.
120     */

121     public java.lang.String JavaDoc getServletContextName()
122     {
123         return null;
124     }
125     
126     /**
127      * Returns the MIME type of the specified file, or <code>null</code> if
128      * the MIME type is not known. The MIME type is determined
129      * by the configuration of the servlet engine. Common MIME
130      * types are <code>"text/html"</code> and <code>"image/gif"</code>.
131      *
132      *
133      * @param a <code>String</code> specifying the name
134      * of the file whose MIME type you want
135      * to check
136      *
137      * @return a <code>String</code> specifying the MIME type
138      *
139      */

140
141     public String JavaDoc getMimeType(String JavaDoc file)
142      {
143         return null;
144      }
145     
146     
147
148     /**
149      * Returns the minor version of the Servlet API that this
150      * Web server supports. All implementations that comply
151      * with Version 2.1 must have this method
152      * return the integer 1.
153      *
154      * @return 1
155      *
156      */

157
158     public int getMinorVersion()
159     {
160         return 2;
161     }
162     
163
164     /**
165      * Returns the resource that is mapped to a specified
166      * path. The path must be in the form
167      * <code>/dir/dir/file.ext</code>.
168      *
169      * <p>This method allows the Web
170      * server to make a resource available to a servlet from
171      * any source. Resources
172      * can be located on a local or remote
173      * file system, in a database, or on a remote network site.
174      *
175      * <p>This method can return <code>null</code>
176      * if no resource is mapped to the pathname.
177      *
178      * <p>The servlet engine must implement the URL handlers
179      * and <code>URLConnection</code> objects that are necessary
180      * to access the resource.
181      *
182      * <p>This method has a different purpose than
183      * <code>java.lang.Class.getResource</code>,
184      * which looks up resources based on a class loader. This
185      * method does not use class loaders.
186      *
187      * @param path a <code>String</code> specifying
188      * the path to the resource,
189      * in the form <code>/dir/dir/file.ext</code>
190      *
191      * @return the resource located at the named path,
192      * or <code>null</code> if there is no resource
193      * at that path
194      *
195      * @exception MalformedURLException if the pathname is not given in
196      * the correct form
197      *
198      */

199     
200     public URL JavaDoc getResource(String JavaDoc path) throws MalformedURLException JavaDoc
201     {return null;}
202     
203     
204
205
206
207     /**
208      * Returns the resource located at the named path as
209      * an <code>InputStream</code> object.
210      *
211      * <p>The data in the <code>InputStream</code> can be
212      * of any type or length. The path must be of
213      * the form <code>/dir/dir/file.ext</code>. This method
214      * returns <code>null</code> if no resource exists at
215      * the specified path.
216      *
217      * <p>Metainformation such as content length and content type
218      * that is available when you use the <code>getResource</code>
219      * method is lost when you use this method.
220      *
221      * <p>The servlet engine must implement the URL handlers
222      * and <code>URLConnection</code> objects necessary to access
223      * the resource.
224      *
225      * <p>This method is different from
226      * <code>java.lang.Class.getResourceAsStream</code>,
227      * which uses a class loader. This method allows servlet engines
228      * to make a resource available
229      * to a servlet from any location, without using a class loader.
230      *
231      *
232      * @param name a <code>String</code> specifying the path
233      * to the resource,
234      * in the form <code>/dir/dir/file.ext</code>
235      *
236      * @return the <code>InputStream</code> returned to the
237      * servlet, or <code>null</code> if no resource
238      * exists at the specified path
239      *
240      *
241      */

242
243     public InputStream JavaDoc getResourceAsStream(String JavaDoc path)
244     {
245         return null;
246     }
247     
248     
249     
250
251
252
253     /**
254      *
255      * Returns a {@link RequestDispatcher} object that acts
256      * as a wrapper for the resource located at the named path.
257      * You can use a <code>RequestDispatcher</code> object to forward
258      * a request to the resource or include a resource in a response.
259      *
260      * <p>The pathname must be in the form <code>/dir/dir/file.ext</code>.
261      * This method returns <code>null</code> if the <code>ServletContext</code>
262      * cannot return a <code>RequestDispatcher</code>.
263      *
264      * <p>The servlet engine is responsible for wrapping the resource
265      * with a <code>RequestDispatcher</code> object.
266      *
267      * @param urlpath a <code>String</code> specifying the pathname
268      * to the resource
269      *
270      * @return a <code>RequestDispatcher</code> object
271      * that acts as a wrapper for the resource
272      * at the path you specify
273      *
274      * @see RequestDispatcher
275      *
276      */

277
278     public RequestDispatcher getRequestDispatcher(String JavaDoc urlpath)
279     {
280         return null;
281     }
282     
283     
284     
285     
286     
287     /**
288      *
289      * @deprecated As of Java Servlet API 2.1, with no replacement.
290      *
291      * <p>This method was originally defined to retrieve a servlet
292      * from a <code>ServletContext</code>. In this version, this method
293      * always returns <code>null</code> and remains only to preserve
294      * binary compatibility. This method will be permanently removed
295      * in a future version of the Java Servlet API.
296      *
297      */

298
299     public Servlet getServlet(String JavaDoc name) throws ServletException
300     {
301         return null;
302     }
303     
304   
305   
306   
307     
308
309     /**
310      *
311      *
312 @deprecated As of Java Servlet API 2.0, with no replacement.
313      *
314      * <p>This method was originally defined to return an <code>Enumeration</code>
315      * of all the servlets known to this servlet context. In this
316      * version, this method always returns an empty enumeration and
317      * remains only to preserve binary compatibility. This method
318      * will be permanently removed in a future version of the Java
319      * Servlet API.
320      *
321      */

322     
323     public Enumeration JavaDoc getServlets()
324     {
325         return null;
326     }
327     
328     
329     
330     
331     
332
333     /**
334      * @deprecated As of Java Servlet API 2.1, with no replacement.
335      *
336      * <p>This method was originally defined to return an
337      * <code>Enumeration</code>
338      * of all the servlet names known to this context. In this version,
339      * this method always returns an empty <code>Enumeration</code> and
340      * remains only to preserve binary compatibility. This method will
341      * be permanently removed in a future version of the Java Servlet API.
342      *
343      */

344  
345     public Enumeration JavaDoc getServletNames()
346     {
347         return null;
348     }
349     
350     
351   
352   
353     
354     
355     /**
356      *
357      * Writes the specified message to a servlet log file, which is usually
358      * an event log. The message provides explanatory information about
359      * an exception or error or an action the servlet engine takes. The name
360      * and type of the servlet log file is specific to the servlet engine.
361      *
362      *
363      * @param msg a <code>String</code> specifying the explanatory
364      * message to be written to the log file
365      *
366      */

367      
368     public void log(String JavaDoc msg)
369     {}
370     
371     
372     
373     
374     
375
376     /**
377      * @deprecated As of Java Servlet API 2.1, use
378      * {@link log(String message, Throwable throwable)}
379      * instead.
380      *
381      * <p>This method was originally defined to write an
382      * exception's stack trace and an explanatory error message
383      * to the servlet log file.
384      *
385      */

386
387     public void log(Exception JavaDoc exception, String JavaDoc msg)
388     {}
389     
390     
391     
392     
393
394     /**
395      * Writes the stack trace and an explanatory message
396      * for a given <code>Throwable</code> exception
397      * to the servlet log file. The stack trace is
398      * part of the <code>Throwable</code> object, and
399      * the message is the one you specify in the <code>message</code>
400      * parameter. The name and type of the servlet log file is specific to
401      * the servlet engine, but it is usually an event log.
402      *
403      *
404      * @param message a <code>String</code> that
405      * describes the error or exception
406      *
407      * @param throwable the <code>Throwable</code> error
408      * or exception
409      *
410      */

411     
412     public void log(String JavaDoc message, Throwable JavaDoc throwable)
413     {}
414     
415     
416     
417     
418     
419     /**
420      * Returns a <code>String</code> containing the real path
421      * that corresponds to a virtual path. A virtual path contains
422      * a servlet name followed by the name of a file the servlet
423      * should act upon, in the form
424      * <code><i>/dir/dir/servlet/file.ext</i></code>.
425      * In this form, <i>file.ext</i> is a filename used instead
426      * of the path to the file. The servlet locates the file and
427      * translates the file name to the path that locates the file.
428      *
429      * <p>The real path the servlet returns is in a form
430      * appropriate to the computer and operating system on
431      * which the servlet engine is running, including the
432      * proper path separators. This method returns <code>null</code>
433      * if the servlet engine cannot translate the virtual path
434      * to a real path for any reason.
435      *
436      *
437      * @param path a <code>String</code> specifying a virtual path,
438      * in the form
439      * <code><i>/dir/dir/servlet/file.ext</i></code>
440      *
441      *
442      * @return a <code>String</code> specifying the real path,
443      * with path separators appropriate for the system
444      * on which the servlet engine is running
445      *
446      *
447      */

448     public String JavaDoc getRealPath(String JavaDoc path)
449     {
450         if (docRoot == null)
451             return path;
452         return docRoot + path;
453     }
454     
455     
456
457
458     /**
459      * Returns the name and version of the servlet engine on which
460      * the servlet is running.
461      *
462      * <p>The form of the returned string is <i>servername</i>/<i>versionnumber</i>.
463      * For example, the Java Web Server can return the string
464      * <code>Java Web Server/1.1.3</code>.
465      *
466      * <p>You can design the servlet engine to have this method return
467      * other optional information in parentheses after the primary string,
468      * for example,
469      * <code>Java Web Server/1.1.3 (JDK 1.1.6; Windows NT 4.0 x86)</code>.
470      *
471      *
472      * @return a <code>String</code> containing at least the
473      * servlet engine name and version number
474      *
475      */

476
477     public String JavaDoc getServerInfo()
478     {
479         return "Webman Server";
480     }
481     
482
483     /**
484      * Returns the servlet engine attribute with the given name,
485      * or <code>null</code>
486      * if there is none. An attribute allows a servlet engine to give the
487      * servlet additional information not
488      * already provided by this interface. See your
489      * Web server documentation for information about its attributes.
490      *
491      * <p>The attribute is returned as a <code>java.lang.Object</code>.
492      * Attribute names should follow the same convention as package
493      * names. The Java Servlet API specification reserves names
494      * matching <code>java.*</code>, <code>javax.*</code>,
495      * and <code>sun.*</code>.
496      *
497      * @param name a <code>String</code> specifying the name
498      * of the attribute
499      *
500      * @return an <code>Object</code containing the value
501      * of the attribute, or <code>null</code>
502      * if no attribute exists matching the given
503      * name
504      *
505      *
506      */

507   
508     public Object JavaDoc getAttribute(String JavaDoc name)
509     {
510         return null;
511     }
512     
513     
514     
515
516     /**
517      * Returns an <code>Enumeration</code> containing the
518      * attribute names available
519      * within this servlet context. You can use the
520      * {@link #getAttribute} method with an attribute name
521      * to get the value of an attribute.
522      *
523      * @return an <code>Enumeration</code> of attribute
524      * names
525      *
526      * @see #getAttribute
527      *
528      */

529
530     public Enumeration JavaDoc getAttributeNames()
531     {
532         return new java.util.Hashtable JavaDoc().elements();
533     
534     }
535     
536     
537     /**
538      *
539      * Gives an attribute a name in this servlet context. If
540      * the name specified is already used for an attribute, this
541      * method will overwrite the old attribute and bind the name
542      * to the new attribute.
543      *
544      * <p>Attribute names should follow the same convention as package
545      * names. The Java Servlet API specification reserves names
546      * matching <code>java.*</code>, <code>javax.*</code>, and
547      * <code>sun.*</code>.
548      *
549      *
550      * @param name a <code>String</code> specifying the name
551      * of the attribute
552      *
553      *
554      * @param object an <code>Object</code> representing the
555      * attribute to be given the name
556      *
557      *
558      *
559      */

560     
561     public void setAttribute(String JavaDoc name, Object JavaDoc object)
562     {}
563     
564     
565
566     public String JavaDoc getInitParameter(String JavaDoc param)
567     {
568         return "";
569     }
570     
571     public java.util.Enumeration JavaDoc getInitParameterNames()
572     {
573         return new java.util.Hashtable JavaDoc().elements();
574     }
575
576     public RequestDispatcher getNamedDispatcher(String JavaDoc name)
577     {
578         return null;
579     }
580     /**
581      * Removes the attribute with the given name from
582      * the servlet context. If you remove an attribute, and
583      * then use {@link #getAttribute} to retrieve the
584      * attribute's value, <code>getAttribute</code> returns <code>null</code>.
585      *
586      *
587      * @param name a <code>String</code> specifying the name
588      * of the attribute to be removed
589      *
590      */

591
592     public void removeAttribute(String JavaDoc name)
593     {}
594 }
595
596
597
Popular Tags