24
|
1 |
/*
|
|
2 |
* Copyright (c) 2000 - 2001 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include "cxml_internal.h"
|
|
20 |
#include <xml/cxml/nw_dom_element.h>
|
|
21 |
#include <xml/cxml/nw_dom_attribute.h>
|
|
22 |
#include <xml/cxml/nw_dom_document.h>
|
|
23 |
#include <xml/cxml/nw_wbxml_dictionary.h>
|
|
24 |
|
|
25 |
/*
|
|
26 |
* Returns
|
|
27 |
* NW_STAT_DOM_NODE_TYPE_ERR - if it is not an Element Node
|
|
28 |
* NW_STAT_OUT_OF_MEMORY
|
|
29 |
* NW_STAT_DOM_NO_STRING_RETURNED
|
|
30 |
* NW_STAT_SUCCESS
|
|
31 |
*
|
|
32 |
* MODIFIED name (of the element)
|
|
33 |
*/
|
|
34 |
|
|
35 |
EXPORT_C NW_Status_t
|
|
36 |
NW_DOM_ElementNode_getTagName(NW_DOM_ElementNode_t *elem,
|
|
37 |
NW_String_t *name)
|
|
38 |
{
|
|
39 |
NW_DOM_DocumentNode_t *docNode;
|
|
40 |
NW_Uint32 encoding;
|
|
41 |
NW_Status_t status;
|
|
42 |
NW_Uint32 token;
|
|
43 |
NW_TinyTree_t *tiny_tree;
|
|
44 |
|
|
45 |
NW_ASSERT(elem != NULL);
|
|
46 |
NW_ASSERT(name != NULL);
|
|
47 |
|
|
48 |
if (NW_DOM_Node_getNodeType(elem) != NW_DOM_ELEMENT_NODE){
|
|
49 |
return NW_STAT_DOM_NODE_TYPE_ERR;
|
|
50 |
}
|
|
51 |
|
|
52 |
/*
|
|
53 |
* Following method will return name if the node is XML type
|
|
54 |
* or it is a literal tag
|
|
55 |
*/
|
|
56 |
|
|
57 |
tiny_tree = NW_TinyTree_Node_findTree(elem);
|
|
58 |
|
|
59 |
status = NW_TinyDom_getTagName(NW_TinyDom_getParser(tiny_tree), elem, name);
|
|
60 |
|
|
61 |
if (status == NW_STAT_SUCCESS){
|
|
62 |
return NW_STAT_SUCCESS;
|
|
63 |
}
|
|
64 |
/* No string returned means that getTagName succeeded but
|
|
65 |
* didn't find a literal name . . .
|
|
66 |
*/
|
|
67 |
|
|
68 |
if (status != NW_STAT_WBXML_NO_NAME){
|
|
69 |
return NW_STAT_DOM_NO_STRING_RETURNED;
|
|
70 |
}
|
|
71 |
|
|
72 |
/* . . . so we try to get a name from dictionary */
|
|
73 |
|
|
74 |
docNode = NW_DOM_Node_getOwnerDocument(elem);
|
|
75 |
encoding = NW_DOM_DocumentNode_getCharacterEncoding(docNode);
|
|
76 |
token = NW_TinyDom_getTagToken(NW_TinyDom_getParser(tiny_tree), elem);
|
|
77 |
return NW_String_tokenToString(token, name, encoding);
|
|
78 |
}
|
|
79 |
|
|
80 |
/*
|
|
81 |
* Returns the fully qualified token for the node
|
|
82 |
*/
|
|
83 |
|
|
84 |
EXPORT_C NW_Uint16
|
|
85 |
NW_DOM_ElementNode_getTagToken(NW_DOM_ElementNode_t *elem)
|
|
86 |
{
|
|
87 |
NW_Uint16 type;
|
|
88 |
NW_TinyTree_t *tiny_tree;
|
|
89 |
|
|
90 |
NW_ASSERT(elem != NULL);
|
|
91 |
|
|
92 |
type = NW_TinyDom_Node_getType(elem);
|
|
93 |
|
|
94 |
if (type != NW_DOM_ELEMENT_NODE){
|
|
95 |
return 0;
|
|
96 |
}
|
|
97 |
tiny_tree = NW_TinyTree_Node_findTree(elem);
|
|
98 |
|
|
99 |
if (elem->token == 0)
|
|
100 |
{
|
|
101 |
elem->token =
|
|
102 |
(NW_Uint16)NW_TinyDom_getTagToken(NW_TinyDom_getParser(tiny_tree), elem);
|
|
103 |
|
|
104 |
/* if (NW_DOM_Node_hasChildNodes(elem)){
|
|
105 |
token |= NW_WBXML_FLAGS_CONTENT;
|
|
106 |
}
|
|
107 |
if (NW_DOM_ElementNode_hasAttributes(elem)){
|
|
108 |
token |= NW_WBXML_FLAGS_ATTRIBUTES;
|
|
109 |
}
|
|
110 |
elem->token = token;*/
|
|
111 |
}
|
|
112 |
return (NW_Uint16)(elem->token & 0xff3f);
|
|
113 |
}
|
|
114 |
|
|
115 |
|
|
116 |
/*
|
|
117 |
* Returns
|
|
118 |
* NW_STAT_DOM_NODE_TYPE_ERR
|
|
119 |
* NW_STAT_NOT_FOUND - if attribute is not found
|
|
120 |
* NW_STAT_DOM_NO_STRING_RETURNED
|
|
121 |
* NW_STAT_SUCCESS
|
|
122 |
*
|
|
123 |
* This method returns attribute value as string
|
|
124 |
* IN - attributeName - name of attribute
|
|
125 |
* MODIFIED - attributeValue
|
|
126 |
|
|
127 |
Note: The passed in argument "attributeName" must be given as aligned,
|
|
128 |
native byte order, null terminated, UCS-2. The reason is that clients
|
|
129 |
wish to process documents in various encodings but they don't want to
|
|
130 |
have to convert element and attribute names which are program constants
|
|
131 |
into whatever charset the document appears in.
|
|
132 |
*/
|
|
133 |
|
|
134 |
EXPORT_C NW_Status_t
|
|
135 |
NW_DOM_ElementNode_getAttribute(
|
|
136 |
NW_DOM_ElementNode_t *elem,
|
|
137 |
NW_String_t *attributeName,
|
|
138 |
NW_String_t *attributeValue)
|
|
139 |
{
|
|
140 |
NW_DOM_AttributeHandle_t attributeHandle;
|
|
141 |
NW_Status_t status;
|
|
142 |
|
|
143 |
NW_ASSERT(elem != NULL);
|
|
144 |
NW_ASSERT(attributeName != NULL);
|
|
145 |
NW_ASSERT(attributeValue != NULL);
|
|
146 |
|
|
147 |
if ((NW_DOM_Node_getNodeType(elem) != NW_DOM_ELEMENT_NODE)
|
|
148 |
&& (NW_DOM_Node_getNodeType(elem) != NW_DOM_PROCESSING_INSTRUCTION_NODE)) {
|
|
149 |
return NW_STAT_DOM_NODE_TYPE_ERR;
|
|
150 |
}
|
|
151 |
|
|
152 |
status = NW_DOM_ElementNode_getAttributeHandleByName(elem,
|
|
153 |
attributeName,
|
|
154 |
&attributeHandle);
|
|
155 |
if (status != NW_STAT_SUCCESS){
|
|
156 |
return status;
|
|
157 |
}
|
|
158 |
|
|
159 |
return NW_DOM_AttributeHandle_getValue(&attributeHandle, attributeValue);
|
|
160 |
}
|
|
161 |
|
|
162 |
|
|
163 |
/*
|
|
164 |
* Returns NW_TRUE if element has attributes, otherwise NW_FALSE
|
|
165 |
*/
|
|
166 |
|
|
167 |
EXPORT_C NW_Bool
|
|
168 |
NW_DOM_ElementNode_hasAttributes(NW_DOM_ElementNode_t *elem)
|
|
169 |
{
|
|
170 |
NW_DOM_Node_t *child;
|
|
171 |
|
|
172 |
NW_ASSERT(elem != NULL);
|
|
173 |
|
|
174 |
if ((NW_DOM_Node_getNodeType(elem) != NW_DOM_ELEMENT_NODE)
|
|
175 |
&& (NW_DOM_Node_getNodeType(elem) != NW_DOM_PROCESSING_INSTRUCTION_NODE))
|
|
176 |
{
|
|
177 |
return NW_FALSE;
|
|
178 |
}
|
|
179 |
|
|
180 |
child = NW_TinyTree_findFirstChild(elem);
|
|
181 |
|
|
182 |
while(child){
|
|
183 |
if (NW_TinyDom_Node_getType(child) == T_DOM_NODE_ATTR){
|
|
184 |
return NW_TRUE;
|
|
185 |
}
|
|
186 |
child = NW_TinyTree_findNextSibling(child);
|
|
187 |
}
|
|
188 |
return NW_FALSE;
|
|
189 |
}
|
|
190 |
|
|
191 |
/*
|
|
192 |
* Returns
|
|
193 |
* NW_STAT_DOM_NODE_TYPE_ERR
|
|
194 |
* NW_STAT_SUCCESS
|
|
195 |
* MODIFIED iterator
|
|
196 |
* WAP-adapted DOM extension
|
|
197 |
*/
|
|
198 |
|
|
199 |
EXPORT_C NW_Status_t
|
|
200 |
NW_DOM_ElementNode_getAttributeListIterator(NW_DOM_Node_t *node,
|
|
201 |
NW_DOM_AttributeListIterator_t
|
|
202 |
*iterator)
|
|
203 |
{
|
|
204 |
NW_DOM_Node_t *child;
|
|
205 |
NW_TinyTree_t *tiny_tree;
|
|
206 |
|
|
207 |
NW_ASSERT(node != NULL);
|
|
208 |
NW_ASSERT(iterator != NULL);
|
|
209 |
|
|
210 |
if ((NW_DOM_Node_getNodeType(node) != NW_DOM_ELEMENT_NODE)
|
|
211 |
&& (NW_DOM_Node_getNodeType(node) != NW_DOM_PROCESSING_INSTRUCTION_NODE))
|
|
212 |
{
|
|
213 |
return NW_STAT_DOM_NODE_TYPE_ERR;
|
|
214 |
}
|
|
215 |
|
|
216 |
tiny_tree = NW_TinyTree_Node_findTree(node);
|
|
217 |
|
|
218 |
(void) NW_DOM_AttributeListIterator_initialize(iterator);
|
|
219 |
|
|
220 |
child = NW_TinyTree_findFirstChild(node);
|
|
221 |
iterator->node = child;
|
|
222 |
if(child){
|
|
223 |
if (NW_TinyDom_Node_getType(child) == T_DOM_NODE_ATTR){
|
|
224 |
NW_TinyDom_AttrListHandle_init(&iterator->attrListHandle,
|
|
225 |
NW_TinyDom_getParser(tiny_tree),
|
|
226 |
child);
|
|
227 |
return NW_STAT_SUCCESS;
|
|
228 |
}
|
|
229 |
child = NW_TinyTree_findNextSibling(child);
|
|
230 |
while (child){
|
|
231 |
if (NW_TinyDom_Node_getType(child) == T_DOM_NODE_ATTR){
|
|
232 |
NW_TinyDom_AttrListHandle_init(&iterator->attrListHandle,
|
|
233 |
NW_TinyDom_getParser(tiny_tree),
|
|
234 |
child);
|
|
235 |
return NW_STAT_SUCCESS;
|
|
236 |
}
|
|
237 |
child = NW_TinyTree_findNextSibling(child);
|
|
238 |
}
|
|
239 |
}
|
|
240 |
return NW_STAT_NOT_FOUND;
|
|
241 |
}
|
|
242 |
|
|
243 |
/*
|
|
244 |
* Returns
|
|
245 |
* NW_STAT_DOM_NODE_TYPE_ERR
|
|
246 |
* NW_STAT_NOT_FOUND - if attribute is not found
|
|
247 |
* NW_STAT_SUCCESS
|
|
248 |
*
|
|
249 |
* IN - attributeName
|
|
250 |
* MODIFIED - handle
|
|
251 |
*/
|
|
252 |
|
|
253 |
EXPORT_C NW_Status_t
|
|
254 |
NW_DOM_ElementNode_getAttributeHandleByName(NW_DOM_ElementNode_t *elem,
|
|
255 |
NW_String_t *attributeName,
|
|
256 |
NW_DOM_AttributeHandle_t
|
|
257 |
*attributeHandle)
|
|
258 |
{
|
|
259 |
NW_Status_t nwStatus;
|
|
260 |
NW_Status_t status;
|
|
261 |
NW_DOM_AttributeListIterator_t attrListIterator;
|
|
262 |
NW_Bool attributeFound = NW_FALSE;
|
|
263 |
NW_String_t currentName;
|
|
264 |
NW_Uint32 docEncoding;
|
|
265 |
NW_Int32 charCount;
|
|
266 |
NW_Uint32 byteCount = 0;
|
|
267 |
NW_Int32 cmpResult;
|
|
268 |
|
|
269 |
NW_ASSERT(elem != NULL);
|
|
270 |
NW_ASSERT(attributeHandle != NULL);
|
|
271 |
NW_ASSERT(attributeName != NULL);
|
|
272 |
|
|
273 |
if ((NW_DOM_Node_getNodeType(elem) != NW_DOM_ELEMENT_NODE)
|
|
274 |
&& (NW_DOM_Node_getNodeType(elem) != NW_DOM_PROCESSING_INSTRUCTION_NODE))
|
|
275 |
{
|
|
276 |
return NW_STAT_DOM_NODE_TYPE_ERR;
|
|
277 |
}
|
|
278 |
|
|
279 |
if (!NW_DOM_ElementNode_hasAttributes(elem)){
|
|
280 |
return NW_STAT_NOT_FOUND;
|
|
281 |
}
|
|
282 |
|
|
283 |
/* Initialize the handle */
|
|
284 |
status =
|
|
285 |
NW_DOM_ElementNode_getAttributeListIterator(elem, &attrListIterator);
|
|
286 |
|
|
287 |
if (status != NW_STAT_SUCCESS){
|
|
288 |
return status;
|
|
289 |
}
|
|
290 |
|
|
291 |
while (!attributeFound){
|
|
292 |
if (NW_DOM_AttributeListIterator_getNextAttribute(&attrListIterator,
|
|
293 |
attributeHandle)
|
|
294 |
== NW_STAT_WBXML_ITERATE_DONE){
|
|
295 |
return NW_STAT_NOT_FOUND;
|
|
296 |
}
|
|
297 |
|
|
298 |
status = NW_DOM_AttributeHandle_getName(attributeHandle, ¤tName);
|
|
299 |
if (status != NW_STAT_SUCCESS){
|
|
300 |
continue;
|
|
301 |
}
|
|
302 |
|
|
303 |
docEncoding = NW_DOM_AttributeHandle_getEncoding (attributeHandle);
|
|
304 |
charCount = NW_String_charBuffGetLength(currentName.storage, docEncoding,
|
|
305 |
&byteCount);
|
|
306 |
if (charCount < 0) {
|
|
307 |
return NW_STAT_FAILURE;
|
|
308 |
}
|
|
309 |
|
|
310 |
nwStatus = NW_String_CmpToNativeAlignedUCS2(docEncoding, (NW_Uint32) charCount,
|
|
311 |
currentName.storage,
|
|
312 |
(NW_Uint16*)(attributeName->storage),
|
|
313 |
&cmpResult);
|
|
314 |
NW_String_deleteStorage(¤tName);
|
|
315 |
if (NW_STAT_IS_FAILURE(nwStatus)){
|
|
316 |
continue;
|
|
317 |
}
|
|
318 |
if (cmpResult == 0){
|
|
319 |
attributeFound = NW_TRUE;
|
|
320 |
}
|
|
321 |
}
|
|
322 |
|
|
323 |
/* Proceed: Attribute Found */
|
|
324 |
|
|
325 |
/* If attributeHandle->node != NULL, that means that the attribute has an
|
|
326 |
independent node to itself, and is not a part of list node */
|
|
327 |
|
|
328 |
if (attributeHandle->node != NULL){
|
|
329 |
NW_Bool nextAttrWithSameNameFound = NW_FALSE;
|
|
330 |
NW_DOM_AttributeHandle_t h;
|
|
331 |
h.node = NULL;
|
|
332 |
|
|
333 |
while (!nextAttrWithSameNameFound){
|
|
334 |
if (NW_DOM_AttributeListIterator_getNextAttribute(&attrListIterator, &h)
|
|
335 |
== NW_STAT_WBXML_ITERATE_DONE){
|
|
336 |
break;
|
|
337 |
}
|
|
338 |
status = NW_DOM_AttributeHandle_getName(&h, ¤tName);
|
|
339 |
if (status != NW_STAT_SUCCESS){
|
|
340 |
break;
|
|
341 |
}
|
|
342 |
docEncoding = NW_DOM_AttributeHandle_getEncoding(attributeHandle);
|
|
343 |
charCount = NW_String_charBuffGetLength(currentName.storage, docEncoding,
|
|
344 |
&byteCount);
|
|
345 |
if (charCount < 0) {
|
|
346 |
return NW_STAT_FAILURE;
|
|
347 |
}
|
|
348 |
nwStatus = NW_String_CmpToNativeAlignedUCS2(docEncoding, (NW_Uint32)charCount,
|
|
349 |
currentName.storage,
|
|
350 |
(NW_Uint16*)(attributeName->storage),
|
|
351 |
&cmpResult);
|
|
352 |
NW_String_deleteStorage(¤tName);
|
|
353 |
if (NW_STAT_IS_FAILURE(nwStatus)){
|
|
354 |
continue;
|
|
355 |
}
|
|
356 |
if (cmpResult == 0){
|
|
357 |
nextAttrWithSameNameFound = NW_TRUE;
|
|
358 |
}
|
|
359 |
}
|
|
360 |
|
|
361 |
if (nextAttrWithSameNameFound){
|
|
362 |
NW_TinyDom_Parser_t *parser =
|
|
363 |
attrListIterator.attrListHandle.tiny_parser;
|
|
364 |
NW_DOM_AttributeHandle_initWithNode(attributeHandle, parser, h.node);
|
|
365 |
}
|
|
366 |
}
|
|
367 |
|
|
368 |
return NW_STAT_SUCCESS;
|
|
369 |
}
|
|
370 |
|
|
371 |
/**
|
|
372 |
* The following 2 methods use token to return attributes
|
|
373 |
*/
|
|
374 |
|
|
375 |
/*
|
|
376 |
* Returns
|
|
377 |
* NW_STAT_DOM_NODE_TYPE_ERR
|
|
378 |
* NW_STAT_NOT_FOUND - if attribute is not found
|
|
379 |
* NW_STAT_SUCCESS
|
|
380 |
*
|
|
381 |
* IN - token
|
|
382 |
* MODIFIED - handle
|
|
383 |
*/
|
|
384 |
|
|
385 |
EXPORT_C NW_Status_t
|
|
386 |
NW_DOM_ElementNode_getAttributeHandleByToken(NW_DOM_ElementNode_t *elem,
|
|
387 |
NW_Uint16 token,
|
|
388 |
NW_DOM_AttributeHandle_t *handle)
|
|
389 |
{
|
|
390 |
NW_DOM_AttributeListIterator_t attributeListIterator;
|
|
391 |
NW_Bool attributeFound = NW_FALSE;
|
|
392 |
NW_Uint16 currentToken = 0;
|
|
393 |
NW_Status_t status;
|
|
394 |
NW_TinyDom_Parser_t *parser;
|
|
395 |
|
|
396 |
NW_ASSERT(token != 0);
|
|
397 |
NW_ASSERT(elem != NULL);
|
|
398 |
NW_ASSERT(handle != NULL);
|
|
399 |
|
|
400 |
if ((NW_DOM_Node_getNodeType(elem) != NW_DOM_ELEMENT_NODE)
|
|
401 |
&& (NW_DOM_Node_getNodeType(elem) != NW_DOM_PROCESSING_INSTRUCTION_NODE)){
|
|
402 |
return NW_STAT_DOM_NODE_TYPE_ERR;
|
|
403 |
}
|
|
404 |
|
|
405 |
if (!NW_DOM_ElementNode_hasAttributes(elem)){
|
|
406 |
return NW_STAT_NOT_FOUND;
|
|
407 |
}
|
|
408 |
|
|
409 |
status =
|
|
410 |
NW_DOM_ElementNode_getAttributeListIterator(elem, &attributeListIterator);
|
|
411 |
|
|
412 |
if (status != NW_STAT_SUCCESS){
|
|
413 |
return status;
|
|
414 |
}
|
|
415 |
|
|
416 |
while (!attributeFound){
|
|
417 |
if (NW_DOM_AttributeListIterator_getNextAttribute(&attributeListIterator,
|
|
418 |
handle)
|
|
419 |
== NW_STAT_WBXML_ITERATE_DONE){
|
|
420 |
return NW_STAT_NOT_FOUND;
|
|
421 |
}
|
|
422 |
currentToken = NW_DOM_AttributeHandle_getToken(handle);
|
|
423 |
if (currentToken == token){
|
|
424 |
attributeFound = NW_TRUE;
|
|
425 |
}
|
|
426 |
}
|
|
427 |
/* if we arrive here, attributeFound must be NW_TRUE */
|
|
428 |
if (handle->node != NULL)
|
|
429 |
{
|
|
430 |
NW_Bool nextAttrWithSameNameFound = NW_FALSE;
|
|
431 |
NW_DOM_AttributeHandle_t h;
|
|
432 |
h.node = NULL;
|
|
433 |
|
|
434 |
while (!nextAttrWithSameNameFound){
|
|
435 |
if (NW_DOM_AttributeListIterator_getNextAttribute(&attributeListIterator,
|
|
436 |
&h)
|
|
437 |
== NW_STAT_WBXML_ITERATE_DONE){
|
|
438 |
return NW_STAT_BAD_INPUT_PARAM;
|
|
439 |
}
|
|
440 |
|
|
441 |
currentToken = NW_DOM_AttributeHandle_getToken(&h);
|
|
442 |
if (currentToken == token)
|
|
443 |
nextAttrWithSameNameFound = NW_TRUE;
|
|
444 |
}
|
|
445 |
|
|
446 |
parser = attributeListIterator.attrListHandle.tiny_parser;
|
|
447 |
NW_DOM_AttributeHandle_initWithNode(handle, parser, h.node);
|
|
448 |
}
|
|
449 |
|
|
450 |
return NW_STAT_SUCCESS;
|
|
451 |
}
|
|
452 |
|
|
453 |
/*
|
|
454 |
* Returns
|
|
455 |
* NW_STAT_NOT_FOUND - if attribute is not found
|
|
456 |
* NW_STAT_DOM_NODE_TYPE_ERR
|
|
457 |
* NW_STAT_DOM_NO_STRING_RETURNED
|
|
458 |
* NW_STAT_SUCCESS
|
|
459 |
*
|
|
460 |
* This method returns attribute value as string
|
|
461 |
* IN - token of attribute
|
|
462 |
* MODIFIED - attributeValue
|
|
463 |
*/
|
|
464 |
|
|
465 |
NW_Status_t
|
|
466 |
NW_DOM_ElementNode_getAttributeValueStringByToken(NW_DOM_ElementNode_t *elem,
|
|
467 |
NW_Uint16 token,
|
|
468 |
NW_String_t *attributeValue)
|
|
469 |
{
|
|
470 |
NW_DOM_AttributeHandle_t attributeHandle;
|
|
471 |
NW_Status_t status;
|
|
472 |
|
|
473 |
NW_ASSERT(elem != NULL);
|
|
474 |
NW_ASSERT(attributeValue != NULL);
|
|
475 |
|
|
476 |
if ((NW_DOM_Node_getNodeType(elem) != NW_DOM_ELEMENT_NODE)
|
|
477 |
&& (NW_DOM_Node_getNodeType(elem) != NW_DOM_PROCESSING_INSTRUCTION_NODE))
|
|
478 |
{
|
|
479 |
return NW_STAT_DOM_NODE_TYPE_ERR;
|
|
480 |
}
|
|
481 |
|
|
482 |
status =
|
|
483 |
NW_DOM_ElementNode_getAttributeHandleByToken(elem,
|
|
484 |
token,
|
|
485 |
&attributeHandle);
|
|
486 |
if (status != NW_STAT_SUCCESS){
|
|
487 |
return status;
|
|
488 |
}
|
|
489 |
|
|
490 |
return NW_DOM_AttributeHandle_getValue(&attributeHandle, attributeValue);
|
|
491 |
}
|
|
492 |
|
|
493 |
/*
|
|
494 |
* IN - name - of element
|
|
495 |
*/
|
|
496 |
|
|
497 |
NW_Status_t
|
|
498 |
NW_DOM_ElementNode_getElementIteratorByTagName(NW_DOM_ElementNode_t *elem,
|
|
499 |
NW_String_t* name,
|
|
500 |
NW_DOM_NodeIterator_t *handle)
|
|
501 |
{
|
|
502 |
NW_DOM_DocumentNode_t *doc;
|
|
503 |
NW_WBXML_Dictionary_t *dict = NULL;
|
|
504 |
NW_String_UCS2Buff_t *buff = NULL;
|
|
505 |
|
|
506 |
NW_Uint32 encoding;
|
|
507 |
NW_Int16 token = 0;
|
|
508 |
|
|
509 |
NW_ASSERT(elem != NULL);
|
|
510 |
NW_ASSERT(name != NULL);
|
|
511 |
NW_ASSERT(handle != NULL);
|
|
512 |
|
|
513 |
doc = NW_DOM_Node_getOwnerDocument(elem);
|
|
514 |
if (doc == NULL) {
|
|
515 |
return NW_STAT_FAILURE;
|
|
516 |
}
|
|
517 |
encoding = NW_DOM_DocumentNode_getCharacterEncoding(doc);
|
|
518 |
|
|
519 |
dict = NW_DOM_DocumentNode_getDictionary(doc);
|
|
520 |
buff = NW_String_stringToUCS2Buff(name, encoding);
|
|
521 |
if((dict == NULL) || (buff == NULL)){
|
|
522 |
NW_Mem_Free(buff);
|
|
523 |
return NW_STAT_FAILURE;
|
|
524 |
}
|
|
525 |
token = NW_WBXML_Dictionary_getTagToken(dict, buff, NW_TRUE);
|
|
526 |
NW_Mem_Free(buff);
|
|
527 |
if (token < 0) {
|
|
528 |
return NW_STAT_FAILURE;
|
|
529 |
}
|
|
530 |
return NW_DOM_ElementNode_getElementIteratorByTagToken(elem,
|
|
531 |
(NW_Uint16)token,
|
|
532 |
handle);
|
|
533 |
}
|
|
534 |
|
|
535 |
/*
|
|
536 |
* IN - token - of element
|
|
537 |
*/
|
|
538 |
|
|
539 |
NW_Status_t
|
|
540 |
NW_DOM_ElementNode_getElementIteratorByTagToken(NW_DOM_ElementNode_t *elem,
|
|
541 |
NW_Uint16 token,
|
|
542 |
NW_DOM_NodeIterator_t *handle)
|
|
543 |
{
|
|
544 |
|
|
545 |
NW_ASSERT(elem != NULL);
|
|
546 |
NW_ASSERT(handle != NULL);
|
|
547 |
|
|
548 |
if (NW_DOM_Node_getNodeType(elem) != NW_DOM_ELEMENT_NODE)
|
|
549 |
return NW_STAT_DOM_NODE_TYPE_ERR;
|
|
550 |
|
|
551 |
return NW_DOM_NodeIterator_initialize(handle, elem, token);
|
|
552 |
}
|
|
553 |
|
|
554 |
|
|
555 |
|
|
556 |
/*
|
|
557 |
* If the attribute with the given name exists then a its value will
|
|
558 |
* be changed to input value, otherwise a new attribute will be created
|
|
559 |
* LIMITATION: If the given attribute was already present when the document
|
|
560 |
* was parsed the first time, it can not be removed. In this case a new
|
|
561 |
* attribute is added, and you will have 2 attributes with same name
|
|
562 |
* Returns
|
|
563 |
* NW_STAT_BAD_INPUT_PARAM - If input args are NULL
|
|
564 |
* NW_STAT_DOM_NODE_TYPE_ERR - If it is not an element node
|
|
565 |
* NW_STAT_SUCCESS
|
|
566 |
*
|
|
567 |
*/
|
|
568 |
|
|
569 |
EXPORT_C NW_Status_t
|
|
570 |
NW_DOM_ElementNode_setAttribute(NW_DOM_ElementNode_t *elem,
|
|
571 |
NW_String_t *attrName,
|
|
572 |
NW_String_t *val)
|
|
573 |
{
|
|
574 |
NW_Status_t status;
|
|
575 |
NW_TinyTree_t* tiny_tree;
|
|
576 |
NW_TinyDom_Tree_t *tree;
|
|
577 |
NW_TinyTree_Node_t *attr = NULL;
|
|
578 |
NW_DOM_DocumentNode_t *doc = NW_DOM_Node_getOwnerDocument(elem);
|
|
579 |
NW_WBXML_Dictionary_t *dictionary = NW_DOM_DocumentNode_getDictionary(doc);
|
|
580 |
NW_Uint32 encoding = NW_DOM_DocumentNode_getCharacterEncoding(doc);
|
|
581 |
NW_Int32 fqToken;
|
|
582 |
NW_DOM_AttrVal_t attrValue;
|
|
583 |
|
|
584 |
if ((elem == NULL) || (attrName == NULL) ||
|
|
585 |
(val == NULL) || (dictionary == NULL)){
|
|
586 |
return NW_STAT_BAD_INPUT_PARAM;
|
|
587 |
}
|
|
588 |
|
|
589 |
if (NW_DOM_Node_getNodeType(elem) != NW_DOM_ELEMENT_NODE)
|
|
590 |
return NW_STAT_DOM_NODE_TYPE_ERR;
|
|
591 |
|
|
592 |
status = NW_DOM_ElementNode_removeAttribute(elem, attrName);
|
|
593 |
if ((status != NW_STAT_SUCCESS) && (status != NW_STAT_NOT_FOUND)) {
|
|
594 |
return status;
|
|
595 |
}
|
|
596 |
|
|
597 |
tiny_tree = NW_TinyTree_Node_findTree(elem);
|
|
598 |
tree = NW_TinyDom_getTree(tiny_tree);
|
|
599 |
|
|
600 |
fqToken = NW_WBXML_Dictionary_getAttributeToken(dictionary, attrName, encoding, NW_TRUE);
|
|
601 |
|
|
602 |
status = NW_DOM_AttrVal_initFromString(&attrValue, val);
|
|
603 |
if (fqToken == -1)
|
|
604 |
attr = NW_TinyDom_createAttributeByName(tree, attrName, &attrValue);
|
|
605 |
else
|
|
606 |
attr = NW_TinyDom_createAttributeByToken(tree, (NW_Uint8)fqToken, &attrValue);
|
|
607 |
|
|
608 |
return NW_DOM_Node_appendChild(elem, attr);
|
|
609 |
}
|
|
610 |
|
|
611 |
/**
|
|
612 |
* Removes given attribute
|
|
613 |
* Limited Use: You can only remove attributes that you
|
|
614 |
* explicitly created and added to the element. None of the
|
|
615 |
* attributes in the originally parsed document can not be removed
|
|
616 |
* Returns
|
|
617 |
* NW_STAT_BAD_INPUT_PARAM - If input args are NULL
|
|
618 |
* NW_STAT_DOM_NODE_TYPE_ERR - If it is not an element node
|
|
619 |
* NW_STAT_NOT_FOUND - if attribute is not found
|
|
620 |
* NW_STAT_SUCCESS
|
|
621 |
**/
|
|
622 |
EXPORT_C NW_Status_t
|
|
623 |
NW_DOM_ElementNode_removeAttribute(
|
|
624 |
NW_DOM_ElementNode_t *elem, NW_String_t* attributeName)
|
|
625 |
{
|
|
626 |
NW_DOM_AttributeHandle_t attrHandle;
|
|
627 |
NW_Status_t status;
|
|
628 |
|
|
629 |
if ((elem == NULL) || (attributeName == NULL))
|
|
630 |
return NW_STAT_BAD_INPUT_PARAM;
|
|
631 |
|
|
632 |
if (NW_DOM_Node_getNodeType(elem) != NW_DOM_ELEMENT_NODE)
|
|
633 |
return NW_STAT_DOM_NODE_TYPE_ERR;
|
|
634 |
|
|
635 |
status = NW_DOM_ElementNode_getAttributeHandleByName(elem, attributeName, &attrHandle);
|
|
636 |
if (status != NW_STAT_SUCCESS)
|
|
637 |
return status;
|
|
638 |
|
|
639 |
/*
|
|
640 |
* If the attribute was a newly added one it is deleted,
|
|
641 |
* but SUCCESS is returned in both cases
|
|
642 |
*/
|
|
643 |
if (attrHandle.node != NULL)
|
|
644 |
NW_TinyTree_deleteNode(attrHandle.node);
|
|
645 |
|
|
646 |
return NW_STAT_SUCCESS;
|
|
647 |
}
|
|
648 |
|
|
649 |
|
|
650 |
|
|
651 |
/*
|
|
652 |
* If the attribute with the given name exists then its value will
|
|
653 |
* be changed to input value, otherwise a new attribute will be created
|
|
654 |
* LIMITATION: If the given attribute was already present when the document
|
|
655 |
* was parsed the first time, it can not be removed. In this case a new
|
|
656 |
* attribute is added, and you will have 2 attributes with same name
|
|
657 |
* Returns
|
|
658 |
* NW_STAT_BAD_INPUT_PARAM - If input args are NULL
|
|
659 |
* NW_STAT_NOT_FOUND - if attribute is not found
|
|
660 |
* NW_STAT_DOM_NODE_TYPE_ERR - If it is not an element node
|
|
661 |
* NW_STAT_SUCCESS
|
|
662 |
*
|
|
663 |
*/
|
|
664 |
EXPORT_C NW_Status_t
|
|
665 |
NW_DOM_ElementNode_setAttributeByToken(
|
|
666 |
NW_DOM_ElementNode_t *elem, NW_Uint16 token, NW_DOM_AttrVal_t *attrValue)
|
|
667 |
{
|
|
668 |
NW_Status_t status;
|
|
669 |
NW_TinyTree_t* tinyTree;
|
|
670 |
NW_TinyDom_Tree_t *tree;
|
|
671 |
NW_TinyTree_Node_t *attr = NULL;
|
|
672 |
NW_DOM_DocumentNode_t *doc = NW_DOM_Node_getOwnerDocument(elem);
|
|
673 |
NW_WBXML_Dictionary_t *dictionary = NW_DOM_DocumentNode_getDictionary(doc);
|
|
674 |
|
|
675 |
if ((elem == NULL) || (attrValue == NULL) || (dictionary == NULL)){
|
|
676 |
return NW_STAT_BAD_INPUT_PARAM;
|
|
677 |
}
|
|
678 |
|
|
679 |
if (NW_DOM_Node_getNodeType(elem) != NW_DOM_ELEMENT_NODE) {
|
|
680 |
return NW_STAT_DOM_NODE_TYPE_ERR;
|
|
681 |
}
|
|
682 |
|
|
683 |
tinyTree = NW_TinyTree_Node_findTree(elem);
|
|
684 |
tree = NW_TinyDom_getTree(tinyTree);
|
|
685 |
|
|
686 |
status = NW_DOM_ElementNode_removeAttributeByToken(elem, token);
|
|
687 |
if ((status == NW_STAT_SUCCESS) || (status == NW_STAT_NOT_FOUND)) {
|
|
688 |
attr = NW_TinyDom_createAttributeByToken(tree, (NW_Uint8)token, attrValue);
|
|
689 |
return NW_DOM_Node_appendChild(elem, attr);
|
|
690 |
}
|
|
691 |
return status;
|
|
692 |
}
|
|
693 |
|
|
694 |
/**
|
|
695 |
* If the attribute with the given name exists then a its value will
|
|
696 |
* be changed to input value, otherwise a new attribute will be created
|
|
697 |
* LIMITATION: If the given attribute was already present when the document
|
|
698 |
* was parsed the first time, it can not be removed. In this case a new
|
|
699 |
* attribute is added, and you will have 2 attributes with same name
|
|
700 |
* Returns
|
|
701 |
* NW_STAT_BAD_INPUT_PARAM - If input args are NULL
|
|
702 |
* NW_STAT_DOM_NODE_TYPE_ERR - If it is not an element node
|
|
703 |
* NW_STAT_SUCCESS
|
|
704 |
*
|
|
705 |
*/
|
|
706 |
EXPORT_C NW_Status_t
|
|
707 |
NW_DOM_ElementNode_setAttributeByAttrVal(
|
|
708 |
NW_DOM_ElementNode_t *elem,
|
|
709 |
NW_String_t *attrName,
|
|
710 |
NW_DOM_AttrVal_t *attrValue)
|
|
711 |
{
|
|
712 |
NW_Status_t status;
|
|
713 |
NW_TinyTree_t* tinyTree;
|
|
714 |
NW_TinyDom_Tree_t *tree;
|
|
715 |
NW_TinyTree_Node_t *attr = NULL;
|
|
716 |
NW_DOM_DocumentNode_t *doc = NW_DOM_Node_getOwnerDocument(elem);
|
|
717 |
NW_WBXML_Dictionary_t *dictionary = NW_DOM_DocumentNode_getDictionary(doc);
|
|
718 |
NW_Uint32 encoding = NW_DOM_DocumentNode_getCharacterEncoding(doc);
|
|
719 |
NW_Int32 fqToken;
|
|
720 |
|
|
721 |
if ((elem == NULL) || (attrName == NULL) ||
|
|
722 |
(attrValue == NULL) || (dictionary == NULL)){
|
|
723 |
return NW_STAT_BAD_INPUT_PARAM;
|
|
724 |
}
|
|
725 |
|
|
726 |
if (NW_DOM_Node_getNodeType(elem) != NW_DOM_ELEMENT_NODE)
|
|
727 |
return NW_STAT_DOM_NODE_TYPE_ERR;
|
|
728 |
|
|
729 |
status = NW_DOM_ElementNode_removeAttribute(elem, attrName);
|
|
730 |
if ((status != NW_STAT_SUCCESS) && (status != NW_STAT_NOT_FOUND)) {
|
|
731 |
return status;
|
|
732 |
}
|
|
733 |
tinyTree = NW_TinyTree_Node_findTree(elem);
|
|
734 |
tree = NW_TinyDom_getTree(tinyTree);
|
|
735 |
|
|
736 |
fqToken = NW_WBXML_Dictionary_getAttributeToken(dictionary, attrName, encoding, NW_TRUE);
|
|
737 |
if (fqToken == -1){
|
|
738 |
attr = NW_TinyDom_createAttributeByName(tree, attrName, attrValue);
|
|
739 |
} else {
|
|
740 |
attr = NW_TinyDom_createAttributeByToken(tree, (NW_Uint8)fqToken, attrValue);
|
|
741 |
}
|
|
742 |
return NW_DOM_Node_appendChild(elem, attr);
|
|
743 |
}
|
|
744 |
|
|
745 |
EXPORT_C NW_Status_t
|
|
746 |
NW_DOM_ElementNode_setAttributeByAttributeHandle(NW_DOM_ElementNode_t* elem,
|
|
747 |
NW_DOM_AttributeHandle_t* handle)
|
|
748 |
{
|
|
749 |
if ((elem == NULL)
|
|
750 |
|| (handle == NULL)) {
|
|
751 |
return NW_STAT_BAD_INPUT_PARAM;
|
|
752 |
}
|
|
753 |
if (NW_DOM_Node_getNodeType(elem) != NW_DOM_ELEMENT_NODE) {
|
|
754 |
return NW_STAT_DOM_NODE_TYPE_ERR;
|
|
755 |
}
|
|
756 |
if (handle->node == NULL) {
|
|
757 |
return NW_STAT_FAILURE;
|
|
758 |
}
|
|
759 |
return NW_DOM_Node_appendChild(elem, handle->node);
|
|
760 |
}
|
|
761 |
|
|
762 |
/**
|
|
763 |
* Removes given attribute
|
|
764 |
* Limited Use: You can only remove attributes that you
|
|
765 |
* explicitly created and added to the element. None of the
|
|
766 |
* attributes in the originally parsed document can not be removed
|
|
767 |
* Returns
|
|
768 |
* NW_STAT_BAD_INPUT_PARAM - If input args are NULL
|
|
769 |
* NW_STAT_NOT_FOUND - if attribute is not found
|
|
770 |
* NW_STAT_DOM_NODE_TYPE_ERR - If it is not an element node
|
|
771 |
* NW_STAT_SUCCESS
|
|
772 |
*/
|
|
773 |
NW_Status_t
|
|
774 |
NW_DOM_ElementNode_removeAttributeByToken(
|
|
775 |
NW_DOM_ElementNode_t *elem, NW_Uint16 attributeToken)
|
|
776 |
{
|
|
777 |
NW_DOM_AttributeHandle_t attrHandle;
|
|
778 |
NW_Status_t status;
|
|
779 |
|
|
780 |
if ((elem == NULL) || (attributeToken == 0))
|
|
781 |
return NW_STAT_BAD_INPUT_PARAM;
|
|
782 |
|
|
783 |
if (NW_DOM_Node_getNodeType(elem) != NW_DOM_ELEMENT_NODE)
|
|
784 |
return NW_STAT_DOM_NODE_TYPE_ERR;
|
|
785 |
|
|
786 |
status = NW_DOM_ElementNode_getAttributeHandleByToken(elem, attributeToken, &attrHandle);
|
|
787 |
if ((status != NW_STAT_SUCCESS))
|
|
788 |
return status;
|
|
789 |
|
|
790 |
/*
|
|
791 |
* If the attribute was a newly added one it is deleted,
|
|
792 |
* but SUCCESS is returned in both cases
|
|
793 |
*/
|
|
794 |
if (attrHandle.node != NULL)
|
|
795 |
NW_TinyTree_deleteNode(attrHandle.node);
|
|
796 |
|
|
797 |
return NW_STAT_SUCCESS;
|
|
798 |
}
|
|
799 |
|