I've this JRuby working code (stolen from Keith's Blog), which wraps the SAXON xslt processor API.
Now, I wonder whether I can and how can I wrap the same API in Ruby framework?
Please tell me if this question is non-sense or if it can be improved in some way.
This is the java doc reference for the wanted API.
And this is the JRuby code I'm using:
require 'java'
module JXslt
include_class "javax.xml.transform.TransformerFactory"
include_class "javax.xml.transform.Transformer"
include_class "javax.xml.transform.stream.StreamSource"
include_class "javax.xml.transform.stream.StreamResult"
include_class "java.lang.System"
class XsltProcessor
def transform(xslt,infile,outfile)
transformer = @tf.newTransformer(StreamSource.new(xslt))
transformer.transform(StreamSource.new(infile), StreamResult.new(outfile))
end
end # XsltProcessor
class Saxon < XsltProcessor
TRANSFORMER_FACTORY_IMPL = "net.sf.saxon.TransformerFactoryImpl"
def initialize
System.setProperty("javax.xml.transform.TransformerFactory", TRANSFORMER_FACTORY_IMPL)
@tf = TransformerFactory.newInstance
end
end
end