Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ServletContextUtil |
|
| 2.6666666666666665;2.667 |
1 | /* | |
2 | * Copyright 2004-2011 the Seasar Foundation and the Others. | |
3 | * | |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | |
13 | * either express or implied. See the License for the specific language | |
14 | * governing permissions and limitations under the License. | |
15 | */ | |
16 | package org.seasar.teeda.core.util; | |
17 | ||
18 | import java.io.IOException; | |
19 | import java.io.InputStream; | |
20 | import java.net.URL; | |
21 | ||
22 | import javax.servlet.ServletContext; | |
23 | ||
24 | import org.seasar.framework.exception.IORuntimeException; | |
25 | import org.seasar.framework.util.URLUtil; | |
26 | ||
27 | /** | |
28 | * @author higa | |
29 | */ | |
30 | public class ServletContextUtil { | |
31 | ||
32 | 0 | private ServletContextUtil() { |
33 | 0 | } |
34 | ||
35 | public static URL getResource(ServletContext servletContext, String path) { | |
36 | try { | |
37 | 0 | return servletContext.getResource(path); |
38 | 0 | } catch (IOException e) { |
39 | 0 | throw new IORuntimeException(e); |
40 | } | |
41 | } | |
42 | ||
43 | public static InputStream getResourceAsStream( | |
44 | ServletContext servletContext, String path) { | |
45 | 0 | URL url = getResource(servletContext, path); |
46 | 0 | if (url == null) { |
47 | 0 | return null; |
48 | } | |
49 | 0 | return URLUtil.openStream(url); |
50 | } | |
51 | } |