Class: Saxon::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/saxon/processor.rb

Overview

Saxon::Processor wraps the S9API::Processor object. This is the object responsible for creating an XSLT compiler or an XML Document object.

The Processor is threadsafe, and can be shared between threads. But, most importantly XSLT or XML objects created by a Processor can only be used with other XSLT or XML objects created by the same Processor instance.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(s9_processor) ⇒ Processor

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Processor.

Parameters:

  • s9_processor (net.sf.saxon.s9api.Processor)

    The Saxon Processor instance to wrap



43
44
45
# File 'lib/saxon/processor.rb', line 43

def initialize(s9_processor)
  @s9_processor = s9_processor
end

Class Method Details

.create(config = nil) ⇒ Saxon::Processor

Parameters:

  • config (File, String, IO, Saxon::Configuration) (defaults to: nil)

    an open File, or string, containing a Saxon configuration file; an existing Saxon::Configuration object

Returns:



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/saxon/processor.rb', line 26

def self.create(config = nil)
  Saxon::Loader.load!
  case config
  when nil
    licensed_or_config_source = false
  when Saxon::Configuration
    licensed_or_config_source = config.to_java
  else
    licensed_or_config_source = Saxon::SourceHelper.to_stream_source(config)
  end
  s9_processor = S9API::Processor.new(licensed_or_config_source)
  new(s9_processor)
end

.defaultSaxon::Processor

Provides a processor with default configuration. Essentially a singleton instance

Returns:



18
19
20
# File 'lib/saxon/processor.rb', line 18

def self.default
  @processor ||= create(Saxon::Configuration.default)
end

Instance Method Details

#==(other) ⇒ Object

compare equal if the underlying java processor is the same instance for self and other

Parameters:

  • other

    object to compare against



69
70
71
# File 'lib/saxon/processor.rb', line 69

def ==(other)
  other.to_java === to_java
end

#configSaxon::Configuration

Returns This processor’s configuration instance.

Returns:



74
75
76
# File 'lib/saxon/processor.rb', line 74

def config
  @config ||= Saxon::Configuration.create(self)
end

#to_javanet.sf.saxon.s9api.Processor

Returns The underlying Saxon processor.

Returns:

  • (net.sf.saxon.s9api.Processor)

    The underlying Saxon processor



62
63
64
# File 'lib/saxon/processor.rb', line 62

def to_java
  @s9_processor
end

#XML(input, opts = {}) ⇒ Saxon::XML::Document

Returns the new XML Document.

Parameters:

  • input (File, IO, String)

    the input XML file

  • opts (Hash) (defaults to: {})

    options for the XML file

Returns:



57
58
59
# File 'lib/saxon/processor.rb', line 57

def XML(input, opts = {})
  Saxon::XML::Document.parse(self, input, opts)
end

#XSLT(input, opts = {}) ⇒ Saxon::XSLT::Stylesheet

Returns the new XSLT Stylesheet.

Parameters:

  • input (File, IO, String)

    the input XSLT file

  • opts (Hash) (defaults to: {})

    options for the XSLT

Returns:



50
51
52
# File 'lib/saxon/processor.rb', line 50

def XSLT(input, opts = {})
  Saxon::XSLT::Stylesheet.parse(self, input, opts)
end