01: /*
02: * Copyright 2005 Joe Walker
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package jsx3.net;
17:
18: /**
19: * @author Joe Walker [joe at getahead dot ltd dot uk]
20: */
21: public class URIResolver {
22: /**
23: * {jsx3.net.URIResolver} The default URI resolver. This resolver can
24: * resolve any of the absolute URI formats supported by the system. Other
25: * absolute URIs and all relative URIs are unmodified. The absolute URI
26: * formats are:
27: * <ul>
28: * <li><code>JSX/...</code> –</li>
29: * <li><code>JSXAPPS/...</code> –</li>
30: * <li><code>GI_Builder/...</code> –</li>
31: * <li><code>jsx:/...</code> –</li>
32: * <li><code>jsxapp://appPath/...</code> –</li>
33: * <li><code>jsxaddin://addinKey/...</code> –</li>
34: * <li><code>jsxuser:/...</code> –</li>
35: * </ul>
36: */
37: public static final URIResolver DEFAULT = new URIResolver(
38: "jsx3.net.URIResolver.DEFAULT");
39:
40: /**
41: * {jsx3.net.URIResolver} Resolves URIs according to the default resolver
42: * except that all relative URIs are resolved relative to the
43: * <code>JSX/</code> directory. This resolver resolves the following URIs to
44: * the same value:
45: * <ul>
46: * <li><code>JSX/file.xml</code></li>
47: * <li><code>jsx:/file.xml</code></li>
48: * <li><code>file.xml</code></li>
49: * </ul>
50: */
51: public static final URIResolver JSX = new URIResolver(
52: "jsx3.net.URIResolver.JSX");
53:
54: /**
55: * {jsx3.net.URIResolver} Resolves URIs according to the default resolver
56: * except that all relative URIs are resolved relative to the user directory
57: * (or <code>JSXAPPS/../</code>). This resolver resolves the following URIs
58: * to the same value:
59: * <ul>
60: * <li><code>JSXAPPS/../file.xml</code></li>
61: * <li><code>jsxuser:/file.xml</code></li>
62: * <li><code>file.xml</code></li>
63: * </ul>
64: */
65: public static final URIResolver USER = new URIResolver(
66: "jsx3.net.URIResolver.USER");
67:
68: /**
69: * @param name
70: */
71: protected static URIResolver toURIResolver(String name) {
72: if (name.equals(URIResolver.DEFAULT.constant)) {
73: return URIResolver.DEFAULT;
74: }
75:
76: if (name.equals(URIResolver.JSX.constant)) {
77: return URIResolver.JSX;
78: }
79:
80: if (name.equals(URIResolver.USER.constant)) {
81: return URIResolver.USER;
82: }
83:
84: return null;
85: }
86:
87: /**
88: * @param constant
89: */
90: public URIResolver(String constant) {
91: this .constant = constant;
92: }
93:
94: /**
95: * The string to send to Javascript
96: */
97: protected final String constant;
98: }
|