RE: [xsl] Using a custom URIResolver

Subject: RE: [xsl] Using a custom URIResolver
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Tue, 6 Apr 2004 11:14:55 +0100
In Saxon, calling getURIResolver() on the Transformer object will give you
the standard URI resolver if no user-defined URIResolver has been set;
however, the JAXP specification isn't explicit that this is what should
happen, and I've no idea if Xalan does the same.

My thinking was that you write your URIResolver something like

public MyURIResolver(URIResolver systemURIResolver) {
  this.systemURIResolver = systemURIResolver;

  public Source resolve(href, base) {
     Source s = null;
     try {
     	   s = systemURIResolver.resolve(href, base);
     } catch (TransformerException e) {
         s = null;
     }
     if (s == null) {
         // handle it here
   }
}

Then you can set this up (assuming Xalan behaves like Saxon) as:

   Transformer t = templates.newTransformer();
   MyURIResolver u = new MyURIResolver(t.getURIResolver());
   t.setURIResolver(u):

Michael Kay 

> -----Original Message-----
> From: Bjvrn Boxstart [mailto:Boxstart@xxxxxxxx] 
> Sent: 06 April 2004 08:30
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE: [xsl] Using a custom URIResolver
> 
> Michael Kay wrote:
> >I'm not sure there is a portable way to do this. Given a 
> specific JAXP implementation (such as Saxon or Xalan) you can 
> do it by making your
> >URIResolver be a subclass of the standard URIResolver, and 
> invoking the
> >super.resolve() method. You could make it a bit more 
> portable by having = your URIResolver accept a reference to 
> the standard URIResolver
> >using a setStandardURIResolver() method when it is first 
> instantiated.
> 
> Thanks for your reaction. I'm indeed using trax (with xalan, 
> I've should have told this in my previous email). The thing 
> is that javax.xml.transform.URIResolver is an Interface and 
> that I have not been able yet to find out which class 
> implements this interface to perform as the standard URI 
> resolver. So I don't know which class to subclass. Could you 
> please explain what you mean with 'accept a reference to the 
> standard URIResolver using a setStandardURIResolver()' method.
> Do you mean that I add a public method 
> 'setStandardURIResolver' to my own class that implements the 
> interface (or to let the standard URI resolver be passed as a 
> parameter in the constructor) and that the value being passed 
> to this method can be retrieved from the transformer by using 
> the 'getURIResolver()' method, or does this method only 
> return a URI resolver in case you set your own resolver before?
> 
> Thanks in advance for your reaction!
> 
> Bjvrn

Current Thread