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



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

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:



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

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::Source.create(config).to_java
  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:



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

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



93
94
95
# File 'lib/saxon/processor.rb', line 93

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

#configSaxon::Configuration

Returns This processor’s configuration instance.

Returns:



98
99
100
# File 'lib/saxon/processor.rb', line 98

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

#declare_collations(collations) ⇒ Object

Declare custom collations for use by XSLT, XPath, and XQuery processors

Parameters:

  • collations (Hash<String => java.text.Collator>)

    collations to declare, as a hash of URI => Collator



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

def declare_collations(collations)
  collations.each do |uri, collation|
    @s9_processor.declareCollation(uri, collation)
  end
end

#document_builderSaxon::DocumentBuilder

Generate a new DocumentBuilder that uses this Processor. Sharing DocumentBuilders across threads is not recommended/

Returns:



52
53
54
# File 'lib/saxon/processor.rb', line 52

def document_builder
  Saxon::DocumentBuilder.new(@s9_processor.newDocumentBuilder)
end

#to_javanet.sf.saxon.s9api.Processor

Returns The underlying Saxon processor.

Returns:

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

    The underlying Saxon processor



86
87
88
# File 'lib/saxon/processor.rb', line 86

def to_java
  @s9_processor
end

#xpath_compiler { ... } ⇒ Saxon::XPath::Compiler

Generate a new XPath::Compiler that uses this Processor. Sharing XPath::Compilers across threads is fine as long as the static context is not changed.

Yields:

Returns:



71
72
73
# File 'lib/saxon/processor.rb', line 71

def xpath_compiler(&block)
  Saxon::XPath::Compiler.create(self, &block)
end

#xslt_compiler { ... } ⇒ Saxon::XSLT::Compiler

Generate a new XSLT::Compiler that uses this Processor. Sharing XSLT::Compilers across threads is fine as long as the static context is not changed.

Yields:

Returns:



81
82
83
# File 'lib/saxon/processor.rb', line 81

def xslt_compiler(&block)
  Saxon::XSLT::Compiler.create(self, &block)
end