1 5 package com.opensymphony.webwork.views.xslt; 6 7 import org.apache.commons.logging.Log; 8 import org.apache.commons.logging.LogFactory; 9 10 import javax.servlet.ServletContext ; 11 import javax.xml.transform.Source ; 12 import javax.xml.transform.TransformerException ; 13 import javax.xml.transform.URIResolver ; 14 import javax.xml.transform.stream.StreamSource ; 15 import java.io.InputStream ; 16 17 18 23 public class ServletURIResolver implements URIResolver { 24 26 protected static Log log = LogFactory.getLog(URIResolver .class); 27 static final String protocol = "res:"; 28 29 31 private ServletContext sc; 32 33 35 public ServletURIResolver(ServletContext sc) { 36 this.sc = sc; 37 } 38 39 41 public Source resolve(String href, String base) throws TransformerException { 42 if (href.startsWith(protocol)) { 43 String res = href.substring(protocol.length()); 44 log.debug("Resolving resource <" + res + ">"); 45 46 InputStream is = sc.getResourceAsStream(res); 47 48 if (is == null) { 49 throw new TransformerException ("Resource " + res + " not found in resources."); 50 } 51 52 return new StreamSource (is); 53 } 54 55 throw new TransformerException ("Cannot handle procotol of resource " + href); 56 } 57 } 58 | Popular Tags |