1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.scxml.env;
18
19 import java.io.Serializable;
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, Serializable {
33
34 /*** Serial version UID. */
35 private static final long serialVersionUID = 1L;
36
37 /*** Implementation independent log category. */
38 private Log log = LogFactory.getLog(PathResolver.class);
39
40 /*** The base URL to resolve against. */
41 private URL baseURL = null;
42
43 /***
44 * Constructor.
45 *
46 * @param baseURL The base URL to resolve against
47 */
48 public URLResolver(final URL baseURL) {
49 this.baseURL = baseURL;
50 }
51
52 /***
53 * Uses URL(URL, String) constructor to combine URL's.
54 * @see org.apache.commons.scxml.PathResolver#resolvePath(java.lang.String)
55 */
56 public String resolvePath(final String ctxPath) {
57 URL combined;
58 try {
59 combined = new URL(baseURL, ctxPath);
60 return combined.toString();
61 } catch (MalformedURLException e) {
62 log.error("Malformed URL", e);
63 }
64 return null;
65 }
66
67 /***
68 * @see org.apache.commons.scxml.PathResolver#getResolver(java.lang.String)
69 */
70 public PathResolver getResolver(final String ctxPath) {
71 URL combined;
72 try {
73 combined = new URL(baseURL, ctxPath);
74 return new URLResolver(combined);
75 } catch (MalformedURLException e) {
76 log.error("Malformed URL", e);
77 }
78 return null;
79 }
80
81 }
82