Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
URLResolver |
|
| 2.3333333333333335;2.333 |
1 | /* |
|
2 | * |
|
3 | * Copyright 2005-2006 The Apache Software Foundation. |
|
4 | * |
|
5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
6 | * you may not use this file except in compliance with the License. |
|
7 | * 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 | */ |
|
18 | package org.apache.commons.scxml.env; |
|
19 | ||
20 | import java.net.MalformedURLException; |
|
21 | import java.net.URL; |
|
22 | ||
23 | import org.apache.commons.logging.Log; |
|
24 | import org.apache.commons.logging.LogFactory; |
|
25 | import org.apache.commons.scxml.PathResolver; |
|
26 | ||
27 | /** |
|
28 | * A PathResolver implementation that resolves against a base URL. |
|
29 | * |
|
30 | * @see org.apache.commons.scxml.PathResolver |
|
31 | */ |
|
32 | public class URLResolver implements PathResolver { |
|
33 | ||
34 | /** Implementation independent log category. */ |
|
35 | 45 | private Log log = LogFactory.getLog(PathResolver.class); |
36 | ||
37 | /** The base URL to resolve against. */ |
|
38 | 39 | private URL baseURL = null; |
39 | ||
40 | /** |
|
41 | * Constructor. |
|
42 | * |
|
43 | * @param baseURL The base URL to resolve against |
|
44 | */ |
|
45 | 39 | public URLResolver(final URL baseURL) { |
46 | 39 | this.baseURL = baseURL; |
47 | 39 | } |
48 | ||
49 | /** |
|
50 | * Uses URL(URL, String) constructor to combine URL's. |
|
51 | * @see org.apache.commons.scxml.PathResolver#resolvePath(java.lang.String) |
|
52 | */ |
|
53 | public String resolvePath(final String ctxPath) { |
|
54 | URL combined; |
|
55 | try { |
|
56 | 3 | combined = new URL(baseURL, ctxPath); |
57 | 3 | return combined.toString(); |
58 | 0 | } catch (MalformedURLException e) { |
59 | 0 | log.error("Malformed URL", e); |
60 | } |
|
61 | 0 | return null; |
62 | } |
|
63 | ||
64 | /** |
|
65 | * @see org.apache.commons.scxml.PathResolver#getResolver(java.lang.String) |
|
66 | */ |
|
67 | public PathResolver getResolver(final String ctxPath) { |
|
68 | URL combined; |
|
69 | try { |
|
70 | 1 | combined = new URL(baseURL, ctxPath); |
71 | 1 | return new URLResolver(combined); |
72 | 0 | } catch (MalformedURLException e) { |
73 | 0 | log.error("Malformed URL", e); |
74 | } |
|
75 | 0 | return null; |
76 | } |
|
77 | ||
78 | } |
|
79 |