vcdom 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/lib/vcdom/attr.rb +70 -0
  2. data/lib/vcdom/attr_node_map.rb +30 -0
  3. data/lib/vcdom/attr_ns.rb +38 -0
  4. data/lib/vcdom/character_data.rb +22 -0
  5. data/lib/vcdom/child.rb +53 -0
  6. data/lib/vcdom/document.rb +126 -0
  7. data/lib/vcdom/element.rb +332 -0
  8. data/lib/vcdom/element_ns.rb +44 -0
  9. data/lib/vcdom/node.rb +278 -0
  10. data/lib/vcdom/node_list.rb +32 -0
  11. data/lib/vcdom/parent.rb +126 -0
  12. data/lib/vcdom/text.rb +23 -0
  13. data/lib/vcdom/xml_parser.rb +368 -0
  14. data/lib/vcdom/xml_serializer.rb +55 -0
  15. metadata +48 -81
  16. data/History.txt +0 -4
  17. data/Manifest.txt +0 -34
  18. data/PostInstall.txt +0 -7
  19. data/README.rdoc +0 -51
  20. data/Rakefile +0 -26
  21. data/lib/vcdom/minidom/attr.rb +0 -139
  22. data/lib/vcdom/minidom/attr_ns.rb +0 -47
  23. data/lib/vcdom/minidom/cdata_section.rb +0 -34
  24. data/lib/vcdom/minidom/character_data.rb +0 -263
  25. data/lib/vcdom/minidom/comment.rb +0 -34
  26. data/lib/vcdom/minidom/document.rb +0 -245
  27. data/lib/vcdom/minidom/dom_exception.rb +0 -51
  28. data/lib/vcdom/minidom/dom_implementation.rb +0 -214
  29. data/lib/vcdom/minidom/element.rb +0 -512
  30. data/lib/vcdom/minidom/element_ns.rb +0 -42
  31. data/lib/vcdom/minidom/mini_parser.rb +0 -9
  32. data/lib/vcdom/minidom/mini_serializer.rb +0 -118
  33. data/lib/vcdom/minidom/minidom_standard_error.rb +0 -9
  34. data/lib/vcdom/minidom/mod_child_node.rb +0 -51
  35. data/lib/vcdom/minidom/mod_elements_getter.rb +0 -49
  36. data/lib/vcdom/minidom/mod_namespaceuri_manageable.rb +0 -152
  37. data/lib/vcdom/minidom/mod_parent_node.rb +0 -307
  38. data/lib/vcdom/minidom/named_node_map_attr.rb +0 -277
  39. data/lib/vcdom/minidom/node.rb +0 -178
  40. data/lib/vcdom/minidom/node_list.rb +0 -41
  41. data/lib/vcdom/minidom/text.rb +0 -77
  42. data/lib/vcdom/minidom/xml_reg_exp.rb +0 -39
  43. data/lib/vcdom/minidom.rb +0 -9
  44. data/lib/vcdom.rb +0 -6
  45. data/script/console +0 -10
  46. data/script/destroy +0 -14
  47. data/script/generate +0 -14
  48. data/test/test_helper.rb +0 -3
  49. data/test/test_vcdom.rb +0 -11
