Skip to content

Instantly share code, notes, and snippets.

@BDF
Last active October 1, 2016 20:50
Show Gist options
  • Save BDF/019b770faa4eb5ff2505 to your computer and use it in GitHub Desktop.
Save BDF/019b770faa4eb5ff2505 to your computer and use it in GitHub Desktop.
Figuring out why saxon does not find license file in a Spring MVC application.
import net.sf.saxon.lib.FeatureKeys;
import net.sf.saxon.s9api.Processor;
import net.sf.saxon.s9api.SaxonApiException;
import net.sf.saxon.s9api.XsltCompiler;
import net.sf.saxon.s9api.XsltExecutable;
import org.springframework.stereotype.Service;
import javax.xml.transform.stream.StreamSource;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
/**
* Created by bforeste on 2/2/16.
*
* @author bforeste
*/
@Service
public class XsltServiceSaxonImpl {
private final Processor proc;
public XsltServiceSaxonImpl() {
proc = new Processor(true);
}
public XsltExecutable compileXslt(StreamSource streamSource) throws SaxonApiException {
XsltCompiler xsltCompiler = proc.newXsltCompiler();
XsltExecutable xsltExe = xsltCompiler.compile(streamSource);
return xsltExe;
}
// URL is the most generic way to handle our path to our XSLT resource.
// Current expected
public XsltExecutable compileXslt(URL urlToXslt) throws IOException, SaxonApiException {
XsltExecutable xsltExecutable;
URLConnection conn = urlToXslt.openConnection();
InputStream fis = conn.getInputStream();
StreamSource streamSource = new StreamSource(fis);
return compileXslt(streamSource);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment