1 package net.sf.saxon.dom; 2 3 import org.w3c.dom.ls.LSResourceResolver ; 4 import org.w3c.dom.ls.LSInput ; 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 import java.io.Reader ; 11 import java.io.InputStream ; 12 import java.io.StringReader ; 13 14 21 22 public class URIResourceResolver implements URIResolver { 23 24 private LSResourceResolver resolver; 25 26 public URIResourceResolver(LSResourceResolver resolver) { 27 this.resolver = resolver; 28 } 29 30 public LSResourceResolver getLSResourceResolver() { 31 return resolver; 32 } 33 34 47 public Source resolve(String href, String base) throws TransformerException { 48 LSInput lsin = resolver.resolveResource( 49 "http://www.w3.org/TR/REC-xml", null, null, href, base); 50 if (lsin == null) { 51 return null; 52 } 53 54 Reader reader = lsin.getCharacterStream(); 55 InputStream stream = lsin.getByteStream(); 56 String content = lsin.getStringData(); 57 String systemId = lsin.getSystemId(); 58 String publicId = lsin.getPublicId(); 59 60 if (content != null) { 61 reader = new StringReader (content); 62 } 63 64 StreamSource source = new StreamSource (); 65 source.setSystemId(systemId); 66 source.setPublicId(publicId); 67 source.setReader(reader); 68 source.setInputStream(stream); 69 70 return source; 71 72 } 73 } 74 75 | Popular Tags |