saxon-xslt 0.6.0-java → 0.7.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/saxon/configuration.rb +71 -0
- data/lib/saxon/processor.rb +16 -4
- data/lib/saxon/s9api.rb +2 -0
- data/lib/saxon/xslt.rb +4 -4
- data/lib/saxon/xslt/version.rb +1 -1
- data/spec/saxon/configuration_spec.rb +46 -0
- data/spec/saxon/processor_spec.rb +15 -5
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0abe4c1503732325841706ee122ecd45daf22476
|
4
|
+
data.tar.gz: 04b185f85c2b0281b65ceb1ef0174527fbd47861
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6d04c3fdfe1db41ba12d1e81809483d8eb9c264ce96bc2974d6366ca1ad51d1cf2ed261296fa359932a725e79bdf0941bd81a5b16081c8489fdc02caba6dba5
|
7
|
+
data.tar.gz: 1b6cc8a925624ac90c450290b1200ea8ddfc84f8be061f0518434d1e9184009d72cf6485ba039f67b1a68529e1ee76152c634bfbc0510a5e02bf20ef463979c0
|
data/README.md
CHANGED
@@ -53,7 +53,7 @@ Values are evaluated as XPath expressions in context of the document being trans
|
|
53
53
|
that, to pass a string, you must pass an XPath that resolves to a string, i.e. "'You must wrap strings in quotes'"
|
54
54
|
|
55
55
|
## Saxon version
|
56
|
-
`saxon-xslt` 0.
|
56
|
+
`saxon-xslt` 0.7 includes Saxon HE 9.5.1.7
|
57
57
|
|
58
58
|
## Differences between Saxon and Nokogiri
|
59
59
|
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Saxon
|
2
|
+
# Wraps the <tt>net.saxon.Configuration</tt> class. See
|
3
|
+
# http://saxonica.com/documentation9.5/javadoc/net/sf/saxon/Configuration.html
|
4
|
+
# for details of what configuration options are available and what values
|
5
|
+
# they accept. See
|
6
|
+
# http://saxonica.com/documentation9.5/javadoc/net/sf/saxon/lib/FeatureKeys.html
|
7
|
+
# for details of the constant names used to access the values
|
8
|
+
class Configuration
|
9
|
+
# @param processor [Saxon::Processor] a Saxon::Processor instance
|
10
|
+
# @return [Saxon::Configuration]
|
11
|
+
def self.create(processor = nil)
|
12
|
+
if processor
|
13
|
+
config = processor.to_java.underlying_configuration
|
14
|
+
else
|
15
|
+
config = Saxon::S9API::Configuration.new
|
16
|
+
end
|
17
|
+
new(config)
|
18
|
+
end
|
19
|
+
|
20
|
+
# @api private
|
21
|
+
# @param config [net.sf.saxon.Configuration] The Saxon Configuration
|
22
|
+
# instance to wrap
|
23
|
+
def initialize(config)
|
24
|
+
@config = config
|
25
|
+
end
|
26
|
+
|
27
|
+
# Get a configuration option value
|
28
|
+
# See http://saxonica.com/documentation9.5/javadoc/net/sf/saxon/lib/FeatureKeys.html
|
29
|
+
# for details of the available options. Use the constant name as a string
|
30
|
+
# or symbol as the option
|
31
|
+
#
|
32
|
+
# @param option [String, Symbol]
|
33
|
+
# @return [Object] the value of the configuration option
|
34
|
+
# @raise [NameError] if the option name does not exist
|
35
|
+
def [](option)
|
36
|
+
@config.getConfigurationProperty(option_url(option))
|
37
|
+
end
|
38
|
+
|
39
|
+
# Get a configuration option value
|
40
|
+
# See http://saxonica.com/documentation9.5/javadoc/net/sf/saxon/lib/FeatureKeys.html
|
41
|
+
# for details of the available options. Use the constant name as a string
|
42
|
+
# or symbol as the option
|
43
|
+
#
|
44
|
+
# @param option [String, Symbol]
|
45
|
+
# @param value [Object] the value of the configuration option
|
46
|
+
# @return [Object] the value you passed in
|
47
|
+
# @raise [NameError] if the option name does not exist
|
48
|
+
def []=(option, value)
|
49
|
+
@config.setConfigurationProperty(option_url(option), value)
|
50
|
+
end
|
51
|
+
|
52
|
+
# @return [net.sf.saxon.Configuration] The underlying Saxon Configuration
|
53
|
+
def to_java
|
54
|
+
@config
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def feature_keys
|
60
|
+
@feature_keys ||= Saxon::S9API::FeatureKeys.java_class
|
61
|
+
end
|
62
|
+
|
63
|
+
def option_url(option)
|
64
|
+
feature_keys.field(normalize_option_name(option)).static_value
|
65
|
+
end
|
66
|
+
|
67
|
+
def normalize_option_name(option)
|
68
|
+
option.to_s.upcase
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/lib/saxon/processor.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'saxon/s9api'
|
2
2
|
require 'saxon/source_helper'
|
3
|
+
require 'saxon/configuration'
|
3
4
|
require 'saxon/xslt'
|
4
5
|
require 'saxon/xml'
|
5
6
|
|
@@ -18,18 +19,24 @@ module Saxon
|
|
18
19
|
@processor ||= create
|
19
20
|
end
|
20
21
|
|
21
|
-
# @param config [File, String, IO] an open File, or string,
|
22
|
-
# containing a Saxon configuration file
|
22
|
+
# @param config [File, String, IO, Saxon::Configuration] an open File, or string,
|
23
|
+
# containing a Saxon configuration file; an existing Saxon::Configuration
|
24
|
+
# object
|
23
25
|
# @return [Saxon::Processor]
|
24
26
|
def self.create(config = nil)
|
25
|
-
|
26
|
-
|
27
|
+
case config
|
28
|
+
when nil
|
29
|
+
licensed_or_config_source = false
|
30
|
+
when Saxon::Configuration
|
31
|
+
licensed_or_config_source = config.to_java
|
32
|
+
else
|
27
33
|
licensed_or_config_source = Saxon::SourceHelper.to_stream_source(config)
|
28
34
|
end
|
29
35
|
s9_processor = S9API::Processor.new(licensed_or_config_source)
|
30
36
|
new(s9_processor)
|
31
37
|
end
|
32
38
|
|
39
|
+
# @api private
|
33
40
|
# @param [net.sf.saxon.s9api.Processor] s9_processor The Saxon Processor
|
34
41
|
# instance to wrap
|
35
42
|
def initialize(s9_processor)
|
@@ -61,5 +68,10 @@ module Saxon
|
|
61
68
|
def ==(other)
|
62
69
|
other.to_java === to_java
|
63
70
|
end
|
71
|
+
|
72
|
+
# @return [Saxon::Configuration] This processor's configuration instance
|
73
|
+
def config
|
74
|
+
@config ||= Saxon::Configuration.create(self)
|
75
|
+
end
|
64
76
|
end
|
65
77
|
end
|
data/lib/saxon/s9api.rb
CHANGED
@@ -6,6 +6,8 @@ module Saxon
|
|
6
6
|
# Puts the Saxon Java classes into a sensible namespace
|
7
7
|
module S9API
|
8
8
|
java_import 'net.sf.saxon.s9api.Processor'
|
9
|
+
java_import 'net.sf.saxon.Configuration'
|
10
|
+
java_import 'net.sf.saxon.lib.FeatureKeys'
|
9
11
|
java_import 'net.sf.saxon.s9api.XdmDestination'
|
10
12
|
java_import 'net.sf.saxon.s9api.QName'
|
11
13
|
end
|
data/lib/saxon/xslt.rb
CHANGED
@@ -28,13 +28,13 @@ module Saxon
|
|
28
28
|
# Compile a stylesheet from an existing Saxon::XML instance of an XSLT
|
29
29
|
# source
|
30
30
|
#
|
31
|
-
# @param [Saxon::XML::Document]
|
31
|
+
# @param document [Saxon::XML::Document] the input XSLT as an XML document
|
32
32
|
# @return [Saxon::XSLT::Stylesheet] the compiled XSLT stylesheet
|
33
33
|
def self.parse_stylesheet_doc(document)
|
34
34
|
new(document)
|
35
35
|
end
|
36
36
|
|
37
|
-
# @param [Saxon::XML::Document]
|
37
|
+
# @param source [Saxon::XML::Document] the input XSLT as an XML document
|
38
38
|
def initialize(source)
|
39
39
|
processor = source.processor
|
40
40
|
compiler = processor.to_java.new_xslt_compiler()
|
@@ -48,7 +48,7 @@ module Saxon
|
|
48
48
|
# you need to pass it quoted: `"'string'"`. An unquoted string is an
|
49
49
|
# XPath reference into the document being transformed.
|
50
50
|
#
|
51
|
-
# @param [Saxon::XML::Document]
|
51
|
+
# @param document [Saxon::XML::Document] the XML Document object to
|
52
52
|
# transform
|
53
53
|
# @param params [Hash,Array] xsl params to set in the xsl document
|
54
54
|
# @return [Saxon::XML::Document] the transformed XML Document
|
@@ -78,7 +78,7 @@ module Saxon
|
|
78
78
|
# Not the most useful serialiser in the world. Provided for Nokogiri API
|
79
79
|
# compatibility
|
80
80
|
#
|
81
|
-
# @param [Saxon::XML::Document]
|
81
|
+
# @param document [Saxon::XML::Document] the XML Document object to
|
82
82
|
# serialise
|
83
83
|
# @return [String] the XML Document serialised to a string
|
84
84
|
def serialize(document)
|
data/lib/saxon/xslt/version.rb
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'saxon/configuration'
|
3
|
+
require 'saxon/processor'
|
4
|
+
|
5
|
+
describe Saxon::Configuration do
|
6
|
+
it "is instantiated from a java Configuration instance" do
|
7
|
+
config = Saxon::Configuration.new(Saxon::S9API::Configuration.new)
|
8
|
+
expect(config).to be_a(Saxon::Configuration)
|
9
|
+
end
|
10
|
+
|
11
|
+
context "creating a new instance safely" do
|
12
|
+
it "can be created without a pre-existing processor" do
|
13
|
+
expect(Saxon::Configuration.create).to be_a(Saxon::Configuration)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "can be created correctly from a Processor" do
|
17
|
+
processor = Saxon::Processor.create
|
18
|
+
expect(Saxon::Configuration.create(processor)).to be_a(Saxon::Configuration)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "getting and setting options" do
|
23
|
+
let(:config) { Saxon::Configuration.new(Saxon::S9API::Configuration.new) }
|
24
|
+
|
25
|
+
it "can get a configuration option's current value" do
|
26
|
+
expect(config[:line_numbering]).to be(false)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "can set a configuration option to a new value" do
|
30
|
+
config[:line_numbering] = true
|
31
|
+
expect(config[:line_numbering]).to be(true)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "returns the passed-in value when setting an option" do
|
35
|
+
expect(config[:default_country] = 'NO').to eq('NO')
|
36
|
+
end
|
37
|
+
|
38
|
+
it "doesn't allow you to set a non-existent configuration option" do
|
39
|
+
expect { config[:rubbish] = "value" }.to raise_error(NameError)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "doesn't allow you to get a non-existent configuration option" do
|
43
|
+
expect { config[:rubbish] }.to raise_error(NameError)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -4,7 +4,7 @@ require 'saxon/processor'
|
|
4
4
|
describe Saxon::Processor do
|
5
5
|
let(:xsl_file) { File.open(fixture_path('eg.xsl')) }
|
6
6
|
|
7
|
-
context "without configuration" do
|
7
|
+
context "without explicit configuration" do
|
8
8
|
let(:processor) { Saxon::Processor.create }
|
9
9
|
|
10
10
|
it "can make a new XSLT instance" do
|
@@ -18,15 +18,25 @@ describe Saxon::Processor do
|
|
18
18
|
it "can return the underlying Saxon Processor" do
|
19
19
|
expect(processor.to_java).to respond_to(:new_xslt_compiler)
|
20
20
|
end
|
21
|
+
|
22
|
+
it "can return the processor's configuration instance" do
|
23
|
+
expect(processor.config).to be_a(Saxon::Configuration)
|
24
|
+
end
|
21
25
|
end
|
22
26
|
|
23
|
-
context "with
|
27
|
+
context "with explicit configuration" do
|
24
28
|
it "works, given a valid config XML file" do
|
25
29
|
processor = Saxon::Processor.create(File.open(fixture_path('config.xml')))
|
26
30
|
|
27
|
-
|
28
|
-
|
29
|
-
|
31
|
+
expect(processor.config[:xml_version]).to eq("1.1")
|
32
|
+
end
|
33
|
+
|
34
|
+
it "works, given a Saxon::Configuration object" do
|
35
|
+
config = Saxon::Configuration.create
|
36
|
+
config[:line_numbering] = true
|
37
|
+
processor = Saxon::Processor.create(config)
|
38
|
+
|
39
|
+
expect(processor.config[:line_numbering]).to be(true)
|
30
40
|
end
|
31
41
|
end
|
32
42
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: saxon-xslt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Matt Patterson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- README.md
|
97
97
|
- Rakefile
|
98
98
|
- lib/saxon-xslt.rb
|
99
|
+
- lib/saxon/configuration.rb
|
99
100
|
- lib/saxon/processor.rb
|
100
101
|
- lib/saxon/s9api.rb
|
101
102
|
- lib/saxon/source_helper.rb
|
@@ -111,6 +112,7 @@ files:
|
|
111
112
|
- spec/fixtures/eg.xsl
|
112
113
|
- spec/fixtures/params-eg.xsl
|
113
114
|
- spec/fixtures/simple-xsl-import.xsl
|
115
|
+
- spec/saxon/configuration_spec.rb
|
114
116
|
- spec/saxon/processor_spec.rb
|
115
117
|
- spec/saxon/source_helper_spec.rb
|
116
118
|
- spec/saxon/xml_spec.rb
|
@@ -153,6 +155,7 @@ test_files:
|
|
153
155
|
- spec/fixtures/eg.xsl
|
154
156
|
- spec/fixtures/params-eg.xsl
|
155
157
|
- spec/fixtures/simple-xsl-import.xsl
|
158
|
+
- spec/saxon/configuration_spec.rb
|
156
159
|
- spec/saxon/processor_spec.rb
|
157
160
|
- spec/saxon/source_helper_spec.rb
|
158
161
|
- spec/saxon/xml_spec.rb
|