Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
ServletContextResolver |
|
| 1.6666666666666667;1.667 |
1 | /* |
|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
3 | * contributor license agreements. See the NOTICE file distributed with |
|
4 | * this work for additional information regarding copyright ownership. |
|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
6 | * (the "License"); you may not use this file except in compliance with |
|
7 | * the License. You may obtain a copy of the License at |
|
8 | * |
|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
10 | * |
|
11 | * Unless required by applicable law or agreed to in writing, software |
|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 | * See the License for the specific language governing permissions and |
|
15 | * limitations under the License. |
|
16 | */ |
|
17 | package org.apache.commons.scxml.env.servlet; |
|
18 | ||
19 | import javax.servlet.ServletContext; |
|
20 | ||
21 | import org.apache.commons.scxml.PathResolver; |
|
22 | ||
23 | /** |
|
24 | * A wrapper around ServletContext that implements PathResolver. |
|
25 | * |
|
26 | * @see org.apache.commons.scxml.PathResolver |
|
27 | */ |
|
28 | public class ServletContextResolver implements PathResolver { |
|
29 | ||
30 | /** Cannot accept a null ServletContext, it will just throw |
|
31 | * NullPointerException down the road. */ |
|
32 | private static final String ERR_SERVLET_CTX_NULL = |
|
33 | "ServletContextResolver cannot be instantiated with a null" |
|
34 | + " ServletContext"; |
|
35 | ||
36 | /** The SevletContext we will use to resolve paths. */ |
|
37 | 1 | private ServletContext ctx = null; |
38 | ||
39 | /** |
|
40 | * Constructor. |
|
41 | * |
|
42 | * @param ctx The ServletContext instance for this web application. |
|
43 | */ |
|
44 | 1 | public ServletContextResolver(final ServletContext ctx) { |
45 | 1 | if (ctx == null) { |
46 | 1 | throw new IllegalArgumentException(ERR_SERVLET_CTX_NULL); |
47 | } |
|
48 | 0 | this.ctx = ctx; |
49 | 0 | } |
50 | ||
51 | /** |
|
52 | * Delegates to the underlying ServletContext's getRealPath(String). |
|
53 | * |
|
54 | * @param ctxPath context sensitive path, can be a relative URL |
|
55 | * @return resolved path (an absolute URL) or <code>null</code> |
|
56 | * @see org.apache.commons.scxml.PathResolver#resolvePath(java.lang.String) |
|
57 | */ |
|
58 | public String resolvePath(final String ctxPath) { |
|
59 | 0 | return ctx.getRealPath(ctxPath); |
60 | } |
|
61 | ||
62 | /** |
|
63 | * Retrieve the PathResolver rooted at the given path. |
|
64 | * |
|
65 | * @param ctxPath context sensitive path, can be a relative URL |
|
66 | * @return returns a new resolver rooted at ctxPath |
|
67 | * @see org.apache.commons.scxml.PathResolver#getResolver(java.lang.String) |
|
68 | */ |
|
69 | public PathResolver getResolver(final String ctxPath) { |
|
70 | 0 | return this; |
71 | } |
|
72 | ||
73 | } |
|
74 |