X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=support%2Fgeneral%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fxml%2FClasspathUriResolver.java;h=6ee7389e4014256d03c67acaa1a7d260e4971f7a;hb=df850821cf26ca07ef2474d4d2cabb61e9104291;hp=38eaf5106e9ea55ae4cb0a54a630299607e17c31;hpb=8de36ff0206c996baf3ee4adc3e2293b12ff5f39;p=utils diff --git a/support/general/src/main/java/org/wamblee/xml/ClasspathUriResolver.java b/support/general/src/main/java/org/wamblee/xml/ClasspathUriResolver.java index 38eaf510..6ee7389e 100644 --- a/support/general/src/main/java/org/wamblee/xml/ClasspathUriResolver.java +++ b/support/general/src/main/java/org/wamblee/xml/ClasspathUriResolver.java @@ -1,12 +1,12 @@ /* - * Copyright 2005 the original author or authors. - * + * Copyright 2005-2010 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,10 +15,14 @@ */ 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; + } + + + } + }