opener-kaf2json 1.0.6-java → 1.0.7-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7760c83a5ff35f56412e0828f6234912b304378f
4
- data.tar.gz: 8a24fef977bb9966202796a3f9066ab1b31469f1
3
+ metadata.gz: 0b118beaf31c6aee85706eae29cb86c0955d4f88
4
+ data.tar.gz: 00331c7616df86de908012522b6d20b0c6e625e7
5
5
  SHA512:
6
- metadata.gz: 3517429f1212c0c70cccc042d3f43706277c83db5b623dddd3fa7aeb0da973d34fc67e738e3681caaab3e42676f4ffa12c90e36b64e393aef9e311a39041986b
7
- data.tar.gz: 76cb00baa6df22e33470145b78cf1d16c7a9080349aebf38a77cb7441f75432c814eff6829c3c05f73d9e532d946c373abc7248f80017ee7c41fbc6496057198
6
+ metadata.gz: 245ac3d40b4b97bb7fc2ff61f1f78e0705fe191d329736e3b9e1ee62af71179d8343cbd5234553b308e5a477cdfa43f58a8a95f9e5e5cd99c26feb8782ac310e
7
+ data.tar.gz: 52874be1c94d65b512cf97aa686b1252459ffdb07df98bb769c3d20ca48174452675e87f305d9a862bcbf1f21fbc648378c5d884fc647cdaa238e3455566fc61
data/README.md CHANGED
@@ -75,16 +75,6 @@ At least you need the following system setup:
75
75
 
76
76
  * JRuby 1.7.9 or newer
77
77
 
78
- Domain Adaption
79
- ---------------
80
-
81
- TODO
82
-
83
- Language Extension
84
- ------------------
85
-
86
- TODO
87
-
88
78
  The Core
89
79
  --------
90
80
 
@@ -95,7 +85,7 @@ The component is a fat wrapper around the actual language technology core. You c
95
85
  Where to go from here
96
86
  ---------------------
97
87
 
98
- * [Check the project websitere](http://opener-project.github.io)
88
+ * [Check the project website](http://opener-project.github.io)
99
89
  * [Checkout the webservice](http://opener.olery.com/kaf2json)
100
90
 
101
91
  Report problem/Get help
@@ -1,7 +1,8 @@
1
+ require 'saxon-xslt'
2
+
1
3
  require_relative 'kaf_to_json/version'
2
4
  require_relative 'kaf_to_json/server'
3
-
4
- require 'saxon-xslt'
5
+ require_relative 'kaf_to_json/error_layer'
5
6
 
6
7
 
7
8
 
@@ -43,9 +44,14 @@ module Opener
43
44
  # @return [Array]
44
45
  #
45
46
  def run(input)
46
- doc = Saxon::XML(input)
47
- xslt = Saxon::XSLT(File.read(xsl))
48
- xslt.transform(doc).to_string
47
+ begin
48
+ doc = Saxon::XML(input)
49
+ xslt = Saxon::XSLT(File.read(xsl))
50
+ return xslt.transform(doc).to_string
51
+
52
+ rescue Exception => error
53
+ return ErrorLayer.new(input, error.message, self.class).add
54
+ end
49
55
  end
50
56
 
51
57
  alias tag run
@@ -0,0 +1,90 @@
1
+ require 'nokogiri'
2
+
3
+ module Opener
4
+ class KafToJson
5
+ ##
6
+ # Add Error Layer to KAF file instead of throwing an error.
7
+ #
8
+ class ErrorLayer
9
+ attr_accessor :input, :document, :error, :klass
10
+
11
+ def initialize(input, error, klass)
12
+ @input = input.to_s
13
+ # Make sure there is always a document, even if it is empty.
14
+ @document = Nokogiri::XML(input) rescue Nokogiri::XML(nil)
15
+ @error = error
16
+ @klass = klass
17
+ end
18
+
19
+ def add
20
+ if is_xml?
21
+ unless has_errors_layer?
22
+ add_errors_layer
23
+ end
24
+ else
25
+ add_root
26
+ add_text
27
+ add_errors_layer
28
+ end
29
+ add_error
30
+
31
+ xml = !!document.encoding ? document.to_xml : document.to_xml(:encoding => "UTF-8")
32
+
33
+ return xml
34
+ end
35
+
36
+ ##
37
+ # Check if the document is a valid XML file.
38
+ #
39
+ def is_xml?
40
+ !!document.root
41
+ end
42
+
43
+ ##
44
+ # Add root element to the XML file.
45
+ #
46
+ def add_root
47
+ root = Nokogiri::XML::Node.new "KAF", document
48
+ document.add_child(root)
49
+ end
50
+
51
+ ##
52
+ # Check if the document already has an errors layer.
53
+ #
54
+ def has_errors_layer?
55
+ !!document.at('errors')
56
+ end
57
+
58
+ ##
59
+ # Add errors element to the XML file.
60
+ #
61
+ def add_errors_layer
62
+ node = Nokogiri::XML::Node.new "errors", document
63
+ document.root.add_child(node)
64
+ end
65
+
66
+ ##
67
+ # Add the text file incase it is not a valid XML document. More
68
+ # info for debugging.
69
+ #
70
+ def add_text
71
+ node = Nokogiri::XML::Node.new "raw", document
72
+ node.inner_html = input
73
+ document.root.add_child(node)
74
+
75
+ end
76
+
77
+ ##
78
+ # Add the actual error to the errors layer.
79
+ #
80
+ def add_error
81
+ node = document.at('errors')
82
+ error_node = Nokogiri::XML::Node.new "error", node
83
+ error_node['class'] = "#{klass.to_s} #{klass::VERSION}"
84
+ error_node.inner_html = error
85
+ node.add_child(error_node)
86
+ end
87
+
88
+ end # ErrorLayer
89
+ end # KafToJson
90
+ end # Opener
@@ -1,5 +1,5 @@
1
1
  module Opener
2
2
  class KafToJson
3
- VERSION = "1.0.6"
3
+ VERSION = "1.0.7"
4
4
  end
5
5
  end
@@ -24,7 +24,7 @@ Gem::Specification.new do |gem|
24
24
 
25
25
  gem.add_dependency 'builder'
26
26
  gem.add_dependency 'sinatra', '~>1.4.2'
27
- #gem.add_dependency 'nokogiri'
27
+ gem.add_dependency 'nokogiri'
28
28
  gem.add_dependency 'saxon-xslt'
29
29
  gem.add_dependency 'puma'
30
30
  gem.add_dependency 'opener-daemons'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opener-kaf2json
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  platform: java
6
6
  authors:
7
7
  - development@olery.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-24 00:00:00.000000000 Z
11
+ date: 2014-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: builder
@@ -38,6 +38,20 @@ dependencies:
38
38
  version: 1.4.2
39
39
  prerelease: false
40
40
  type: :runtime
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ prerelease: false
54
+ type: :runtime
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: saxon-xslt
43
57
  version_requirements: !ruby/object:Gem::Requirement
@@ -181,6 +195,7 @@ files:
181
195
  - config/kaf2json.xsl
182
196
  - exec/kaf-to-json.rb
183
197
  - lib/opener/kaf_to_json.rb
198
+ - lib/opener/kaf_to_json/error_layer.rb
184
199
  - lib/opener/kaf_to_json/public/markdown.css
185
200
  - lib/opener/kaf_to_json/server.rb
186
201
  - lib/opener/kaf_to_json/version.rb