Module: Saxon::Source::Helpers

Defined in:
lib/saxon/source.rb

Class Method Summary collapse

Class Method Details

.base_uri(io) ⇒ String?

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

Parameters:

  • io (File, IO)

    A File or IO object representing the input XML file or data, or a String containing the XML

Returns:

  • (String, nil)

    the path or URI from the IO (or nil if there is none)



19
20
21
22
23
24
# File 'lib/saxon/source.rb', line 19

def self.base_uri(io)
  if io.respond_to?(:base_uri)
    return io.base_uri.to_s
  end
  io.path if io.respond_to?(:path)
end

.file(path) ⇒ java.io.File

Given a path return a Java File object

Parameters:

  • path (String, Pathname)

    the path to the file

Returns:

  • (java.io.File)

    the Java File object



42
43
44
# File 'lib/saxon/source.rb', line 42

def self.file(path)
  java.io.File.new(path.to_s)
end

.inputstream(io) ⇒ java.io.InputStream

Given a File or IO return a Java InputStream

Parameters:

  • io (File, IO, org.jruby.util.IOInputStream, java.io.InputStream)

    input to be converted to an input stream

Returns:

  • (java.io.InputStream)

    the wrapped input



30
31
32
33
34
35
36
37
# File 'lib/saxon/source.rb', line 30

def self.inputstream(io)
  case io
  when org.jruby.util.IOInputStream, java.io.InputStream
    io
  else
    io.to_inputstream if io.respond_to?(:read)
  end
end