1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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 private Log log = LogFactory.getLog(PathResolver.class);
36
37 /*** The base URL to resolve against. */
38 private URL baseURL = null;
39
40 /***
41 * Constructor.
42 *
43 * @param baseURL The base URL to resolve against
44 */
45 public URLResolver(final URL baseURL) {
46 this.baseURL = baseURL;
47 }
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 combined = new URL(baseURL, ctxPath);
57 return combined.toString();
58 } catch (MalformedURLException e) {
59 log.error("Malformed URL", e);
60 }
61 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 combined = new URL(baseURL, ctxPath);
71 return new URLResolver(combined);
72 } catch (MalformedURLException e) {
73 log.error("Malformed URL", e);
74 }
75 return null;
76 }
77
78 }
79