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_node.h>
|
|
21 |
#include <xml/cxml/nw_dom_document.h>
|
|
22 |
#include <xml/cxml/nw_dom_element.h>
|
|
23 |
#include <xml/cxml/nw_tinytree.h>
|
|
24 |
#include <xml/cxml/nw_encoder_wbxmlwriter.h>
|
|
25 |
#include <xml/cxml/nw_xmlp_xmlp2wbxml.h>
|
|
26 |
#include <xml/cxml/nw_tinydom_utils.h>
|
|
27 |
|
|
28 |
/*#include "nw_parser.h"*/
|
|
29 |
|
|
30 |
/************************
|
|
31 |
* DOCUMENT - NODE Methods
|
|
32 |
*************************/
|
|
33 |
|
|
34 |
EXPORT_C void
|
|
35 |
NW_DOM_DocumentNode_Delete(NW_DOM_DocumentNode_t* docNode){
|
|
36 |
NW_WBXML_Parser_t *wbxmlParser;
|
|
37 |
NW_TinyDom_Tree_t *tinyDomTree;
|
|
38 |
NW_WBXML_Document_t *document;
|
|
39 |
NW_TinyTree_t *tinyTree;
|
|
40 |
|
|
41 |
if (docNode == NULL) {
|
|
42 |
return;
|
|
43 |
}
|
|
44 |
|
|
45 |
tinyTree = NW_TinyTree_Node_findTree(docNode);
|
|
46 |
|
|
47 |
if(tinyTree != NULL){
|
|
48 |
document = NW_TinyDom_getDocHeader(tinyTree);
|
|
49 |
tinyDomTree = NW_TinyDom_getTree(tinyTree);
|
|
50 |
wbxmlParser = tinyDomTree->parser;
|
|
51 |
if(wbxmlParser != NULL){
|
|
52 |
NW_WBXML_Parser_delete(wbxmlParser);
|
|
53 |
}
|
|
54 |
if(tinyDomTree != NULL){
|
|
55 |
NW_TinyDom_Tree_destruct(tinyDomTree);
|
|
56 |
}
|
|
57 |
if(document != NULL){
|
|
58 |
NW_WBXML_Document_destruct(document);
|
|
59 |
}
|
|
60 |
}
|
|
61 |
}
|
|
62 |
/* ???? Does the writer need any cleanup ? */
|
|
63 |
|
|
64 |
|
|
65 |
static void
|
|
66 |
NW_TinyDom_Handle_Initialize(NW_TinyDom_Handle_t *h,
|
|
67 |
NW_Uint32 default_public_id,
|
|
68 |
NW_Bool extTNotStringTable)
|
|
69 |
{
|
|
70 |
NW_ASSERT(h != NULL);
|
|
71 |
|
|
72 |
(void) NW_Mem_memset(h, 0, sizeof(*h));
|
|
73 |
|
|
74 |
NW_WBXML_Parser_newInPlace (&(h->wbxmlParser));
|
|
75 |
h->wbxmlParser.ext_t_not_table_index =(NW_Uint8)((extTNotStringTable == NW_FALSE)?
|
|
76 |
CXML_FALSE : CXML_TRUE);
|
|
77 |
NW_WBXML_Document_construct(&(h->document), default_public_id);
|
|
78 |
NW_TinyDom_Tree_construct (&(h->tinyDOMTree),
|
|
79 |
&(h->wbxmlParser),
|
|
80 |
&(h->document),
|
|
81 |
&(h->writer));
|
|
82 |
NW_TinyDom_Parser_construct (&(h->tinyParser), &(h->tinyDOMTree));
|
|
83 |
}
|
|
84 |
|
|
85 |
|
|
86 |
/* ************************************************************************/
|
|
87 |
|
|
88 |
/*
|
|
89 |
* Create and populate a dom tree by parsing a buffer, returning the
|
|
90 |
* document node.
|
|
91 |
*/
|
|
92 |
|
|
93 |
EXPORT_C
|
|
94 |
NW_DOM_DocumentNode_t *
|
|
95 |
NW_DOM_DocumentNode_BuildWBXMLTree(NW_TinyDom_Handle_t *h,
|
|
96 |
NW_Byte *buffer,
|
|
97 |
NW_Int32 length,
|
|
98 |
NW_Bool freeBuff,
|
|
99 |
NW_Bool extTNotStringTable)
|
|
100 |
{
|
|
101 |
NW_Status_t status;
|
|
102 |
|
|
103 |
NW_ASSERT(h != NULL);
|
|
104 |
|
|
105 |
NW_TinyDom_Handle_Initialize(h, 0, extTNotStringTable);
|
|
106 |
|
|
107 |
status = NW_TinyDom_Parser_buildTree (&(h->tinyParser),
|
|
108 |
(char *)buffer,
|
|
109 |
(NW_Uint32)length,
|
|
110 |
freeBuff);
|
|
111 |
if (status == NW_STAT_SUCCESS) {
|
|
112 |
return h->tinyDOMTree.root_node;
|
|
113 |
}
|
|
114 |
return NULL;
|
|
115 |
}
|
|
116 |
|
|
117 |
/*
|
|
118 |
* This function is same at that of NW_DOM_DocumentNode_BuildWBXMLTree(..)
|
|
119 |
* but returns the error code.
|
|
120 |
*/
|
|
121 |
|
|
122 |
static
|
|
123 |
NW_DOM_DocumentNode_t *
|
|
124 |
CXML_DOM_DocumentNode_BuildWBXMLTree(NW_TinyDom_Handle_t *h,
|
|
125 |
NW_Byte *buffer,
|
|
126 |
NW_Int32 length,
|
|
127 |
NW_Bool freeBuff,
|
|
128 |
NW_Bool extTNotStringTable,
|
|
129 |
NW_Status_t* errorStatus)
|
|
130 |
{
|
|
131 |
NW_Status_t status;
|
|
132 |
|
|
133 |
NW_ASSERT(h != NULL);
|
|
134 |
|
|
135 |
NW_TinyDom_Handle_Initialize(h, 0, extTNotStringTable);
|
|
136 |
|
|
137 |
status = NW_TinyDom_Parser_buildTree (&(h->tinyParser),
|
|
138 |
(char *)buffer,
|
|
139 |
(NW_Uint32)length,
|
|
140 |
freeBuff);
|
|
141 |
if (status == NW_STAT_SUCCESS)
|
|
142 |
{
|
|
143 |
*errorStatus = status;
|
|
144 |
return h->tinyDOMTree.root_node;
|
|
145 |
}
|
|
146 |
*errorStatus = status;
|
|
147 |
return NULL;
|
|
148 |
}
|
|
149 |
|
|
150 |
|
|
151 |
/* Function to copy the string table extension values from the
|
|
152 |
* WBXML encoder to WBXML parser
|
|
153 |
*/
|
|
154 |
|
|
155 |
static NW_Status_t
|
|
156 |
NW_DOM_Write_WBXML_StrTbl(NW_TinyDom_Handle_t *p, void* WBXMLEncStrTbl)
|
|
157 |
{
|
|
158 |
NW_Status_t status = NW_STAT_SUCCESS;
|
|
159 |
NW_Status_t s = NW_STAT_WBXML_ITERATE_DONE;
|
|
160 |
NW_Uint32 stringTableByteCount = 0;
|
|
161 |
NW_Encoder_StringTableIterator_t strTableIterator;
|
|
162 |
NW_Uint8* pLiteralBuf;
|
|
163 |
NW_String_t pLiteralStr;
|
|
164 |
NW_Uint32 docTableIndex;
|
|
165 |
NW_Encoder_StringTable_t* strTable = NULL;
|
|
166 |
NW_WBXML_Document_t* doc = &(p->document);
|
|
167 |
|
|
168 |
strTable = (NW_Encoder_StringTable_t*) WBXMLEncStrTbl;
|
|
169 |
|
|
170 |
stringTableByteCount = NW_Encoder_StringTable_getTotalBytes(strTable);
|
|
171 |
|
|
172 |
|
|
173 |
if(stringTableByteCount > 0)
|
|
174 |
{
|
|
175 |
/*The following function always return success so why bother to check? */
|
|
176 |
|
|
177 |
NW_Encoder_StringTable_StringTableIterateInit(WBXMLEncStrTbl,&strTableIterator);
|
|
178 |
|
|
179 |
|
|
180 |
s = NW_Encoder_StringTable_StringTableIterateNext
|
|
181 |
(&strTableIterator,&stringTableByteCount,&pLiteralBuf);
|
|
182 |
|
|
183 |
while(s == NW_STAT_WBXML_ITERATE_MORE)
|
|
184 |
{
|
|
185 |
|
|
186 |
pLiteralStr.length = stringTableByteCount;
|
|
187 |
pLiteralStr.storage = pLiteralBuf;
|
|
188 |
|
|
189 |
status = NW_WBXML_Document_putTableString(doc,&pLiteralStr,&docTableIndex) ;
|
|
190 |
|
|
191 |
if(status != NW_STAT_SUCCESS)
|
|
192 |
{
|
|
193 |
break;
|
|
194 |
}
|
|
195 |
|
|
196 |
s = NW_Encoder_StringTable_StringTableIterateNext
|
|
197 |
(&strTableIterator,&stringTableByteCount,&pLiteralBuf) ;
|
|
198 |
|
|
199 |
}/*end while */
|
|
200 |
|
|
201 |
}/*end if(stringTableByteCount > 0)*/
|
|
202 |
|
|
203 |
//Delete the tree
|
|
204 |
|
|
205 |
NW_Encoder_StringTable_delete(WBXMLEncStrTbl);
|
|
206 |
WBXMLEncStrTbl = NULL;
|
|
207 |
return status;
|
|
208 |
}/*end NW_DOM_Write_WBXML_StrTbl()*/
|
|
209 |
|
|
210 |
static
|
|
211 |
NW_DOM_DocumentNode_t*
|
|
212 |
NW_DOM_DocumentNode_BuildXMLTree(NW_TinyDom_Handle_t *h,
|
|
213 |
NW_Byte *buffer,
|
|
214 |
NW_Int32 length,
|
|
215 |
NW_Uint32 publicID,
|
|
216 |
NW_Bool extTNotStringTable)
|
|
217 |
{
|
|
218 |
|
|
219 |
NW_Buffer_t inBuff;
|
|
220 |
NW_Buffer_t *outBuff = NULL;
|
|
221 |
NW_Uint32 encoding;
|
|
222 |
NW_Endianness_t endianness;
|
|
223 |
NW_DOM_DocumentNode_t* docNode;
|
|
224 |
NW_Status_t status;
|
|
225 |
NW_Uint32 line;
|
|
226 |
void* WBXMLEncStrTbl;
|
|
227 |
|
|
228 |
inBuff.length = length;
|
|
229 |
inBuff.data = buffer;
|
|
230 |
|
|
231 |
status = NW_XML_ComputeEncoding(length,
|
|
232 |
buffer,
|
|
233 |
&encoding,
|
|
234 |
&endianness);
|
|
235 |
if(status != NW_STAT_SUCCESS){
|
|
236 |
return NULL;
|
|
237 |
}
|
|
238 |
|
|
239 |
/*
|
|
240 |
* If applications want to use HTML Parser they can call the exported
|
|
241 |
* NW_HTMLP_HtmlToWbxml() and then call NW_DOM_DocumentNode_BuildWBXMLTree()
|
|
242 |
*/
|
|
243 |
status = NW_XML_XmlToWbxml(&inBuff, encoding, &outBuff, &line, publicID,&WBXMLEncStrTbl);
|
|
244 |
|
|
245 |
|
|
246 |
|
|
247 |
if(status != NW_STAT_SUCCESS){
|
|
248 |
if(outBuff != NULL){
|
|
249 |
NW_Mem_Free(outBuff);
|
|
250 |
}
|
|
251 |
|
|
252 |
return NULL;
|
|
253 |
}
|
|
254 |
docNode = NW_DOM_DocumentNode_BuildWBXMLTree(h,
|
|
255 |
outBuff->data,
|
|
256 |
outBuff->length,
|
|
257 |
NW_TRUE,
|
|
258 |
extTNotStringTable);
|
|
259 |
|
|
260 |
/* Write extension string table related information to the WBXML encoder. */
|
|
261 |
|
|
262 |
if( docNode && WBXMLEncStrTbl)
|
|
263 |
{
|
|
264 |
status = NW_DOM_Write_WBXML_StrTbl(h,WBXMLEncStrTbl);
|
|
265 |
if(status != NW_STAT_SUCCESS)
|
|
266 |
{
|
|
267 |
if(outBuff != NULL)
|
|
268 |
{
|
|
269 |
NW_Mem_Free(outBuff);
|
|
270 |
}
|
|
271 |
}
|
|
272 |
}/* end if(WBXMLEncStrTbl)*/
|
|
273 |
|
|
274 |
NW_Mem_Free(outBuff);
|
|
275 |
return docNode;
|
|
276 |
}
|
|
277 |
|
|
278 |
static
|
|
279 |
NW_DOM_DocumentNode_t*
|
|
280 |
CXML_DOM_DocumentNode_BuildXMLTree(NW_TinyDom_Handle_t *h,
|
|
281 |
NW_Byte *buffer,
|
|
282 |
NW_Int32 length,
|
|
283 |
NW_Uint32 publicID,
|
|
284 |
NW_Bool extTNotStringTable,
|
|
285 |
NW_Status_t* errorStatus)
|
|
286 |
{
|
|
287 |
|
|
288 |
NW_Buffer_t inBuff;
|
|
289 |
NW_Buffer_t *outBuff = NULL;
|
|
290 |
NW_Uint32 encoding;
|
|
291 |
NW_Endianness_t endianness;
|
|
292 |
NW_DOM_DocumentNode_t* docNode;
|
|
293 |
NW_Status_t status;
|
|
294 |
NW_Uint32 line;
|
|
295 |
void* WBXMLEncStrTbl;
|
|
296 |
|
|
297 |
inBuff.length = length;
|
|
298 |
inBuff.data = buffer;
|
|
299 |
|
|
300 |
status = NW_XML_ComputeEncoding(length,
|
|
301 |
buffer,
|
|
302 |
&encoding,
|
|
303 |
&endianness);
|
|
304 |
if(status != NW_STAT_SUCCESS)
|
|
305 |
{
|
|
306 |
*errorStatus = status;
|
|
307 |
return NULL;
|
|
308 |
}
|
|
309 |
|
|
310 |
/*
|
|
311 |
* If applications want to use HTML Parser they can call the exported
|
|
312 |
* NW_HTMLP_HtmlToWbxml() and then call NW_DOM_DocumentNode_BuildWBXMLTree()
|
|
313 |
*/
|
|
314 |
status = NW_XML_XmlToWbxml(&inBuff, encoding, &outBuff, &line, publicID,&WBXMLEncStrTbl);
|
|
315 |
|
|
316 |
|
|
317 |
|
|
318 |
if(status != NW_STAT_SUCCESS){
|
|
319 |
if(outBuff != NULL){
|
|
320 |
NW_Mem_Free(outBuff);
|
|
321 |
}
|
|
322 |
*errorStatus = status;
|
|
323 |
return NULL;
|
|
324 |
}
|
|
325 |
|
|
326 |
docNode = CXML_DOM_DocumentNode_BuildWBXMLTree(h,
|
|
327 |
outBuff->data,
|
|
328 |
outBuff->length,
|
|
329 |
NW_TRUE,
|
|
330 |
extTNotStringTable,
|
|
331 |
errorStatus);
|
|
332 |
|
|
333 |
/* Write extension string table related information to the WBXML encoder. */
|
|
334 |
|
|
335 |
if( docNode && WBXMLEncStrTbl)
|
|
336 |
{
|
|
337 |
status = NW_DOM_Write_WBXML_StrTbl(h,WBXMLEncStrTbl);
|
|
338 |
if(status != NW_STAT_SUCCESS)
|
|
339 |
{
|
|
340 |
if(outBuff != NULL)
|
|
341 |
{
|
|
342 |
NW_Mem_Free(outBuff);
|
|
343 |
}
|
|
344 |
*errorStatus = status;
|
|
345 |
}
|
|
346 |
}/* end if(WBXMLEncStrTbl)*/
|
|
347 |
|
|
348 |
NW_Mem_Free(outBuff);
|
|
349 |
return docNode;
|
|
350 |
}/*CXML_DOM_DocumentNode_BuildXMLTree() */
|
|
351 |
|
|
352 |
EXPORT_C NW_DOM_DocumentNode_t*
|
|
353 |
NW_DOM_DocumentNode_BuildTree(NW_TinyDom_Handle_t *h,
|
|
354 |
NW_Byte *buffer,
|
|
355 |
NW_Int32 length,
|
|
356 |
NW_Bool encoded,
|
|
357 |
NW_Uint32 publicID,
|
|
358 |
NW_Bool extTNotStringTable)
|
|
359 |
{
|
|
360 |
if(encoded == NW_TRUE){
|
|
361 |
return NW_DOM_DocumentNode_BuildWBXMLTree(h,
|
|
362 |
buffer,
|
|
363 |
length,
|
|
364 |
NW_FALSE,
|
|
365 |
extTNotStringTable);
|
|
366 |
}
|
|
367 |
|
|
368 |
return NW_DOM_DocumentNode_BuildXMLTree(h,buffer, length, publicID, extTNotStringTable);
|
|
369 |
}
|
|
370 |
|
|
371 |
|
|
372 |
|
|
373 |
|
|
374 |
/*
|
|
375 |
* Returns publicId of the document (WBXML Specific)
|
|
376 |
* otherwise 0
|
|
377 |
*/
|
|
378 |
|
|
379 |
EXPORT_C NW_Uint32
|
|
380 |
NW_DOM_DocumentNode_getPublicIdAsNumber(NW_DOM_DocumentNode_t *doc)
|
|
381 |
{
|
|
382 |
NW_WBXML_Document_t *header;
|
|
383 |
NW_TinyTree_t *tiny_tree;
|
|
384 |
|
|
385 |
NW_ASSERT(doc != NULL);
|
|
386 |
|
|
387 |
if (NW_DOM_Node_getNodeType(doc) != NW_DOM_DOCUMENT_NODE){
|
|
388 |
return 0;
|
|
389 |
}
|
|
390 |
|
|
391 |
tiny_tree = NW_TinyTree_Node_findTree(doc);
|
|
392 |
header = NW_TinyDom_getDocHeader(tiny_tree);
|
|
393 |
NW_ASSERT(header != NULL);
|
|
394 |
|
|
395 |
return header->publicid;
|
|
396 |
}
|
|
397 |
|
|
398 |
/*
|
|
399 |
* Gets the publicid as string
|
|
400 |
* Returns
|
|
401 |
* NW_STAT_DOM_NODE_TYPE_ERR
|
|
402 |
* NW_STAT_SUCCESS
|
|
403 |
* MODIFIED - docType
|
|
404 |
*/
|
|
405 |
|
|
406 |
EXPORT_C NW_Status_t
|
|
407 |
NW_DOM_DocumentNode_getPublicId(NW_DOM_DocumentNode_t *doc,
|
|
408 |
NW_String_t *docType)
|
|
409 |
{
|
|
410 |
NW_WBXML_Document_t *header;
|
|
411 |
NW_TinyTree_t *tiny_tree;
|
|
412 |
|
|
413 |
NW_ASSERT(doc != NULL);
|
|
414 |
NW_ASSERT(docType != NULL);
|
|
415 |
|
|
416 |
if (NW_DOM_Node_getNodeType(doc) != NW_DOM_DOCUMENT_NODE)
|
|
417 |
return NW_STAT_DOM_NODE_TYPE_ERR;
|
|
418 |
|
|
419 |
tiny_tree = NW_TinyTree_Node_findTree(doc);
|
|
420 |
header = NW_TinyDom_getDocHeader(tiny_tree);
|
|
421 |
|
|
422 |
NW_ASSERT(header != NULL);
|
|
423 |
NW_String_shallowCopy(docType, header->doc_type);
|
|
424 |
|
|
425 |
return NW_STAT_SUCCESS;
|
|
426 |
}
|
|
427 |
|
|
428 |
/*
|
|
429 |
* Returns the version of the document,
|
|
430 |
* 0 in case of invalid operation (e.g. NULL doc)
|
|
431 |
*/
|
|
432 |
|
|
433 |
EXPORT_C NW_Uint8
|
|
434 |
NW_DOM_DocumentNode_getVersion(NW_DOM_DocumentNode_t *doc)
|
|
435 |
{
|
|
436 |
NW_WBXML_Document_t *header;
|
|
437 |
NW_TinyTree_t *tiny_tree;
|
|
438 |
|
|
439 |
NW_ASSERT(doc != NULL);
|
|
440 |
|
|
441 |
if (NW_DOM_Node_getNodeType(doc) != NW_DOM_DOCUMENT_NODE){
|
|
442 |
return 0;
|
|
443 |
}
|
|
444 |
|
|
445 |
tiny_tree = NW_TinyTree_Node_findTree(doc);
|
|
446 |
header = NW_TinyDom_getDocHeader(tiny_tree);
|
|
447 |
NW_ASSERT(header != NULL);
|
|
448 |
|
|
449 |
return header->version;
|
|
450 |
|
|
451 |
}
|
|
452 |
|
|
453 |
/*
|
|
454 |
* Returns the supported encoding of the document
|
|
455 |
* or 0 for invalid document
|
|
456 |
*/
|
|
457 |
|
|
458 |
EXPORT_C NW_Uint32
|
|
459 |
NW_DOM_DocumentNode_getCharacterEncoding(NW_DOM_DocumentNode_t *doc)
|
|
460 |
{
|
|
461 |
NW_WBXML_Document_t *header;
|
|
462 |
NW_TinyTree_t *tiny_tree;
|
|
463 |
|
|
464 |
NW_ASSERT(doc != NULL);
|
|
465 |
|
|
466 |
if (NW_DOM_Node_getNodeType(doc) != NW_DOM_DOCUMENT_NODE)
|
|
467 |
return 0;
|
|
468 |
|
|
469 |
tiny_tree = NW_TinyTree_Node_findTree(doc);
|
|
470 |
header = NW_TinyDom_getDocHeader(tiny_tree);
|
|
471 |
NW_ASSERT(header != NULL);
|
|
472 |
|
|
473 |
return header->charset;
|
|
474 |
}
|
|
475 |
|
|
476 |
/*
|
|
477 |
* Returns child node that is the root of this document
|
|
478 |
*/
|
|
479 |
|
|
480 |
EXPORT_C NW_DOM_ElementNode_t *
|
|
481 |
NW_DOM_DocumentNode_getDocumentElement(NW_DOM_DocumentNode_t *doc)
|
|
482 |
{
|
|
483 |
NW_DOM_Node_t *docChild;
|
|
484 |
NW_Uint16 type;
|
|
485 |
|
|
486 |
NW_ASSERT(doc != NULL);
|
|
487 |
|
|
488 |
if (NW_DOM_Node_getNodeType(doc) != NW_DOM_DOCUMENT_NODE){
|
|
489 |
return NULL;
|
|
490 |
}
|
|
491 |
|
|
492 |
/*
|
|
493 |
* Get the first child of the document node
|
|
494 |
* (can be a PI node)
|
|
495 |
*/
|
|
496 |
|
|
497 |
docChild = NW_DOM_Node_getFirstChild(doc);
|
|
498 |
|
|
499 |
type = NW_DOM_Node_getNodeType(docChild);
|
|
500 |
if (type == 0){
|
|
501 |
return NULL;
|
|
502 |
}
|
|
503 |
|
|
504 |
while (type != NW_DOM_ELEMENT_NODE){
|
|
505 |
docChild = NW_DOM_Node_getNextSibling(docChild);
|
|
506 |
type = NW_DOM_Node_getNodeType(docChild);
|
|
507 |
}
|
|
508 |
|
|
509 |
return docChild;
|
|
510 |
}
|
|
511 |
|
|
512 |
/*
|
|
513 |
* Gets the dictionary
|
|
514 |
*/
|
|
515 |
|
|
516 |
EXPORT_C NW_WBXML_Dictionary_t *
|
|
517 |
NW_DOM_DocumentNode_getDictionary(NW_DOM_DocumentNode_t *doc)
|
|
518 |
{
|
|
519 |
NW_Uint32 publicid = 0;
|
|
520 |
NW_Uint32 encoding;
|
|
521 |
NW_WBXML_Dictionary_t *dictionary = NULL;
|
|
522 |
NW_Status_t status;
|
|
523 |
|
|
524 |
NW_ASSERT(doc != NULL);
|
|
525 |
|
|
526 |
encoding = NW_DOM_DocumentNode_getCharacterEncoding(doc);
|
|
527 |
publicid = NW_DOM_DocumentNode_getPublicIdAsNumber(doc);
|
|
528 |
|
|
529 |
if (publicid != 0){
|
|
530 |
dictionary = NW_WBXML_Dictionary_getByPublicId(publicid);
|
|
531 |
}
|
|
532 |
else{
|
|
533 |
NW_String_t docType;
|
|
534 |
|
|
535 |
status = NW_DOM_DocumentNode_getPublicId(doc, &docType);
|
|
536 |
if (status != NW_STAT_SUCCESS){
|
|
537 |
return NULL;
|
|
538 |
}
|
|
539 |
dictionary = NW_WBXML_Dictionary_getByDocType(&docType, encoding);
|
|
540 |
}
|
|
541 |
return dictionary;
|
|
542 |
}
|
|
543 |
|
|
544 |
|
|
545 |
|
|
546 |
NW_Status_t
|
|
547 |
NW_DOM_DocumentNode_getElementIteratorByTagName(NW_DOM_DocumentNode_t *doc,
|
|
548 |
NW_String_t* name,
|
|
549 |
NW_DOM_NodeIterator_t *handle)
|
|
550 |
{
|
|
551 |
NW_WBXML_Dictionary_t *dict = NULL;
|
|
552 |
NW_String_UCS2Buff_t *buff = NULL;
|
|
553 |
NW_Uint32 encoding;
|
|
554 |
NW_Int16 token;
|
|
555 |
|
|
556 |
NW_ASSERT(doc != NULL);
|
|
557 |
NW_ASSERT(name != NULL);
|
|
558 |
NW_ASSERT(handle != NULL);
|
|
559 |
|
|
560 |
encoding = NW_DOM_DocumentNode_getCharacterEncoding(doc);
|
|
561 |
dict = NW_DOM_DocumentNode_getDictionary(doc);
|
|
562 |
buff = NW_String_stringToUCS2Buff(name, encoding);
|
|
563 |
if((buff == NULL) || (dict == NULL)){
|
|
564 |
NW_Mem_Free(buff);
|
|
565 |
return NW_STAT_FAILURE;
|
|
566 |
}
|
|
567 |
token = NW_WBXML_Dictionary_getTagToken(dict, buff, NW_TRUE);
|
|
568 |
NW_Mem_Free(buff);
|
|
569 |
if (token < 0) {
|
|
570 |
return NW_STAT_FAILURE;
|
|
571 |
}
|
|
572 |
else {
|
|
573 |
return NW_DOM_DocumentNode_getElementIteratorByTagToken(doc,
|
|
574 |
(NW_Uint16)token,
|
|
575 |
handle);
|
|
576 |
}
|
|
577 |
}
|
|
578 |
|
|
579 |
NW_Status_t
|
|
580 |
NW_DOM_DocumentNode_getElementIteratorByTagToken(NW_DOM_DocumentNode_t *doc,
|
|
581 |
NW_Uint16 token,
|
|
582 |
NW_DOM_NodeIterator_t *handle)
|
|
583 |
{
|
|
584 |
|
|
585 |
NW_DOM_ElementNode_t *elem;
|
|
586 |
|
|
587 |
NW_ASSERT(doc != NULL);
|
|
588 |
NW_ASSERT(handle != NULL);
|
|
589 |
|
|
590 |
if (NW_DOM_Node_getNodeType(doc) != NW_DOM_DOCUMENT_NODE)
|
|
591 |
return NW_STAT_DOM_NODE_TYPE_ERR;
|
|
592 |
|
|
593 |
elem = NW_DOM_DocumentNode_getDocumentElement(doc);
|
|
594 |
NW_ASSERT(elem != NULL);
|
|
595 |
|
|
596 |
return NW_DOM_NodeIterator_initialize(handle, elem, token);
|
|
597 |
}
|
|
598 |
|
|
599 |
|
|
600 |
|
|
601 |
|
|
602 |
|
|
603 |
/*
|
|
604 |
* Returns a pointer to the created Element Node
|
|
605 |
*/
|
|
606 |
EXPORT_C NW_DOM_ElementNode_t *
|
|
607 |
NW_DOM_DocumentNode_createElementNode(
|
|
608 |
NW_DOM_DocumentNode_t *doc, NW_String_t *name)
|
|
609 |
{
|
|
610 |
NW_Uint32 encoding = NW_DOM_DocumentNode_getCharacterEncoding(doc);
|
|
611 |
NW_String_UCS2Buff_t *ucs2Buff = NULL;
|
|
612 |
NW_Uint8 *uint8Buf = NULL;
|
|
613 |
NW_Int32 fqToken = 0;
|
|
614 |
NW_WBXML_Dictionary_t *dictionary = NW_DOM_DocumentNode_getDictionary(doc);
|
|
615 |
NW_TinyTree_t* tinyTree;
|
|
616 |
NW_TinyDom_Tree_t *tree;
|
|
617 |
|
|
618 |
if ((doc == NULL) || (name == NULL) || (dictionary == NULL))
|
|
619 |
{
|
|
620 |
return NULL;
|
|
621 |
}
|
|
622 |
|
|
623 |
ucs2Buff = NW_String_stringToUCS2Buff(name, encoding);
|
|
624 |
if (ucs2Buff == NULL){
|
|
625 |
return NULL;
|
|
626 |
}
|
|
627 |
uint8Buf = (NW_Uint8 *) CXML_Str_CvtToAscii((NW_Ucs2*) ucs2Buff);
|
|
628 |
NW_Mem_Free(ucs2Buff);
|
|
629 |
if(uint8Buf == NULL){
|
|
630 |
return NULL;
|
|
631 |
}
|
|
632 |
tinyTree = NW_TinyTree_Node_findTree(doc);
|
|
633 |
tree = NW_TinyDom_getTree(tinyTree);
|
|
634 |
|
|
635 |
fqToken = (NW_Int32) NW_WBXML_Dictionary_getTagToken(dictionary, ucs2Buff, NW_TRUE);
|
|
636 |
NW_Mem_Free(uint8Buf);
|
|
637 |
if (fqToken == -1){
|
|
638 |
return NW_TinyDom_createElementByName(tree, name);
|
|
639 |
}
|
|
640 |
|
|
641 |
return NW_TinyDom_createElementByToken(tree, (NW_Uint16)fqToken);
|
|
642 |
}
|
|
643 |
|
|
644 |
/*
|
|
645 |
* Returns a pointer to the created Element Node
|
|
646 |
*/
|
|
647 |
EXPORT_C NW_DOM_ElementNode_t *
|
|
648 |
NW_DOM_DocumentNode_createElementNodeByToken(
|
|
649 |
NW_DOM_DocumentNode_t *doc, NW_Uint16 token)
|
|
650 |
{
|
|
651 |
NW_TinyTree_t* tinyTree;
|
|
652 |
NW_TinyDom_Tree_t *tree;
|
|
653 |
NW_WBXML_Dictionary_t *dictionary;
|
|
654 |
|
|
655 |
dictionary = NW_DOM_DocumentNode_getDictionary(doc);
|
|
656 |
if ((doc == NULL) || (dictionary == NULL) || (token == 0))
|
|
657 |
{
|
|
658 |
return NULL;
|
|
659 |
}
|
|
660 |
|
|
661 |
tinyTree = NW_TinyTree_Node_findTree(doc);
|
|
662 |
tree = NW_TinyDom_getTree(tinyTree);
|
|
663 |
|
|
664 |
return NW_TinyDom_createElementByToken(tree, (NW_Uint16)token);
|
|
665 |
}
|
|
666 |
|
|
667 |
|
|
668 |
/*
|
|
669 |
* Returns a pointer to the created Text Node
|
|
670 |
*/
|
|
671 |
EXPORT_C NW_DOM_TextNode_t *
|
|
672 |
NW_DOM_DocumentNode_createTextNodeWithTextItem(
|
|
673 |
NW_DOM_DocumentNode_t *doc, NW_DOM_TextItem_t *data)
|
|
674 |
{
|
|
675 |
NW_TinyTree_t* tinyTree;
|
|
676 |
NW_TinyDom_Tree_t *tree;
|
|
677 |
|
|
678 |
if ((doc == NULL) || (data == NULL))
|
|
679 |
return NULL;
|
|
680 |
|
|
681 |
tinyTree = NW_TinyTree_Node_findTree(doc);
|
|
682 |
tree = NW_TinyDom_getTree(tinyTree);
|
|
683 |
|
|
684 |
return NW_TinyDom_createTextNode(tree, data);
|
|
685 |
}
|
|
686 |
|
|
687 |
/*
|
|
688 |
* Returns a pointer to the created Text Node
|
|
689 |
*/
|
|
690 |
EXPORT_C NW_DOM_TextNode_t *
|
|
691 |
NW_DOM_DocumentNode_createTextNode(
|
|
692 |
NW_DOM_DocumentNode_t *doc, NW_String_t *data)
|
|
693 |
{
|
|
694 |
NW_TinyTree_t* tinyTree;
|
|
695 |
NW_TinyDom_Tree_t *tree;
|
|
696 |
NW_DOM_TextItem_t item;
|
|
697 |
|
|
698 |
if (NW_DOM_TextItem_initFromString(&item, data) != NW_STAT_SUCCESS)
|
|
699 |
return NULL;
|
|
700 |
|
|
701 |
if ((doc == NULL) || (data == NULL))
|
|
702 |
return NULL;
|
|
703 |
|
|
704 |
tinyTree = NW_TinyTree_Node_findTree(doc);
|
|
705 |
tree = NW_TinyDom_getTree(tinyTree);
|
|
706 |
|
|
707 |
return NW_TinyDom_createTextNode(tree, &item);
|
|
708 |
}
|
|
709 |
|
|
710 |
/*
|
|
711 |
* Returns a pointer to the created Comment Node
|
|
712 |
*/
|
|
713 |
NW_DOM_CommentNode_t *
|
|
714 |
NW_DOM_DocumentNode_createCommentNode(
|
|
715 |
NW_DOM_DocumentNode_t *doc, NW_String_t *data)
|
|
716 |
{
|
|
717 |
NW_DOM_TextNode_t *t =
|
|
718 |
NW_DOM_DocumentNode_createTextNode(doc, data);
|
|
719 |
if (t == NULL)
|
|
720 |
return NULL;
|
|
721 |
NW_TinyTree_Node_setUserFlags(t, T_DOM_NODE_COMMENT);
|
|
722 |
t->flags |= T_DOM_NODE_XML;
|
|
723 |
return (NW_DOM_CommentNode_t *)t;
|
|
724 |
}
|
|
725 |
|
|
726 |
|
|
727 |
/*
|
|
728 |
* Returns a pointer to the created CDataSection Node
|
|
729 |
*/
|
|
730 |
NW_DOM_CDATASectionNode_t *
|
|
731 |
NW_DOM_DocumentNode_createCDATASectionNode(
|
|
732 |
NW_DOM_DocumentNode_t *doc, NW_String_t *data)
|
|
733 |
{
|
|
734 |
NW_DOM_TextNode_t *t =
|
|
735 |
NW_DOM_DocumentNode_createTextNode(doc, data);
|
|
736 |
if (t == NULL)
|
|
737 |
return NULL;
|
|
738 |
NW_TinyTree_Node_setUserFlags(t, T_DOM_NODE_CDATASECTION);
|
|
739 |
t->flags |= T_DOM_NODE_XML;
|
|
740 |
return (NW_DOM_CommentNode_t *)t;
|
|
741 |
}
|
|
742 |
|
|
743 |
|
|
744 |
/*
|
|
745 |
* Returns a pointer to the created ProcessingInstructionNode Node
|
|
746 |
*/
|
|
747 |
NW_DOM_ProcessingInstructionNode_t *
|
|
748 |
NW_DOM_DocumentNode_createProcessingInstructionNodeByAttrVal(NW_DOM_DocumentNode_t* pDoc,
|
|
749 |
NW_String_t* pTargetString,
|
|
750 |
NW_DOM_AttrVal_t* pData)
|
|
751 |
{
|
|
752 |
NW_TinyTree_Node_t* pPiNode;
|
|
753 |
NW_TinyTree_Node_t* pAttrNode;
|
|
754 |
NW_TinyTree_t* pTinyTree;
|
|
755 |
NW_TinyDom_Tree_t* pTree;
|
|
756 |
NW_WBXML_Dictionary_t* pDictionary;
|
|
757 |
NW_Uint32 encoding;
|
|
758 |
NW_Int32 fqToken;
|
|
759 |
|
|
760 |
if ((pDoc == NULL) || (pTargetString == NULL) || (pData == NULL)) {
|
|
761 |
return NULL;
|
|
762 |
}
|
|
763 |
pTinyTree = NW_TinyTree_Node_findTree(pDoc);
|
|
764 |
pTree = NW_TinyDom_getTree(pTinyTree);
|
|
765 |
|
|
766 |
pDictionary = NW_DOM_DocumentNode_getDictionary(pDoc);
|
|
767 |
if (pDictionary == NULL) {
|
|
768 |
return NULL;
|
|
769 |
}
|
|
770 |
encoding = NW_DOM_DocumentNode_getCharacterEncoding(pDoc);
|
|
771 |
fqToken = NW_WBXML_Dictionary_getAttributeToken(pDictionary,
|
|
772 |
pTargetString,
|
|
773 |
encoding,
|
|
774 |
NW_TRUE /* name */);
|
|
775 |
if (fqToken == -1)
|
|
776 |
{
|
|
777 |
pPiNode = NW_TinyTree_createNode(&(pTree->tree), 0);
|
|
778 |
if (pPiNode == NULL) {
|
|
779 |
return NULL;
|
|
780 |
}
|
|
781 |
NW_TinyTree_Node_setUserFlags(pPiNode, T_DOM_NODE_PI);
|
|
782 |
|
|
783 |
pAttrNode = NW_TinyDom_createAttributeByName(pTree,
|
|
784 |
pTargetString,
|
|
785 |
pData);
|
|
786 |
if (pAttrNode == NULL) {
|
|
787 |
(void)NW_TinyTree_deleteNode(pPiNode);
|
|
788 |
return NULL;
|
|
789 |
}
|
|
790 |
(void)NW_TinyTree_attachChild(pPiNode, pAttrNode);
|
|
791 |
return pPiNode;
|
|
792 |
}
|
|
793 |
return NW_DOM_DocumentNode_createProcessingInstructionNodeByToken(pDoc,
|
|
794 |
(NW_Uint16)fqToken,
|
|
795 |
pData);
|
|
796 |
}
|
|
797 |
|
|
798 |
/*
|
|
799 |
* Returns a pointer to the created ProcessingInstructionNode Node
|
|
800 |
*/
|
|
801 |
|
|
802 |
NW_DOM_ProcessingInstructionNode_t *
|
|
803 |
NW_DOM_DocumentNode_createProcessingInstructionNodeByToken(
|
|
804 |
NW_DOM_DocumentNode_t *pDoc, NW_Uint16 token, NW_DOM_AttrVal_t *pData)
|
|
805 |
{
|
|
806 |
NW_TinyTree_Node_t* pPiNode;
|
|
807 |
NW_TinyTree_Node_t* pAttrNode;
|
|
808 |
NW_TinyTree_t* pTinyTree;
|
|
809 |
NW_TinyDom_Tree_t* pTree;
|
|
810 |
|
|
811 |
if ((pDoc == NULL) || (token == 0) || (pData == NULL))
|
|
812 |
return NULL;
|
|
813 |
|
|
814 |
pTinyTree = NW_TinyTree_Node_findTree(pDoc);
|
|
815 |
pTree = NW_TinyDom_getTree(pTinyTree);
|
|
816 |
pPiNode = NW_TinyTree_createNode(&(pTree->tree), 0);
|
|
817 |
if (pPiNode == NULL) {
|
|
818 |
return NULL;
|
|
819 |
}
|
|
820 |
NW_TinyTree_Node_setUserFlags(pPiNode, T_DOM_NODE_PI);
|
|
821 |
|
|
822 |
pAttrNode = NW_TinyDom_createAttributeByToken(pTree,
|
|
823 |
(NW_Uint8)token,
|
|
824 |
pData);
|
|
825 |
if (pAttrNode == NULL) {
|
|
826 |
(void)NW_TinyTree_deleteNode(pPiNode);
|
|
827 |
return NULL;
|
|
828 |
}
|
|
829 |
(void)NW_TinyTree_attachChild(pPiNode, pAttrNode);
|
|
830 |
return pPiNode;
|
|
831 |
}
|
|
832 |
|
|
833 |
/*
|
|
834 |
* Returns a pointer to the created ProcessingInstructionNode Node
|
|
835 |
*/
|
|
836 |
NW_DOM_ProcessingInstructionNode_t *
|
|
837 |
NW_DOM_DocumentNode_createProcessingInstructionNode(
|
|
838 |
NW_DOM_DocumentNode_t *doc, NW_String_t *target, NW_String_t *data)
|
|
839 |
{
|
|
840 |
NW_DOM_AttrVal_t val;
|
|
841 |
|
|
842 |
if ((doc == NULL) || (target == 0) || (data == NULL))
|
|
843 |
return NULL;
|
|
844 |
|
|
845 |
NW_DOM_AttrVal_initFromString(&val, data);
|
|
846 |
return NW_DOM_DocumentNode_createProcessingInstructionNodeByAttrVal(doc, target, &val);
|
|
847 |
}
|
|
848 |
|
|
849 |
/*
|
|
850 |
* Returns a pointer to the created Document Node
|
|
851 |
* - NOT SUPPRTED - ask Steve
|
|
852 |
NW_DOM_DocumentNode_t *
|
|
853 |
NW_DOM_DocumentNode_createDocument(
|
|
854 |
NW_Uint8 version, NW_String_t *publicid, NW_Uint32 encoding)
|
|
855 |
{
|
|
856 |
NW_WBXML_Parser_t *WBXMLParser;
|
|
857 |
NW_TinyDom_Parser_t *tinyParser;
|
|
858 |
NW_TinyDom_Tree_t *domTree;
|
|
859 |
NW_WBXML_Writer_t *writer;
|
|
860 |
NW_Status_t status;
|
|
861 |
|
|
862 |
WBXMLParser = NW_Mem_Malloc(sizeof(NW_WBXML_Parser_t));
|
|
863 |
tinyParser = NW_Mem_Malloc(sizeof(NW_TinyDom_Parser_t));
|
|
864 |
domTree = NW_Mem_Malloc(sizeof(NW_TinyDom_Tree_t));
|
|
865 |
writer = NW_Mem_Malloc(sizeof(NW_WBXML_Writer_t));
|
|
866 |
|
|
867 |
NW_WBXML_Parser_reset(WBXMLParser);
|
|
868 |
domTree->doc->version = version;
|
|
869 |
domTree->doc->doc_type = publicid;
|
|
870 |
domTree->doc->charset = encoding;
|
|
871 |
NW_TinyDom_Tree_construct(domTree, WBXMLParser, domTree->doc, writer);
|
|
872 |
NW_TinyDom_Parser_construct(tinyParser, domTree);
|
|
873 |
status = NW_TinyDom_Tree_create(domTree, tinyParser, domTree->doc,
|
|
874 |
WBXMLParser, writer, 2);
|
|
875 |
if (status != NW_STAT_SUCCESS)
|
|
876 |
return NULL;
|
|
877 |
return NW_TinyDom_writeDocHeader(domTree, version, publicid, encoding);
|
|
878 |
}*/
|
|
879 |
|
|
880 |
/*
|
|
881 |
* Create an empty dom tree, returning the document node.
|
|
882 |
*/
|
|
883 |
|
|
884 |
EXPORT_C NW_DOM_DocumentNode_t *
|
|
885 |
NW_DOM_DocumentNode_createDocumentWithNumberPublicId(NW_TinyDom_Handle_t *h,
|
|
886 |
NW_Uint8 version,
|
|
887 |
NW_Uint32 publicid,
|
|
888 |
NW_Uint32 encoding,
|
|
889 |
NW_Bool extTNotStringTable,
|
|
890 |
NW_Bool enableStringTable)
|
|
891 |
{
|
|
892 |
NW_Status_t status = NW_STAT_SUCCESS;
|
|
893 |
NW_TinyDom_Handle_Initialize(h, publicid, extTNotStringTable);
|
|
894 |
|
|
895 |
h->document.charset = encoding;
|
|
896 |
h->document.publicid = publicid;
|
|
897 |
h->document.version = version;
|
|
898 |
|
|
899 |
|
|
900 |
status = NW_TinyDom_Tree_create(&h->tinyDOMTree, &h->tinyParser,
|
|
901 |
&h->document, &h->wbxmlParser,
|
|
902 |
&h->writer, 4, enableStringTable);
|
|
903 |
|
|
904 |
|
|
905 |
|
|
906 |
if(status == NW_STAT_SUCCESS)
|
|
907 |
{
|
|
908 |
return h->tinyDOMTree.root_node;
|
|
909 |
}
|
|
910 |
else
|
|
911 |
{
|
|
912 |
|
|
913 |
return NULL;
|
|
914 |
}
|
|
915 |
}
|
|
916 |
|
|
917 |
|
|
918 |
/*
|
|
919 |
* One of the API for Building the DOM tree.
|
|
920 |
*/
|
|
921 |
|
|
922 |
EXPORT_C NW_DOM_DocumentNode_t*
|
|
923 |
CXML_DOM_DocumentNode_BuildTree(NW_TinyDom_Handle_t* h,
|
|
924 |
NW_Byte* buffer,
|
|
925 |
NW_Int32 length,
|
|
926 |
NW_Bool encoded,
|
|
927 |
NW_Uint32 publicID,
|
|
928 |
NW_Bool extTNotStringTable,
|
|
929 |
NW_Status_t* errorStatus)
|
|
930 |
{
|
|
931 |
*errorStatus = NW_STAT_SUCCESS;
|
|
932 |
if(encoded == NW_TRUE)
|
|
933 |
{
|
|
934 |
return CXML_DOM_DocumentNode_BuildWBXMLTree(h,
|
|
935 |
buffer,
|
|
936 |
length,
|
|
937 |
NW_FALSE,
|
|
938 |
extTNotStringTable,
|
|
939 |
errorStatus);
|
|
940 |
}
|
|
941 |
|
|
942 |
return CXML_DOM_DocumentNode_BuildXMLTree(h,
|
|
943 |
buffer,
|
|
944 |
length,
|
|
945 |
publicID,
|
|
946 |
extTNotStringTable,
|
|
947 |
errorStatus);
|
|
948 |
|
|
949 |
|
|
950 |
}/*end CXML_DOM_DocumentNode_BuildTree()*/
|
|
951 |
|