KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > services > servlet > TurbineServlet


1 package org.apache.turbine.services.servlet;
2
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License")
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import java.io.InputStream JavaDoc;
20 import java.net.URL JavaDoc;
21 import javax.servlet.ServletConfig JavaDoc;
22 import javax.servlet.ServletContext JavaDoc;
23
24 import org.apache.turbine.services.TurbineServices;
25
26 /**
27  * Simple static accessor to the EngineContextService
28  *
29  * @author <a HREF="mailto:burton@apache.org">Kevin A. Burton</a>
30  * @author <a HREF="mailto:raphael@apache.org">RaphaŽl Luta</a>
31  * @author <a HREF="mailto:ekkerbj@netscape.net">Jeff Brekke</a>
32  * @author <a HREF="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
33  * @version $Id: TurbineServlet.java,v 1.3.2.2 2004/05/20 03:06:49 seade Exp $
34  */

35 public class TurbineServlet
36 {
37     /**
38      * Utility method for accessing the service
39      * implementation
40      *
41      * @return a ServletService implementation instance
42      */

43     protected static ServletService getService()
44     {
45         return (ServletService) TurbineServices
46                 .getInstance().getService(ServletService.SERVICE_NAME);
47     }
48
49     /**
50      * Returns an URL object for a given URI string.
51      * This URI is considered relative to the context.
52      *
53      * @param uri the URI to resolve as an URL
54      * @return an URL object or null is the uri is malformed or can't be resolved
55      */

56     public static URL JavaDoc getResource(String JavaDoc uri)
57     {
58         return getService().getResource(uri);
59     }
60
61     /**
62      * Same as getResource except that it returns an InputStream
63      *
64      * @see javax.servlet.ServletContext#getResourceAsStream
65      * @param uri the URI to resolve
66      * @return an InputStream on the URI content or null
67      */

68     public static InputStream JavaDoc getResourceAsStream(String JavaDoc uri)
69     {
70         return getService().getResourceAsStream(uri);
71     }
72
73     /**
74      * Returns the complete filesystem path for a
75      * given URI
76      *
77      * @see javax.servlet.ServletContext#getRealPath
78      * @param uri the URI to resolve
79      * @return the full system path of this URI
80      */

81     public static String JavaDoc getRealPath(String JavaDoc path)
82     {
83         return getService().getRealPath(path);
84     }
85
86     /**
87      * Returns the servlet config used by this
88      * Turbine web application.
89      *
90      * @return turbine servlet config
91      */

92     public static ServletConfig JavaDoc getServletConfig()
93     {
94         return getService().getServletConfig();
95     }
96
97     /**
98      * Returns the servlet context used by this
99      * Turbine web application.
100      *
101      * @return turbine servlet context
102      */

103     public static ServletContext JavaDoc getServletContext()
104     {
105         return getService().getServletContext();
106     }
107
108     /**
109      * Returns the server scheme for this
110      * Turbine application. This will either
111      * be http or https.
112      *
113      * @return String
114      */

115     public static String JavaDoc getServerScheme()
116     {
117         return getService().getServerScheme();
118     }
119
120     /**
121      * Returns the server name that this
122      * Turbine application is running
123      * on.
124      *
125      * @return String
126      */

127     public static String JavaDoc getServerName()
128     {
129         return getService().getServerName();
130     }
131
132     /**
133      * Returns the port that this Turbine
134      * application is running through
135      * on the server.
136      *
137      * @return String
138      */

139     public static String JavaDoc getServerPort()
140     {
141         return getService().getServerPort();
142     }
143
144     /**
145      * Returns the context path for this
146      * Turbine application.
147      *
148      * @return String
149      */

150     public static String JavaDoc getContextPath()
151     {
152         return getService().getContextPath();
153     }
154 }
155
Popular Tags