ClasspathUriResolver is now also an LSInputResolver so it can be used for both XSLT...
[utils] / support / general / src / main / java / org / wamblee / xml / ClasspathUriResolver.java
index 61212dc16ac30c1669dba632eed7b5c5827bf592..6ee7389e4014256d03c67acaa1a7d260e4971f7a 100644 (file)
  */
 package org.wamblee.xml;
 
+import org.w3c.dom.ls.DOMImplementationLS;
+import org.w3c.dom.ls.LSInput;
+import org.w3c.dom.ls.LSResourceResolver;
 import org.wamblee.io.ClassPathResource;
 import org.wamblee.io.InputResource;
 
 import java.io.IOException;
+import java.io.InputStream;
 
 import javax.xml.transform.Source;
 import javax.xml.transform.TransformerException;
@@ -28,7 +32,7 @@ import javax.xml.transform.stream.StreamSource;
 /**
  * URI resolver that resolves stylesheets through the classpath.
  */
-public class ClasspathUriResolver implements URIResolver {
+public class ClasspathUriResolver implements URIResolver, LSResourceResolver {
     /**
      * Constructs the resolver.
      * 
@@ -55,4 +59,24 @@ public class ClasspathUriResolver implements URIResolver {
                 e);
         }
     }
+
+    @Override
+    public LSInput resolveResource(String aType, String aNamespaceURI,
+        String aPublicId, String aSystemId, String aBaseURI) {
+        try {
+            InputStream xslt = new ClassPathResource(aSystemId)
+                .getInputStream();
+            DOMImplementationLS impl = DomUtils.getDomImplementationLS();
+            LSInput input = impl.createLSInput();
+            input.setPublicId(aPublicId);
+            input.setSystemId(aSystemId);
+            input.setByteStream(xslt);
+            return input;
+        } catch (IOException e) {
+            return null;
+        }
+       
+       
+    }
+
 }