/[eiffelstudio]/vendor/gobosoft.com/gobo/4.0d/library/xml/src/tree/xm_element.e
ViewVC logotype

Contents of /vendor/gobosoft.com/gobo/4.0d/library/xml/src/tree/xm_element.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 98698 - (show annotations)
Mon May 9 13:53:54 2016 UTC (3 years, 5 months ago) by manus
File size: 13125 byte(s)
Update 4.0d version with changes in Gobo from 2016/05/09

1 note
2
3 description:
4
5 "XML element nodes"
6
7 library: "Gobo Eiffel XML Library"
8 copyright: "Copyright (c) 2001-2014, Andreas Leitner and others"
9 license: "MIT License"
10 date: "$Date$"
11 revision: "$Revision$"
12
13 class XM_ELEMENT
14
15 inherit
16
17 XM_COMPOSITE
18 undefine
19 last,
20 root_node,
21 parent
22 end
23
24 XM_NAMED_NODE
25
26 XM_DOCUMENT_NODE
27
28 create
29
30 make,
31 make_last,
32 make_root,
33 make_child
34
35 feature {NONE} -- Initialization
36
37 make (a_parent: like parent; a_name: like name; a_ns: like namespace)
38 -- Create a new child element, without attaching to parent.
39 require
40 a_parent_not_void: a_parent /= Void
41 a_name_not_void: a_name /= Void
42 a_ns_not_void: a_ns /= Void
43 do
44 parent := a_parent
45 name := a_name
46 namespace := a_ns
47 create children.make
48 ensure
49 parent_set: parent = a_parent
50 name_set: name = a_name
51 ns_prefix_set: namespace = a_ns
52 end
53
54 make_last (a_parent: XM_ELEMENT; a_name: like name; a_ns: like namespace)
55 -- Create a new child element, and add it to the parent.
56 require
57 a_parent_not_void: a_parent /= Void
58 a_name_not_void: a_name /= Void
59 a_ns_not_void: a_ns /= Void
60 do
61 name := a_name
62 namespace := a_ns
63 parent := a_parent
64 create children.make
65 a_parent.force_last (Current)
66 ensure
67 parent_set: parent = a_parent
68 in_parent: a_parent.last = Current
69 name_set: name = a_name
70 ns_prefix_set: namespace = a_ns
71 end
72
73 make_root (a_parent: XM_DOCUMENT; a_name: like name; a_ns: like namespace)
74 -- Create a new root element, and add it to the document parent.
75 require
76 a_parent_not_void: a_parent /= Void
77 a_name_not_void: a_name /= Void
78 a_ns_not_void: a_ns /= Void
79 do
80 name := a_name
81 namespace := a_ns
82 parent := a_parent
83 create children.make
84 a_parent.set_root_element (Current)
85 ensure
86 parent_set: parent = a_parent
87 in_parent: a_parent.last = Current
88 name_set: name = a_name
89 ns_prefix_set: namespace = a_ns
90 end
91
92 make_child (a_parent: like parent; a_name: like name; a_ns: like namespace)
93 -- Create a new child element.
94 obsolete
95 "Use make"
96 require
97 a_parent_not_void: a_parent /= Void
98 a_name_not_void: a_name /= Void
99 a_ns_not_void: a_ns /= Void
100 do
101 make (a_parent, a_name, a_ns)
102 end
103
104 feature -- Status report
105
106 has_attribute_by_qualified_name (a_uri: STRING; a_name: STRING): BOOLEAN
107 -- Does current element contain an attribute with
108 -- this qualified name?
109 require
110 a_uri_not_void: a_uri /= Void
111 a_name_not_void: a_name /= Void
112 local
113 a_cursor: DS_LINEAR_CURSOR [XM_NODE]
114 do
115 a_cursor := new_cursor
116 from a_cursor.start until a_cursor.after loop
117 if attached {XM_ATTRIBUTE} a_cursor.item as l_attribute and then l_attribute.has_qualified_name (a_uri, a_name) then
118 Result := True
119 a_cursor.go_after -- Jump out of the loop.
120 else
121 a_cursor.forth
122 end
123 end
124 end
125
126 has_attribute_by_name (a_name: STRING): BOOLEAN
127 -- Does current element contain an attribute named `a_name'?
128 -- element?
129 require
130 a_name_not_void: a_name /= Void
131 local
132 a_cursor: DS_LINEAR_CURSOR [XM_NODE]
133 do
134 a_cursor := new_cursor
135 from a_cursor.start until a_cursor.after loop
136 if attached {XM_ATTRIBUTE} a_cursor.item as l_attribute and then attribute_same_name (l_attribute, a_name) then
137 Result := True
138 a_cursor.go_after -- Jump out of the loop.
139 else
140 a_cursor.forth
141 end
142 end
143 end
144
145 feature {NONE} -- Name comparison with namespace.
146
147 attribute_same_name (a_named: XM_ATTRIBUTE; a_name: STRING): BOOLEAN
148 -- Has 'a_named' attribute the same name as `a_name',
149 -- either because of same namespace or within the
150 -- default namespace.
151 require
152 a_named_not_void: a_named /= Void
153 a_name_not_void: a_name /= Void
154 do
155 Result := same_string (a_named.name, a_name) and (a_named.namespace.uri.count = 0)
156 ensure
157 same_name: Result implies same_string (a_named.name, a_name)
158 default_ns: (a_named.namespace.uri.count = 0) implies (Result = same_string (a_named.name, a_name))
159 end
160
161 named_same_name (a_named: XM_NAMED_NODE; a_name: STRING): BOOLEAN
162 -- Has 'a_named' same name as 'a_name' and
163 -- same namespace as current node?
164 require
165 a_named_not_void: a_named /= Void
166 a_name_not_void: a_name /= Void
167 do
168 Result := same_string (a_named.name, a_name) and same_namespace (a_named)
169 ensure
170 same_name: Result implies same_string (a_named.name, a_name)
171 end
172
173 feature -- Access (from XM_COMPOSITE)
174
175 has_element_by_name (a_name: STRING): BOOLEAN
176 -- Has current node at least one direct child
177 -- element with the name `a_name'?
178 local
179 a_cursor: DS_LINEAR_CURSOR [XM_NODE]
180 do
181 a_cursor := new_cursor
182 from a_cursor.start until a_cursor.after loop
183 if attached {XM_ELEMENT} a_cursor.item as l_element and then named_same_name (l_element, a_name) then
184 Result := True
185 a_cursor.go_after -- Jump out of the loop.
186 else
187 a_cursor.forth
188 end
189 end
190 end
191
192 has_element_by_qualified_name (a_uri: STRING; a_name: STRING): BOOLEAN
193 -- Has current node at least one direct child
194 -- element with this qualified name?
195 local
196 a_cursor: DS_LINEAR_CURSOR [XM_NODE]
197 do
198 a_cursor := new_cursor
199 from a_cursor.start until a_cursor.after loop
200 if attached {XM_ELEMENT} a_cursor.item as l_element and then l_element.has_qualified_name (a_uri, a_name) then
201 Result := True
202 a_cursor.go_after -- Jump out of the loop.
203 else
204 a_cursor.forth
205 end
206 end
207 end
208
209 element_by_name (a_name: STRING): detachable XM_ELEMENT
210 -- Direct child element with name `a_name';
211 -- If there are more than one element with that name, anyone may be returned.
212 -- Return Void if no element with that name is a child of current node.
213 local
214 a_cursor: DS_LINEAR_CURSOR [XM_NODE]
215 do
216 a_cursor := new_cursor
217 from a_cursor.start until a_cursor.after loop
218 if attached {XM_ELEMENT} a_cursor.item as l_element and then named_same_name (l_element, a_name) then
219 Result := l_element
220 a_cursor.go_after -- Jump out of the loop.
221 else
222 a_cursor.forth
223 end
224 end
225 end
226
227 element_by_qualified_name (a_uri: STRING; a_name: STRING): detachable XM_ELEMENT
228 -- Direct child element with given qualified name;
229 -- If there are more than one element with that name, anyone may be returned.
230 -- Return Void if no element with that name is a child of current node.
231 local
232 a_cursor: DS_LINEAR_CURSOR [XM_NODE]
233 do
234 a_cursor := new_cursor
235 from a_cursor.start until a_cursor.after loop
236 if attached {XM_ELEMENT} a_cursor.item as l_element and then l_element.has_qualified_name (a_uri, a_name) then
237 Result := l_element
238 a_cursor.go_after -- Jump out of the loop.
239 else
240 a_cursor.forth
241 end
242 end
243 end
244
245 feature -- Access
246
247 last: XM_ELEMENT_NODE
248 -- Last child
249 do
250 Result := children.last
251 end
252
253 attribute_by_name (a_name: STRING): detachable XM_ATTRIBUTE
254 -- Attribute named `a_name' in current element;
255 -- Return Void if no such attribute was found.
256 require
257 a_name_not_void: a_name /= Void
258 local
259 a_cursor: DS_LINEAR_CURSOR [XM_NODE]
260 do
261 a_cursor := new_cursor
262 from a_cursor.start until a_cursor.after loop
263 if attached {XM_ATTRIBUTE} a_cursor.item as l_attribute and then attribute_same_name (l_attribute, a_name) then
264 Result := l_attribute
265 a_cursor.go_after -- Jump out of the loop.
266 else
267 a_cursor.forth
268 end
269 end
270 ensure
271 attribute_not_void: has_attribute_by_name (a_name) = (Result /= Void)
272 namespace: Result /= Void implies (not Result.has_prefix)
273 end
274
275 attribute_by_qualified_name (a_uri: STRING; a_name: STRING): detachable XM_ATTRIBUTE
276 -- Attribute named `a_name' in current element;
277 -- Return Void if no such attribute was found.
278 require
279 a_uri_not_void: a_uri /= Void
280 a_name_not_void: a_name /= Void
281 local
282 a_cursor: DS_LINEAR_CURSOR [XM_NODE]
283 do
284 a_cursor := new_cursor
285 from a_cursor.start until a_cursor.after loop
286 if attached {XM_ATTRIBUTE} a_cursor.item as l_attribute and then l_attribute.has_qualified_name (a_uri, a_name) then
287 Result := l_attribute
288 a_cursor.go_after -- Jump out of the loop.
289 else
290 a_cursor.forth
291 end
292 end
293 ensure
294 attribute_not_void: has_attribute_by_qualified_name (a_uri, a_name) = (Result /= Void)
295 namespace: Result /= Void implies Result.has_qualified_name (a_uri, a_name)
296 end
297
298 namespace_declarations: DS_LINKED_LIST [XM_NAMESPACE]
299 -- Namespaces declared directly in this element;
300 -- This list must contain at most one namespace with a
301 -- void prefix. If such a namespace exists it is a declared
302 -- default namespace.
303 -- (Returns a new list object at each call.)
304 local
305 a_cursor: DS_LINEAR_CURSOR [XM_NODE]
306 do
307 create Result.make
308 a_cursor := new_cursor
309 from a_cursor.start until a_cursor.after loop
310 if attached {XM_ATTRIBUTE} a_cursor.item as l_attribute and then l_attribute.is_namespace_declaration then
311 Result.force_last (l_attribute.namespace_declaration)
312 end
313 a_cursor.forth
314 end
315 ensure
316 namespace_declarations_not_void: Result /= Void
317 no_void_declaration: not Result.has_void
318 end
319
320 attributes: DS_LIST [XM_ATTRIBUTE]
321 -- List of all attributes in current element
322 -- (Create a new list at each call.)
323 local
324 a_cursor: DS_LINEAR_CURSOR [XM_NODE]
325 do
326 create {DS_BILINKED_LIST [XM_ATTRIBUTE]} Result.make
327 a_cursor := new_cursor
328 from a_cursor.start until a_cursor.after loop
329 if attached {XM_ATTRIBUTE} a_cursor.item as l_attribute then
330 Result.force_last (l_attribute)
331 end
332 a_cursor.forth
333 end
334 ensure
335 attributes_not_void: Result /= Void
336 no_void_attribute: not Result.has_void
337 end
338
339 feature -- Element change
340
341 add_unqualified_attribute (a_name: STRING; a_value: STRING)
342 -- Add an attribute without a specific namespace.
343 require
344 a_name_not_void: a_name /= Void
345 a_name_not_empty: a_name.count > 0
346 a_value_not_void: a_value /= Void
347 do
348 add_attribute (a_name, Default_ns, a_value)
349 ensure
350 attribute_added: has_attribute_by_name (a_name)
351 end
352
353 add_attribute (a_name: STRING; a_ns: XM_NAMESPACE; a_value: STRING)
354 -- Add an attribute to current element.
355 -- (at end if last is an attribute, at beginning otherwise)
356 require
357 a_name_not_void: a_name /= Void
358 a_name_not_empty: a_name.count > 0
359 a_ns_not_void: a_ns /= Void
360 a_value_not_void: a_value /= Void
361 local
362 an_attribute: XM_ATTRIBUTE
363 typer: XM_NODE_TYPER
364 do
365 create an_attribute.make (a_name, a_ns, a_value, Current)
366 if is_empty then
367 force_last (an_attribute)
368 else
369 create typer
370 last.process (typer)
371 if typer.is_attribute then
372 force_last (an_attribute)
373 else
374 force_first (an_attribute)
375 end
376 end
377 ensure
378 attribute_added: has_attribute_by_qualified_name (a_ns.uri, a_name)
379 end
380
381 feature -- Removal
382
383 remove_attribute_by_name (a_name: STRING)
384 -- Remove attribute named `a_name' from current element.
385 require
386 a_name_not_void: a_name /= Void
387 has_attribute: has_attribute_by_name (a_name)
388 local
389 a_cursor: like new_cursor
390 do
391 a_cursor := new_cursor
392 from a_cursor.start until a_cursor.after loop
393 if attached {XM_ATTRIBUTE} a_cursor.item as l_attribute and then attribute_same_name (l_attribute, a_name) then
394 children.remove_at_cursor (a_cursor)
395 else
396 a_cursor.forth
397 end
398 end
399 end
400
401 remove_attribute_by_qualified_name (a_uri: STRING; a_name: STRING)
402 -- Remove attribute named `a_name' from current element.
403 require
404 a_uri_not_void: a_uri /= Void
405 a_name_not_void: a_name /= Void
406 has_attribute: has_attribute_by_qualified_name (a_uri, a_name)
407 local
408 a_cursor: like new_cursor
409 do
410 a_cursor := new_cursor
411 from a_cursor.start until a_cursor.after loop
412 if attached {XM_ATTRIBUTE} a_cursor.item as l_attribute and then l_attribute.has_qualified_name (a_uri, a_name) then
413 children.remove_at_cursor (a_cursor)
414 else
415 a_cursor.forth
416 end
417 end
418 end
419
420 join_text_nodes
421 -- Join sequences of text nodes.
422 local
423 joint_text_node: XM_CHARACTER_DATA
424 a_cursor: like new_cursor
425 do
426 a_cursor := new_cursor
427 from a_cursor.start until a_cursor.after loop
428 if attached {XM_CHARACTER_DATA} a_cursor.item as l_character_data then
429 -- Found a text node.
430 -- Now join all text-nodes that are following it
431 -- until there is a node that is no text-node.
432 joint_text_node := l_character_data.cloned_object
433 children.remove_at_cursor (a_cursor)
434 from
435 until
436 a_cursor.after
437 loop
438 if attached {XM_CHARACTER_DATA} a_cursor.item as l_other_character_data then
439 -- Found another text-node -> join.
440 joint_text_node.append_content (l_other_character_data)
441 children.remove_at_cursor (a_cursor)
442 else
443 a_cursor.forth
444 end
445 end
446 before_addition (joint_text_node)
447 children.force_left_cursor (joint_text_node, a_cursor)
448 else
449 a_cursor.forth
450 end
451 end
452 end
453
454 feature -- Processing
455
456 process (a_processor: XM_NODE_PROCESSOR)
457 -- Process current node with `a_processor'.
458 do
459 a_processor.process_element (Current)
460 end
461
462 end

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.23