1 package org.apache.turbine.services.servlet;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.InputStream;
23 import java.net.URL;
24 import javax.servlet.ServletConfig;
25 import javax.servlet.ServletContext;
26
27 import org.apache.turbine.services.TurbineServices;
28
29 /***
30 * Simple static accessor to the EngineContextService
31 *
32 * @author <a href="mailto:burton@apache.org">Kevin A. Burton</a>
33 * @author <a href="mailto:raphael@apache.org">Raphaël Luta</a>
34 * @author <a href="mailto:ekkerbj@netscape.net">Jeff Brekke</a>
35 * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
36 * @version $Id: TurbineServlet.java 534527 2007-05-02 16:10:59Z tv $
37 */
38 public class TurbineServlet
39 {
40 /***
41 * Utility method for accessing the service
42 * implementation
43 *
44 * @return a ServletService implementation instance
45 */
46 protected static ServletService getService()
47 {
48 return (ServletService) TurbineServices
49 .getInstance().getService(ServletService.SERVICE_NAME);
50 }
51
52 /***
53 * Returns an URL object for a given URI string.
54 * This URI is considered relative to the context.
55 *
56 * @param uri the URI to resolve as an URL
57 * @return an URL object or null is the uri is malformed or can't be resolved
58 */
59 public static URL getResource(String uri)
60 {
61 return getService().getResource(uri);
62 }
63
64 /***
65 * Same as getResource except that it returns an InputStream
66 *
67 * @see javax.servlet.ServletContext#getResourceAsStream
68 * @param uri the URI to resolve
69 * @return an InputStream on the URI content or null
70 */
71 public static InputStream getResourceAsStream(String uri)
72 {
73 return getService().getResourceAsStream(uri);
74 }
75
76 /***
77 * Returns the complete filesystem path for a
78 * given URI
79 *
80 * @see javax.servlet.ServletContext#getRealPath
81 * @param uri the URI to resolve
82 * @return the full system path of this URI
83 */
84 public static String getRealPath(String path)
85 {
86 return getService().getRealPath(path);
87 }
88
89 /***
90 * Returns the servlet config used by this
91 * Turbine web application.
92 *
93 * @return turbine servlet config
94 */
95 public static ServletConfig getServletConfig()
96 {
97 return getService().getServletConfig();
98 }
99
100 /***
101 * Returns the servlet context used by this
102 * Turbine web application.
103 *
104 * @return turbine servlet context
105 */
106 public static ServletContext getServletContext()
107 {
108 return getService().getServletContext();
109 }
110
111 /***
112 * Returns the server scheme for this
113 * Turbine application. This will either
114 * be http or https.
115 *
116 * @return String
117 */
118 public static String getServerScheme()
119 {
120 return getService().getServerScheme();
121 }
122
123 /***
124 * Returns the server name that this
125 * Turbine application is running
126 * on.
127 *
128 * @return String
129 */
130 public static String getServerName()
131 {
132 return getService().getServerName();
133 }
134
135 /***
136 * Returns the port that this Turbine
137 * application is running through
138 * on the server.
139 *
140 * @return String
141 */
142 public static String getServerPort()
143 {
144 return getService().getServerPort();
145 }
146
147 /***
148 * Returns the context path for this
149 * Turbine application.
150 *
151 * @return String
152 */
153 public static String getContextPath()
154 {
155 return getService().getContextPath();
156 }
157 }