001: package de.webman.template.jsp;
002:
003: import javax.servlet.*;
004:
005: import java.io.InputStream;
006: import java.io.IOException;
007: import java.net.URL;
008: import java.net.MalformedURLException;
009: import java.util.Enumeration;
010:
011: /**
012: *
013: * Defines a set of methods that a servlet uses to communicate
014: * with a servlet engine, for example, to get the MIME type of a file,
015: * locate other servlets running on the server, or
016: * write to a servlet log file.
017: *
018: * <p>The servlet engine talks to the servlet by returning
019: * a <code>ServletContext</code> object (defined by this interface)
020: * that gives servlets information about their environment. Servlets use the
021: * {@link ServletConfig#getServletContext} method to get
022: * the <code>ServletContext</code> object.
023: *
024: * <p>If the server supports
025: * multiple or virtual hosts, the <code>ServletContext</code> object
026: * must be at least as unique as the host. Servlet engines can also
027: * create <code>ServletContext</code> objects
028: * that are unique to a group of servlets
029: * and are tied to a specific part of the host's URL namespace.
030: * You can assign this grouping administratively or define it in
031: * a deployment descriptor file.
032: *
033: * <p>The <code>ServletContext</code> object is contained within
034: * the {@link ServletConfig} object, which the
035: * Web server provides the
036: * servlet when the servlet is initialized. You can access
037: * the <code>ServletConfig</code> object by using the
038: * {@link Servlet#getServletConfig} method.
039: *
040: * @author Various
041: * @version $Version$
042: *
043: * @see Servlet#getServletConfig
044: * @see ServletConfig#getServletContext
045: *
046: */
047:
048: public class WebManServletContext implements ServletContext {
049:
050: /** Document Root */
051: private String docRoot;
052:
053: /**
054: * Returns a <code>ServletContext</code> object that
055: * corresponds to a specified URL on the server.
056: *
057: * <p>This method allows servlets to gain
058: * access to the resources located at a specified URL and obtain
059: * {@link RequestDispatcher} objects from it.
060: *
061: * <p>In security conscious environments, the servlet engine can
062: * return <code>null</code> for a given URL.
063: *
064: * @param uripath a <code>String</code> specifying the URL for
065: * which you are requesting a <code>ServletContext</code>
066: * object
067: *
068: * @return the <code>ServletContext</code> object that
069: * corresponds to the named URL
070: *
071: * @see RequestDispatcher
072: *
073: */
074:
075: public ServletContext getContext(String uripath) {
076: return this ;
077: }
078:
079: public void setDocRoot(String root) {
080: docRoot = root;
081: }
082:
083: /**
084: * Returns the major version of the Java Servlet API that this
085: * Web server supports. All implementations that comply
086: * with Version 2.1 must have this method
087: * return the integer 2.
088: *
089: * @return 2
090: *
091: */
092:
093: public int getMajorVersion() {
094: return 2;
095: }
096:
097: /**
098: 2.3
099: Returns a directory-like listing of all the paths to resources within the web application
100: whose longest sub-path matches the supplied path argument.
101: Paths indicating subdirectory paths end with a '/'.
102: The returned paths are all relative to the root of the web application and have a leading '/'.
103: */
104: public java.util.Set getResourcePaths(java.lang.String path) {
105: return null;
106: }
107:
108: /**
109: 2.3
110: Returns the name of this web application correponding to this ServletContext
111: as specified in the deployment descriptor for this web application
112: by the display-name element.
113: */
114: public java.lang.String getServletContextName() {
115: return null;
116: }
117:
118: /**
119: * Returns the MIME type of the specified file, or <code>null</code> if
120: * the MIME type is not known. The MIME type is determined
121: * by the configuration of the servlet engine. Common MIME
122: * types are <code>"text/html"</code> and <code>"image/gif"</code>.
123: *
124: *
125: * @param a <code>String</code> specifying the name
126: * of the file whose MIME type you want
127: * to check
128: *
129: * @return a <code>String</code> specifying the MIME type
130: *
131: */
132:
133: public String getMimeType(String file) {
134: return null;
135: }
136:
137: /**
138: * Returns the minor version of the Servlet API that this
139: * Web server supports. All implementations that comply
140: * with Version 2.1 must have this method
141: * return the integer 1.
142: *
143: * @return 1
144: *
145: */
146:
147: public int getMinorVersion() {
148: return 2;
149: }
150:
151: /**
152: * Returns the resource that is mapped to a specified
153: * path. The path must be in the form
154: * <code>/dir/dir/file.ext</code>.
155: *
156: * <p>This method allows the Web
157: * server to make a resource available to a servlet from
158: * any source. Resources
159: * can be located on a local or remote
160: * file system, in a database, or on a remote network site.
161: *
162: * <p>This method can return <code>null</code>
163: * if no resource is mapped to the pathname.
164: *
165: * <p>The servlet engine must implement the URL handlers
166: * and <code>URLConnection</code> objects that are necessary
167: * to access the resource.
168: *
169: * <p>This method has a different purpose than
170: * <code>java.lang.Class.getResource</code>,
171: * which looks up resources based on a class loader. This
172: * method does not use class loaders.
173: *
174: * @param path a <code>String</code> specifying
175: * the path to the resource,
176: * in the form <code>/dir/dir/file.ext</code>
177: *
178: * @return the resource located at the named path,
179: * or <code>null</code> if there is no resource
180: * at that path
181: *
182: * @exception MalformedURLException if the pathname is not given in
183: * the correct form
184: *
185: */
186:
187: public URL getResource(String path) throws MalformedURLException {
188: return null;
189: }
190:
191: /**
192: * Returns the resource located at the named path as
193: * an <code>InputStream</code> object.
194: *
195: * <p>The data in the <code>InputStream</code> can be
196: * of any type or length. The path must be of
197: * the form <code>/dir/dir/file.ext</code>. This method
198: * returns <code>null</code> if no resource exists at
199: * the specified path.
200: *
201: * <p>Metainformation such as content length and content type
202: * that is available when you use the <code>getResource</code>
203: * method is lost when you use this method.
204: *
205: * <p>The servlet engine must implement the URL handlers
206: * and <code>URLConnection</code> objects necessary to access
207: * the resource.
208: *
209: * <p>This method is different from
210: * <code>java.lang.Class.getResourceAsStream</code>,
211: * which uses a class loader. This method allows servlet engines
212: * to make a resource available
213: * to a servlet from any location, without using a class loader.
214: *
215: *
216: * @param name a <code>String</code> specifying the path
217: * to the resource,
218: * in the form <code>/dir/dir/file.ext</code>
219: *
220: * @return the <code>InputStream</code> returned to the
221: * servlet, or <code>null</code> if no resource
222: * exists at the specified path
223: *
224: *
225: */
226:
227: public InputStream getResourceAsStream(String path) {
228: return null;
229: }
230:
231: /**
232: *
233: * Returns a {@link RequestDispatcher} object that acts
234: * as a wrapper for the resource located at the named path.
235: * You can use a <code>RequestDispatcher</code> object to forward
236: * a request to the resource or include a resource in a response.
237: *
238: * <p>The pathname must be in the form <code>/dir/dir/file.ext</code>.
239: * This method returns <code>null</code> if the <code>ServletContext</code>
240: * cannot return a <code>RequestDispatcher</code>.
241: *
242: * <p>The servlet engine is responsible for wrapping the resource
243: * with a <code>RequestDispatcher</code> object.
244: *
245: * @param urlpath a <code>String</code> specifying the pathname
246: * to the resource
247: *
248: * @return a <code>RequestDispatcher</code> object
249: * that acts as a wrapper for the resource
250: * at the path you specify
251: *
252: * @see RequestDispatcher
253: *
254: */
255:
256: public RequestDispatcher getRequestDispatcher(String urlpath) {
257: return null;
258: }
259:
260: /**
261: *
262: * @deprecated As of Java Servlet API 2.1, with no replacement.
263: *
264: * <p>This method was originally defined to retrieve a servlet
265: * from a <code>ServletContext</code>. In this version, this method
266: * always returns <code>null</code> and remains only to preserve
267: * binary compatibility. This method will be permanently removed
268: * in a future version of the Java Servlet API.
269: *
270: */
271:
272: public Servlet getServlet(String name) throws ServletException {
273: return null;
274: }
275:
276: /**
277: *
278: *
279: @deprecated As of Java Servlet API 2.0, with no replacement.
280: *
281: * <p>This method was originally defined to return an <code>Enumeration</code>
282: * of all the servlets known to this servlet context. In this
283: * version, this method always returns an empty enumeration and
284: * remains only to preserve binary compatibility. This method
285: * will be permanently removed in a future version of the Java
286: * Servlet API.
287: *
288: */
289:
290: public Enumeration getServlets() {
291: return null;
292: }
293:
294: /**
295: * @deprecated As of Java Servlet API 2.1, with no replacement.
296: *
297: * <p>This method was originally defined to return an
298: * <code>Enumeration</code>
299: * of all the servlet names known to this context. In this version,
300: * this method always returns an empty <code>Enumeration</code> and
301: * remains only to preserve binary compatibility. This method will
302: * be permanently removed in a future version of the Java Servlet API.
303: *
304: */
305:
306: public Enumeration getServletNames() {
307: return null;
308: }
309:
310: /**
311: *
312: * Writes the specified message to a servlet log file, which is usually
313: * an event log. The message provides explanatory information about
314: * an exception or error or an action the servlet engine takes. The name
315: * and type of the servlet log file is specific to the servlet engine.
316: *
317: *
318: * @param msg a <code>String</code> specifying the explanatory
319: * message to be written to the log file
320: *
321: */
322:
323: public void log(String msg) {
324: }
325:
326: /**
327: * @deprecated As of Java Servlet API 2.1, use
328: * {@link log(String message, Throwable throwable)}
329: * instead.
330: *
331: * <p>This method was originally defined to write an
332: * exception's stack trace and an explanatory error message
333: * to the servlet log file.
334: *
335: */
336:
337: public void log(Exception exception, String msg) {
338: }
339:
340: /**
341: * Writes the stack trace and an explanatory message
342: * for a given <code>Throwable</code> exception
343: * to the servlet log file. The stack trace is
344: * part of the <code>Throwable</code> object, and
345: * the message is the one you specify in the <code>message</code>
346: * parameter. The name and type of the servlet log file is specific to
347: * the servlet engine, but it is usually an event log.
348: *
349: *
350: * @param message a <code>String</code> that
351: * describes the error or exception
352: *
353: * @param throwable the <code>Throwable</code> error
354: * or exception
355: *
356: */
357:
358: public void log(String message, Throwable throwable) {
359: }
360:
361: /**
362: * Returns a <code>String</code> containing the real path
363: * that corresponds to a virtual path. A virtual path contains
364: * a servlet name followed by the name of a file the servlet
365: * should act upon, in the form
366: * <code><i>/dir/dir/servlet/file.ext</i></code>.
367: * In this form, <i>file.ext</i> is a filename used instead
368: * of the path to the file. The servlet locates the file and
369: * translates the file name to the path that locates the file.
370: *
371: * <p>The real path the servlet returns is in a form
372: * appropriate to the computer and operating system on
373: * which the servlet engine is running, including the
374: * proper path separators. This method returns <code>null</code>
375: * if the servlet engine cannot translate the virtual path
376: * to a real path for any reason.
377: *
378: *
379: * @param path a <code>String</code> specifying a virtual path,
380: * in the form
381: * <code><i>/dir/dir/servlet/file.ext</i></code>
382: *
383: *
384: * @return a <code>String</code> specifying the real path,
385: * with path separators appropriate for the system
386: * on which the servlet engine is running
387: *
388: *
389: */
390: public String getRealPath(String path) {
391: if (docRoot == null)
392: return path;
393: return docRoot + path;
394: }
395:
396: /**
397: * Returns the name and version of the servlet engine on which
398: * the servlet is running.
399: *
400: * <p>The form of the returned string is <i>servername</i>/<i>versionnumber</i>.
401: * For example, the Java Web Server can return the string
402: * <code>Java Web Server/1.1.3</code>.
403: *
404: * <p>You can design the servlet engine to have this method return
405: * other optional information in parentheses after the primary string,
406: * for example,
407: * <code>Java Web Server/1.1.3 (JDK 1.1.6; Windows NT 4.0 x86)</code>.
408: *
409: *
410: * @return a <code>String</code> containing at least the
411: * servlet engine name and version number
412: *
413: */
414:
415: public String getServerInfo() {
416: return "Webman Server";
417: }
418:
419: /**
420: * Returns the servlet engine attribute with the given name,
421: * or <code>null</code>
422: * if there is none. An attribute allows a servlet engine to give the
423: * servlet additional information not
424: * already provided by this interface. See your
425: * Web server documentation for information about its attributes.
426: *
427: * <p>The attribute is returned as a <code>java.lang.Object</code>.
428: * Attribute names should follow the same convention as package
429: * names. The Java Servlet API specification reserves names
430: * matching <code>java.*</code>, <code>javax.*</code>,
431: * and <code>sun.*</code>.
432: *
433: * @param name a <code>String</code> specifying the name
434: * of the attribute
435: *
436: * @return an <code>Object</code containing the value
437: * of the attribute, or <code>null</code>
438: * if no attribute exists matching the given
439: * name
440: *
441: *
442: */
443:
444: public Object getAttribute(String name) {
445: return null;
446: }
447:
448: /**
449: * Returns an <code>Enumeration</code> containing the
450: * attribute names available
451: * within this servlet context. You can use the
452: * {@link #getAttribute} method with an attribute name
453: * to get the value of an attribute.
454: *
455: * @return an <code>Enumeration</code> of attribute
456: * names
457: *
458: * @see #getAttribute
459: *
460: */
461:
462: public Enumeration getAttributeNames() {
463: return new java.util.Hashtable().elements();
464:
465: }
466:
467: /**
468: *
469: * Gives an attribute a name in this servlet context. If
470: * the name specified is already used for an attribute, this
471: * method will overwrite the old attribute and bind the name
472: * to the new attribute.
473: *
474: * <p>Attribute names should follow the same convention as package
475: * names. The Java Servlet API specification reserves names
476: * matching <code>java.*</code>, <code>javax.*</code>, and
477: * <code>sun.*</code>.
478: *
479: *
480: * @param name a <code>String</code> specifying the name
481: * of the attribute
482: *
483: *
484: * @param object an <code>Object</code> representing the
485: * attribute to be given the name
486: *
487: *
488: *
489: */
490:
491: public void setAttribute(String name, Object object) {
492: }
493:
494: public String getInitParameter(String param) {
495: return "";
496: }
497:
498: public java.util.Enumeration getInitParameterNames() {
499: return new java.util.Hashtable().elements();
500: }
501:
502: public RequestDispatcher getNamedDispatcher(String name) {
503: return null;
504: }
505:
506: /**
507: * Removes the attribute with the given name from
508: * the servlet context. If you remove an attribute, and
509: * then use {@link #getAttribute} to retrieve the
510: * attribute's value, <code>getAttribute</code> returns <code>null</code>.
511: *
512: *
513: * @param name a <code>String</code> specifying the name
514: * of the attribute to be removed
515: *
516: */
517:
518: public void removeAttribute(String name) {
519: }
520: }
|