View Javadoc

1   /*
2    * Created on 27.7.2004
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          // TODO Auto-generated constructor stub
29      }
30  
31      /***
32       * @param privateCatalog
33       */
34      public XTResolver(boolean privateCatalog) {
35          super(privateCatalog);
36  
37          // TODO Auto-generated constructor stub
38      }
39  
40      /***
41       * @param manager
42       */
43      public XTResolver(CatalogManager manager) {
44          super(manager);
45  
46          // TODO Auto-generated constructor stub
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       * (non-Javadoc)
65       * 
66       * @see org.apache.xml.resolver.tools.CatalogResolver#getResolvedEntity(java.lang.String,
67       *      java.lang.String)
68       */
69      public String getResolvedEntity(String publicId, String systemId) {
70          // TODO Auto-generated method stub
71          return super.getResolvedEntity(publicId, systemId);
72      }
73  
74      /*
75       * (non-Javadoc)
76       * 
77       * @see javax.xml.transform.URIResolver#resolve(java.lang.String,
78       *      java.lang.String)
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              // FIXME base ignored; is this OK?
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 }