@@ -0,0 +1,44 @@
1
+ # coding : utf-8
2
+
3
+ require "vcdom/node"
4
+ require "vcdom/element"
5
+
6
+ module VCDOM
7
+ class ElementNS < Element
8
+
9
+ def initialize( doc, namespace_uri, prefix, local_name )
10
+ super( doc, local_name )
11
+ @namespace_uri = namespace_uri
12
+ @prefix = prefix
13
+ end
14
+
15
+ def node_type
16
+ ELEMENT_NODE
17
+ end
18
+
19
+ def tag_name
20
+ if @prefix then
21
+ "#{@prefix.to_s}:#{@local_name.to_s}"
22
+ else
23
+ @local_name.to_s()
24
+ end
25
+ end
26
+ alias :node_name :tag_name
27
+
28
+ def prefix
29
+ @prefix.nil? ? nil : @prefix.to_s()
30
+ end
31
+ def local_name
32
+ @local_name.to_s()
33
+ end
34
+ def namespace_uri
35
+ @namespace_uri.nil? ? nil : @namespace_uri.to_s()
36
+ end
37
+
38
+ def append_child( new_child )
39
+ # �m�[�h�̃^�C�v�`�F�b�N�Ȃ�
40
+ _append_child( new_child )
41
+ end
42
+
43
+ end
44
+ end
data/lib/vcdom/node.rb ADDED
@@ -0,0 +1,278 @@
1
+ # coding : utf-8
2
+
3
+ module VCDOM
4
+ class Node
5
+
6
+ ELEMENT_NODE = 1
7
+ ATTRIBUTE_NODE = 2
8
+ TEXT_NODE = 3
9
+ CDATA_SECTION_NODE = 4
10
+ ENTITY_REFERENCE_NODE = 5
11
+ ENTITY_NODE = 6
12
+ PROCESSING_INSTRUCTION_NODE = 7
13
+ COMMENT_NODE = 8
14
+ DOCUMENT_NODE = 9
15
+ DOCUMENT_TYPE_NODE = 10
16
+ DOCUMENT_FRAGMENT_NODE = 11
17
+ NOTATION_NODE = 12
18
+
19
+ class << self
20
+ alias :_new :new
21
+ private :new
22
+ end
23
+
24
+ def initialize( owner_document )
25
+ @owner_document = owner_document
26
+ end
27
+
28
+ def owner_document
29
+ @owner_document
30
+ end
31
+
32
+ def prefix
33
+ nil
34
+ end
35
+ def namespace_uri
36
+ nil
37
+ end
38
+
39
+ def parent_node
40
+ nil
41
+ end
42
+ def previous_sibling
43
+ nil
44
+ end
45
+ def next_sibling
46
+ nil
47
+ end
48
+ def node_value
49
+ nil
50
+ end
51
+ def attributes
52
+ nil
53
+ end
54
+ def node_list
55
+ NodeList::EMPTY_NODE_LIST
56
+ end
57
+ def attributes
58
+ nil
59
+ end
60
+
61
+
62
+
63
+ def lookup_prefix( namespace_uri )
64
+ if namespace_uri.nil? then #(namespaceURI has no value, i.e. namespaceURI is null or empty string) {
65
+ return nil
66
+ end
67
+ case self.node_type
68
+ when ELEMENT_NODE then
69
+ return lookup_namespace_prefix( namespace_uri, self )
70
+ when DOCUMENT_NODE then
71
+ #//////////////////////
72
+ # ����ł����́H
73
+ #//////////////////////
74
+ return self.document_element.lookup_namespace_prefix( namespace_uri, self )
75
+ when ENTITY_NODE, NOTATION_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_TYPE_NODE then
76
+ return nil # type is unknown
77
+ when ATTRIBUTE_NODE then
78
+ if not self.owner_element.nil? then #( Attr has an owner Element )
79
+ #//////////////////////
80
+ # ����ł����́H
81
+ #//////////////////////
82
+ return self.owner_element.lookup_namespace_prefix( namespace_uri, self )
83
+ end
84
+ return nil
85
+ else
86
+ anc_node = self.parent_node
87
+ loop do
88
+ if anc_node.nil? or anc_node.node_type == ELEMENT_NODE then
89
+ break
90
+ end
91
+ anc_node = anc_node.parent_node
92
+ end
93
+ if not anc_node.nil? then
94
+ #// EntityReferences may have to be skipped to get to it
95
+ #//////////////////////
96
+ # ����ł����́H
97
+ #//////////////////////
98
+ return anc_node.lookup_namespace_prefix( namespace_uri, self )
99
+ end
100
+ return nil
101
+ end
102
+ end
103
+ def lookup_namespace_prefix( namespace_uri, original_element )
104
+ if not self.namespace_uri.nil? and self.namespace_uri == namespace_uri and
105
+ not self.prefix.nil? and original_element.lookup_namespace_uri( self.prefix ) == namespace_uri then
106
+ #( Element has a namespace and Element's namespace == namespaceURI and
107
+ # Element has a prefix and
108
+ #originalElement.lookupNamespaceURI(Element's prefix) == namespaceURI)
109
+ return self.prefix
110
+ end
111
+ self.each_attr_node do |attr|
112
+ #if #( Element has attributes) {
113
+ #for ( all DOM Level 2 valid local namespace declaration attributes of Element ) {
114
+ #//////////////////////////
115
+ # �v�ύX
116
+ #//////////////////////////
117
+ if attr.prefix == "xmlns" and attr[0].data == namespace_uri and
118
+ original_element.lookup_namespace_uri( attr.local_name ) == namespace_uri then
119
+ #if (Attr's prefix == "xmlns" and Attr's value == namespaceURI and
120
+ # originalElement.lookupNamespaceURI(Attr's localname) == namespaceURI)
121
+ return attr.local_name
122
+ end
123
+ #}
124
+ end #}
125
+ anc_node = self.parent_node
126
+ loop do
127
+ if anc_node.nil? or anc_node.node_type == ELEMENT_NODE then
128
+ break
129
+ end
130
+ anc_node = anc_node.parent_node
131
+ end
132
+ if not anc_node.nil? then
133
+ #// EntityReferences may have to be skipped to get to it
134
+ #//////////////////////
135
+ # ����ł����́H
136
+ #//////////////////////
137
+ return anc_node.lookup_namespace_prefix( namespace_uri, original_element )
138
+ end
139
+ #if (Node has an ancestor Element )
140
+ # // EntityReferences may have to be skipped to get to it
141
+ #{
142
+ # return ancestor.lookupNamespacePrefix(namespaceURI, originalElement);
143
+ #}
144
+ return nil
145
+ end
146
+
147
+
148
+ def lookup_namespace_uri( prefix )
149
+ case self.node_type
150
+ when ELEMENT_NODE then
151
+ if not self.namespace_uri.nil? and self.prefix == prefix then
152
+ #( Element's namespace != null and Element's prefix == prefix )
153
+ # Note: prefix could be "null" in this case we are looking for default namespace
154
+ return self.namespace_uri
155
+ end
156
+ #if ( Element has attributes)
157
+ #for ( all DOM Level 2 valid local namespace declaration attributes of Element )
158
+ self.each_attr_node do |attr|
159
+ if attr.prefix == "xmlns" and attr.local_name == prefix then
160
+ #if (Attr's prefix == "xmlns" and Attr's localName == prefix )
161
+ # // non default namespace
162
+ # /////////////////////
163
+ # �ύX���K�v
164
+ # /////////////////////
165
+ if not attr[0].nil? then
166
+ #if (Attr's value is not empty) {
167
+ return attr[0].data
168
+ end
169
+ return nil
170
+ elsif attr.local_name == "xmlns" and prefix == nil then
171
+ #(Attr's localname == "xmlns" and prefix == null)
172
+ # // default namespace {
173
+ # /////////////////////
174
+ # �ύX���K�v
175
+ # /////////////////////
176
+ if not attr[0].nil? then
177
+ # if (Attr's value is not empty) {
178
+ return attr[0].data
179
+ end
180
+ return nil
181
+ end
182
+ end
183
+ anc_node = self.parent_node
184
+ loop do
185
+ if anc_node.nil? or anc_node.node_type == ELEMENT_NODE then
186
+ break
187
+ end
188
+ anc_node = anc_node.parent_node
189
+ end
190
+ if not anc_node.nil? then
191
+ #if ( Element has an ancestor Element )
192
+ #// EntityReferences may have to be skipped to get to it {
193
+ return anc_node.lookup_namespace_uri( prefix )
194
+ end
195
+ return nil
196
+ when DOCUMENT_NODE then
197
+ return self.document_element.lookup_namespace_uri( prefix )
198
+ when ENTITY_NODE, NOTATION_NODE, DOCUMENT_TYPE_NODE, DOCUMENT_FRAGMENT_NODE then
199
+ return nil
200
+ when ATTRIBUTE_NODE then
201
+ if not self.owner_element.nil? then #(Attr has an owner Element) {
202
+ return self.owner_element.lookup_namespace_uri( prefix )
203
+ else
204
+ return nil
205
+ end
206
+ else
207
+ anc_node = self.parent_node
208
+ loop do
209
+ if anc_node.nil? or anc_node.node_type == ELEMENT_NODE then
210
+ break
211
+ end
212
+ anc_node = anc_node.parent_node
213
+ end
214
+ if not anc_node.nil? then
215
+ #if(Node has an ancestor Element) // EntityReferences may have to be skipped to get to it {
216
+ return anc_node.lookup_namespace_uri( prefix )
217
+ else
218
+ return nil
219
+ end
220
+ end
221
+ end
222
+
223
+ def is_default_namespace( namespace_uri )
224
+ case self.node_type
225
+ when ELEMENT_NODE then
226
+ if self.prefix.nil? then
227
+ return self.namespace_uri == namespace_uri
228
+ end
229
+ self.each_attr_node do |attr|
230
+ #( Element has attributes and there is a valid DOM Level 2 default namespace declaration, i.e.
231
+ #Attr's localName == "xmlns" ) {
232
+ if attr.local_name == "xmlns" then
233
+ #/////////////////////////////////
234
+ # �ύX�K�v
235
+ #/////////////////////////////////
236
+ return attr[0] == namespace_uri
237
+ end
238
+ end
239
+ anc_node = self.parent_node
240
+ loop do
241
+ if anc_node.nil? or anc_node.node_type == ELEMENT_NODE then
242
+ break
243
+ end
244
+ anc_node = anc_node.parent_node
245
+ end
246
+ if not anc_node.nil? then #( Element has an ancestor Element ) // EntityReferences may have to be skipped to get to it {
247
+ return anc_node.is_default_namespace( namespace_uri )
248
+ else
249
+ return false
250
+ end
251
+ when DOCUMENT_NODE then
252
+ return self.document_element.is_default_namespace( namespace_uri )
253
+ when ENTITY_NODE, NOTATION_NODE, DOCUMENT_TYPE_NODE, DOCUMENT_FRAGMENT_NODE then
254
+ return false
255
+ when ATTRIBUTE_NODE then
256
+ if not self.owner_element.nil? then#( Attr has an owner Element ) {
257
+ return self.owner_element.is_default_namespace( namespace_uri )
258
+ else
259
+ return false
260
+ end
261
+ else
262
+ anc_node = self.parent_node
263
+ loop do
264
+ if anc_node.nil? or anc_node.node_type == ELEMENT_NODE then
265
+ break
266
+ end
267
+ anc_node = anc_node.parent_node
268
+ end
269
+ if not anc_node.nil? then #( Element has an ancestor Element ) // EntityReferences may have to be skipped to get to it {
270
+ return anc_node.is_default_namespace( namespace_uri )
271
+ else
272
+ return false
273
+ end
274
+ end
275
+ end
276
+
277
+ end
278
+ end
@@ -0,0 +1,32 @@
1
+ # coding : utf-8
2
+
3
+ require "vcdom/node"
4
+
5
+ module VCDOM
6
+ class NodeList
7
+
8
+ include Enumerable
9
+
10
+ def initialize( nodes )
11
+ @nodes = nodes
12
+ end
13
+ def item( index )
14
+ @nodes[index]
15
+ end
16
+ def length
17
+ @nodes.length
18
+ end
19
+ def each
20
+ @nodes.each do |n|
21
+ yield n
22
+ end
23
+ end
24
+
25
+ def inspect
26
+ "#<VCXML::DOM::NodeList>"
27
+ end
28
+
29
+ #EMPTY_NODE_LIST = NodeList.new( Array.new() )
30
+
31
+ end
32
+ end
@@ -0,0 +1,126 @@
1
+ # coding : utf-8
2
+
3
+ require "vcdom/node_list"
4
+
5
+ module VCDOM
6
+ module Parent
7
+
8
+ class ChildNodes
9
+ def initialize()
10
+ @first_child = nil
11
+ @last_child = nil
12
+ @length = 0
13
+ end
14
+ def first_child; @first_child end
15
+ def first_child=(c); @first_child = c end
16
+ def last_child; @last_child end
17
+ def last_child=(c); @last_child = c end
18
+ def length; @length end
19
+ def length=(c); @length = c end
20
+
21
+ def each
22
+ node = @first_child
23
+ while not node.nil? do
24
+ yield node
25
+ node = node.next_sibling
26
+ end
27
+ end
28
+ def []( index )
29
+ if index >= 0 then
30
+ node = @first_child
31
+ index.times do
32
+ if node.nil? then
33
+ return node
34
+ end
35
+ node = node.next_sibling
36
+ end
37
+ elsif index < 0 then
38
+ node = @last_child
39
+ index *= -1
40
+ index -= 1
41
+ index.times do
42
+ if node.nil? then
43
+ return node
44
+ end
45
+ node = node.next_sibling
46
+ end
47
+ else
48
+ raise "ERROR"
49
+ end
50
+ return node
51
+ end
52
+ end
53
+
54
+ def initialize_parent()
55
+ @child_nodes = ChildNodes.new()
56
+ end
57
+
58
+ def each_child_node
59
+ @child_nodes.each do |n|
60
+ yield n
61
+ end
62
+ end
63
+ def child_nodes
64
+ NodeList.new( @child_nodes )
65
+ end
66
+ def first_child
67
+ @child_nodes.first_child
68
+ end
69
+ def last_child
70
+ @child_nodes.last_child
71
+ end
72
+
73
+ def _append_child( new_child )
74
+ #@child_nodes << new_child
75
+ if not new_child.parent_node.nil? then
76
+ # ��c�����݂���
77
+ # new_child �������̐�c����Ȃ����m�F����
78
+ node = self.parent_node
79
+ while not node.nil? do
80
+ if node.equal? new_child then
81
+ raise "HIERARCHY_REQUEST_ERR"
82
+ end
83
+ node = node.parent_node
84
+ end
85
+ # new_child ���Ƃ肠�����c���[����폜
86
+ new_child.parent_node.remove_child( new_child )
87
+ end
88
+ new_child._set_parent_node( self )
89
+ if @child_nodes.last_child.nil? then
90
+ @child_nodes.first_child = new_child
91
+ else
92
+ @child_nodes.last_child._set_next_sibling( new_child )
93
+ end
94
+ @child_nodes.last_child = new_child
95
+ @child_nodes.length += 1
96
+ new_child
97
+ end
98
+ private :_append_child
99
+ def <<( new_child )
100
+ self.append_child( new_child )
101
+ self
102
+ end
103
+ def remove_child( old_child )
104
+ if not old_child.is_a? Node then
105
+ raise ArgumentError.new()
106
+ end
107
+ if old_child.parent_node and old_child.parent_node.equal? self then
108
+ @child_nodes.length -= 1
109
+ else
110
+ raise "ERROR"
111
+ end
112
+ if @child_nodes.first_child.equal? old_child then
113
+ @child_nodes.first_child = old_child.next_sibling
114
+ end
115
+ if @child_nodes.last_child.equal? old_child then
116
+ @child_nodes.last_child = old_child.previous_sibling
117
+ end
118
+ old_child._leave_from_tree()
119
+ return old_child
120
+ end
121
+ def []( index )
122
+ @child_nodes[index]
123
+ end
124
+
125
+ end
126
+ end
data/lib/vcdom/text.rb ADDED
@@ -0,0 +1,23 @@
1
+ # coding : utf-8
2
+
3
+ require "vcdom/character_data"
4
+ require "vcdom/child"
5
+
6
+ module VCDOM
7
+ class Text < CharacterData
8
+
9
+ include Child
10
+
11
+ def initialize( doc, data )
12
+ super( doc, data )
13
+ end
14
+
15
+ def node_type
16
+ TEXT_NODE
17
+ end
18
+ def node_name
19
+ "#text"
20
+ end
21
+
22
+ end
23
+ end