schematronium 0.1.0-java → 0.1.4-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/bin/schematronium +12 -7
- data/lib/schematronium.rb +4 -3
- data/schematronium.gemspec +1 -2
- data/test/test_data/schematron/test.sch +10 -2
- data/test/test_schematronium.rb +9 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74beaa03afb2404a3160870d78430983bc61622d
|
4
|
+
data.tar.gz: 56a65d7aaadce1887c8d4055e2578903ae7dafbd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97e89b77ba28e47f438ed80c7b4ea34f61c6d2c5af43610b09f79d8c12c13444d276d7f35ba5fb8ebbd0f125465b8d50f61f41790e10506112dd6c84aace5457
|
7
|
+
data.tar.gz: b0212f6ef6a938ccab58f9dc142181a36406fb5bc57ea7db8e501f4106cba012b4c612180fbf44ca5a7bf8bc4348b7d58d3cdd4684748a6dd9c2548a07ec7e82
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
Schematronium is a gem providing:
|
4
4
|
|
5
5
|
1. A single-object, single-function API for compiling a [schematron](http://www.schematron.com/) script, and running it over an XML file, returning a [Nokogiri](Nokogiri.org) [NodeSet](http://www.rubydoc.info/github/sparklemotion/nokogiri/Nokogiri/XML/NodeSet) of the resulting `failed-assert`s and `successful-report`s.
|
6
|
-
2. A script ([schematronium](bin/schematronium)) to run a schematron over one or many XML files and return aggregate date in a TBD format. Mostly meant as an example of something you could to with it.
|
6
|
+
2. A script ([schematronium](bin/schematronium)) to run a schematron over one or many XML files and return aggregate date in a TBD format. Mostly meant as an example of something you could to with it. Also shows how to turn off some parser features to prevent XXE vulnerabilities, which is VERY IMPORTANT if you are parsing XML you do not personally 100% control. Schematronium does NOT do this by default.
|
7
7
|
|
8
8
|
The goals of Schematronium are very similar to [schematron-wrapper](https://github.com/Agilefreaks/schematron-wrapper). The primary difference is that, where schematron-wrapper runs the saxon jar via backticks per file, Schematronium uses the jRuby-only [saxon-xslt](https://github.com/fidothe/saxon-xslt) library to compile and run the schematron. This has the upshot of not incurring the penalty of JDK initialization per file, which tends to be a substantial cost savings over even a small number of files.
|
9
9
|
|
data/bin/schematronium
CHANGED
@@ -6,6 +6,14 @@ raise "Not enough arguments" if ARGV.length < 2
|
|
6
6
|
|
7
7
|
Saxon::Processor.default.config[:line_numbering] = true
|
8
8
|
|
9
|
+
# Disable a bunch of stuff in parser to prevent XXE vulnerabilities
|
10
|
+
parser_options = Saxon::Processor.default.to_java.getUnderlyingConfiguration.parseOptions
|
11
|
+
parser_options.add_parser_feature("http://apache.org/xml/features/disallow-doctype-decl", true)
|
12
|
+
parser_options.add_parser_feature("http://xml.org/sax/features/external-general-entities", false)
|
13
|
+
parser_options.add_parser_feature("http://xml.org/sax/features/external-parameter-entities", false)
|
14
|
+
|
15
|
+
|
16
|
+
|
9
17
|
stron = Schematronium.new(ARGV.shift)
|
10
18
|
|
11
19
|
@fnames = []
|
@@ -14,14 +22,11 @@ if ARGV.empty?
|
|
14
22
|
@fnames = @fnames + Dir[File.join('.', "*.xml")]
|
15
23
|
else
|
16
24
|
ARGV.each do |arg|
|
17
|
-
|
18
|
-
arg = arg.sub(/~/, Dir.home)
|
19
|
-
|
20
|
-
@fnames += case File.absolute_path(arg)
|
25
|
+
@fnames += case File.expand_path(arg)
|
21
26
|
when File.method(:directory?).to_proc
|
22
|
-
Dir[File.join(File.
|
27
|
+
Dir[File.join(File.expand_path(arg), "*.xml")]
|
23
28
|
when File.method(:file?).to_proc
|
24
|
-
[File.
|
29
|
+
[File.expand_path(arg)]
|
25
30
|
else
|
26
31
|
[]
|
27
32
|
end
|
@@ -35,7 +40,7 @@ puts '<?xml version="1.0" encoding="UTF-8"?><files>'
|
|
35
40
|
xml = stron.check(s_xml)
|
36
41
|
xml.remove_namespaces!
|
37
42
|
|
38
|
-
xml = xml.xpath("
|
43
|
+
xml = xml.xpath("//failed-assert|//successful-report")
|
39
44
|
xml.each do |el|
|
40
45
|
el["line-number"] = s_xml.xpath(el.attr("location")).get_line_number
|
41
46
|
end
|
data/lib/schematronium.rb
CHANGED
@@ -14,15 +14,16 @@ class Schematronium
|
|
14
14
|
iso_abstract_expand.xsl
|
15
15
|
iso_svrl_for_xslt2.xsl|.map{|s| iso_file s}
|
16
16
|
|
17
|
-
schematron =
|
18
|
-
when IO
|
17
|
+
schematron = if schematron.respond_to? :read
|
19
18
|
Saxon.XML(schematron.read)
|
20
|
-
|
19
|
+
elsif schematron.kind_of? String
|
21
20
|
if File.file? schematron
|
22
21
|
Saxon.XML(File.open(schematron))
|
23
22
|
else
|
24
23
|
Saxon.XML(schematron)
|
25
24
|
end
|
25
|
+
else
|
26
|
+
raise "Unable to generate Schematron document from #{schematron.class.to_s}"
|
26
27
|
end
|
27
28
|
|
28
29
|
# Run schematron through each stage of the iso_schematron pipeline
|
data/schematronium.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.name = 'schematronium'
|
3
|
-
gem.version = '0.1.
|
3
|
+
gem.version = '0.1.4'
|
4
4
|
gem.date = '2015-07-27'
|
5
5
|
gem.summary = 'Tool for running schematron against XML strings/files'
|
6
6
|
gem.description = 'Wraps the saxon-xslt wrapper for Saxon 9 HE, providing a simple (one function) interface for running a schematron against an XML string or file'
|
@@ -22,5 +22,4 @@ Gem::Specification.new do |gem|
|
|
22
22
|
|
23
23
|
gem.add_development_dependency "rake", '~> 10.4'
|
24
24
|
gem.add_development_dependency "minitest"
|
25
|
-
|
26
25
|
end
|
@@ -1,6 +1,9 @@
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
2
2
|
<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
|
3
|
-
<
|
3
|
+
<phase id="testphase">
|
4
|
+
<active pattern="b" />
|
5
|
+
</phase>
|
6
|
+
<pattern id="a">
|
4
7
|
<rule context="*:test">
|
5
8
|
<report test="*:testable">
|
6
9
|
There should be 'testable' elements within 'test's.
|
@@ -9,5 +12,10 @@
|
|
9
12
|
<rule context="*:test/*:testable">
|
10
13
|
<assert test="@test-attr">Testables must have have the 'test-attr' attribute.</assert>
|
11
14
|
</rule>
|
12
|
-
|
15
|
+
</pattern>
|
16
|
+
<pattern id="b">
|
17
|
+
<rule context="*:test[1]">
|
18
|
+
<assert test="@test-attr">Testables must have have the 'test-attr' attribute.</assert>
|
19
|
+
</rule>
|
20
|
+
</pattern>
|
13
21
|
</schema>
|
data/test/test_schematronium.rb
CHANGED
@@ -8,15 +8,18 @@ class SchematroniumTest < MiniTest::Test
|
|
8
8
|
File.join(File.expand_path(File.dirname(__FILE__)), 'test_data', *path_segments)
|
9
9
|
end
|
10
10
|
|
11
|
-
def setup
|
12
|
-
@stron = Schematronium.new(td('schematron', 'test.sch'))
|
13
|
-
end
|
14
|
-
|
15
11
|
def test_check_with_file
|
16
|
-
|
12
|
+
stron = Schematronium.new(td('schematron', 'test.sch'))
|
13
|
+
results = stron.check(File.open(td('xml', 'test.xml')))
|
17
14
|
results.remove_namespaces!
|
18
|
-
assert_equal
|
15
|
+
assert_equal 2, results.xpath("//failed-assert").count, "Expects two failures"
|
19
16
|
assert_equal 2, results.xpath("//successful-report").count, "Expects two reports"
|
20
17
|
end
|
21
18
|
|
19
|
+
def test_check_with_phase
|
20
|
+
stron = Schematronium.new(td('schematron', 'test.sch'), "'testphase'")
|
21
|
+
results = stron.check(File.open(td('xml', 'test.xml')))
|
22
|
+
results.remove_namespaces!
|
23
|
+
assert_equal 1, results.xpath("//failed-assert").count, "Expects one failure"
|
24
|
+
end
|
22
25
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schematronium
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Dave Mayo
|
@@ -119,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
119
|
version: '0'
|
120
120
|
requirements: []
|
121
121
|
rubyforge_project:
|
122
|
-
rubygems_version: 2.4.
|
122
|
+
rubygems_version: 2.4.8
|
123
123
|
signing_key:
|
124
124
|
specification_version: 4
|
125
125
|
summary: Tool for running schematron against XML strings/files
|