libxml-jruby-fixed 1.0.0-jruby

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. data/History.txt +4 -0
  2. data/Manifest.txt +91 -0
  3. data/README.txt +50 -0
  4. data/Rakefile +40 -0
  5. data/lib/libxml-jruby.rb +84 -0
  6. data/lib/libxml-jruby/xml.rb +1 -0
  7. data/lib/libxml-jruby/xml/attr.rb +46 -0
  8. data/lib/libxml-jruby/xml/attributes.rb +68 -0
  9. data/lib/libxml-jruby/xml/document.rb +52 -0
  10. data/lib/libxml-jruby/xml/dtd.rb +25 -0
  11. data/lib/libxml-jruby/xml/node.rb +285 -0
  12. data/lib/libxml-jruby/xml/ns.rb +19 -0
  13. data/lib/libxml-jruby/xml/parser.rb +121 -0
  14. data/lib/libxml-jruby/xml/xpath.rb +98 -0
  15. data/lib/libxml.rb +1 -0
  16. data/lib/xml.rb +13 -0
  17. data/lib/xml/libxml.rb +8 -0
  18. data/script/benchmark/depixelate.rb +633 -0
  19. data/script/benchmark/hamlet.xml +9055 -0
  20. data/script/benchmark/sock_entries.xml +507 -0
  21. data/script/benchmark/throughput.rb +40 -0
  22. data/script/benchmark/xml_benchmarks.rb +228 -0
  23. data/script/test +6 -0
  24. data/tasks/ann.rake +81 -0
  25. data/tasks/bones.rake +21 -0
  26. data/tasks/gem.rake +126 -0
  27. data/tasks/git.rake +41 -0
  28. data/tasks/manifest.rake +49 -0
  29. data/tasks/notes.rake +28 -0
  30. data/tasks/post_load.rake +39 -0
  31. data/tasks/rdoc.rake +51 -0
  32. data/tasks/rubyforge.rake +57 -0
  33. data/tasks/setup.rb +268 -0
  34. data/tasks/spec.rake +55 -0
  35. data/tasks/svn.rake +48 -0
  36. data/tasks/test.rake +38 -0
  37. data/test/etc_doc_to_s.rb +19 -0
  38. data/test/ets_copy_bug.rb +21 -0
  39. data/test/ets_copy_bug3.rb +38 -0
  40. data/test/ets_doc_file.rb +15 -0
  41. data/test/ets_doc_to_s.rb +21 -0
  42. data/test/ets_gpx.rb +26 -0
  43. data/test/ets_node_gc.rb +21 -0
  44. data/test/ets_test.xml +2 -0
  45. data/test/ets_tsr.rb +9 -0
  46. data/test/model/books.xml +147 -0
  47. data/test/model/default_validation_bug.rb +0 -0
  48. data/test/model/merge_bug_data.xml +58 -0
  49. data/test/model/rubynet.xml +78 -0
  50. data/test/model/rubynet_project +1 -0
  51. data/test/model/saxtest.xml +5 -0
  52. data/test/model/shiporder.rnc +28 -0
  53. data/test/model/shiporder.rng +86 -0
  54. data/test/model/shiporder.xml +23 -0
  55. data/test/model/shiporder.xsd +31 -0
  56. data/test/model/simple.xml +7 -0
  57. data/test/model/soap.xml +27 -0
  58. data/test/model/xinclude.xml +5 -0
  59. data/test/tc_attributes.rb +110 -0
  60. data/test/tc_deprecated_require.rb +13 -0
  61. data/test/tc_document.rb +97 -0
  62. data/test/tc_document_write.rb +139 -0
  63. data/test/tc_dtd.rb +70 -0
  64. data/test/tc_html_parser.rb +63 -0
  65. data/test/tc_node.rb +108 -0
  66. data/test/tc_node_attr.rb +176 -0
  67. data/test/tc_node_cdata.rb +51 -0
  68. data/test/tc_node_comment.rb +32 -0
  69. data/test/tc_node_copy.rb +40 -0
  70. data/test/tc_node_edit.rb +98 -0
  71. data/test/tc_node_set.rb +24 -0
  72. data/test/tc_node_set2.rb +37 -0
  73. data/test/tc_node_text.rb +17 -0
  74. data/test/tc_node_xlink.rb +28 -0
  75. data/test/tc_ns.rb +18 -0
  76. data/test/tc_parser.rb +308 -0
  77. data/test/tc_parser_context.rb +126 -0
  78. data/test/tc_properties.rb +37 -0
  79. data/test/tc_reader.rb +112 -0
  80. data/test/tc_relaxng.rb +39 -0
  81. data/test/tc_sax_parser.rb +113 -0
  82. data/test/tc_schema.rb +39 -0
  83. data/test/tc_traversal.rb +220 -0
  84. data/test/tc_well_formed.rb +11 -0
  85. data/test/tc_xinclude.rb +26 -0
  86. data/test/tc_xpath.rb +130 -0
  87. data/test/tc_xpath_context.rb +72 -0
  88. data/test/tc_xpointer.rb +78 -0
  89. data/test/test_libxml-jruby.rb +0 -0
  90. data/test/test_suite.rb +31 -0
  91. data/test/ts_working.rb +31 -0
  92. metadata +146 -0
