Class: Saxon::Processor
- Inherits:
-
Object
- Object
- Saxon::Processor
- 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
- .create(config = nil) ⇒ Saxon::Processor
-
.default ⇒ Saxon::Processor
Provides a processor with default configuration.
Instance Method Summary collapse
-
#==(other) ⇒ Object
compare equal if the underlying java processor is the same instance for self and other.
-
#config ⇒ Saxon::Configuration
This processor’s configuration instance.
-
#declare_collations(collations) ⇒ Object
Declare custom collations for use by XSLT, XPath, and XQuery processors.
-
#document_builder ⇒ Saxon::DocumentBuilder
Generate a new DocumentBuilder that uses this Processor.
-
#initialize(s9_processor) ⇒ Processor
constructor
private
A new instance of Processor.
-
#to_java ⇒ net.sf.saxon.s9api.Processor
The underlying Saxon processor.
-
#xpath_compiler { ... } ⇒ Saxon::XPath::Compiler
Generate a new
XPath::Compilerthat uses thisProcessor. -
#xslt_compiler { ... } ⇒ Saxon::XSLT::Compiler
Generate a new
XSLT::Compilerthat uses thisProcessor.
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.
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
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 |
.default ⇒ Saxon::Processor
Provides a processor with default configuration. Essentially a singleton instance
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
93 94 95 |
# File 'lib/saxon/processor.rb', line 93 def ==(other) other.to_java === to_java end |
#config ⇒ Saxon::Configuration
Returns This processor’s configuration instance.
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
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_builder ⇒ Saxon::DocumentBuilder
Generate a new DocumentBuilder that uses this Processor. Sharing DocumentBuilders across threads is not recommended/
52 53 54 |
# File 'lib/saxon/processor.rb', line 52 def document_builder Saxon::DocumentBuilder.new(@s9_processor.newDocumentBuilder) end |
#to_java ⇒ net.sf.saxon.s9api.Processor
Returns 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.
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.
81 82 83 |
# File 'lib/saxon/processor.rb', line 81 def xslt_compiler(&block) Saxon::XSLT::Compiler.create(self, &block) end |