smile-xml 1.0.0-jruby → 1.0.2-jruby

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. data/lib/smile-xml.jar +0 -0
  2. data/src/main/java/smile/xml/AttrJ.java +160 -0
  3. data/src/main/java/smile/xml/AttributesJ.java +212 -0
  4. data/src/main/java/smile/xml/BaseJ.java +60 -0
  5. data/src/main/java/smile/xml/DocumentJ.java +435 -0
  6. data/src/main/java/smile/xml/EncodingJ.java +94 -0
  7. data/src/main/java/smile/xml/ErrorJ.java +162 -0
  8. data/src/main/java/smile/xml/NamespaceJ.java +67 -0
  9. data/src/main/java/smile/xml/NamespacesJ.java +62 -0
  10. data/src/main/java/smile/xml/NodeJ.java +1029 -0
  11. data/src/main/java/smile/xml/NodeSetJ.java +90 -0
  12. data/src/main/java/smile/xml/ParserContextJ.java +44 -0
  13. data/src/main/java/smile/xml/ParserJ.java +196 -0
  14. data/src/main/java/smile/xml/ParserOptionsJ.java +58 -0
  15. data/src/main/java/smile/xml/ReaderJ.java +34 -0
  16. data/src/main/java/smile/xml/SchemaJ.java +66 -0
  17. data/src/main/java/smile/xml/SmileXML.java +65 -0
  18. data/src/main/java/smile/xml/XmlJ.java +58 -0
  19. data/src/main/java/smile/xml/sax/CallbackHandler.java +113 -0
  20. data/src/main/java/smile/xml/sax/SaxParserCallbacksJ.java +71 -0
  21. data/src/main/java/smile/xml/sax/SaxParserJ.java +153 -0
  22. data/src/main/java/smile/xml/util/UtilJ.java +424 -0
  23. data/src/main/java/smile/xml/xpath/CustomNamespaceContext.java +59 -0
  24. data/src/main/java/smile/xml/xpath/XPathContextJ.java +154 -0
  25. data/src/main/java/smile/xml/xpath/XPathExpressionJ.java +62 -0
  26. data/src/main/java/smile/xml/xpath/XPathJ.java +36 -0
  27. data/src/main/java/smile/xml/xpath/XPathObjectJ.java +196 -0
  28. data/src/main/java/smile/xml/xpath/XPointerJ.java +32 -0
  29. data/src/main/ruby/xml/libxml.rb +1 -0
  30. data/src/main/ruby/xml.rb +5 -0
  31. data/src/test/ruby/etc_doc_to_s.rb +21 -0
  32. data/src/test/ruby/ets_doc_file.rb +17 -0
  33. data/src/test/ruby/ets_doc_to_s.rb +23 -0
  34. data/src/test/ruby/ets_gpx.rb +28 -0
  35. data/src/test/ruby/ets_node_gc.rb +23 -0
  36. data/src/test/ruby/ets_test.xml +2 -0
  37. data/src/test/ruby/ets_tsr.rb +11 -0
  38. data/src/test/ruby/model/atom.xml +13 -0
  39. data/src/test/ruby/model/bands.iso-8859-1.xml +5 -0
  40. data/src/test/ruby/model/bands.utf-8.xml +5 -0
  41. data/src/test/ruby/model/bands.xml +5 -0
  42. data/src/test/ruby/model/books.xml +146 -0
  43. data/src/test/ruby/model/merge_bug_data.xml +58 -0
  44. data/src/test/ruby/model/ruby-lang.html +238 -0
  45. data/src/test/ruby/model/rubynet.xml +79 -0
  46. data/src/test/ruby/model/shiporder.rnc +28 -0
  47. data/src/test/ruby/model/shiporder.rng +86 -0
  48. data/src/test/ruby/model/shiporder.xml +23 -0
  49. data/src/test/ruby/model/shiporder.xsd +31 -0
  50. data/src/test/ruby/model/soap.xml +27 -0
  51. data/src/test/ruby/model/xinclude.xml +5 -0
  52. data/src/test/ruby/smile_xml_test.rb +64 -0
  53. data/src/test/ruby/tc_attr.rb +191 -0
  54. data/src/test/ruby/tc_attr_decl.rb +133 -0
  55. data/src/test/ruby/tc_attributes.rb +135 -0
  56. data/src/test/ruby/tc_deprecated_require.rb +13 -0
  57. data/src/test/ruby/tc_document.rb +162 -0
  58. data/src/test/ruby/tc_document_write.rb +212 -0
  59. data/src/test/ruby/tc_dtd.rb +125 -0
  60. data/src/test/ruby/tc_error.rb +150 -0
  61. data/src/test/ruby/tc_html_parser.rb +140 -0
  62. data/src/test/ruby/tc_namespace.rb +62 -0
  63. data/src/test/ruby/tc_namespaces.rb +210 -0
  64. data/src/test/ruby/tc_node.rb +273 -0
  65. data/src/test/ruby/tc_node_cdata.rb +51 -0
  66. data/src/test/ruby/tc_node_comment.rb +33 -0
  67. data/src/test/ruby/tc_node_copy.rb +42 -0
  68. data/src/test/ruby/tc_node_edit.rb +178 -0
  69. data/src/test/ruby/tc_node_text.rb +73 -0
  70. data/src/test/ruby/tc_node_write.rb +108 -0
  71. data/src/test/ruby/tc_node_xlink.rb +29 -0
  72. data/src/test/ruby/tc_parser.rb +371 -0
  73. data/src/test/ruby/tc_parser_context.rb +189 -0
  74. data/src/test/ruby/tc_properties.rb +40 -0
  75. data/src/test/ruby/tc_reader.rb +306 -0
  76. data/src/test/ruby/tc_relaxng.rb +54 -0
  77. data/src/test/ruby/tc_sax_parser.rb +340 -0
  78. data/src/test/ruby/tc_schema.rb +59 -0
  79. data/src/test/ruby/tc_traversal.rb +222 -0
  80. data/src/test/ruby/tc_xinclude.rb +21 -0
  81. data/src/test/ruby/tc_xml.rb +226 -0
  82. data/src/test/ruby/tc_xpath.rb +210 -0
  83. data/src/test/ruby/tc_xpath_context.rb +80 -0
  84. data/src/test/ruby/tc_xpath_expression.rb +38 -0
  85. data/src/test/ruby/tc_xpointer.rb +74 -0
  86. data/src/test/ruby/test_helper.rb +23 -0
  87. data/src/test/ruby/test_suite.rb +41 -0
  88. metadata +91 -5