@@ -0,0 +1,25 @@
1
+ module LibXMLJRuby
2
+ module XML
3
+ class Dtd
4
+ def initialize(schema)
5
+ @schema = schema
6
+ end
7
+
8
+ def validate(doc)
9
+ validator.validate(doc)
10
+ end
11
+
12
+ def schema_factory
13
+ SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema")
14
+ end
15
+
16
+ def schema
17
+ schema = schema_factory.newSchema(StreamSource.new(ByteArrayInputStream.new(@schema.to_java_bytes)))
18
+ end
19
+
20
+ def validator
21
+ schema.newValidator
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,285 @@
1
+ module LibXMLJRuby
2
+ module XML
3
+ class Node
4
+ ATTRIBUTE_NODE = org.w3c.dom.Node.ATTRIBUTE_NODE
5
+ CDATA_SECTION_NODE = org.w3c.dom.Node.CDATA_SECTION_NODE
6
+ COMMENT_NODE = org.w3c.dom.Node.COMMENT_NODE
7
+ DOCUMENT_FRAG_NODE = org.w3c.dom.Node.DOCUMENT_FRAGMENT_NODE
8
+ DOCUMENT_NODE = org.w3c.dom.Node.DOCUMENT_NODE
9
+ DOCUMENT_TYPE_NODE = org.w3c.dom.Node.DOCUMENT_TYPE_NODE
10
+ ELEMENT_NODE = org.w3c.dom.Node.ELEMENT_NODE
11
+ ENTITY_NODE = org.w3c.dom.Node.ENTITY_NODE
12
+ ENTITY_REFERENCE_NODE = org.w3c.dom.Node.ENTITY_REFERENCE_NODE
13
+ NOTATION_NODE = org.w3c.dom.Node.NOTATION_NODE
14
+ PROCESSING_INSTRUCTION_NODE = org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE
15
+ TEXT_NODE = org.w3c.dom.Node.TEXT_NODE
16
+
17
+ class << self
18
+ def from_java(java_obj)
19
+ return nil if java_obj.nil?
20
+ n = allocate
21
+ n.java_obj = java_obj
22
+ n
23
+ end
24
+ end
25
+
26
+ include Enumerable
27
+
28
+ attr_accessor :java_obj # org.w3c.dom.Element(Node?)
29
+
30
+ def initialize(name, content = nil)
31
+ jdoc = DocumentBuilderFactory.new_instance.new_document_builder.new_document
32
+ self.java_obj = jdoc.createElement(name)
33
+ self.content = content
34
+ end
35
+
36
+ def name
37
+ java_obj.node_name ||= @name
38
+ end
39
+
40
+ def content
41
+ java_obj.text_content ||= @content
42
+ end
43
+
44
+ def name=(name)
45
+ @name = name
46
+ java_obj.node_name = @name if @name
47
+ end
48
+
49
+ def base
50
+ b = java_obj.getAttributeNS('xml', 'base')
51
+ b.empty? ? nil : b
52
+ end
53
+
54
+ def content=(content)
55
+ @content = content
56
+ java_obj.node_value = @value if @value
57
+ end
58
+
59
+ def child_add(node)
60
+ java_obj.getOwnerDocument.adoptNode(node.java_obj)
61
+ java_obj.appendChild(node.java_obj) # should this be importNode?
62
+ end
63
+
64
+ def copy(deep = false)
65
+ LibXMLJRuby::XML::Node.from_java(java_obj.cloneNode(deep))
66
+ end
67
+
68
+ def <<(node)
69
+
70
+ end
71
+
72
+ def each(&block)
73
+ children.each(&block)
74
+ end
75
+
76
+ def each_element
77
+ if block_given?
78
+ each do |node|
79
+ yield(node) if node.node_type == ELEMENT_NODE
80
+ end
81
+ else
82
+ select do |node|
83
+ node.node_type == org.w3c.dom.Node.ELEMENT_NODE
84
+ end
85
+ end
86
+ end
87
+
88
+ def find(expr)
89
+ LibXMLJRuby::XML::XPath::Object.new(expr, java_obj)
90
+ end
91
+
92
+ def find_first(expr)
93
+ raise TypeError if java_obj.nil?
94
+ find(expr).first
95
+ end
96
+
97
+ def node_type
98
+ java_obj.node_type
99
+ end
100
+
101
+ def node_type_name
102
+ case node_type
103
+ # Most common choices first
104
+ when ATTRIBUTE_NODE
105
+ 'attribute'
106
+ when DOCUMENT_NODE
107
+ 'document_xml'
108
+ when ELEMENT_NODE
109
+ 'element'
110
+ when TEXT_NODE
111
+ 'text'
112
+
113
+ # Now the rest
114
+ when ATTRIBUTE_DECL
115
+ 'attribute_decl'
116
+ when CDATA_SECTION_NODE
117
+ 'cdata'
118
+ when COMMENT_NODE
119
+ 'comment'
120
+ when DOCB_DOCUMENT_NODE
121
+ 'document_docbook'
122
+ when DOCUMENT_FRAG_NODE
123
+ 'fragment'
124
+ when DOCUMENT_TYPE_NODE
125
+ 'doctype'
126
+ when DTD_NODE
127
+ 'dtd'
128
+ when ELEMENT_DECL
129
+ 'elem_decl'
130
+ when ENTITY_DECL
131
+ 'entity_decl'
132
+ when ENTITY_NODE
133
+ 'entity'
134
+ when ENTITY_REF_NODE
135
+ 'entity_ref'
136
+ when HTML_DOCUMENT_NODE
137
+ 'document_html'
138
+ when NAMESPACE_DECL
139
+ 'namespace'
140
+ when NOTATION_NODE
141
+ 'notation'
142
+ when PI_NODE
143
+ 'pi'
144
+ when XINCLUDE_START
145
+ 'xinclude_start'
146
+ when XINCLUDE_END
147
+ 'xinclude_end'
148
+ else
149
+ raise(UnknownType, "Unknown node type: %n", node.node_type);
150
+ end
151
+ end
152
+
153
+ def first
154
+ child
155
+ end
156
+
157
+ def children
158
+ @children ||= LibXMLJRuby::XML::Node::Set.from_java(java_obj.getChildNodes).to_a
159
+ end
160
+
161
+ def child?
162
+ !!child
163
+ end
164
+
165
+ def prev?
166
+ !!prev
167
+ end
168
+
169
+ def next?
170
+ !!self.next
171
+ end
172
+
173
+ def parent?
174
+ !!parent
175
+ end
176
+
177
+ def parent
178
+ @parent ||= LibXMLJRuby::XML::Node.from_java(java_obj.parent_node)
179
+ end
180
+
181
+ def prev
182
+ @prev ||= LibXMLJRuby::XML::Node.from_java(java_obj.previous_sibling)
183
+ end
184
+
185
+ def last
186
+ @last ||= LibXMLJRuby::XML::Node.from_java(java_obj.last_child)
187
+ end
188
+
189
+ def child
190
+ @child ||= LibXMLJRuby::XML::Node.from_java(java_obj.first_child)
191
+ end
192
+
193
+ def next
194
+ @next ||= LibXMLJRuby::XML::Node.from_java(java_obj.next_sibling)
195
+ end
196
+
197
+ def attributes
198
+ @attributes ||= LibXMLJRuby::XML::Attributes.from_java(java_obj)
199
+ end
200
+
201
+ def [](name)
202
+ attributes[name]
203
+ end
204
+
205
+ def []=(name, value)
206
+ attributes[name] = value
207
+ end
208
+
209
+ def ==(other)
210
+ eql?(other)
211
+ end
212
+
213
+ def eql?(other)
214
+ return false if other.nil?
215
+ raise TypeError unless self.class === other
216
+ (java_obj.eql?(other.java_obj) || self.to_s == other.to_s)
217
+ end
218
+
219
+ def equal?(other)
220
+ self.class === other && java_obj.equal?(other.java_obj)
221
+ end
222
+
223
+ def doc
224
+ @doc ||= LibXMLJRuby::XML::Document.from_java(java_obj.owner_document)
225
+ end
226
+
227
+ def to_s
228
+ transformer = TransformerFactory.newInstance.newTransformer
229
+ result = StreamResult.new(StringWriter.new)
230
+ source = DOMSource.new(java_obj)
231
+ transformer.transform(source, result)
232
+ result.getWriter.toString
233
+ end
234
+
235
+ def document?
236
+ doc == self
237
+ end
238
+
239
+ alias :properties :attributes
240
+
241
+ class Set
242
+ class << self
243
+ def from_java(java_obj)
244
+ s = new
245
+ s.java_obj = java_obj
246
+ s
247
+ end
248
+ end
249
+
250
+ include Enumerable
251
+
252
+ attr_accessor :java_obj
253
+
254
+ def initialize
255
+ @java_obj = java_obj
256
+ @node_cache = {}
257
+ end
258
+
259
+ def length
260
+ java_obj.length
261
+ end
262
+
263
+ def empty?
264
+ java_obj.length < 1
265
+ end
266
+
267
+ def [](index)
268
+ @node_cache[index] ||= LibXMLJRuby::XML::Node.from_java(java_obj.item(index))
269
+ end
270
+
271
+ def first
272
+ self[0]
273
+ end
274
+
275
+ def each
276
+ i = 0
277
+ while(i < java_obj.length)
278
+ yield self[i]
279
+ i += 1
280
+ end
281
+ end
282
+ end
283
+ end
284
+ end
285
+ end
@@ -0,0 +1,19 @@
1
+ module LibXMLJRuby
2
+ module XML
3
+ class NS
4
+ class << self
5
+ def from_java(java_obj)
6
+
7
+ end
8
+ end
9
+
10
+ def initialize(node, href, prefix)
11
+ @node, @href, @prefix = node, href, prefix
12
+ end
13
+
14
+ attr_reader :href, :prefix
15
+ def href?; !!href; end
16
+ def prefix?; !!prefix; end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,121 @@
1
+ class LibXMLJRuby::XML::Parser
2
+ class ParseError < RuntimeError; end
3
+
4
+ VERNUM = 0
5
+ VERSION = '0'
6
+
7
+ @default_tree_indent_string = ' '
8
+ @check_lib_versions = ''
9
+ @features = []
10
+
11
+ class << self
12
+ attr_accessor :debug_entities, :default_compression,
13
+ :default_keep_blanks, :default_line_numbers,
14
+ :default_substitute_entities,
15
+ :default_tree_indent_string,
16
+ :default_validity_checking, :default_warnings,
17
+ :features, :indent_tree_output,
18
+ :check_lib_versions
19
+
20
+ def register_error_handler(handler = nil, &block)
21
+
22
+ end
23
+
24
+ def file(filename)
25
+ p = new
26
+ p.filename = filename
27
+ p
28
+ end
29
+
30
+ def string(string)
31
+ p = new
32
+ p.string = string
33
+ p
34
+ end
35
+
36
+ def io(io)
37
+ p = new
38
+ p.io = io
39
+ p
40
+ end
41
+ end
42
+
43
+ def initialize
44
+ @source_type = nil
45
+ @parsed = false
46
+ end
47
+
48
+ attr_reader :string, :filename, :io
49
+
50
+ def string=(string = nil)
51
+ raise TypeError if string.nil?
52
+ @parsed = false
53
+ @source_type = String
54
+ @string = string
55
+ end
56
+
57
+ def filename=(filename)
58
+ @source_type = File
59
+ @filename = filename
60
+ end
61
+
62
+ def io=(io)
63
+ raise TypeError if StringIO === io
64
+ @io = io
65
+ self.string = @io.read
66
+ end
67
+
68
+ def parse
69
+ raise ParseError, "You cannot parse twice" if @parsed
70
+ raise ParseError, "No input specified, please specify an input" unless @source_type
71
+ doc = send("parse_#{@source_type.to_s.downcase}")
72
+ @parsed = true
73
+ doc
74
+ end
75
+
76
+ def document_builder_factory
77
+ @dbf ||= DocumentBuilderFactory.new_instance
78
+ end
79
+
80
+ def document_builder
81
+ document_builder_factory.namespace_aware = true
82
+ document_builder_factory.new_document_builder
83
+ end
84
+
85
+ def string_reader
86
+ StringReader.new(@string)
87
+ end
88
+
89
+ def input_source
90
+ InputSource.new(string_reader)
91
+ end
92
+
93
+ def parse_string
94
+ raise ParseError if @string.empty?
95
+ builder = document_builder
96
+
97
+ begin
98
+ jdoc = builder.parse(input_source)
99
+ rescue NativeException
100
+ raise ParseError
101
+ end
102
+
103
+ LibXMLJRuby::XML::Document.from_java(jdoc)
104
+ end
105
+
106
+ def parse_file
107
+ builder = document_builder
108
+
109
+ begin
110
+ jdoc = builder.parse(@filename)
111
+ rescue
112
+ raise ParseError
113
+ end
114
+
115
+ LibXMLJRuby::XML::Document.from_java(jdoc)
116
+ end
117
+
118
+ def parse_io
119
+ parse_string
120
+ end
121
+ end