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.
-
#serializer { ... } ⇒ Saxon::Serializer::Object
Generate a new
Serializer
for directly serializing XDM Values that uses thisProcessor
. -
#to_java ⇒ net.sf.saxon.s9api.Processor
The underlying Saxon processor.
-
#XML(input, opts = {}) ⇒ Saxon::XDM::Node
Create a DocumentBuilder and construct a Source and parse some XML.
-
#xpath_compiler { ... } ⇒ Saxon::XPath::Compiler
Generate a new
XPath::Compiler
that uses thisProcessor
. -
#XSLT(input, opts = {}) { ... } ⇒ Saxon::XSLT::Executable
Construct a Source containing an XSLT stylesheet, create an XSLT::Compiler, and compile the source, returning the XSLT::Executable produced.
-
#xslt_compiler { ... } ⇒ Saxon::XSLT::Compiler
Generate a new
XSLT::Compiler
that 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.
45 46 47 |
# File 'lib/saxon/processor.rb', line 45 def initialize(s9_processor) @s9_processor = s9_processor end |
Class Method Details
.create(config = nil) ⇒ Saxon::Processor
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/saxon/processor.rb', line 28 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
20 21 22 |
# File 'lib/saxon/processor.rb', line 20 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
107 108 109 |
# File 'lib/saxon/processor.rb', line 107 def ==(other) other.to_java === to_java end |
#config ⇒ Saxon::Configuration
Returns This processor’s configuration instance.
112 113 114 |
# File 'lib/saxon/processor.rb', line 112 def config @config ||= Saxon::Configuration.create(self) end |
#declare_collations(collations) ⇒ Object
Declare custom collations for use by XSLT, XPath, and XQuery processors
63 64 65 66 67 |
# File 'lib/saxon/processor.rb', line 63 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 safe.
55 56 57 |
# File 'lib/saxon/processor.rb', line 55 def document_builder(&block) Saxon::DocumentBuilder.create(self, &block) end |
#serializer { ... } ⇒ Saxon::Serializer::Object
Generate a new Serializer
for directly serializing XDM Values that uses this Processor
. Serializers are effectively one-shot objects, and shouldn’t be reused.
95 96 97 |
# File 'lib/saxon/processor.rb', line 95 def serializer(&block) Saxon::Serializer::Object.create(self, &block) end |
#to_java ⇒ net.sf.saxon.s9api.Processor
Returns The underlying Saxon processor.
100 101 102 |
# File 'lib/saxon/processor.rb', line 100 def to_java @s9_processor end |
#XML(input, opts = {}) ⇒ Saxon::XDM::Node
Create a DocumentBuilder and construct a Source and parse some XML. The args are passed to Source.create, and the returned Source is parsed using DocumentBuilder#build. If a Source is passed in, parse that. Any options in opts
will be ignored in that case.
125 126 127 128 |
# File 'lib/saxon/processor.rb', line 125 def XML(input, opts = {}) source = Source.create(input, opts) document_builder.build(source) end |
#xpath_compiler { ... } ⇒ Saxon::XPath::Compiler
Generate a new XPath::Compiler
that uses this Processor
. Sharing XPath::Compiler
s across threads is fine as long as the static context is not changed.
74 75 76 |
# File 'lib/saxon/processor.rb', line 74 def xpath_compiler(&block) Saxon::XPath::Compiler.create(self, &block) end |
#XSLT(input, opts = {}) { ... } ⇒ Saxon::XSLT::Executable
Construct a Source containing an XSLT stylesheet, create an XSLT::Compiler, and compile the source, returning the XSLT::Executable produced. If a Source is passed as input
, then it will be passed through to the compiler and any source-related options in opts
will be ignored.
142 143 144 145 |
# File 'lib/saxon/processor.rb', line 142 def XSLT(input, opts = {}, &block) source = Source.create(input, opts) xslt_compiler(&block).compile(source) end |
#xslt_compiler { ... } ⇒ Saxon::XSLT::Compiler
Generate a new XSLT::Compiler
that uses this Processor
. Sharing XSLT::Compiler
s across threads is fine as long as the static context is not changed.
84 85 86 |
# File 'lib/saxon/processor.rb', line 84 def xslt_compiler(&block) Saxon::XSLT::Compiler.create(self, &block) end |