View Javadoc

1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd.util.database;
5   
6   import javax.xml.transform.URIResolver;
7   import javax.xml.transform.Source;
8   import javax.xml.transform.TransformerException;
9   import javax.xml.transform.stream.StreamSource;
10  
11  public class ResourceResolver implements URIResolver
12  {
13    @Override
14    public Source resolve(String href, String base) 
15                                throws TransformerException
16    {
17      if(null==href || href.length() == 0 )
18        return null; // will make Oracle XSLT processor explode, 
19                     // even though it's correct 
20      try    {
21        String resource = href; 
22        ResourceLoader loader = new ResourceLoader();
23        return new StreamSource(loader.getResourceStream(resource), resource);
24      } // try
25      catch(Exception ex)
26      {
27        throw new TransformerException(ex);
28      } // catch
29    } // resolve
30  } // ResourceResolver
31