facturx-schematron 1.2.0
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 +7 -0
- data/LICENSE.txt +22 -0
- data/NOTICE.md +17 -0
- data/lib/facturx/schematron/error.rb +11 -0
- data/lib/facturx/schematron/locator.rb +79 -0
- data/lib/facturx/schematron/registry.rb +72 -0
- data/lib/facturx/schematron/rules/1.09.2/basic/FACTUR-X_BASIC.xslt +9554 -0
- data/lib/facturx/schematron/rules/1.09.2/basic/FACTUR-X_BASIC_codedb.xml +4878 -0
- data/lib/facturx/schematron/rules/1.09.2/basic-wl/FACTUR-X_BASIC-WL.xslt +6938 -0
- data/lib/facturx/schematron/rules/1.09.2/basic-wl/FACTUR-X_BASIC-WL_codedb.xml +2268 -0
- data/lib/facturx/schematron/rules/1.09.2/en16931/FACTUR-X_EN16931.xslt +12265 -0
- data/lib/facturx/schematron/rules/1.09.2/en16931/FACTUR-X_EN16931_codedb.xml +5909 -0
- data/lib/facturx/schematron/rules/1.09.2/extended/FACTUR-X_EXTENDED.xslt +28086 -0
- data/lib/facturx/schematron/rules/1.09.2/extended/FACTUR-X_EXTENDED_codedb.xml +8605 -0
- data/lib/facturx/schematron/rules/1.09.2/minimum/FACTUR-X_MINIMUM.xslt +1451 -0
- data/lib/facturx/schematron/rules/1.09.2/minimum/FACTUR-X_MINIMUM_codedb.xml +1119 -0
- data/lib/facturx/schematron/rules/LICENSE-APACHE-2.0.txt +201 -0
- data/lib/facturx/schematron/rules/SHA256SUMS +10 -0
- data/lib/facturx/schematron/svrl_parser.rb +82 -0
- data/lib/facturx/schematron/validator.rb +93 -0
- data/lib/facturx/schematron/version_probe.rb +71 -0
- data/lib/facturx/schematron.rb +16 -0
- data/rbi/facturx-schematron.rbi +9 -0
- metadata +83 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 38cb4b9f11f3396868e5efb28abba143340cae9132f0d621aeeb105b24a97eb3
|
|
4
|
+
data.tar.gz: 66e24e5f6fed9532cca684886d4ec52ed6a4c7991254dc65bcd7d97e69c4bffa
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 42645236157a7a28ba20bdc11635a7f9a87d048d2f4d02290a1e92ad067cdb3aad80723056b45b2a5d36d0b9e4baf4e13631d2092f1270a3a7c987c109356b42
|
|
7
|
+
data.tar.gz: 38fe45c13001f394e7433f72117c04dd183040967f823cd8b433f51ba3ca254f66eb459a66632a0dc63aec87edb809c62788c245a541e22af3a5f279996298af
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2026 AdVitam (https://www.advitam.fr)
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/NOTICE.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
## Factur-X Schematron validation artifacts
|
|
4
|
+
|
|
5
|
+
This gem includes the compiled XSLT 2.0 stylesheets and adjacent code databases
|
|
6
|
+
for the MINIMUM, BASIC WL, BASIC, EN 16931, and EXTENDED profiles from the
|
|
7
|
+
official Factur-X 1.09.2 / ZUGFeRD 2.5.2 English package.
|
|
8
|
+
|
|
9
|
+
FeRD publishes these technical artifacts under the Apache License 2.0. Its text
|
|
10
|
+
is included in `lib/facturx/schematron/rules/LICENSE-APACHE-2.0.txt`. The ten
|
|
11
|
+
files under `rules/1.09.2/` are byte-for-byte copies of their upstream
|
|
12
|
+
counterparts; their SHA-256 digests are recorded in `rules/SHA256SUMS`.
|
|
13
|
+
|
|
14
|
+
Sources:
|
|
15
|
+
|
|
16
|
+
- https://www.ferd-net.de/en/downloads/publications/details/zugferd-252-english
|
|
17
|
+
- https://www.ferd-net.de/en/ueber-uns/ressourcen-1/veroeffentlichungen/disclaimer-and-rights-of-use-zugferd
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Facturx
|
|
4
|
+
module Schematron
|
|
5
|
+
class Error < Facturx::Error; end
|
|
6
|
+
class UnavailableError < Error; end
|
|
7
|
+
class ExecutionError < Error; end
|
|
8
|
+
class InvalidOutputError < ExecutionError; end
|
|
9
|
+
class RulePackError < ExecutionError; end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'error'
|
|
4
|
+
require_relative 'version_probe'
|
|
5
|
+
|
|
6
|
+
module Facturx
|
|
7
|
+
module Schematron
|
|
8
|
+
class Locator
|
|
9
|
+
ENV_KEY = 'FACTURX_SAXONC_TRANSFORM'
|
|
10
|
+
BINARY_NAME = 'Transform'
|
|
11
|
+
private_constant :ENV_KEY, :BINARY_NAME
|
|
12
|
+
|
|
13
|
+
def initialize(runner:, env: ENV)
|
|
14
|
+
@env = env
|
|
15
|
+
@version_probe = VersionProbe.new(runner:)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def preflight!
|
|
19
|
+
@preflight ||= begin
|
|
20
|
+
binary = resolve_binary
|
|
21
|
+
raise_missing unless binary
|
|
22
|
+
|
|
23
|
+
@version_probe.call(binary)
|
|
24
|
+
binary
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def resolve_binary
|
|
31
|
+
configured = @env[ENV_KEY]
|
|
32
|
+
return find_executable(configured) if configured && !configured.empty?
|
|
33
|
+
|
|
34
|
+
find_executable(BINARY_NAME)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def find_executable(value)
|
|
38
|
+
path = value.to_s
|
|
39
|
+
return executable_file(path) if path.include?(File::SEPARATOR) || alt_separator?(path)
|
|
40
|
+
|
|
41
|
+
executable_names(path).each do |name|
|
|
42
|
+
search_paths.each do |directory|
|
|
43
|
+
executable = executable_file(File.join(directory, name))
|
|
44
|
+
return executable if executable
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
nil
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def executable_names(name)
|
|
51
|
+
return [name] unless Gem.win_platform? && File.extname(name).empty?
|
|
52
|
+
|
|
53
|
+
extensions = @env.fetch('PATHEXT', '.COM;.EXE;.BAT;.CMD').split(';')
|
|
54
|
+
[name, *extensions.map { |extension| "#{name}#{extension.downcase}" }]
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def search_paths
|
|
58
|
+
@env.fetch('PATH', '').split(File::PATH_SEPARATOR).reject(&:empty?)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def executable_file(path)
|
|
62
|
+
expanded = File.expand_path(path)
|
|
63
|
+
expanded if File.file?(expanded) && File.executable?(expanded)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def alt_separator?(path)
|
|
67
|
+
File::ALT_SEPARATOR && path.include?(File::ALT_SEPARATOR)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def raise_missing
|
|
71
|
+
raise UnavailableError.new(
|
|
72
|
+
'Schematron validation is unavailable: SaxonC Transform was not found',
|
|
73
|
+
reason: :missing_binary,
|
|
74
|
+
environment_variable: ENV_KEY
|
|
75
|
+
)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'error'
|
|
4
|
+
|
|
5
|
+
module Facturx
|
|
6
|
+
module Schematron
|
|
7
|
+
class Registry
|
|
8
|
+
RuleSet = Data.define(:directory, :stylesheet, :code_db)
|
|
9
|
+
RULES_ROOT = File.expand_path('rules/1.09.2', __dir__)
|
|
10
|
+
ENTRIES = {
|
|
11
|
+
minimum: %w[minimum FACTUR-X_MINIMUM],
|
|
12
|
+
basic_wl: %w[basic-wl FACTUR-X_BASIC-WL],
|
|
13
|
+
basic: %w[basic FACTUR-X_BASIC],
|
|
14
|
+
en16931: %w[en16931 FACTUR-X_EN16931],
|
|
15
|
+
extended: %w[extended FACTUR-X_EXTENDED]
|
|
16
|
+
}.freeze
|
|
17
|
+
private_constant :RULES_ROOT, :ENTRIES
|
|
18
|
+
|
|
19
|
+
def initialize
|
|
20
|
+
@rule_sets = {}
|
|
21
|
+
@mutex = Mutex.new
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def fetch(profile)
|
|
25
|
+
@rule_sets[profile.id] || @mutex.synchronize do
|
|
26
|
+
@rule_sets[profile.id] ||= build(profile)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
def build(profile)
|
|
33
|
+
directory_name, basename = ENTRIES.fetch(profile.id) { raise_unknown_profile(profile) }
|
|
34
|
+
directory = File.join(RULES_ROOT, directory_name)
|
|
35
|
+
rule_set = RuleSet.new(
|
|
36
|
+
directory:,
|
|
37
|
+
stylesheet: File.join(directory, "#{basename}.xslt"),
|
|
38
|
+
code_db: File.join(directory, "#{basename}_codedb.xml")
|
|
39
|
+
)
|
|
40
|
+
ensure_readable!(rule_set, profile)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def ensure_readable!(rule_set, profile)
|
|
44
|
+
missing = missing_artifacts(rule_set)
|
|
45
|
+
return rule_set if missing.empty?
|
|
46
|
+
|
|
47
|
+
raise RulePackError.new(
|
|
48
|
+
"The Factur-X #{profile.id} Schematron rule pack is incomplete",
|
|
49
|
+
reason: :missing_artifacts,
|
|
50
|
+
profile: profile.id,
|
|
51
|
+
missing:
|
|
52
|
+
)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def missing_artifacts(rule_set)
|
|
56
|
+
%i[stylesheet code_db].reject { |name| readable?(rule_set.public_send(name)) }
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def readable?(path)
|
|
60
|
+
File.file?(path) && File.readable?(path)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def raise_unknown_profile(profile)
|
|
64
|
+
raise RulePackError.new(
|
|
65
|
+
"No Schematron rule pack is registered for Factur-X profile #{profile.id.inspect}",
|
|
66
|
+
reason: :unknown_profile,
|
|
67
|
+
profile: profile.id
|
|
68
|
+
)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|