Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
TurbineServlet |
|
| 1.0;1 |
1 | package org.apache.turbine.services.servlet; | |
2 | ||
3 | ||
4 | /* | |
5 | * Licensed to the Apache Software Foundation (ASF) under one | |
6 | * or more contributor license agreements. See the NOTICE file | |
7 | * distributed with this work for additional information | |
8 | * regarding copyright ownership. The ASF licenses this file | |
9 | * to you under the Apache License, Version 2.0 (the | |
10 | * "License"); you may not use this file except in compliance | |
11 | * with the License. You may obtain a copy of the License at | |
12 | * | |
13 | * http://www.apache.org/licenses/LICENSE-2.0 | |
14 | * | |
15 | * Unless required by applicable law or agreed to in writing, | |
16 | * software distributed under the License is distributed on an | |
17 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
18 | * KIND, either express or implied. See the License for the | |
19 | * specific language governing permissions and limitations | |
20 | * under the License. | |
21 | */ | |
22 | ||
23 | ||
24 | import java.io.InputStream; | |
25 | import java.net.URL; | |
26 | ||
27 | import javax.servlet.ServletConfig; | |
28 | import javax.servlet.ServletContext; | |
29 | ||
30 | import org.apache.turbine.services.TurbineServices; | |
31 | ||
32 | /** | |
33 | * Simple static accessor to the EngineContextService | |
34 | * | |
35 | * @author <a href="mailto:burton@apache.org">Kevin A. Burton</a> | |
36 | * @author <a href="mailto:raphael@apache.org">Raphaƫl Luta</a> | |
37 | * @author <a href="mailto:ekkerbj@netscape.net">Jeff Brekke</a> | |
38 | * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a> | |
39 | * @version $Id: TurbineServlet.java 1706239 2015-10-01 13:18:35Z tv $ | |
40 | */ | |
41 | 0 | public class TurbineServlet |
42 | { | |
43 | /** | |
44 | * Utility method for accessing the service | |
45 | * implementation | |
46 | * | |
47 | * @return a ServletService implementation instance | |
48 | */ | |
49 | protected static ServletService getService() | |
50 | { | |
51 | 0 | return (ServletService) TurbineServices |
52 | .getInstance().getService(ServletService.SERVICE_NAME); | |
53 | } | |
54 | ||
55 | /** | |
56 | * Returns an URL object for a given URI string. | |
57 | * This URI is considered relative to the context. | |
58 | * | |
59 | * @param uri the URI to resolve as an URL | |
60 | * @return an URL object or null is the uri is malformed or can't be resolved | |
61 | */ | |
62 | public static URL getResource(String uri) | |
63 | { | |
64 | 0 | return getService().getResource(uri); |
65 | } | |
66 | ||
67 | /** | |
68 | * Same as getResource except that it returns an InputStream | |
69 | * | |
70 | * @see javax.servlet.ServletContext#getResourceAsStream | |
71 | * @param uri the URI to resolve | |
72 | * @return an InputStream on the URI content or null | |
73 | */ | |
74 | public static InputStream getResourceAsStream(String uri) | |
75 | { | |
76 | 0 | return getService().getResourceAsStream(uri); |
77 | } | |
78 | ||
79 | /** | |
80 | * Returns the complete filesystem path for a | |
81 | * given URI | |
82 | * | |
83 | * @see javax.servlet.ServletContext#getRealPath | |
84 | * @param path the URI to resolve | |
85 | * @return the full system path of this URI | |
86 | */ | |
87 | public static String getRealPath(String path) | |
88 | { | |
89 | 0 | return getService().getRealPath(path); |
90 | } | |
91 | ||
92 | /** | |
93 | * Returns the servlet config used by this | |
94 | * Turbine web application. | |
95 | * | |
96 | * @return turbine servlet config | |
97 | */ | |
98 | public static ServletConfig getServletConfig() | |
99 | { | |
100 | 0 | return getService().getServletConfig(); |
101 | } | |
102 | ||
103 | /** | |
104 | * Returns the servlet context used by this | |
105 | * Turbine web application. | |
106 | * | |
107 | * @return turbine servlet context | |
108 | */ | |
109 | public static ServletContext getServletContext() | |
110 | { | |
111 | 0 | return getService().getServletContext(); |
112 | } | |
113 | ||
114 | /** | |
115 | * Returns the server scheme for this | |
116 | * Turbine application. This will either | |
117 | * be http or https. | |
118 | * | |
119 | * @return String | |
120 | */ | |
121 | public static String getServerScheme() | |
122 | { | |
123 | 0 | return getService().getServerScheme(); |
124 | } | |
125 | ||
126 | /** | |
127 | * Returns the server name that this | |
128 | * Turbine application is running | |
129 | * on. | |
130 | * | |
131 | * @return String | |
132 | */ | |
133 | public static String getServerName() | |
134 | { | |
135 | 0 | return getService().getServerName(); |
136 | } | |
137 | ||
138 | /** | |
139 | * Returns the port that this Turbine | |
140 | * application is running through | |
141 | * on the server. | |
142 | * | |
143 | * @return String | |
144 | */ | |
145 | public static String getServerPort() | |
146 | { | |
147 | 0 | return getService().getServerPort(); |
148 | } | |
149 | ||
150 | /** | |
151 | * Returns the context path for this | |
152 | * Turbine application. | |
153 | * | |
154 | * @return String | |
155 | */ | |
156 | public static String getContextPath() | |
157 | { | |
158 | 0 | return getService().getContextPath(); |
159 | } | |
160 | } |