Class: Saxon::SourceHelper
- Inherits:
-
Object
- Object
- Saxon::SourceHelper
- Defined in:
- lib/saxon/source_helper.rb
Overview
Helper methods for converting Ruby File, IO, Path, or String objects into a Javax StreamSource object for Saxon’s Document parser or XSLT compiler to consume
Class Method Summary collapse
-
.to_inputstream(path_io_or_string) ⇒ java.io.InputStream, java.io.StringReader
Given a File, IO, or String return a Java InputStream or StringReader.
-
.to_stream_source(path_io_or_string, opts = {}) ⇒ java.xml.transform.stream.StreamSource
Creates a StreamSource from its input.
-
.to_system_id(path_io_or_string) ⇒ Object
Given a File, or IO object which will return either #path or #base_uri, return the #base_uri, if present, or the #path, if present, or nil.
Class Method Details
.to_inputstream(path_io_or_string) ⇒ java.io.InputStream, java.io.StringReader
Given a File, IO, or String return a Java InputStream or StringReader
39 40 41 42 43 |
# File 'lib/saxon/source_helper.rb', line 39 def self.to_inputstream(path_io_or_string) return path_io_or_string if org.jruby.util.IOInputStream === path_io_or_string return path_io_or_string.to_inputstream if path_io_or_string.respond_to?(:read) return java.io.StringReader.new(path_io_or_string) end |
.to_stream_source(path_io_or_string, opts = {}) ⇒ java.xml.transform.stream.StreamSource
Creates a StreamSource from its input
17 18 19 20 |
# File 'lib/saxon/source_helper.rb', line 17 def self.to_stream_source(path_io_or_string, opts = {}) system_id = opts.fetch(:system_id) { to_system_id(path_io_or_string) } StreamSource.new(to_inputstream(path_io_or_string), system_id) end |
.to_system_id(path_io_or_string) ⇒ Object
Given a File, or IO object which will return either #path or #base_uri, return the #base_uri, if present, or the #path, if present, or nil
28 29 30 31 32 33 |
# File 'lib/saxon/source_helper.rb', line 28 def self.to_system_id(path_io_or_string) if path_io_or_string.respond_to?(:base_uri) return path_io_or_string.base_uri.to_s end return path_io_or_string.path if path_io_or_string.respond_to?(:path) end |