forked from andreww/fox
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathm_dom_namednodemap.m4
439 lines (363 loc) · 13 KB
/
m_dom_namednodemap.m4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
TOHW_m_dom_publics(`
public :: getNamedItem
public :: setNamedItem
public :: removeNamedItem
! public :: item
! public :: getLength
public :: getNamedItemNS
public :: setNamedItemNS
public :: removeNamedItemNS
! public :: append
public :: setReadOnlyMap
public :: destroyNamedNodeMap
interface item
module procedure item_nnm
end interface
interface getLength
module procedure getLength_nnm
end interface
')`'dnl
dnl
TOHW_m_dom_contents(`
TOHW_function(getNamedItem, (map, name), np)
type(NamedNodeMap), pointer :: map
character(len=*), intent(in) :: name
type(Node), pointer :: np
integer :: i
if (.not.associated(map)) then
TOHW_m_dom_throw_error(FoX_MAP_IS_NULL)
endif
do i = 1, map%length
if (str_vs(map%nodes(i)%this%nodeName)==name) then
np => map%nodes(i)%this
return
endif
enddo
np => null()
end function getNamedItem
TOHW_function(setNamedItem, (map, arg), np)
type(NamedNodeMap), pointer :: map
type(Node), pointer :: arg
type(Node), pointer :: np
integer :: i
if (.not.associated(map)) then
TOHW_m_dom_throw_error(FoX_MAP_IS_NULL)
endif
if (.not.associated(arg)) then
TOHW_m_dom_throw_error(FoX_NODE_IS_NULL)
endif
if (map%readonly) then
TOHW_m_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR)
elseif (map%ownerElement%nodeType==ELEMENT_NODE) then
if (.not.associated(map%ownerElement%ownerDocument, arg%ownerDocument)) then
TOHW_m_dom_throw_error(WRONG_DOCUMENT_ERR)
elseif (getNodeType(arg)/=ATTRIBUTE_NODE) then
!Additional check from DOM 3
TOHW_m_dom_throw_error(HIERARCHY_REQUEST_ERR)
endif
endif
if (getNodeType(arg)==ATTRIBUTE_NODE) then
if (associated(map%ownerElement, getOwnerElement(arg))) then
! we are looking at literally the same node
np => arg
return
elseif (associated(getOwnerElement(arg))) then
TOHW_m_dom_throw_error(INUSE_ATTRIBUTE_ERR)
endif
arg%elExtras%ownerElement => map%ownerElement
endif
do i = 0, getLength(map)-1
np => item(map, i)
if (getNodeName(np)==getNodeName(arg)) then
map%nodes(i+1)%this => arg
exit
endif
enddo
if (i<getLength(map)) then
if (getGCstate(getOwnerDocument(map%ownerElement)).and.np%inDocument) then
call removeNodesFromDocument(getOwnerDocument(map%ownerElement), np)
np%inDocument = .false.
endif
else
! If not found, insert it at the end of the linked list
np => null()
call append_nnm(map, arg)
endif
if (map%ownerElement%nodeType==ELEMENT_NODE) then
if (getGCstate(getOwnerDocument(map%ownerElement))) then
! We need to worry about importing this node
if (map%ownerElement%inDocument) then
if (.not.arg%inDocument) &
call putNodesInDocument(getOwnerDocument(map%ownerElement), arg)
else
if (arg%inDocument) &
call removeNodesFromDocument(getOwnerDocument(map%ownerElement), arg)
endif
endif
endif
! Otherwise we only ever setNNM when building the doc, so we know this
! does not matter
end function setNamedItem
TOHW_function(removeNamedItem, (map, name), np)
type(NamedNodeMap), pointer :: map
character(len=*), intent(in) :: name
type(Node), pointer :: np
type(xml_doc_state), pointer :: xds
type(element_t), pointer :: elem
type(attribute_t), pointer :: att
type(ListNode), pointer :: temp_nl(:)
integer :: i, i2
if (.not.associated(map)) then
TOHW_m_dom_throw_error(FoX_MAP_IS_NULL)
endif
if (map%readonly) then
TOHW_m_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR)
endif
do i = 0, map%length-1
np => item(map, i)
if (getNodeName(np)==name) then
xds => getXds(getOwnerDocument(map%ownerElement))
elem => get_element(xds%element_list, getNodeName(map%ownerElement))
att => get_attribute_declaration(elem, name)
if (associated(att)) then
if (attribute_has_default(att)) then ! there is a default value
! Well swap the old one out & put a new one in.
! Do *nothing* about namespace handling at this stage,
! wait until we are asked for namespace normalization
if (getParameter( &
getDomConfig(getOwnerDocument(map%ownerElement)), &
"namespaces")) then
np => createAttributeNS(getOwnerDocument(map%ownerElement), "", name)
else
np => createAttribute(getOwnerDocument(map%ownerElement), name)
endif
call setValue(np, str_vs(att%default))
call setSpecified(np, .false.)
np => setNamedItem(map, np)
call setSpecified(np, .true.)
return
endif
endif
! Otherwise there was no default value, so we just remove the node.
! Grab this node
if (getNodeType(np)==ATTRIBUTE_NODE) np%elExtras%ownerElement => null()
! and shrink the node list
temp_nl => map%nodes
allocate(map%nodes(size(temp_nl)-1))
do i2 = 1, i
map%nodes(i2)%this => temp_nl(i2)%this
enddo
do i2 = i + 2, map%length
map%nodes(i2-1)%this => temp_nl(i2)%this
enddo
map%length = size(map%nodes)
deallocate(temp_nl)
if (np%inDocument.and.getGCstate(getOwnerDocument(map%ownerElement))) &
call removeNodesFromDocument(getOwnerDocument(map%ownerElement), np)
!otherwise we are only going to destroy these nodes anyway,
! and finish
return
endif
enddo
TOHW_m_dom_throw_error(NOT_FOUND_ERR)
end function removeNamedItem
TOHW_function(item_nnm, (map, index), np)
type(NamedNodeMap), pointer :: map
integer, intent(in) :: index
type(Node), pointer :: np
if (.not.associated(map)) then
TOHW_m_dom_throw_error(FoX_MAP_IS_NULL)
endif
if (index<0 .or. index>map%length-1) then
np => null()
else
np => map%nodes(index+1)%this
endif
end function item_nnm
TOHW_function(getLength_nnm, (map), n)
type(namedNodeMap), pointer :: map
integer :: n
if (.not.associated(map)) then
TOHW_m_dom_throw_error(FoX_MAP_IS_NULL)
endif
n = map%length
end function getLength_nnm
TOHW_function(getNamedItemNS, (map, namespaceURI, localName), np)
type(NamedNodeMap), pointer :: map
character(len=*), intent(in) :: namespaceURI
character(len=*), intent(in) :: localName
type(Node), pointer :: np
integer :: i
if (.not.associated(map)) then
TOHW_m_dom_throw_error(FoX_MAP_IS_NULL)
elseif (map%ownerElement%nodeType/=ELEMENT_NODE) then
np => null()
return
endif
do i = 0, getLength(map) - 1
np => item(map, i)
if (getNamespaceURI(np)==namespaceURI &
.and. getLocalName(np)==localName) then
return
endif
enddo
np => null()
end function getNamedItemNS
TOHW_function(setNamedItemNS, (map, arg), np)
type(NamedNodeMap), pointer :: map
type(Node), pointer :: arg
type(Node), pointer :: np
integer :: i
if (.not.associated(map)) then
TOHW_m_dom_throw_error(FoX_MAP_IS_NULL)
endif
if (.not.associated(arg)) then
TOHW_m_dom_throw_error(FoX_NODE_IS_NULL)
endif
if (map%readonly) then
TOHW_m_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR)
elseif (map%ownerElement%nodeType==ELEMENT_NODE) then
if (.not.associated(map%ownerElement%ownerDocument, arg%ownerDocument)) then
TOHW_m_dom_throw_error(WRONG_DOCUMENT_ERR)
elseif (getNodeType(arg)/=ATTRIBUTE_NODE) then
!Additional check from DOM 3
TOHW_m_dom_throw_error(HIERARCHY_REQUEST_ERR)
endif
endif
if (getNodeType(arg)==ATTRIBUTE_NODE) then
if (associated(map%ownerElement, getOwnerElement(arg))) then
! we are looking at literally the same node, so do nothing else
np => arg
return
elseif (associated(getOwnerElement(arg))) then
TOHW_m_dom_throw_error(INUSE_ATTRIBUTE_ERR)
endif
arg%elExtras%ownerElement => map%ownerElement
endif
do i = 0, getLength(map) - 1
np => item(map, i)
if ((getLocalName(arg)==getLocalName(np) &
.and.getNamespaceURI(arg)==getNamespaceURI(np)) &
! Additional case to catch adding of specified attributeNS over
! default (NS but unspecified URI) attribute
.or.(getNamespaceURI(arg)=="".and.getName(arg)==getName(np))) then
map%nodes(i+1)%this => arg
exit
endif
enddo
if (i<getLength(map)) then
if (getGCstate(getOwnerDocument(map%ownerElement))) then
if (np%inDocument) then
call removeNodesFromDocument(getOwnerDocument(map%ownerElement), np)
arg%inDocument = .false.
endif
endif
else
! If not found, insert it at the end of the linked list
np => null()
call append_nnm(map, arg)
endif
if (map%ownerElement%nodeType==ELEMENT_NODE) then
if (getGCstate(getOwnerDocument(map%ownerElement))) then
! We need to worry about importing this node
if (map%ownerElement%inDocument) then
if (.not.arg%inDocument) &
call putNodesInDocument(getOwnerDocument(map%ownerElement), arg)
else
if (arg%inDocument) &
call removeNodesFromDocument(getOwnerDocument(map%ownerElement), arg)
endif
endif
endif
end function setNamedItemNS
TOHW_function(removeNamedItemNS, (map, namespaceURI, localName), np)
type(NamedNodeMap), pointer :: map
character(len=*), intent(in) :: namespaceURI
character(len=*), intent(in) :: localName
type(Node), pointer :: np
type(xml_doc_state), pointer :: xds
type(element_t), pointer :: elem
type(attribute_t), pointer :: att
type(ListNode), pointer :: temp_nl(:)
integer :: i, i2
if (.not.associated(map)) then
TOHW_m_dom_throw_error(FoX_MAP_IS_NULL)
endif
if (map%readonly) then
TOHW_m_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR)
endif
do i = 0, getLength(map) - 1
np => item(map, i)
if (getNamespaceURI(np)==namespaceURI &
.and. getLocalName(np)==localName) then
! Grab this node
xds => getXds(getOwnerDocument(map%ownerElement))
elem => get_element(xds%element_list, getNodeName(map%ownerElement))
att => get_attribute_declaration(elem, getName(np))
if (associated(att)) then
if (attribute_has_default(att)) then ! there is a default value
! Well swap the old one out & put a new one in.
! Do *nothing* about namespace handling at this stage,
! wait until we are asked for namespace normalization
np => createAttributeNS(getOwnerDocument(map%ownerElement), getNamespaceURI(np), getName(np))
call setValue(np, str_vs(att%default))
call setSpecified(np, .false.)
np => setNamedItemNS(map, np)
call setSpecified(np, .true.)
return
endif
endif
! Otherwise there was no default value, so we just remove the node.
! and shrink the node list
if (getNodeType(np)==ATTRIBUTE_NODE) np%elExtras%ownerElement => null()
temp_nl => map%nodes
allocate(map%nodes(size(temp_nl)-1))
do i2 = 1, i
map%nodes(i2)%this => temp_nl(i2)%this
enddo
do i2 = i + 2, map%length
map%nodes(i2-1)%this => temp_nl(i2)%this
enddo
map%length = size(map%nodes)
deallocate(temp_nl)
if (np%inDocument.and.getGCstate(getOwnerDocument(map%ownerElement))) &
call removeNodesFromDocument(getOwnerDocument(map%ownerElement), np)
!otherwise we are only going to destroy these nodes anyway,
! and finish
return
endif
enddo
TOHW_m_dom_throw_error(NOT_FOUND_ERR)
end function removeNamedItemNS
subroutine append_nnm(map, arg)
type(namedNodeMap), pointer :: map
type(node), pointer :: arg
type(ListNode), pointer :: temp_nl(:)
integer :: i
if (.not.associated(map%nodes)) then
allocate(map%nodes(1))
map%nodes(1)%this => arg
map%length = 1
else
temp_nl => map%nodes
allocate(map%nodes(size(temp_nl)+1))
do i = 1, size(temp_nl)
map%nodes(i)%this => temp_nl(i)%this
enddo
deallocate(temp_nl)
map%nodes(size(map%nodes))%this => arg
map%length = size(map%nodes)
endif
if (getNodeType(arg)==ATTRIBUTE_NODE) arg%elExtras%ownerElement => map%ownerElement
end subroutine append_nnm
subroutine setReadOnlyMap(map, r)
type(namedNodeMap), pointer :: map
logical, intent(in) :: r
map%readonly = r
end subroutine setReadOnlyMap
subroutine destroyNamedNodeMap(map)
type(namedNodeMap), pointer :: map
if (associated(map%nodes)) deallocate(map%nodes)
deallocate(map)
end subroutine destroyNamedNodeMap
')`'dnl