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      }
21      try    {
22        String resource = href; 
23        ResourceLoader loader = new ResourceLoader();
24        return new StreamSource(loader.getResourceStream(resource), resource);
25      } // try
26      catch(Exception ex)
27      {
28        throw new TransformerException(ex);
29      } // catch
30    } // resolve
31  } // ResourceResolver
32