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_attribute.h>
|
|
21 |
#include <xml/cxml/nw_wbxml_dictionary.h>
|
|
22 |
#include <xml/cxml/nw_tinydom.h>
|
|
23 |
#include <xml/cxml/nw_string_string.h>
|
|
24 |
#include "nw_dom_wbxmltypes.h"
|
|
25 |
|
|
26 |
/*
|
|
27 |
* ATTRIBUTE LIST HANDLE
|
|
28 |
* is used to iterate over the list of attributes of an element
|
|
29 |
*/
|
|
30 |
|
|
31 |
/*
|
|
32 |
* Allocates memory for NW_DOM_AttributeListIterator
|
|
33 |
* Returns NULL in case of failure to do so
|
|
34 |
*/
|
|
35 |
|
|
36 |
NW_DOM_AttributeListIterator_t *
|
|
37 |
NW_DOM_AttributeListIterator_new(void)
|
|
38 |
{
|
|
39 |
NW_DOM_AttributeListIterator_t *handle =
|
|
40 |
(NW_DOM_AttributeListIterator_t *)
|
|
41 |
NW_Mem_Malloc(sizeof (NW_DOM_AttributeListIterator_t));
|
|
42 |
if (handle == NULL)
|
|
43 |
return NULL;
|
|
44 |
handle->node = NULL;
|
|
45 |
return handle;
|
|
46 |
}
|
|
47 |
|
|
48 |
/*
|
|
49 |
* Initializes an AttributeListIterator
|
|
50 |
* Returns NW_STAT_SUCCESS
|
|
51 |
*/
|
|
52 |
|
|
53 |
NW_Status_t
|
|
54 |
NW_DOM_AttributeListIterator_initialize(NW_DOM_AttributeListIterator_t *handle)
|
|
55 |
{
|
|
56 |
|
|
57 |
NW_ASSERT(handle != NULL);
|
|
58 |
|
|
59 |
handle->node = NULL;
|
|
60 |
handle->attrListHandle.state = NW_STAT_SUCCESS;
|
|
61 |
handle->attrListHandle.offset = 0;
|
|
62 |
handle->attrListHandle.tiny_parser = NULL;
|
|
63 |
handle->attrListHandle.context = NULL;
|
|
64 |
|
|
65 |
return NW_STAT_SUCCESS;
|
|
66 |
}
|
|
67 |
|
|
68 |
NW_Status_t
|
|
69 |
NW_DOM_AttributeListIterator_delete(NW_DOM_AttributeListIterator_t *handle)
|
|
70 |
{
|
|
71 |
NW_ASSERT(handle != NULL);
|
|
72 |
NW_Mem_Free(handle);
|
|
73 |
return NW_STAT_SUCCESS;
|
|
74 |
}
|
|
75 |
|
|
76 |
/*
|
|
77 |
* Returns
|
|
78 |
* NW_STAT_WBXML_ITERATE_MORE
|
|
79 |
* NW_STAT_WBXML_ITERATE_DONE
|
|
80 |
*
|
|
81 |
* MODIFIED attributeHandle
|
|
82 |
*/
|
|
83 |
|
|
84 |
EXPORT_C NW_Status_t
|
|
85 |
NW_DOM_AttributeListIterator_getNextAttribute(NW_DOM_AttributeListIterator_t* listHandle,
|
|
86 |
NW_DOM_AttributeHandle_t *attributeHandle)
|
|
87 |
{
|
|
88 |
NW_TinyTree_Offset_t offset = 0;
|
|
89 |
NW_TinyDom_Parser_t *parser = NULL;
|
|
90 |
|
|
91 |
NW_ASSERT(listHandle != NULL);
|
|
92 |
NW_ASSERT(listHandle->node != NULL);
|
|
93 |
NW_ASSERT(attributeHandle != NULL);
|
|
94 |
|
|
95 |
if (listHandle->attrListHandle.state == NW_STAT_WBXML_ITERATE_MORE){
|
|
96 |
parser = listHandle->attrListHandle.tiny_parser;
|
|
97 |
offset = NW_TinyDom_AttrListHandle_iterate(&listHandle->attrListHandle);
|
|
98 |
if (offset != 0){
|
|
99 |
NW_DOM_AttributeHandle_initWithOffset(attributeHandle, parser, offset);
|
|
100 |
return NW_STAT_WBXML_ITERATE_MORE;
|
|
101 |
}
|
|
102 |
}
|
|
103 |
|
|
104 |
/*
|
|
105 |
* Once we are done iterating over the initial set of attributes,
|
|
106 |
* next attribute node is located. A reference to this node is kept,
|
|
107 |
* so that in subsequent call to this method we can proceed from there
|
|
108 |
*/
|
|
109 |
|
|
110 |
NW_ASSERT(listHandle->node != NULL);
|
|
111 |
|
|
112 |
listHandle->node = NW_TinyTree_findNextSibling(listHandle->node);
|
|
113 |
parser = listHandle->attrListHandle.tiny_parser;
|
|
114 |
if (parser == NULL)
|
|
115 |
return NW_STAT_FAILURE;
|
|
116 |
|
|
117 |
while (listHandle->node){
|
|
118 |
if (NW_TinyDom_Node_getType(listHandle->node) == T_DOM_NODE_ATTR){
|
|
119 |
NW_DOM_AttributeHandle_initWithNode(attributeHandle, parser, listHandle->node);
|
|
120 |
return NW_STAT_WBXML_ITERATE_MORE;
|
|
121 |
}
|
|
122 |
listHandle->node = NW_TinyTree_findNextSibling(listHandle->node);
|
|
123 |
}
|
|
124 |
return NW_STAT_WBXML_ITERATE_DONE;
|
|
125 |
}
|
|
126 |
|
|
127 |
NW_DOM_AttrVal_t *
|
|
128 |
NW_DOM_AttrVal_new(void)
|
|
129 |
{
|
|
130 |
return (NW_DOM_AttrVal_t *) NW_Mem_Malloc(sizeof (NW_DOM_AttrVal_t));
|
|
131 |
}
|
|
132 |
|
|
133 |
/*
|
|
134 |
* Initializes an AttrVal of type NW_DOM_ATTR_VAL_STRING
|
|
135 |
* Returns NW_STAT_SUCCESS
|
|
136 |
*/
|
|
137 |
|
|
138 |
EXPORT_C NW_Status_t
|
|
139 |
NW_DOM_AttrVal_initFromString (NW_DOM_AttrVal_t *val,
|
|
140 |
NW_String_t * string)
|
|
141 |
{
|
|
142 |
NW_Status_t status;
|
|
143 |
|
|
144 |
NW_ASSERT(val != NULL);
|
|
145 |
NW_ASSERT(string != NULL);
|
|
146 |
|
|
147 |
status = NW_DOM_AttrVal_setType(val, NW_DOM_ATTR_VAL_STRING);
|
|
148 |
if (status != NW_STAT_SUCCESS)
|
|
149 |
return status;
|
|
150 |
val->component.string = *string;
|
|
151 |
return NW_STAT_SUCCESS;
|
|
152 |
}
|
|
153 |
|
|
154 |
/*
|
|
155 |
* Initializes an AttrVal of type NW_WBXML_ATTR_COMPONENT_ENTITY
|
|
156 |
* Returns NW_STAT_SUCCESS
|
|
157 |
*/
|
|
158 |
|
|
159 |
NW_Status_t
|
|
160 |
NW_DOM_AttrVal_initFromEntity (NW_DOM_AttrVal_t *val,
|
|
161 |
NW_Uint32 entity)
|
|
162 |
{
|
|
163 |
NW_ASSERT(val != NULL);
|
|
164 |
|
|
165 |
val->type = NW_WBXML_ATTR_COMPONENT_ENTITY;
|
|
166 |
val->component.entity = entity;
|
|
167 |
return NW_STAT_SUCCESS;
|
|
168 |
}
|
|
169 |
|
|
170 |
|
|
171 |
/*
|
|
172 |
Initializes an AttrVal of type NW_WBXML_ATTR_COMPONENT_EXT
|
|
173 |
Returns NW_STAT_SUCCESS or NW_STAT_FAILURE if args are not valid.
|
|
174 |
|
|
175 |
Makes a shallow copy of str.
|
|
176 |
*/
|
|
177 |
NW_Status_t
|
|
178 |
NW_DOM_AttrVal_initFromExtension (NW_DOM_AttrVal_t *val,
|
|
179 |
NW_Uint16 token,
|
|
180 |
NW_String_t *str)
|
|
181 |
{
|
|
182 |
NW_Uint8 t; /* 8-bit token */
|
|
183 |
|
|
184 |
NW_ASSERT(val != NULL);
|
|
185 |
NW_ASSERT(token != 0);
|
|
186 |
|
|
187 |
val->type = NW_WBXML_ATTR_COMPONENT_INVALID;
|
|
188 |
t = (NW_Uint8)token;
|
|
189 |
if ((t == NW_WBXML_EXT_0)
|
|
190 |
|| (t == NW_WBXML_EXT_1)
|
|
191 |
|| (t == NW_WBXML_EXT_2)
|
|
192 |
|| (t == NW_WBXML_EXT_T_0)
|
|
193 |
|| (t == NW_WBXML_EXT_T_1)
|
|
194 |
|| (t == NW_WBXML_EXT_T_2)
|
|
195 |
|| (t == NW_WBXML_EXT_I_0)
|
|
196 |
|| (t == NW_WBXML_EXT_I_1)
|
|
197 |
|| (t == NW_WBXML_EXT_I_2)) {
|
|
198 |
if ((t != NW_WBXML_EXT_0)
|
|
199 |
&& (t != NW_WBXML_EXT_1)
|
|
200 |
&& (t != NW_WBXML_EXT_2)
|
|
201 |
&& (str->storage == NULL)) {
|
|
202 |
return NW_STAT_FAILURE;
|
|
203 |
}
|
|
204 |
val->type = NW_WBXML_ATTR_COMPONENT_EXT;
|
|
205 |
val->component.ext.type = NW_TINYDOM_EXTENSION_TYPE_NORMAL;
|
|
206 |
val->component.ext.token = token;
|
|
207 |
if ((t == NW_WBXML_EXT_0)
|
|
208 |
|| (t == NW_WBXML_EXT_1)
|
|
209 |
|| (t == NW_WBXML_EXT_2)) {
|
|
210 |
NW_String_initialize(&(val->component.ext.value.string), NULL, 0);
|
|
211 |
} else {
|
|
212 |
/* struct assignment, shallow copy */
|
|
213 |
val->component.ext.value.string = *str;
|
|
214 |
}
|
|
215 |
return NW_STAT_SUCCESS;
|
|
216 |
}
|
|
217 |
return NW_STAT_FAILURE;
|
|
218 |
}
|
|
219 |
|
|
220 |
NW_Status_t
|
|
221 |
NW_DOM_AttrVal_initFromExtensionInt (NW_DOM_AttrVal_t* val,
|
|
222 |
NW_Uint16 token,
|
|
223 |
NW_Uint32 x)
|
|
224 |
{
|
|
225 |
NW_Uint8 t = (NW_Uint8)token;
|
|
226 |
|
|
227 |
NW_ASSERT(val != NULL);
|
|
228 |
|
|
229 |
if ((t == NW_WBXML_EXT_T_0)
|
|
230 |
|| (t == NW_WBXML_EXT_T_1)
|
|
231 |
|| (t == NW_WBXML_EXT_T_2)) {
|
|
232 |
val->type = NW_WBXML_ATTR_COMPONENT_EXT;
|
|
233 |
val->component.ext.type = NW_TINYDOM_EXTENSION_TYPE_EXT_T_INTEGER;
|
|
234 |
val->component.ext.token = token;
|
|
235 |
val->component.ext.value.x = x;
|
|
236 |
return NW_STAT_SUCCESS;
|
|
237 |
}
|
|
238 |
return NW_STAT_FAILURE;
|
|
239 |
}
|
|
240 |
|
|
241 |
/*
|
|
242 |
* Initializes an AttrVal of type NW_WBXML_ATTR_COMPONENT_OPAQUE
|
|
243 |
* Returns NW_STAT_SUCCESS
|
|
244 |
*/
|
|
245 |
|
|
246 |
NW_Status_t
|
|
247 |
NW_DOM_AttrVal_initFromOpaque (NW_DOM_AttrVal_t *val,
|
|
248 |
NW_Uint32 length,
|
|
249 |
NW_Byte* data)
|
|
250 |
{
|
|
251 |
NW_ASSERT(val != NULL);
|
|
252 |
NW_ASSERT(data != NULL);
|
|
253 |
|
|
254 |
val->type = NW_WBXML_ATTR_COMPONENT_OPAQUE;
|
|
255 |
val->component.opaque.data = data;
|
|
256 |
val->component.opaque.length = length;
|
|
257 |
return NW_STAT_SUCCESS;
|
|
258 |
}
|
|
259 |
|
|
260 |
|
|
261 |
/*
|
|
262 |
* Initializes an AttrVal of type NW_WBXML_ATTR_COMPONENT_TOKEN
|
|
263 |
* Returns NW_STAT_SUCCESS
|
|
264 |
*/
|
|
265 |
|
|
266 |
EXPORT_C NW_Status_t
|
|
267 |
NW_DOM_AttrVal_initFromToken (NW_DOM_AttrVal_t *val, NW_Uint16 token)
|
|
268 |
{
|
|
269 |
NW_ASSERT(val != NULL);
|
|
270 |
|
|
271 |
val->type = NW_WBXML_ATTR_COMPONENT_TOKEN;
|
|
272 |
val->component.value_token = (NW_Uint32)token;
|
|
273 |
return NW_STAT_SUCCESS;
|
|
274 |
}
|
|
275 |
|
|
276 |
|
|
277 |
NW_Status_t
|
|
278 |
NW_DOM_AttrVal_delete (NW_DOM_AttrVal_t * attrVal)
|
|
279 |
{
|
|
280 |
NW_ASSERT(attrVal != NULL);
|
|
281 |
|
|
282 |
NW_Mem_Free(attrVal);
|
|
283 |
|
|
284 |
return NW_STAT_SUCCESS;
|
|
285 |
}
|
|
286 |
|
|
287 |
/*
|
|
288 |
* Returns the type of attribute value
|
|
289 |
*/
|
|
290 |
|
|
291 |
EXPORT_C NW_Uint16
|
|
292 |
NW_DOM_AttrVal_getType(NW_DOM_AttrVal_t *val)
|
|
293 |
{
|
|
294 |
NW_ASSERT(val != NULL);
|
|
295 |
|
|
296 |
switch(val->type)
|
|
297 |
{
|
|
298 |
case NW_WBXML_ATTR_COMPONENT_EXT:
|
|
299 |
return NW_DOM_ATTR_VAL_EXTENSION;
|
|
300 |
case NW_WBXML_ATTR_COMPONENT_STRING:
|
|
301 |
return NW_DOM_ATTR_VAL_STRING;
|
|
302 |
case NW_WBXML_ATTR_COMPONENT_ENTITY:
|
|
303 |
return NW_DOM_ATTR_VAL_ENTITY;
|
|
304 |
case NW_WBXML_ATTR_COMPONENT_TOKEN:
|
|
305 |
return NW_DOM_ATTR_VAL_TOKEN;
|
|
306 |
case NW_WBXML_ATTR_COMPONENT_OPAQUE:
|
|
307 |
return NW_DOM_ATTR_VAL_OPAQUE;
|
|
308 |
default:
|
|
309 |
return 0;
|
|
310 |
}
|
|
311 |
}
|
|
312 |
|
|
313 |
/*
|
|
314 |
* Sets the type of attribute value
|
|
315 |
* Returns NW_STAT_SUCCESS
|
|
316 |
*/
|
|
317 |
|
|
318 |
/* TBD This is a very dangerous function and should be made internal
|
|
319 |
use only (i.e., static)! */
|
|
320 |
NW_Status_t
|
|
321 |
NW_DOM_AttrVal_setType(NW_DOM_AttrVal_t *val,
|
|
322 |
NW_Uint16 type)
|
|
323 |
{
|
|
324 |
NW_ASSERT(val != NULL);
|
|
325 |
|
|
326 |
switch(type)
|
|
327 |
{
|
|
328 |
case NW_DOM_ATTR_VAL_EXTENSION:
|
|
329 |
val->type = NW_WBXML_ATTR_COMPONENT_EXT;
|
|
330 |
break;
|
|
331 |
case NW_DOM_ATTR_VAL_STRING:
|
|
332 |
val->type = NW_WBXML_ATTR_COMPONENT_STRING;
|
|
333 |
break;
|
|
334 |
case NW_DOM_ATTR_VAL_ENTITY:
|
|
335 |
val->type = NW_WBXML_ATTR_COMPONENT_ENTITY;
|
|
336 |
break;
|
|
337 |
case NW_DOM_ATTR_VAL_TOKEN:
|
|
338 |
val->type = NW_WBXML_ATTR_COMPONENT_TOKEN;
|
|
339 |
break;
|
|
340 |
case NW_DOM_ATTR_VAL_OPAQUE:
|
|
341 |
val->type = NW_WBXML_ATTR_COMPONENT_OPAQUE;
|
|
342 |
break;
|
|
343 |
default:
|
|
344 |
return NW_STAT_BAD_INPUT_PARAM;
|
|
345 |
}
|
|
346 |
return NW_STAT_SUCCESS;
|
|
347 |
}
|
|
348 |
|
|
349 |
/*
|
|
350 |
* Returns
|
|
351 |
* NW_STAT_WBXML_ERROR_CHARSET_UNSUPPORTED - invalid encoding
|
|
352 |
* NW_STAT_DOM_NO_STRING_RETURNED - if the type of AttrVal was invalid
|
|
353 |
* NW_STAT_SUCCESS
|
|
354 |
*
|
|
355 |
* MODIFIED string (the value of NW_DOM_AttrVal)
|
|
356 |
*/
|
|
357 |
|
|
358 |
EXPORT_C NW_Status_t
|
|
359 |
NW_DOM_AttrVal_toString(NW_DOM_AttrVal_t *av,
|
|
360 |
NW_String_t * string,
|
|
361 |
NW_Uint32 encoding)
|
|
362 |
{
|
|
363 |
NW_Status_t status;
|
|
364 |
|
|
365 |
NW_ASSERT(av != NULL);
|
|
366 |
NW_ASSERT(string != NULL);
|
|
367 |
|
|
368 |
NW_String_initialize(string, NULL, 0);
|
|
369 |
|
|
370 |
if ((NW_String_charsetValid(encoding)) != NW_STAT_SUCCESS)
|
|
371 |
return NW_STAT_WBXML_ERROR_CHARSET_UNSUPPORTED;
|
|
372 |
|
|
373 |
switch (NW_DOM_AttrVal_getType(av))
|
|
374 |
{
|
|
375 |
case NW_DOM_ATTR_VAL_TOKEN:
|
|
376 |
status = NW_String_tokenToString(av->component.value_token, string, encoding);
|
|
377 |
if(status != NW_STAT_SUCCESS){
|
|
378 |
return NW_STAT_DOM_NO_STRING_RETURNED;
|
|
379 |
}
|
|
380 |
return NW_STAT_SUCCESS;
|
|
381 |
|
|
382 |
case NW_DOM_ATTR_VAL_STRING:
|
|
383 |
{
|
|
384 |
NW_Byte *storage = av->component.string.storage;
|
|
385 |
status = NW_String_initialize(string, storage, encoding);
|
|
386 |
if(status != NW_STAT_SUCCESS){
|
|
387 |
return NW_STAT_DOM_NO_STRING_RETURNED;
|
|
388 |
}
|
|
389 |
return NW_STAT_SUCCESS;
|
|
390 |
}
|
|
391 |
|
|
392 |
case NW_DOM_ATTR_VAL_ENTITY:
|
|
393 |
status = NW_String_entityToString(av->component.entity,
|
|
394 |
string, encoding);
|
|
395 |
if(status != NW_STAT_SUCCESS){
|
|
396 |
return NW_STAT_DOM_NO_STRING_RETURNED;
|
|
397 |
}
|
|
398 |
return NW_STAT_SUCCESS;
|
|
399 |
|
|
400 |
case NW_DOM_ATTR_VAL_OPAQUE:
|
|
401 |
return NW_STAT_DOM_NO_STRING_RETURNED;
|
|
402 |
case NW_DOM_ATTR_VAL_EXTENSION:
|
|
403 |
{
|
|
404 |
NW_Uint8 t; /* 8-bit token */
|
|
405 |
|
|
406 |
t = (NW_Uint8)(av->component.ext.token);
|
|
407 |
if ((t == NW_WBXML_EXT_0)
|
|
408 |
|| (t == NW_WBXML_EXT_1)
|
|
409 |
|| (t == NW_WBXML_EXT_2)) {
|
|
410 |
return NW_STAT_DOM_NO_STRING_RETURNED;
|
|
411 |
}
|
|
412 |
if (av->component.ext.value.string.storage == NULL) {
|
|
413 |
return NW_STAT_DOM_NO_STRING_RETURNED;
|
|
414 |
}
|
|
415 |
/* struct assignment, shallow copy */
|
|
416 |
*string = av->component.ext.value.string;
|
|
417 |
return NW_STAT_SUCCESS;
|
|
418 |
}
|
|
419 |
default:
|
|
420 |
return NW_STAT_DOM_NO_STRING_RETURNED;
|
|
421 |
}
|
|
422 |
}
|
|
423 |
|
|
424 |
/*
|
|
425 |
* If attribute value is of type NW_DOM_ATTR_VAL_ENTITY
|
|
426 |
* return the associated entity
|
|
427 |
*/
|
|
428 |
|
|
429 |
NW_Uint32
|
|
430 |
NW_DOM_AttrVal_getEntity(NW_DOM_AttrVal_t *val)
|
|
431 |
{
|
|
432 |
NW_ASSERT(val != NULL);
|
|
433 |
|
|
434 |
if (NW_DOM_AttrVal_getType(val) != NW_DOM_ATTR_VAL_ENTITY)
|
|
435 |
return val->component.entity;
|
|
436 |
return 0;
|
|
437 |
}
|
|
438 |
|
|
439 |
NW_Status_t
|
|
440 |
NW_DOM_AttrVal_getExtensionToken(NW_DOM_AttrVal_t* val,
|
|
441 |
NW_Uint16* token)
|
|
442 |
{
|
|
443 |
if (NW_DOM_AttrVal_getType(val) != NW_DOM_ATTR_VAL_EXTENSION) {
|
|
444 |
return NW_STAT_FAILURE;
|
|
445 |
}
|
|
446 |
*token = (NW_Uint16)(val->component.ext.token);
|
|
447 |
return NW_STAT_SUCCESS;
|
|
448 |
}
|
|
449 |
|
|
450 |
/* If attribute value is of type NW_DOM_TEXT_ITEM_EXTENSION returns token
|
|
451 |
otherwise returns 0 and returns str->length = 0, str->storage = NULL.
|
|
452 |
|
|
453 |
All returned strings are shallow copies and the only proper way to
|
|
454 |
free these is to call NW_String_delete(pStr). */
|
|
455 |
EXPORT_C NW_Uint16
|
|
456 |
NW_DOM_AttrVal_getExtension(NW_DOM_AttrVal_t *val,
|
|
457 |
NW_String_t *str)
|
|
458 |
{
|
|
459 |
NW_Uint16 fqToken;
|
|
460 |
NW_Uint8 t; /* 8-bit token */
|
|
461 |
|
|
462 |
NW_ASSERT (val != NULL);
|
|
463 |
NW_ASSERT (str != NULL);
|
|
464 |
|
|
465 |
NW_String_initialize(str, NULL, 0);
|
|
466 |
|
|
467 |
if (NW_DOM_AttrVal_getType(val) != NW_DOM_ATTR_VAL_EXTENSION) {
|
|
468 |
return 0;
|
|
469 |
}
|
|
470 |
|
|
471 |
/* TBD If it could be gauranteed that the extension was constructed
|
|
472 |
correctly then it would be enough to just unconditionally
|
|
473 |
shallowCopy. */
|
|
474 |
|
|
475 |
fqToken = (NW_Uint16)(val->component.ext.token);
|
|
476 |
t = (NW_Uint8)fqToken;
|
|
477 |
|
|
478 |
if (((t == NW_WBXML_EXT_T_0)
|
|
479 |
|| (t == NW_WBXML_EXT_T_1)
|
|
480 |
|| (t == NW_WBXML_EXT_T_2))
|
|
481 |
&& (val->component.ext.type
|
|
482 |
== NW_TINYDOM_EXTENSION_TYPE_EXT_T_INTEGER)) {
|
|
483 |
/* This function is not for this case: use "getExtensionInt" form. */
|
|
484 |
return 0;
|
|
485 |
}
|
|
486 |
|
|
487 |
if ((t != NW_WBXML_EXT_0) && (t != NW_WBXML_EXT_1) && (t != NW_WBXML_EXT_2)) {
|
|
488 |
/* By fiat we do nothing with the single byte extension tokens. A
|
|
489 |
more correct version might be to callback to the client to
|
|
490 |
request a mapping to a client determined string.
|
|
491 |
|
|
492 |
In the normal case where EXT_T refers to the string table, both
|
|
493 |
the EXT_T and EXT_I forms are represented by an explicit pointer
|
|
494 |
to the string value since for the EXT_T form we don't have a
|
|
495 |
pointer to the string table anyway. */
|
|
496 |
NW_String_shallowCopy(str, &val->component.ext.value.string);
|
|
497 |
}
|
|
498 |
return fqToken;
|
|
499 |
}
|
|
500 |
|
|
501 |
NW_Status_t
|
|
502 |
NW_DOM_AttrVal_getExtensionInt(NW_DOM_AttrVal_t* val,
|
|
503 |
NW_Uint32* x)
|
|
504 |
{
|
|
505 |
NW_Uint16 fqToken;
|
|
506 |
NW_Uint8 t; /* 8-bit token */
|
|
507 |
|
|
508 |
NW_ASSERT(val != NULL);
|
|
509 |
NW_ASSERT(x != NULL);
|
|
510 |
|
|
511 |
if ((NW_DOM_AttrVal_getType(val) != NW_DOM_ATTR_VAL_EXTENSION)
|
|
512 |
|| ((val->component.ext.type
|
|
513 |
!= NW_TINYDOM_EXTENSION_TYPE_EXT_T_INTEGER)))
|
|
514 |
{
|
|
515 |
return NW_STAT_FAILURE;
|
|
516 |
}
|
|
517 |
|
|
518 |
fqToken = (NW_Uint16)(val->component.ext.token);
|
|
519 |
t = (NW_Uint8)fqToken;
|
|
520 |
if ((t == NW_WBXML_EXT_T_0)
|
|
521 |
|| (t == NW_WBXML_EXT_T_1)
|
|
522 |
|| (t == NW_WBXML_EXT_T_2)) {
|
|
523 |
*x = val->component.ext.value.x;
|
|
524 |
return NW_STAT_SUCCESS;
|
|
525 |
}
|
|
526 |
return NW_STAT_FAILURE;
|
|
527 |
}
|
|
528 |
|
|
529 |
/*
|
|
530 |
* If attribute value is of type NW_DOM_ATTR_VAL_OPAQUE
|
|
531 |
* returns the associated opaque data and length.
|
|
532 |
*/
|
|
533 |
|
|
534 |
/* Note: change the signature so both values are out params? */
|
|
535 |
|
|
536 |
EXPORT_C NW_Byte *
|
|
537 |
NW_DOM_AttrVal_getOpaque(NW_DOM_AttrVal_t *val,
|
|
538 |
NW_Uint32 *opaqueLen)
|
|
539 |
{
|
|
540 |
NW_ASSERT(val != NULL);
|
|
541 |
NW_ASSERT(opaqueLen != NULL);
|
|
542 |
|
|
543 |
if (NW_DOM_AttrVal_getType(val) != NW_DOM_ATTR_VAL_OPAQUE)
|
|
544 |
return NULL;
|
|
545 |
|
|
546 |
*opaqueLen = val->component.opaque.length;
|
|
547 |
return val->component.opaque.data;
|
|
548 |
}
|
|
549 |
|
|
550 |
/*
|
|
551 |
* If attribute value is of type NW_WBXML_ATTR_COMPONENT_TOKEN,
|
|
552 |
* returns the associated token
|
|
553 |
*/
|
|
554 |
|
|
555 |
NW_Uint16
|
|
556 |
NW_DOM_AttrVal_getToken(NW_DOM_AttrVal_t *val)
|
|
557 |
{
|
|
558 |
NW_ASSERT(val != NULL);
|
|
559 |
|
|
560 |
if (val->type == NW_WBXML_ATTR_COMPONENT_TOKEN)
|
|
561 |
return (NW_Uint16)val->component.value_token;
|
|
562 |
|
|
563 |
return 0;
|
|
564 |
}
|
|
565 |
|
|
566 |
|
|
567 |
/*****************************************
|
|
568 |
* ATTRIBUTE VAL ITERATOR
|
|
569 |
* iterates over the values of an attribute
|
|
570 |
******************************************/
|
|
571 |
|
|
572 |
EXPORT_C NW_Uint32
|
|
573 |
NW_DOM_AttributeHandle_getEncoding(NW_DOM_AttributeHandle_t *handle)
|
|
574 |
{
|
|
575 |
NW_ASSERT(handle != NULL);
|
|
576 |
|
|
577 |
return handle->tinyHandle.tlit.tiny_parser->dom_tree->doc->charset;
|
|
578 |
}
|
|
579 |
/* the following functions are not referenced, 8/12/01 */
|
|
580 |
/*
|
|
581 |
NW_Uint32
|
|
582 |
NW_DOM_AttributeHandle_getPublicId(NW_DOM_AttributeHandle_t *handle)
|
|
583 |
{
|
|
584 |
NW_ASSERT(handle != NULL);
|
|
585 |
|
|
586 |
return handle->tinyHandle.tlit.tiny_parser->dom_tree->doc->publicid;
|
|
587 |
}
|
|
588 |
|
|
589 |
|
|
590 |
NW_Status_t
|
|
591 |
NW_DOM_AttributeHandle_getDocType(NW_DOM_AttributeHandle_t *handle,
|
|
592 |
NW_String_t *str)
|
|
593 |
{
|
|
594 |
NW_String_t *docType;
|
|
595 |
|
|
596 |
NW_ASSERT(handle != NULL);
|
|
597 |
NW_ASSERT(str != NULL);
|
|
598 |
|
|
599 |
docType = handle->tinyHandle.tlit.tiny_parser->dom_tree->doc->doc_type;
|
|
600 |
return NW_String_shallowCopy(str, docType);
|
|
601 |
}
|
|
602 |
*/
|
|
603 |
|
|
604 |
/*
|
|
605 |
* Allocates memory for NW_DOM_AttributeHandle
|
|
606 |
* Returns NULL in case of failure to do so
|
|
607 |
*/
|
|
608 |
|
|
609 |
NW_DOM_AttributeHandle_t *
|
|
610 |
NW_DOM_AttributeHandle_new(void)
|
|
611 |
{
|
|
612 |
NW_DOM_AttributeHandle_t *handle =
|
|
613 |
(NW_DOM_AttributeHandle_t *) NW_Mem_Malloc(sizeof (NW_DOM_AttributeHandle_t));
|
|
614 |
if (handle == NULL){
|
|
615 |
return NULL;
|
|
616 |
}
|
|
617 |
handle->node = NULL;
|
|
618 |
return handle;
|
|
619 |
}
|
|
620 |
|
|
621 |
/* Initializes an attribute handle with an attribute node. Note that
|
|
622 |
only some attributes have nodes of their own. Such attributes are
|
|
623 |
initilized by this method. Also, this method initializes the
|
|
624 |
attribute handle so that it may be used by
|
|
625 |
NW_DOM_AttributeHandle_addVal().
|
|
626 |
|
|
627 |
Returns NW_STAT_SUCCESS */
|
|
628 |
|
|
629 |
NW_Status_t
|
|
630 |
NW_DOM_AttributeHandle_initWithNode(NW_DOM_AttributeHandle_t *handle,
|
|
631 |
NW_TinyDom_Parser_t *parser,
|
|
632 |
NW_TinyTree_Node_t *node)
|
|
633 |
{
|
|
634 |
NW_TinyTree_Offset_t offset;
|
|
635 |
|
|
636 |
NW_ASSERT(handle != NULL);
|
|
637 |
NW_ASSERT(node != NULL);
|
|
638 |
NW_ASSERT(parser != NULL);
|
|
639 |
|
|
640 |
offset = NW_TinyTree_Node_getSourceOffset(node);
|
|
641 |
handle->node = node;
|
|
642 |
NW_TinyDom_AttributeHandle_init(&handle->tinyHandle, parser, offset);
|
|
643 |
return NW_STAT_SUCCESS;
|
|
644 |
}
|
|
645 |
|
|
646 |
/*
|
|
647 |
* Initializes and Attribute Handle with a offset.
|
|
648 |
* Returns NW_STAT_SUCCESS
|
|
649 |
*/
|
|
650 |
|
|
651 |
NW_Status_t
|
|
652 |
NW_DOM_AttributeHandle_initWithOffset(NW_DOM_AttributeHandle_t *handle,
|
|
653 |
NW_TinyDom_Parser_t *parser,
|
|
654 |
NW_TinyTree_Offset_t offset)
|
|
655 |
{
|
|
656 |
NW_ASSERT(handle != NULL);
|
|
657 |
NW_ASSERT(parser != NULL);
|
|
658 |
|
|
659 |
handle->node = NULL;
|
|
660 |
NW_TinyDom_AttributeHandle_init(&handle->tinyHandle, parser, offset);
|
|
661 |
return NW_STAT_SUCCESS;
|
|
662 |
}
|
|
663 |
|
|
664 |
EXPORT_C NW_Status_t
|
|
665 |
NW_DOM_AttributeHandle_initWithStartToken(NW_DOM_AttributeHandle_t* handle,
|
|
666 |
NW_TinyDom_Parser_t* parser,
|
|
667 |
NW_Uint16 fqToken)
|
|
668 |
{
|
|
669 |
NW_ASSERT(handle != NULL);
|
|
670 |
NW_ASSERT(parser != NULL);
|
|
671 |
|
|
672 |
handle->node = NULL;
|
|
673 |
return NW_TinyDom_AttributeHandle_initWithStartToken(&handle->tinyHandle,
|
|
674 |
&handle->node,
|
|
675 |
parser,
|
|
676 |
fqToken);
|
|
677 |
}
|
|
678 |
|
|
679 |
EXPORT_C NW_Status_t
|
|
680 |
NW_DOM_AttributeHandle_addVal(NW_DOM_AttributeHandle_t* handle,
|
|
681 |
NW_DOM_AttrVal_t* value)
|
|
682 |
{
|
|
683 |
NW_ASSERT(handle != NULL);
|
|
684 |
NW_ASSERT(value != NULL);
|
|
685 |
|
|
686 |
return NW_TinyDom_AttributeHandle_addVal(&(handle->tinyHandle),
|
|
687 |
handle->node,
|
|
688 |
value);
|
|
689 |
}
|
|
690 |
|
|
691 |
NW_Status_t
|
|
692 |
NW_DOM_AttributeHandle_delete(NW_DOM_AttributeHandle_t *handle)
|
|
693 |
{
|
|
694 |
NW_ASSERT(handle != NULL);
|
|
695 |
|
|
696 |
NW_Mem_Free(handle);
|
|
697 |
return NW_STAT_SUCCESS;
|
|
698 |
}
|
|
699 |
|
|
700 |
/*
|
|
701 |
* Returns the attribute name (without prefix if any)
|
|
702 |
* Returns
|
|
703 |
* NW_STAT_OUT_OF_MEMORY
|
|
704 |
* NW_STAT_DOM_NO_STRING_RETURNED
|
|
705 |
* NW_STAT_SUCCESS
|
|
706 |
*
|
|
707 |
* Modifies attributeName
|
|
708 |
*/
|
|
709 |
|
|
710 |
EXPORT_C NW_Status_t
|
|
711 |
NW_DOM_AttributeHandle_getName(NW_DOM_AttributeHandle_t *handle,
|
|
712 |
NW_String_t* attributeName)
|
|
713 |
{
|
|
714 |
NW_Status_t status;
|
|
715 |
NW_Byte *p; /* pointer to find '=' sign location */
|
|
716 |
NW_Uint32 encoding;
|
|
717 |
NW_String_t temp;
|
|
718 |
|
|
719 |
NW_ASSERT(handle != NULL);
|
|
720 |
NW_ASSERT(attributeName != NULL);
|
|
721 |
|
|
722 |
encoding = NW_DOM_AttributeHandle_getEncoding(handle);
|
|
723 |
|
|
724 |
status = NW_DOM_AttributeHandle_getNameWithPrefix(handle, attributeName);
|
|
725 |
if (status != NW_STAT_SUCCESS)
|
|
726 |
return status;
|
|
727 |
|
|
728 |
/*
|
|
729 |
* Before returning the attribute name, strip off any
|
|
730 |
* part that is actually the attribute value's prefix.
|
|
731 |
* For example, if name is "href=http://", the name
|
|
732 |
* that should be returned is only "href".
|
|
733 |
*/
|
|
734 |
if ((p = NW_String_findChar(attributeName, '=', encoding)) != NULL)
|
|
735 |
{
|
|
736 |
/* There an attribute value_prefix - so strip prefix
|
|
737 |
* Create a new string without the '=...' or there
|
|
738 |
* will be wasted memory.
|
|
739 |
*/
|
|
740 |
status = NW_String_deepCopy(&temp, attributeName);
|
|
741 |
if (status != NW_STAT_SUCCESS) {
|
|
742 |
return status;
|
|
743 |
}
|
|
744 |
/* set rest of buffer to NULL */
|
|
745 |
p = NW_String_findChar(&temp, '=', encoding);
|
|
746 |
NW_Mem_memset(p, 0, (NW_Uint32)(temp.storage + NW_String_getByteCount(&temp) - p));
|
|
747 |
|
|
748 |
/* Free up any user-owned storage in original string */
|
|
749 |
NW_String_deleteStorage(attributeName);
|
|
750 |
status = NW_String_initialize(attributeName, temp.storage, encoding);
|
|
751 |
NW_String_setUserOwnsStorage(attributeName);
|
|
752 |
}
|
|
753 |
|
|
754 |
return NW_STAT_SUCCESS;
|
|
755 |
}
|
|
756 |
|
|
757 |
/*
|
|
758 |
* Returns the token for the attribute
|
|
759 |
*/
|
|
760 |
|
|
761 |
EXPORT_C NW_Uint16
|
|
762 |
NW_DOM_AttributeHandle_getToken(NW_DOM_AttributeHandle_t *handle)
|
|
763 |
{
|
|
764 |
NW_ASSERT(handle != NULL);
|
|
765 |
|
|
766 |
return (NW_Uint16)NW_TinyDom_AttributeHandle_getToken(&handle->tinyHandle);
|
|
767 |
}
|
|
768 |
|
|
769 |
/*
|
|
770 |
* Returns the attribute prefix (for e.g. href="http://"
|
|
771 |
* will return "http://"
|
|
772 |
* Returns
|
|
773 |
* NW_STAT_OUT_OF_MEMORY
|
|
774 |
* NW_STAT_DOM_NO_STRING_RETURNED
|
|
775 |
* NW_STAT_DOM_NO_VALUE_PREFIX
|
|
776 |
* NW_STAT_SUCCESS
|
|
777 |
*
|
|
778 |
* Modifies prefixName
|
|
779 |
*/
|
|
780 |
|
|
781 |
EXPORT_C NW_Status_t
|
|
782 |
NW_DOM_AttributeHandle_getValuePrefix(NW_DOM_AttributeHandle_t *handle,
|
|
783 |
NW_String_t* prefixName)
|
|
784 |
{
|
|
785 |
NW_Status_t status;
|
|
786 |
NW_Byte *p = NULL;
|
|
787 |
NW_Uint32 encoding;
|
|
788 |
|
|
789 |
NW_ASSERT(handle != NULL);
|
|
790 |
NW_ASSERT(prefixName != NULL);
|
|
791 |
|
|
792 |
encoding = NW_DOM_AttributeHandle_getEncoding(handle);
|
|
793 |
status = NW_DOM_AttributeHandle_getNameWithPrefix(handle, prefixName);
|
|
794 |
|
|
795 |
if (status != NW_STAT_SUCCESS)
|
|
796 |
return status;
|
|
797 |
|
|
798 |
if ((p = NW_String_findChar(prefixName, '=', encoding)) != NULL)
|
|
799 |
{
|
|
800 |
NW_Uint32 len = 0;
|
|
801 |
NW_Byte *prefix = NULL;
|
|
802 |
/* Now make a new string with just the value's prefix */
|
|
803 |
p++;
|
|
804 |
|
|
805 |
if(NW_String_charBuffGetLength(p, encoding, &len) < 0){
|
|
806 |
return NW_STAT_DOM_NO_STRING_RETURNED;
|
|
807 |
}
|
|
808 |
|
|
809 |
prefix = (NW_Byte *) NW_Mem_Malloc(len);
|
|
810 |
if (prefix == NULL)
|
|
811 |
return NW_STAT_OUT_OF_MEMORY;
|
|
812 |
|
|
813 |
NW_Mem_memcpy(prefix, p, len);
|
|
814 |
/* Free up any user-owned storage in old name */
|
|
815 |
NW_String_deleteStorage(prefixName);
|
|
816 |
status = NW_String_initialize(prefixName, prefix, encoding);
|
|
817 |
if (status != NW_STAT_SUCCESS){
|
|
818 |
return NW_STAT_DOM_NO_STRING_RETURNED;
|
|
819 |
}
|
|
820 |
return NW_String_setUserOwnsStorage(prefixName);
|
|
821 |
}else{
|
|
822 |
NW_String_deleteStorage(prefixName);
|
|
823 |
return NW_STAT_DOM_NO_VALUE_PREFIX;
|
|
824 |
}
|
|
825 |
}
|
|
826 |
|
|
827 |
/*
|
|
828 |
* Returns the attribute name with prefix
|
|
829 |
* Returns
|
|
830 |
* NW_STAT_OUT_OF_MEMORY
|
|
831 |
* NW_STAT_DOM_NO_STRING_RETURNED
|
|
832 |
* NW_STAT_SUCCESS
|
|
833 |
*
|
|
834 |
* Modifies attributeName
|
|
835 |
*/
|
|
836 |
|
|
837 |
NW_Status_t
|
|
838 |
NW_DOM_AttributeHandle_getNameWithPrefix(NW_DOM_AttributeHandle_t* handle,
|
|
839 |
NW_String_t* attrName)
|
|
840 |
{
|
|
841 |
NW_Status_t status;
|
|
842 |
NW_Uint32 token;
|
|
843 |
NW_Uint32 encoding;
|
|
844 |
|
|
845 |
NW_ASSERT(handle != NULL);
|
|
846 |
NW_ASSERT(attrName != NULL);
|
|
847 |
|
|
848 |
token = NW_TinyDom_AttributeHandle_getToken(&handle->tinyHandle);
|
|
849 |
encoding = NW_DOM_AttributeHandle_getEncoding(handle);
|
|
850 |
status = NW_TinyDom_AttributeHandle_getName(&handle->tinyHandle, attrName);
|
|
851 |
|
|
852 |
if (status == NW_STAT_SUCCESS)
|
|
853 |
return NW_STAT_SUCCESS;
|
|
854 |
|
|
855 |
if (status == NW_STAT_WBXML_NO_NAME){
|
|
856 |
status = NW_String_tokenToString(token, attrName, encoding);
|
|
857 |
if(status == NW_STAT_OUT_OF_MEMORY){
|
|
858 |
return status;
|
|
859 |
}
|
|
860 |
if(status != NW_STAT_SUCCESS){
|
|
861 |
return NW_STAT_DOM_NO_STRING_RETURNED;
|
|
862 |
}
|
|
863 |
return NW_STAT_SUCCESS;
|
|
864 |
}
|
|
865 |
return NW_STAT_DOM_NO_STRING_RETURNED;
|
|
866 |
}
|
|
867 |
|
|
868 |
/*
|
|
869 |
* Returns
|
|
870 |
* NW_STAT_WBXML_ITERATE_MORE
|
|
871 |
* NW_STAT_WBXML_ITERATE_DONE
|
|
872 |
*
|
|
873 |
* Modifies attrVal (the next NW_DOM_AttrVal in the attribute value list
|
|
874 |
*/
|
|
875 |
|
|
876 |
EXPORT_C NW_Status_t
|
|
877 |
NW_DOM_AttributeHandle_getNextVal(NW_DOM_AttributeHandle_t *handle,
|
|
878 |
NW_DOM_AttrVal_t *attrVal)
|
|
879 |
{
|
|
880 |
NW_TinyTree_Offset_t offset;
|
|
881 |
|
|
882 |
NW_ASSERT(handle != NULL);
|
|
883 |
NW_ASSERT(attrVal != NULL);
|
|
884 |
|
|
885 |
offset = NW_TinyDom_AttributeHandle_iterateValues(&handle->tinyHandle,
|
|
886 |
attrVal);
|
|
887 |
|
|
888 |
if (offset == 0)
|
|
889 |
return NW_STAT_WBXML_ITERATE_DONE;
|
|
890 |
|
|
891 |
return NW_STAT_WBXML_ITERATE_MORE;
|
|
892 |
}
|
|
893 |
|
|
894 |
/*
|
|
895 |
* Returns
|
|
896 |
* NW_STAT_DOM_NO_STRING_RETURNED
|
|
897 |
* NW_STAT_SUCCESS
|
|
898 |
*
|
|
899 |
* output valueString is the complete string representation of attribute value
|
|
900 |
*/
|
|
901 |
|
|
902 |
EXPORT_C NW_Status_t
|
|
903 |
NW_DOM_AttributeHandle_getValue(NW_DOM_AttributeHandle_t *handle,
|
|
904 |
NW_String_t* valueString)
|
|
905 |
{
|
|
906 |
NW_String_t str;
|
|
907 |
NW_Uint32 encoding;
|
|
908 |
NW_Status_t status;
|
|
909 |
NW_Bool prefixFound = NW_FALSE;
|
|
910 |
|
|
911 |
NW_ASSERT(handle != NULL);
|
|
912 |
NW_ASSERT(valueString != NULL);
|
|
913 |
|
|
914 |
encoding = NW_DOM_AttributeHandle_getEncoding(handle);
|
|
915 |
|
|
916 |
valueString->storage = NULL;
|
|
917 |
valueString->length = 0;
|
|
918 |
|
|
919 |
/*
|
|
920 |
* If this attribute's name includes the an attribute value
|
|
921 |
* prefix (e.g. name is something like "href=http://"), then
|
|
922 |
* the attribute's value prefix must be extracted.
|
|
923 |
*/
|
|
924 |
status = NW_DOM_AttributeHandle_getValuePrefix(handle, &str);
|
|
925 |
if (status == NW_STAT_SUCCESS) {
|
|
926 |
status = NW_String_deepCopy(valueString, &str);
|
|
927 |
|
|
928 |
if (status != NW_STAT_SUCCESS){
|
|
929 |
NW_String_deleteStorage(&str);
|
|
930 |
if (status == NW_STAT_OUT_OF_MEMORY)
|
|
931 |
{
|
|
932 |
return NW_STAT_OUT_OF_MEMORY;
|
|
933 |
}
|
|
934 |
else
|
|
935 |
{
|
|
936 |
return NW_STAT_DOM_NO_STRING_RETURNED;
|
|
937 |
}
|
|
938 |
}
|
|
939 |
prefixFound = NW_TRUE;
|
|
940 |
}
|
|
941 |
else if(status != NW_STAT_DOM_NO_VALUE_PREFIX){
|
|
942 |
return status;
|
|
943 |
}
|
|
944 |
|
|
945 |
status = NW_DOM_WbxmlComponent_sequenceToString(NW_WBXML_ATTRIBUTE_VALUE_COMPONENT,
|
|
946 |
&(handle->tinyHandle),
|
|
947 |
encoding,valueString);
|
|
948 |
|
|
949 |
if( (status == NW_STAT_DOM_NO_STRING_RETURNED) &&
|
|
950 |
(valueString->length == 0) &&
|
|
951 |
(prefixFound == NW_TRUE) )
|
|
952 |
{
|
|
953 |
|
|
954 |
status = NW_String_deepCopy(valueString, &str);
|
|
955 |
}
|
|
956 |
|
|
957 |
NW_String_deleteStorage(&str);
|
|
958 |
return status;
|
|
959 |
|
|
960 |
}
|
|
961 |
|
|
962 |
/*
|
|
963 |
* PROCESSING_INSTRUCTION NODE
|
|
964 |
*/
|
|
965 |
|
|
966 |
/*
|
|
967 |
* Gets the name of the target for this processing instruction
|
|
968 |
* Returns one of:
|
|
969 |
* NW_STAT_DOM_NODE_TYPE_ERR - not a DOM_ProcessingInstructionNode_t node
|
|
970 |
* NW_STAT_DOM_NO_STRING_RETURNED
|
|
971 |
* NW_STAT_SUCCESS
|
|
972 |
*/
|
|
973 |
|
|
974 |
NW_Status_t
|
|
975 |
NW_DOM_ProcessingInstructionNode_getTarget(NW_DOM_ProcessingInstructionNode_t* node,
|
|
976 |
NW_String_t *target)
|
|
977 |
{
|
|
978 |
NW_DOM_AttributeHandle_t attrHandle;
|
|
979 |
NW_Status_t status;
|
|
980 |
|
|
981 |
NW_ASSERT(node != NULL);
|
|
982 |
NW_ASSERT(target != NULL);
|
|
983 |
|
|
984 |
status = NW_DOM_ProcessingInstructionNode_getHandle(node, &attrHandle);
|
|
985 |
if (status != NW_STAT_SUCCESS)
|
|
986 |
return status;
|
|
987 |
|
|
988 |
return NW_DOM_AttributeHandle_getName(&attrHandle, target);
|
|
989 |
}
|
|
990 |
|
|
991 |
/*
|
|
992 |
* Returns the token associated with the PI node (WBXML specific
|
|
993 |
*/
|
|
994 |
|
|
995 |
EXPORT_C NW_Uint16
|
|
996 |
NW_DOM_ProcessingInstructionNode_getTargetToken (NW_DOM_ProcessingInstructionNode_t* node)
|
|
997 |
{
|
|
998 |
NW_DOM_AttributeHandle_t attrHandle;
|
|
999 |
NW_Status_t status;
|
|
1000 |
|
|
1001 |
NW_ASSERT(node != NULL);
|
|
1002 |
|
|
1003 |
status = NW_DOM_ProcessingInstructionNode_getHandle(node, &attrHandle);
|
|
1004 |
|
|
1005 |
if (status != NW_STAT_SUCCESS)
|
|
1006 |
return (NW_Uint16)0;
|
|
1007 |
|
|
1008 |
return NW_DOM_AttributeHandle_getToken(&attrHandle);
|
|
1009 |
}
|
|
1010 |
|
|
1011 |
/*
|
|
1012 |
* Returns one of:
|
|
1013 |
* NW_STAT_DOM_NODE_TYPE_ERR - not a NW_DOM_ProcessingInstructionNode_t node
|
|
1014 |
* NW_STAT_DOM_NO_STRING_RETURNED
|
|
1015 |
* NW_STAT_SUCCESS
|
|
1016 |
*/
|
|
1017 |
|
|
1018 |
NW_Status_t
|
|
1019 |
NW_DOM_ProcessingInstructionNode_getData(NW_DOM_ProcessingInstructionNode_t* node,
|
|
1020 |
NW_String_t *data)
|
|
1021 |
{
|
|
1022 |
NW_DOM_AttributeHandle_t attrHandle;
|
|
1023 |
NW_Status_t status;
|
|
1024 |
|
|
1025 |
NW_ASSERT(node != NULL);
|
|
1026 |
NW_ASSERT(data != NULL);
|
|
1027 |
|
|
1028 |
status = NW_DOM_ProcessingInstructionNode_getHandle(node, &attrHandle);
|
|
1029 |
|
|
1030 |
if (status != NW_STAT_SUCCESS)
|
|
1031 |
return status;
|
|
1032 |
|
|
1033 |
return NW_DOM_AttributeHandle_getValue(&attrHandle, data);
|
|
1034 |
}
|
|
1035 |
|
|
1036 |
|
|
1037 |
/*
|
|
1038 |
* Gets the attribute handle associated with the node
|
|
1039 |
* Returns one of:
|
|
1040 |
* NW_STAT_DOM_NODE_TYPE_ERR - not a processing instruction node
|
|
1041 |
* NW_STAT_SUCCESS
|
|
1042 |
* Modifies handle
|
|
1043 |
*/
|
|
1044 |
|
|
1045 |
NW_Status_t
|
|
1046 |
NW_DOM_ProcessingInstructionNode_getHandle(NW_DOM_ProcessingInstructionNode_t* node,
|
|
1047 |
NW_DOM_AttributeHandle_t *handle)
|
|
1048 |
{
|
|
1049 |
NW_TinyTree_t* tiny_tree;
|
|
1050 |
NW_DOM_Node_t *child;
|
|
1051 |
|
|
1052 |
NW_ASSERT(node != NULL);
|
|
1053 |
NW_ASSERT(handle != NULL);
|
|
1054 |
|
|
1055 |
if (NW_DOM_Node_getNodeType(node) != NW_DOM_PROCESSING_INSTRUCTION_NODE)
|
|
1056 |
return NW_STAT_DOM_NODE_TYPE_ERR;
|
|
1057 |
|
|
1058 |
tiny_tree = NW_TinyTree_Node_findTree(node);
|
|
1059 |
child = NW_TinyTree_findFirstChild(node);
|
|
1060 |
|
|
1061 |
while(child){
|
|
1062 |
if (NW_TinyDom_Node_getType(child) == T_DOM_NODE_ATTR){
|
|
1063 |
break;
|
|
1064 |
}
|
|
1065 |
child = NW_TinyTree_findNextSibling(child);
|
|
1066 |
}
|
|
1067 |
if (child) {
|
|
1068 |
return NW_DOM_AttributeHandle_initWithNode(handle,
|
|
1069 |
NW_TinyDom_getParser(tiny_tree),
|
|
1070 |
child);
|
|
1071 |
}
|
|
1072 |
return NW_STAT_DOM_NODE_TYPE_ERR;
|
|
1073 |
}
|