@@ -0,0 +1,59 @@
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+ require 'test/unit'
5
+
6
+ class TestSchema < Test::Unit::TestCase
7
+ def setup
8
+ file = File.join(File.dirname(__FILE__), 'model/shiporder.xml')
9
+ @doc = XML::Document.file(file)
10
+ end
11
+
12
+ def teardown
13
+ @doc = nil
14
+ end
15
+
16
+ def schema
17
+ document = XML::Document.file(File.join(File.dirname(__FILE__), 'model/shiporder.xsd'))
18
+ XML::Schema.document(document)
19
+ end
20
+
21
+ def test_from_doc
22
+ assert_instance_of(XML::Schema, schema)
23
+ end
24
+
25
+ def test_valid
26
+ assert(@doc.validate_schema(schema))
27
+ end
28
+
29
+ def test_invalid
30
+ new_node = XML::Node.new('invalid', 'this will mess up validation')
31
+ @doc.root << new_node
32
+
33
+ error = assert_raise(XML::Error) do
34
+ @doc.validate_schema(schema)
35
+ end
36
+
37
+ assert_not_nil(error)
38
+ assert_kind_of(XML::Error, error)
39
+ puts "TODO #{__FILE__} #{__LINE__}"
40
+ #assert(error.message.match(/Error: Element 'invalid': This element is not expected. Expected is \( item \)/))
41
+ assert_equal(XML::Error::SCHEMASV, error.domain)
42
+ assert_equal(XML::Error::SCHEMAV_ELEMENT_CONTENT, error.code)
43
+ assert_equal(XML::Error::ERROR, error.level)
44
+ puts "TODO #{__FILE__} #{__LINE__}"
45
+ #assert(error.file.match(/shiporder.xml/))
46
+ assert_nil(error.line)
47
+ assert_nil(error.str1)
48
+ assert_nil(error.str2)
49
+ assert_nil(error.str3)
50
+ puts "TODO #{__FILE__} #{__LINE__}"
51
+ #assert_equal(0, error.int1)
52
+ puts "TODO #{__FILE__} #{__LINE__}"
53
+ #assert_equal(0, error.int2)
54
+ puts "TODO #{__FILE__} #{__LINE__}"
55
+ #assert_not_nil(error.node)
56
+ puts "TODO #{__FILE__} #{__LINE__}"
57
+ #assert_equal('invalid', error.node.name)
58
+ end
59
+ end
@@ -0,0 +1,222 @@
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+ require 'test/unit'
5
+
6
+ class TestTranversal < Test::Unit::TestCase
7
+ ROOT_NODES_LENGTH = 25
8
+ ROOT_ELEMENTS_LENGTH = 12
9
+
10
+ def setup
11
+ filename = File.join(File.dirname(__FILE__), 'model/books.xml')
12
+ @doc = XML::Document.file(filename)
13
+ end
14
+
15
+ def teardown
16
+ @doc = nil
17
+ end
18
+
19
+ def test_children
20
+ # Includes text nodes and such
21
+ assert_equal(ROOT_NODES_LENGTH, @doc.root.children.length)
22
+ end
23
+
24
+ def test_children_iteration
25
+ # Includes text nodes and such
26
+ nodes = @doc.root.children.inject([]) do |arr, node|
27
+ arr << node
28
+ arr
29
+ end
30
+
31
+ assert_equal(ROOT_NODES_LENGTH, nodes.length)
32
+ end
33
+
34
+ def test_each
35
+ # Includes text nodes and such
36
+ nodes = @doc.root.inject([]) do |arr, node|
37
+ arr << node
38
+ arr
39
+ end
40
+
41
+ assert_equal(ROOT_NODES_LENGTH, nodes.length)
42
+ end
43
+
44
+ def test_each_element
45
+ # Includes text nodes and such
46
+ nodes = []
47
+ @doc.root.each_element do |node|
48
+ nodes << node
49
+ end
50
+
51
+ assert_equal(ROOT_ELEMENTS_LENGTH, nodes.length)
52
+ end
53
+
54
+ def test_next
55
+ nodes = []
56
+
57
+ node = @doc.root.first
58
+
59
+ while node
60
+ nodes << node
61
+ node = node.next
62
+ end
63
+ assert_equal(ROOT_NODES_LENGTH, nodes.length)
64
+ end
65
+
66
+ def test_next?
67
+ first_node = @doc.root.first
68
+ assert(first_node.next?)
69
+
70
+ last_node = @doc.root.last
71
+ assert(!last_node.next?)
72
+ end
73
+
74
+ def test_prev
75
+ nodes = []
76
+
77
+ node = @doc.root.last
78
+
79
+ while node
80
+ nodes << node
81
+ node = node.prev
82
+ end
83
+ assert_equal(ROOT_NODES_LENGTH, nodes.length)
84
+ end
85
+
86
+ def test_prev?
87
+ first_node = @doc.root.first
88
+ assert(!first_node.prev?)
89
+
90
+ last_node = @doc.root.last
91
+ assert(last_node.prev?)
92
+ end
93
+
94
+ def test_parent?
95
+ assert(!@doc.parent?)
96
+ assert(@doc.root.parent?)
97
+ end
98
+
99
+ def test_child?
100
+ assert(@doc.child?)
101
+ assert(!@doc.root.first.child?)
102
+ end
103
+
104
+ def test_next_prev_equivalence
105
+ next_nodes = []
106
+ last_nodes = []
107
+
108
+ node = @doc.root.first
109
+ while node
110
+ next_nodes << node
111
+ node = node.next
112
+ end
113
+
114
+ node = @doc.root.last
115
+ while node
116
+ last_nodes << node
117
+ node = node.prev
118
+ end
119
+
120
+ assert_equal(next_nodes, last_nodes.reverse)
121
+ end
122
+
123
+ def test_next_children_equivalence
124
+ next_nodes = []
125
+
126
+ node = @doc.root.first
127
+ while node
128
+ next_nodes << node
129
+ node = node.next
130
+ end
131
+
132
+ assert_equal(@doc.root.children, next_nodes)
133
+ end
134
+
135
+ # node = @doc.find_first('book')
136
+ # node.children.each do |node|
137
+ # puts 1
138
+ #end
139
+ # @doc.root.children do |node|
140
+ # if node.node_type == XML::Node::ELEMENT_NODE
141
+ # puts node.name
142
+ #end
143
+ #end
144
+ #assert_equal(12,nodes.length)
145
+ #end
146
+
147
+ #def test_doc_class
148
+ #assert_instance_of(XML::Document, @doc)
149
+ #end
150
+
151
+ #def test_root_class
152
+ #assert_instance_of(XML::Node, @doc.root)
153
+ #end
154
+
155
+ #def test_node_class
156
+ #for n in nodes
157
+ #assert_instance_of(XML::Node, n)
158
+ #end
159
+ #end
160
+
161
+ #def test_find_class
162
+ #set = @doc.find('/ruby_array/fixnum')
163
+ #assert_instance_of(XML::XPath::Object, set)
164
+ #end
165
+
166
+ #def test_node_child_get
167
+ #assert_instance_of(TrueClass, @doc.root.child?)
168
+ #assert_instance_of(XML::Node, @doc.root.child)
169
+ #assert_equal('fixnum', @doc.root.child.name)
170
+ #end
171
+
172
+ #def test_node_doc
173
+ #for n in nodes
174
+ #assert_instance_of(XML::Document, n.doc) if n.document?
175
+ #end
176
+ #end
177
+
178
+ #def test_node_type_name
179
+ #assert_equal('element', nodes[0].node_type_name)
180
+ #assert_equal('element', nodes[1].node_type_name)
181
+ #end
182
+
183
+ #def test_node_find
184
+ #set = @doc.root.find('./fixnum').set
185
+ #assert_instance_of(XML::Node::Set, set)
186
+ #for node in set
187
+ #assert_instance_of(XML::Node, node)
188
+ #end
189
+ #end
190
+
191
+ #def test_equality
192
+ #node_a = @doc.find('/ruby_array/fixnum').first
193
+ #node_b = @doc.root.child
194
+ #assert(node_a == node_b)
195
+ #assert(node_a.eql?(node_b))
196
+ #assert(node_a.equal?(node_b))
197
+
198
+ #xp2 = XML::Parser.new()
199
+ #xp2.string = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
200
+ #doc2 = xp2.parse
201
+
202
+ #node_a2 = doc2.find('/ruby_array/fixnum').first
203
+
204
+ #assert(node_a.to_s == node_a2.to_s)
205
+ #assert(node_a == node_a2)
206
+ #assert(node_a.eql?(node_a2))
207
+ #assert(!node_a.equal?(node_a2))
208
+ #end
209
+
210
+ #def test_content()
211
+ #assert_equal('onetwo', @doc.root.content)
212
+
213
+ #first = @doc.root.child
214
+ #assert_equal('one', first.content)
215
+ #assert_equal('two', first.next.content)
216
+ #end
217
+
218
+ #def test_base
219
+ #doc = XML::Parser.string('<person />').parse
220
+ #assert_nil(doc.root.base)
221
+ #end
222
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+ require 'test/unit'
5
+
6
+ class TestXInclude < Test::Unit::TestCase
7
+ def setup
8
+ @doc = XML::Document.file(File.join(File.dirname(__FILE__), 'model/xinclude.xml'))
9
+ assert_instance_of(XML::Document, @doc)
10
+ end
11
+
12
+ def teardown
13
+ @doc = nil
14
+ end
15
+
16
+ def test_ruby_xml_xinclude
17
+ assert_equal(1, @doc.xinclude)
18
+ assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<document xmlns:xi=\"http://www.w3.org/2001/XInclude\">\n <p>This libxml2 binding has the following project information:\n <code>This is some text to include in an xml file via XInclude.</code></p>\n</document>\n",
19
+ @doc.to_s)
20
+ end
21
+ end
@@ -0,0 +1,226 @@
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+ require 'test/unit'
5
+ require 'stringio'
6
+
7
+ class TestXml < Test::Unit::TestCase
8
+ # ----- Constants ------
9
+ def test_lib_versions
10
+ assert(XML.check_lib_versions)
11
+ end
12
+
13
+ def test_debug_entities
14
+ XML.debug_entities = false
15
+ assert(!XML.debug_entities)
16
+
17
+ XML.debug_entities = true
18
+ assert(XML.debug_entities)
19
+
20
+ XML.debug_entities = false
21
+ assert(!XML.debug_entities)
22
+ end
23
+
24
+ def test_default_compression
25
+ return unless XML.default_compression
26
+
27
+ 0.upto(9) do |i|
28
+ XML.default_compression = i
29
+ assert_equal(i, XML.default_compression)
30
+ end
31
+
32
+ 9.downto(0) do |i|
33
+ assert_equal(i, XML.default_compression = i)
34
+ assert_equal(i, XML.default_compression)
35
+ end
36
+
37
+ 0.downto(-10) do |i|
38
+ assert_equal(i, XML.default_compression = i)
39
+ assert_equal(0, XML.default_compression)
40
+ end
41
+
42
+ 10.upto(20) do |i|
43
+ assert_equal(i, XML.default_compression = i)
44
+ assert_equal(9, XML.default_compression)
45
+ end
46
+ end
47
+
48
+ def test_default_keep_blanks
49
+ XML.default_keep_blanks = false
50
+ assert(!XML.default_keep_blanks)
51
+ assert_equal(XML::Parser::Options::NOBLANKS, XML.default_options)
52
+
53
+ XML.default_keep_blanks = true
54
+ assert(XML.default_keep_blanks)
55
+ assert_equal(0, XML.default_options)
56
+
57
+ XML.default_keep_blanks = false
58
+ assert(!XML.default_keep_blanks)
59
+
60
+ # other tests depend on keeping blanks by default,
61
+ # which is the default default behaviour anyway.
62
+ XML.default_keep_blanks = true
63
+ end
64
+
65
+ def test_default_line_numbers
66
+ XML.default_line_numbers = false
67
+ assert(!XML.default_line_numbers)
68
+
69
+ XML.default_line_numbers = true
70
+ assert(XML.default_line_numbers)
71
+
72
+ XML.default_line_numbers = false
73
+ assert(!XML.default_line_numbers)
74
+ end
75
+
76
+ def test_default_substitute_entities
77
+ XML.default_substitute_entities = false
78
+ assert(!XML.default_substitute_entities)
79
+ assert_equal(0, XML.default_options)
80
+
81
+ XML.default_substitute_entities = true
82
+ assert(XML.default_substitute_entities)
83
+ assert_equal(XML::Parser::Options::NOENT, XML.default_options)
84
+
85
+ XML.default_substitute_entities = false
86
+ assert(!XML.default_substitute_entities)
87
+ end
88
+
89
+ def test_default_tree_indent_string
90
+ s = XML.default_tree_indent_string
91
+ assert_instance_of(String, s)
92
+ assert_equal(' ', s)
93
+ XML.default_tree_indent_string = 'uga'
94
+ s = XML.default_tree_indent_string
95
+ assert_instance_of(String, s)
96
+ assert_equal('uga', s)
97
+ XML.default_tree_indent_string = ' '
98
+ s = XML.default_tree_indent_string
99
+ assert_instance_of(String, s)
100
+ assert_equal(' ', s)
101
+ end
102
+
103
+ def test_default_validity_checking
104
+ XML.default_validity_checking = false
105
+ assert(!XML.default_validity_checking)
106
+ assert_equal(0, XML.default_options)
107
+
108
+ XML.default_validity_checking = true
109
+ assert(XML.default_validity_checking)
110
+ assert_equal(XML::Parser::Options::DTDVALID, XML.default_options)
111
+
112
+ XML.default_validity_checking = false
113
+ assert(!XML.default_validity_checking)
114
+ end
115
+
116
+ def test_default_warnings
117
+ XML.default_warnings = false
118
+ assert(!XML.default_warnings)
119
+ assert_equal(XML::Parser::Options::NOWARNING, XML.default_options)
120
+
121
+ XML.default_warnings = true
122
+ assert(XML.default_warnings)
123
+ assert_equal(0, XML.default_options)
124
+
125
+ XML.default_warnings = false
126
+ assert(!XML.default_warnings)
127
+ end
128
+
129
+ def test_enabled_automata
130
+ assert_equal(true, XML.enabled_automata?)
131
+ end
132
+
133
+ def test_enabled_c14n
134
+ assert_equal(true, XML.enabled_c14n?)
135
+ end
136
+
137
+ def test_enabled_catalog
138
+ assert_equal(true, XML.enabled_catalog?)
139
+ end
140
+
141
+ def test_enabled_debug
142
+ assert_equal(true, XML.enabled_debug?)
143
+ end
144
+
145
+ def test_enabled_docbook
146
+ assert_equal(true, XML.enabled_docbook?)
147
+ end
148
+
149
+ def test_enabled_ftp
150
+ assert_equal(true, XML.enabled_ftp?)
151
+ end
152
+
153
+ def test_enabled_http
154
+ assert_equal(true, XML.enabled_http?)
155
+ end
156
+
157
+ def test_enabled_html
158
+ assert_equal(true, XML.enabled_html?)
159
+ end
160
+
161
+ def test_enabled_iconv
162
+ assert_equal(true, XML.enabled_iconv?)
163
+ end
164
+
165
+ def test_enabled_memory_debug
166
+ assert_equal(false, XML.enabled_memory_debug?)
167
+ end
168
+
169
+ def test_enabled_regexp
170
+ assert_equal(true, XML.enabled_regexp?)
171
+ end
172
+
173
+ def test_enabled_schemas
174
+ assert_equal(true, XML.enabled_schemas?)
175
+ end
176
+
177
+ def test_enabled_thread
178
+ assert_equal(true, XML.enabled_thread?)
179
+ end
180
+
181
+ def test_enabled_unicode
182
+ assert_equal(true, XML.enabled_unicode?)
183
+ end
184
+
185
+ def test_enabled_xinclude
186
+ assert_equal(true, XML.enabled_xinclude?)
187
+ end
188
+
189
+ def test_enabled_xpath
190
+ assert_equal(true, XML.enabled_xpath?)
191
+ end
192
+
193
+ def test_enabled_xpointer
194
+ assert_equal(true, XML.enabled_xpointer?)
195
+ end
196
+
197
+ def test_enabled_zlib
198
+ assert_equal(true, XML.enabled_zlib?)
199
+ end
200
+
201
+ def test_intent_tree_output
202
+ assert(TrueClass, XML.indent_tree_output)
203
+
204
+ XML.indent_tree_output = false
205
+ assert(FalseClass, XML.indent_tree_output)
206
+
207
+ XML.indent_tree_output = true
208
+ assert(TrueClass, XML.indent_tree_output)
209
+ end
210
+
211
+ def test_version
212
+ assert_instance_of(String, XML::VERSION)
213
+ end
214
+
215
+ def test_vernum
216
+ assert_instance_of(Fixnum, XML::VERNUM)
217
+ end
218
+
219
+ def test_libxml_parser_features
220
+ assert_instance_of(Array, XML.features)
221
+ end
222
+
223
+ def test_default_options
224
+ assert_equal(0, XML.default_options)
225
+ end
226
+ end