View Javadoc

1   /*
2    * $Id: LocalURIResolver.java 20321 2010-11-24 15:21:24Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  package org.mule.module.xml.util;
11  
12  import org.mule.util.IOUtils;
13  
14  import java.io.IOException;
15  
16  import javax.xml.transform.URIResolver;
17  import javax.xml.transform.Source;
18  import javax.xml.transform.stream.StreamSource;
19  
20  /**
21   * Will look for the href file on the classpath
22   */
23  public class LocalURIResolver implements URIResolver
24  {
25      public Source resolve(String href, String base) throws javax.xml.transform.TransformerException
26      {
27          try
28          {
29              return new StreamSource(IOUtils.getResourceAsStream(href, getClass()));
30          }
31          catch (IOException e)
32          {
33              throw new javax.xml.transform.TransformerException(e);
34          }
35      }
36  }