saxon-rb 0.6.0-java → 0.8.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.
@@ -0,0 +1,2 @@
1
+ --format progress
2
+ --color
@@ -1 +1 @@
1
- jruby-9.2.6.0
1
+ jruby-9.2.9.0
@@ -0,0 +1 @@
1
+ -e docs/templates/plugin.rb
data/README.md CHANGED
@@ -78,7 +78,7 @@ result_2 = transformer.call_template('main-template')
78
78
  processor = Saxon::Processor.create
79
79
  xpath = processor.xpath_compiler.compile('//element[@attr = $a:var]')
80
80
 
81
- matches = xpath.run(document_node)
81
+ matches = xpath.evaluate(document_node)
82
82
  ```
83
83
 
84
84
  ## Migrating from `saxon-xslt` (or Nokogiri)
data/Rakefile CHANGED
@@ -25,7 +25,7 @@ task :circleci do
25
25
  end
26
26
  end
27
27
  def jruby_image_tags
28
- %w{9.2.9.0 9.1.17.0 9.2.10.0-SNAPSHOT-latest}
28
+ %w{9.2.9.0 9.1.17.0 9.2.10.0 9.2.11.1 9.2.12.0 9.2.13.0-SNAPSHOT-latest}
29
29
  end
30
30
 
31
31
  def jdk_image_tags
@@ -51,7 +51,7 @@ task :circleci do
51
51
 
52
52
  def codeclimate_jobs
53
53
  (alt_saxon_urls.keys << nil).map { |alt_saxon_url|
54
- ["9.2.9.0", "8-jdk-slim", alt_saxon_url]
54
+ ["9.2.12.0", "8-jdk-slim", alt_saxon_url]
55
55
  }
56
56
  end
57
57
 
@@ -190,12 +190,18 @@ task :circleci do
190
190
  def run_tests_step(opts)
191
191
  command = [
192
192
  "mkdir -p /tmp/test-results",
193
- "bundle exec rspec spec --profile 10 --format RspecJunitFormatter --out /tmp/test-results/rspec.xml --format progress"
193
+ "VERIFY_SAXON_LAZY_LOADING=1 bundle exec rspec spec/jar_loading_spec.rb --options .rspec-jar-loading --profile 10 --format RspecJunitFormatter --out /tmp/test-results/rspec-jar-loading.xml"
194
194
  ]
195
195
  if opts.fetch(:run_codeclimate)
196
196
  command.prepend("./cc-test-reporter before-build")
197
- command.append("if [ $? -eq 0 ]; then ./cc-test-reporter format-coverage -t simplecov -o \"cc-coverage#{"-alt-saxon" if opts.fetch(:alt_saxon_url)}.json\"; fi")
197
+ command.append("if [ $? -eq 0 ]; then ./cc-test-reporter format-coverage -t simplecov -o \"cc-coverage-jar-loading#{"-alt-saxon" if opts.fetch(:alt_saxon_url)}.json\"; fi")
198
198
  end
199
+ command.append("rm -rf coverage")
200
+ command.append("bundle exec rspec spec --profile 10 --format RspecJunitFormatter --out /tmp/test-results/rspec.xml --format progress")
201
+ if opts.fetch(:run_codeclimate)
202
+ command.append("if [ $? -eq 0 ]; then ./cc-test-reporter format-coverage -t simplecov -o \"cc-coverage-main#{"-alt-saxon" if opts.fetch(:alt_saxon_url)}.json\"; fi")
203
+ end
204
+
199
205
  {
200
206
  "run" => {
201
207
  "name" => "Run the tests" + (opts.fetch(:run_codeclimate) ? ", and upload coverage data to Code Climate" : ""),
@@ -0,0 +1,73 @@
1
+ include YARD
2
+ include Templates
3
+
4
+ module JavadocHtmlHelper
5
+ JAVA_TYPE_MATCHER = /\A(?:[a-z_$](?:[a-z0-9_$]*)\.)+[A-Z][A-Za-z_$]*/
6
+ RUBY_COLLECTION_TYPE_MATCHER = /\A(?:[A-Z][A-Za-z0-9_])(?:::[A-Z][A-Za-z0-9_]*)*</
7
+ SAXON_TYPE_MATCHER = /\A(?:net\.sf\.saxon|com\.saxonica)/
8
+
9
+ def format_types(typelist, brackets = true)
10
+ return unless typelist.is_a?(Array)
11
+ list = typelist.map { |type|
12
+ case type
13
+ when JAVA_TYPE_MATCHER
14
+ format_java_type(type)
15
+ else
16
+ super([type], false)
17
+ end
18
+ }
19
+ list.empty? ? "" : (brackets ? "(#{list.join(", ")})" : list.join(", "))
20
+ end
21
+
22
+ def format_java_type(type)
23
+ "<tt>" + linkify_saxon_type(type) + "</tt>"
24
+ end
25
+
26
+ def linkify_saxon_type(type)
27
+ case type
28
+ when SAXON_TYPE_MATCHER
29
+ link = url_for_java_object(type)
30
+ else
31
+ link = nil
32
+ end
33
+ link ? link_url(link, type, :title => h(type)) : type
34
+ end
35
+
36
+ def linkify(*args)
37
+ if args.first.is_a?(String)
38
+ case args.first
39
+ when JAVA_TYPE_MATCHER
40
+ link = url_for_java_object(args.first)
41
+ title = args.first
42
+ link ? link_url(link, title, :title => h(title)) : title
43
+ else
44
+ super
45
+ end
46
+ else
47
+ super
48
+ end
49
+ end
50
+
51
+ def url_for(obj, anchor = nil, relative = true)
52
+ case obj
53
+ when JAVA_TYPE_MATCHER
54
+ url_for_java_object(obj, anchor, relative)
55
+ else
56
+ super
57
+ end
58
+ end
59
+
60
+ def url_for_java_object(obj, anchor = nil, relative = nil)
61
+ case obj
62
+ when SAXON_TYPE_MATCHER
63
+ package, _, klass = obj.rpartition(".")
64
+ "http://saxonica.com/documentation/index.html#!javadoc/#{package}/#{klass}"
65
+ else
66
+ path = obj.split(".").join("/")
67
+ "https://docs.oracle.com/javase/8/docs/api/index.html?#{path}.html"
68
+ end
69
+ end
70
+ end
71
+
72
+ Template.extra_includes << proc { |opts| JavadocHtmlHelper if opts.format == :html }
73
+ # Engine.register_template_path(File.dirname(__FILE__))
@@ -1 +0,0 @@
1
- require_relative 'saxon'
@@ -2,12 +2,13 @@ require 'saxon/s9api'
2
2
  require 'saxon/parse_options'
3
3
 
4
4
  module Saxon
5
- # Wraps the <tt>net.saxon.Configuration</tt> class. See
6
- # http://saxonica.com/documentation9.5/javadoc/net/sf/saxon/Configuration.html
7
- # for details of what configuration options are available and what values
8
- # they accept. See
9
- # http://saxonica.com/documentation9.5/javadoc/net/sf/saxon/lib/FeatureKeys.html
10
- # for details of the constant names used to access the values
5
+ # Wraps the <tt>net.sf.saxon.Configuration</tt> class.
6
+ #
7
+ # See {net.sf.saxon.Configuration} for details of what configuration options
8
+ # are available and what values they accept.
9
+ #
10
+ # See {net.sf.saxon.lib.FeatureKeys} for details of the constant names used to
11
+ # access the values
11
12
  class Configuration
12
13
  DEFAULT_SEMAPHORE = Mutex.new
13
14
  private_constant :DEFAULT_SEMAPHORE
@@ -60,22 +61,23 @@ module Saxon
60
61
  end
61
62
 
62
63
  # Get a configuration option value
63
- # See https://www.saxonica.com/html/documentation/javadoc/net/sf/saxon/lib/FeatureKeys.html
64
- # for details of the available options. Use the constant name as a string
65
- # or symbol as the option
64
+ #
65
+ # See {net.sf.saxon.lib.FeatureKeys} for details of the available options.
66
+ # Use the constant name as a string or symbol as the option, e.g.
67
+ # +:allow_multhreading+, +'ALLOW_MULTITHREADING'+, +'allow_multithreading'+.
66
68
  #
67
69
  # @param option [String, Symbol]
68
70
  # @return [Object] the value of the configuration option
69
71
  # @raise [NameError] if the option name does not exist
72
+ # @see net.sf.saxon.lib.FeatureKeys
70
73
  def [](option)
71
74
  @config.getConfigurationProperty(option_url(option))
72
75
  end
73
76
 
74
- # Get a configuration option value
75
- # See http://saxonica.com/documentation9.5/javadoc/net/sf/saxon/lib/FeatureKeys.html
76
- # for details of the available options. Use the constant name as a string
77
- # or symbol as the option
77
+ # Set a configuration option value. See {#[]} for details about the option
78
+ # names.
78
79
  #
80
+ # @see #[]
79
81
  # @param option [String, Symbol]
80
82
  # @param value [Object] the value of the configuration option
81
83
  # @return [Object] the value you passed in
@@ -4,11 +4,217 @@ module Saxon
4
4
  # Builds XDM objects from XML sources, for use in XSLT or for query and
5
5
  # access
6
6
  class DocumentBuilder
7
+ # Provides a simple configuraion DSL for DocumentBuilders.
8
+ # @see DocumentBuilder.create
9
+ class ConfigurationDSL
10
+ # @api private
11
+ #
12
+ # Create a new instance and +instance_exec+ the passed-in block against it
13
+ def self.define(document_builder, block)
14
+ new(document_builder).instance_exec(&block)
15
+ end
16
+
17
+ # @api private
18
+ def initialize(document_builder)
19
+ @document_builder = document_builder
20
+ end
21
+
22
+ # Sets line numbering on or off
23
+ #
24
+ # @see DocumentBuilder#line_numbering=
25
+ #
26
+ # @param value [Boolean] on (true) or off (false)
27
+ def line_numbering(value)
28
+ @document_builder.line_numbering = value
29
+ end
30
+
31
+ # Sets the base URI of documents created using this instance.
32
+ #
33
+ # @see DocumentBuilder.base_uri=
34
+ #
35
+ # @param value [String, URI::File, URI::HTTP] The (absolute) base URI to use
36
+ def base_uri(value)
37
+ @document_builder.base_uri = value
38
+ end
39
+
40
+ # Sets the base URI of documents created using this instance.
41
+ #
42
+ # @see DocumentBuilder.base_uri=
43
+ #
44
+ # @param value [String, URI::File, URI::HTTP] The (absolute) base URI to use
45
+ def whitespace_stripping_policy(value)
46
+ @document_builder.whitespace_stripping_policy = value
47
+ end
48
+
49
+ # Sets the base URI of documents created using this instance.
50
+ #
51
+ # @see DocumentBuilder.base_uri=
52
+ #
53
+ # @param value [String, URI::File, URI::HTTP] The (absolute) base URI to use
54
+ def dtd_validation(value)
55
+ @document_builder.dtd_validation = value
56
+ end
57
+ end
58
+
59
+
60
+ # Create a new DocumentBuilder that can be used to build new XML documents
61
+ # with the passed-in {Saxon::Processor}. If a block is passed in it's
62
+ # executed as a DSL for configuring the builder instance.
63
+ #
64
+ # @param processor [Saxon::Processor] the Processor
65
+ # @yield An DocumentBuilder configuration DSL block
66
+ # @return [Saxon::DocumentBuilder] the new instance
67
+ def self.create(processor, &block)
68
+ new(processor.to_java.newDocumentBuilder, &block)
69
+ end
70
+
71
+ attr_reader :s9_document_builder
72
+ private :s9_document_builder
73
+
7
74
  # @api private
8
75
  # @param [net.sf.saxon.s9api.DocumentBuilder] s9_document_builder The
9
- # Saxon DocumentBuilder instance to wrap
10
- def initialize(s9_document_builder)
76
+ # Saxon DocumentBuilder instance to wrap
77
+ def initialize(s9_document_builder, &block)
11
78
  @s9_document_builder = s9_document_builder
79
+ if block_given?
80
+ ConfigurationDSL.define(self, block)
81
+ end
82
+ end
83
+
84
+ # Report whether documents created using this instance will keep track of
85
+ # the line and column numbers of elements.
86
+ #
87
+ # @return [Boolean] whether line numbering will be tracked
88
+ def line_numbering?
89
+ s9_document_builder.isLineNumbering
90
+ end
91
+
92
+
93
+ # Switch tracking of line and column numbers for elements in documents
94
+ # created by this instance on or off
95
+ #
96
+ # @see https://www.saxonica.com/documentation9.9/index.html#!javadoc/net.sf.saxon.s9api/DocumentBuilder@setLineNumbering
97
+ #
98
+ # @param on_or_not [Boolean] whether or not to track line numbering
99
+ def line_numbering=(on_or_not)
100
+ s9_document_builder.setLineNumbering(on_or_not)
101
+ end
102
+
103
+ # Return the default base URI to be used when building documents using this
104
+ # instance. This value will be ignored if the source being parsed has an
105
+ # intrinsic base URI (e.g. a File).
106
+ #
107
+ # Returns +nil+ if no URI is set (the default).
108
+ #
109
+ # @return [nil, URI::File, URI::HTTP] the default base URI (or nil)
110
+ def base_uri
111
+ uri = s9_document_builder.getBaseURI
112
+ uri.nil? ? uri : URI(uri.to_s)
113
+ end
114
+
115
+ # Set the base URI of documents created using this instance. This value will
116
+ # be ignored if the source being parsed has an intrinsic base URI (e.g. a
117
+ # File)
118
+ #
119
+ # @see https://www.saxonica.com/documentation9.9/index.html#!javadoc/net.sf.saxon.s9api/DocumentBuilder@setBaseURI
120
+ #
121
+ # @param uri [String, URI::File, URI::HTTP] The (absolute) base URI to use
122
+ def base_uri=(uri)
123
+ s9_document_builder.setBaseURI(java.net.URI.new(uri.to_s))
124
+ end
125
+
126
+ # Return the Whitespace stripping policy for this instance. Returns one of
127
+ # the standard policy names as a symbol, or the custom Java
128
+ # WhitespaceStrippingPolicy if one was defined using
129
+ # +#whitespace_stripping_policy = ->(qname) { ... }+. (See
130
+ # {#whitespace_stripping_policy=} for more.)
131
+ #
132
+ # +:all+: All whitespace-only nodes will be discarded
133
+ #
134
+ # +:none+: No whitespace-only nodes will be discarded (the default if DTD or
135
+ # schema validation is not in effect)
136
+ #
137
+ # +:ignorable+: Whitespace-only nodes inside elements defined as
138
+ # element-only in the DTD or schema being used will be discarded (the
139
+ # default if DTD or schema validation is in effect)
140
+ #
141
+ # +:unspecified+: the default, which in practice means :ignorable if DTD or
142
+ # schema validation is in effect, and :none otherwise.
143
+ #
144
+ # @return [:all, :none, :ignorable, :unspecified, Proc]
145
+ def whitespace_stripping_policy
146
+ s9_policy = s9_document_builder.getWhitespaceStrippingPolicy
147
+ case s9_policy
148
+ when Saxon::S9API::WhitespaceStrippingPolicy::UNSPECIFIED
149
+ :unspecified
150
+ when Saxon::S9API::WhitespaceStrippingPolicy::NONE
151
+ :none
152
+ when Saxon::S9API::WhitespaceStrippingPolicy::IGNORABLE
153
+ :ignorable
154
+ when Saxon::S9API::WhitespaceStrippingPolicy::ALL
155
+ :all
156
+ else
157
+ s9_policy
158
+ end
159
+ end
160
+
161
+ # Set the whitespace stripping policy to be used for documents built with
162
+ # this instance.
163
+ #
164
+ # Possible values are:
165
+ #
166
+ # * One of the standard policies, as a symbol (+:all+, +:none+,
167
+ # +:ignorable+, +:unspecified+, see {#whitespace_stripping_policy}).
168
+ # * A Java +net.sf.saxon.s9api.WhitesapceStrippingPolicy+ instance
169
+ # * A Proc/lambda that is handed an element name as a {Saxon::QName}, and
170
+ # should return true (if whitespace should be stripped for this element)
171
+ # or false (it should not).
172
+ # @example
173
+ # whitespace_stripping_policy = ->(element_qname) {
174
+ # element_qname == Saxon::QName.clark("{http://example.org/}element-name")
175
+ # }
176
+ #
177
+ # @see https://www.saxonica.com/documentation9.9/index.html#!javadoc/net.sf.saxon.s9api/DocumentBuilder@setWhitespaceStrippingPolicy
178
+ # @see https://www.saxonica.com/documentation9.9/index.html#!javadoc/net.sf.saxon.s9api/WhitespaceStrippingPolicy
179
+ # @param policy [Symbol, Proc, Saxon::S9API::WhitespaceStrippingPolicy] the
180
+ # policy to use
181
+ def whitespace_stripping_policy=(policy)
182
+ case policy
183
+ when :unspecified, :none, :ignorable, :all
184
+ s9_policy = Saxon::S9API::WhitespaceStrippingPolicy.const_get(policy.to_s.upcase.to_sym)
185
+ when Proc
186
+ wrapped_policy = ->(s9_qname) {
187
+ policy.call(Saxon::QName.new(s9_qname))
188
+ }
189
+ s9_policy = Saxon::S9API::WhitespaceStrippingPolicy.makeCustomPolicy(wrapped_policy)
190
+ when Saxon::S9API::WhitespaceStrippingPolicy
191
+ s9_policy = policy
192
+ else
193
+ raise InvalidWhitespaceStrippingPolicyError, "#{policy.inspect} is not one of the allowed Symbols, or a custom policy"
194
+ end
195
+ s9_document_builder.setWhitespaceStrippingPolicy(s9_policy)
196
+ end
197
+
198
+ # @return [Boolean] whether DTD Validation is enabled
199
+ def dtd_validation?
200
+ s9_document_builder.isDTDValidation
201
+ end
202
+
203
+ # Switches DTD validation on or off.
204
+ #
205
+ # It's important to note that DTD validation only applies to documents that
206
+ # contain a +<!doctype>+, but switching DTD validation off doesn't stop the
207
+ # XML parser Saxon uses from trying to retrieve the DTD that's referenced,
208
+ # which can mean network requests. By default, the SAX parser Saxon uses
209
+ # (Xerces) doesn't make use of XML catalogs, which causes problems when documents reference a DTD with a relative path as in:
210
+ # <!DOCTYPE root-element SYSTEM "example.dtd">
211
+ # This can be controlled through a configuration option, however.
212
+ #
213
+ # @see https://www.saxonica.com/documentation9.9/index.html#!javadoc/net.sf.saxon.s9api/DocumentBuilder@setDTDValidation
214
+ # @see https://www.saxonica.com/documentation9.9/index.html#!sourcedocs/controlling-parsing
215
+ # @param on [Boolean] whether DTD Validation should be enabled
216
+ def dtd_validation=(on)
217
+ s9_document_builder.setDTDValidation(on)
12
218
  end
13
219
 
14
220
  # @param [Saxon::Source] source The Saxon::Source containing the source
@@ -16,13 +222,18 @@ module Saxon
16
222
  # @return [Saxon::XDM::Node] The Saxon::XDM::Node representing the root of the
17
223
  # document tree
18
224
  def build(source)
19
- XDM::Node.new(@s9_document_builder.build(source.to_java))
225
+ XDM::Node.new(s9_document_builder.build(source.to_java))
20
226
  end
21
227
 
22
- # @return [net.sf.saxon.s9api.DocumentBuilder] The underlying Java Saxon
228
+ # @return [Java::NetSfSaxonS9api::DocumentBuilder] The underlying Java Saxon
23
229
  # DocumentBuilder instance
24
230
  def to_java
25
- @s9_document_builder
231
+ s9_document_builder
26
232
  end
27
233
  end
234
+
235
+ # Error raised when someone tries to set an invalid whitespace stripping
236
+ # policy on a {DocumentBuilder}
237
+ class InvalidWhitespaceStrippingPolicyError < RuntimeError
238
+ end
28
239
  end
@@ -0,0 +1,11 @@
1
+ require_relative 'feature_flags/version'
2
+ require_relative 'feature_flags/helpers'
3
+
4
+ module Saxon
5
+ # Allows saxon-rb features to be switched off if they can't be used under one
6
+ # of the otherwise-supported Saxon versions
7
+ #
8
+ # @api private
9
+ module FeatureFlags
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ module Saxon
2
+ module FeatureFlags
3
+ # Error raised if a feature is not available under the loaded version of
4
+ # Saxon
5
+ class UnavailableInThisSaxonVersionError < StandardError
6
+ end
7
+ end
8
+ end