1
2
3
4 package net.sf.tomp.xml.sax;
5
6 import net.sf.tomp.xtcl.Context;
7
8 import org.apache.xml.resolver.CatalogManager;
9 import org.apache.xml.resolver.tools.CatalogResolver;
10
11 import javax.xml.transform.Source;
12 import javax.xml.transform.TransformerException;
13
14 /***
15 * @author tomp
16 */
17 public class XTResolver extends CatalogResolver {
18 protected static final String XTCL_PREFIX = "xtcl:";
19
20 private Context context;
21
22 /***
23 *
24 */
25 public XTResolver() {
26 super();
27
28
29 }
30
31 /***
32 * @param privateCatalog
33 */
34 public XTResolver(boolean privateCatalog) {
35 super(privateCatalog);
36
37
38 }
39
40 /***
41 * @param manager
42 */
43 public XTResolver(CatalogManager manager) {
44 super(manager);
45
46
47 }
48
49 /***
50 * @return Returns the context.
51 */
52 public Context getContext() {
53 return context;
54 }
55
56 /***
57 * @param context The context to set.
58 */
59 public void setContext(Context context) {
60 this.context = context;
61 }
62
63
64
65
66
67
68
69 public String getResolvedEntity(String publicId, String systemId) {
70
71 return super.getResolvedEntity(publicId, systemId);
72 }
73
74
75
76
77
78
79
80 public Source resolve(String href, String base) throws TransformerException {
81 if (isXT(href, base)) {
82 String ref = href;
83 String fragment = null;
84 int hashPos = href.indexOf("#");
85
86 if (hashPos >= 0) {
87 ref = href.substring(0, hashPos);
88 fragment = href.substring(hashPos + 1);
89 }
90
91 ref = ref.substring(XTCL_PREFIX.length());
92
93
94 return context.refToSource(ref);
95 } else {
96 return super.resolve(href, base);
97 }
98 }
99
100 private boolean isXT(String href, String base) {
101 return href.startsWith(XTCL_PREFIX);
102 }
103 }