Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(320)

Side by Side Diff: xfa/src/fxfa/parser/xfa_parser_imp.cpp

Issue 1803723002: Move xfa/src up to xfa/. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase to master Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "xfa/src/fxfa/parser/xfa_parser_imp.h"
8
9 #include "xfa/src/fgas/crt/fgas_codepage.h"
10 #include "xfa/src/fxfa/fm2js/xfa_fm2jsapi.h"
11 #include "xfa/src/fxfa/parser/xfa_basic_imp.h"
12 #include "xfa/src/fxfa/parser/xfa_docdata.h"
13 #include "xfa/src/fxfa/parser/xfa_doclayout.h"
14 #include "xfa/src/fxfa/parser/xfa_document.h"
15 #include "xfa/src/fxfa/parser/xfa_localemgr.h"
16 #include "xfa/src/fxfa/parser/xfa_object.h"
17 #include "xfa/src/fxfa/parser/xfa_parser.h"
18 #include "xfa/src/fxfa/parser/xfa_script.h"
19 #include "xfa/src/fxfa/parser/xfa_utils.h"
20
21 IXFA_Parser* IXFA_Parser::Create(IXFA_ObjFactory* pFactory,
22 FX_BOOL bDocumentParser) {
23 return new CXFA_SimpleParser(pFactory, bDocumentParser);
24 }
25 CXFA_SimpleParser::CXFA_SimpleParser(IXFA_ObjFactory* pFactory,
26 FX_BOOL bDocumentParser)
27 : m_pXMLParser(nullptr),
28 m_pXMLDoc(nullptr),
29 m_pStream(nullptr),
30 m_pFileRead(nullptr),
31 m_pFactory(pFactory),
32 m_pRootNode(nullptr),
33 m_ePacketID(XFA_XDPPACKET_UNKNOWN),
34 m_bDocumentParser(bDocumentParser) {}
35 CXFA_SimpleParser::~CXFA_SimpleParser() {
36 CloseParser();
37 }
38 void CXFA_SimpleParser::SetFactory(IXFA_ObjFactory* pFactory) {
39 m_pFactory = pFactory;
40 }
41 static IFDE_XMLNode* XFA_FDEExtension_GetDocumentNode(
42 IFDE_XMLDoc* pXMLDoc,
43 FX_BOOL bVerifyWellFormness = FALSE) {
44 if (!pXMLDoc) {
45 return NULL;
46 }
47 IFDE_XMLNode* pXMLFakeRoot = pXMLDoc->GetRoot();
48 for (IFDE_XMLNode* pXMLNode =
49 pXMLFakeRoot->GetNodeItem(IFDE_XMLNode::FirstChild);
50 pXMLNode; pXMLNode = pXMLNode->GetNodeItem(IFDE_XMLNode::NextSibling)) {
51 if (pXMLNode->GetType() == FDE_XMLNODE_Element) {
52 if (bVerifyWellFormness) {
53 for (IFDE_XMLNode* pNextNode =
54 pXMLNode->GetNodeItem(IFDE_XMLNode::NextSibling);
55 pNextNode;
56 pNextNode = pNextNode->GetNodeItem(IFDE_XMLNode::NextSibling)) {
57 if (pNextNode->GetType() == FDE_XMLNODE_Element) {
58 return FALSE;
59 }
60 }
61 }
62 return pXMLNode;
63 }
64 }
65 return NULL;
66 }
67 int32_t CXFA_SimpleParser::StartParse(IFX_FileRead* pStream,
68 XFA_XDPPACKET ePacketID) {
69 CloseParser();
70 m_pFileRead = pStream;
71 m_pStream = IFX_Stream::CreateStream(
72 pStream, FX_STREAMACCESS_Read | FX_STREAMACCESS_Text);
73 if (m_pStream == NULL) {
74 return XFA_PARSESTATUS_StreamErr;
75 }
76 FX_WORD wCodePage = m_pStream->GetCodePage();
77 if (wCodePage != FX_CODEPAGE_UTF16LE && wCodePage != FX_CODEPAGE_UTF16BE &&
78 wCodePage != FX_CODEPAGE_UTF8) {
79 m_pStream->SetCodePage(FX_CODEPAGE_UTF8);
80 }
81 m_pXMLDoc = IFDE_XMLDoc::Create();
82 if (m_pXMLDoc == NULL) {
83 return XFA_PARSESTATUS_StatusErr;
84 }
85 m_pXMLParser = new CXFA_XMLParser(m_pXMLDoc->GetRoot(), m_pStream);
86 if (m_pXMLParser == NULL) {
87 return XFA_PARSESTATUS_StatusErr;
88 }
89 if (!m_pXMLDoc->LoadXML(m_pXMLParser)) {
90 return XFA_PARSESTATUS_StatusErr;
91 }
92 m_ePacketID = ePacketID;
93 return XFA_PARSESTATUS_Ready;
94 }
95 int32_t CXFA_SimpleParser::DoParse(IFX_Pause* pPause) {
96 if (m_pXMLDoc == NULL || m_ePacketID == XFA_XDPPACKET_UNKNOWN) {
97 return XFA_PARSESTATUS_StatusErr;
98 }
99 int32_t iRet = m_pXMLDoc->DoLoad(pPause);
100 if (iRet < 0) {
101 return XFA_PARSESTATUS_SyntaxErr;
102 }
103 if (iRet < 100) {
104 return iRet / 2;
105 }
106 m_pRootNode = ParseAsXDPPacket(XFA_FDEExtension_GetDocumentNode(m_pXMLDoc),
107 m_ePacketID);
108 m_pXMLDoc->CloseXML();
109 if (m_pStream) {
110 m_pStream->Release();
111 m_pStream = NULL;
112 }
113 if (!m_pRootNode) {
114 return XFA_PARSESTATUS_StatusErr;
115 }
116 return XFA_PARSESTATUS_Done;
117 }
118 int32_t CXFA_SimpleParser::ParseXMLData(const CFX_WideString& wsXML,
119 IFDE_XMLNode*& pXMLNode,
120 IFX_Pause* pPause) {
121 CloseParser();
122 pXMLNode = NULL;
123 IFX_Stream* pStream = XFA_CreateWideTextRead(wsXML);
124 if (!pStream) {
125 return XFA_PARSESTATUS_StreamErr;
126 }
127 m_pStream = pStream;
128 m_pXMLDoc = IFDE_XMLDoc::Create();
129 if (m_pXMLDoc == NULL) {
130 return XFA_PARSESTATUS_StatusErr;
131 }
132 CXFA_XMLParser* pParser = new CXFA_XMLParser(m_pXMLDoc->GetRoot(), m_pStream);
133 if (pParser == NULL) {
134 return XFA_PARSESTATUS_StatusErr;
135 }
136
137 pParser->m_dwCheckStatus = 0x03;
138 if (!m_pXMLDoc->LoadXML(pParser)) {
139 return XFA_PARSESTATUS_StatusErr;
140 }
141 int32_t iRet = m_pXMLDoc->DoLoad(pPause);
142 if (iRet < 0 || iRet >= 100) {
143 m_pXMLDoc->CloseXML();
144 }
145 if (iRet < 0) {
146 return XFA_PARSESTATUS_SyntaxErr;
147 }
148 if (iRet < 100) {
149 return iRet / 2;
150 }
151 if (m_pStream) {
152 m_pStream->Release();
153 m_pStream = NULL;
154 }
155 pXMLNode = XFA_FDEExtension_GetDocumentNode(m_pXMLDoc);
156 return XFA_PARSESTATUS_Done;
157 }
158
159 void CXFA_SimpleParser::ConstructXFANode(CXFA_Node* pXFANode,
160 IFDE_XMLNode* pXMLNode) {
161 XFA_XDPPACKET ePacketID = (XFA_XDPPACKET)pXFANode->GetPacketID();
162 if (ePacketID == XFA_XDPPACKET_Datasets) {
163 if (pXFANode->GetClassID() == XFA_ELEMENT_DataValue) {
164 for (IFDE_XMLNode* pXMLChild =
165 pXMLNode->GetNodeItem(IFDE_XMLNode::FirstChild);
166 pXMLChild;
167 pXMLChild = pXMLChild->GetNodeItem(IFDE_XMLNode::NextSibling)) {
168 FDE_XMLNODETYPE eNodeType = pXMLChild->GetType();
169 if (eNodeType == FDE_XMLNODE_Instruction)
170 continue;
171
172 if (eNodeType == FDE_XMLNODE_Element) {
173 CXFA_Node* pXFAChild = m_pFactory->CreateNode(XFA_XDPPACKET_Datasets,
174 XFA_ELEMENT_DataValue);
175 if (!pXFAChild)
176 return;
177
178 CFX_WideString wsNodeStr;
179 ((IFDE_XMLElement*)pXMLChild)->GetLocalTagName(wsNodeStr);
180 pXFAChild->SetCData(XFA_ATTRIBUTE_Name, wsNodeStr);
181 CFX_WideString wsChildValue;
182 XFA_GetPlainTextFromRichText((IFDE_XMLElement*)pXMLChild,
183 wsChildValue);
184 if (!wsChildValue.IsEmpty())
185 pXFAChild->SetCData(XFA_ATTRIBUTE_Value, wsChildValue);
186
187 pXFANode->InsertChild(pXFAChild);
188 pXFAChild->SetXMLMappingNode(pXMLChild);
189 pXFAChild->SetFlag(XFA_NODEFLAG_Initialized, TRUE, FALSE);
190 break;
191 }
192 }
193 m_pRootNode = pXFANode;
194 } else {
195 m_pRootNode = DataLoader(pXFANode, pXMLNode, TRUE);
196 }
197 } else if (pXFANode->GetObjectType() == XFA_OBJECTTYPE_ContentNode) {
198 ParseContentNode(pXFANode, pXMLNode, ePacketID);
199 m_pRootNode = pXFANode;
200 } else {
201 m_pRootNode = NormalLoader(pXFANode, pXMLNode, ePacketID);
202 }
203 }
204
205 FX_BOOL XFA_FDEExtension_ResolveNamespaceQualifier(
206 IFDE_XMLElement* pNode,
207 const CFX_WideStringC& wsQualifier,
208 CFX_WideString& wsNamespaceURI) {
209 if (!pNode) {
210 return FALSE;
211 }
212 IFDE_XMLNode* pFakeRoot = pNode->GetNodeItem(IFDE_XMLNode::Root);
213 CFX_WideString wsNSAttribute;
214 FX_BOOL bRet = FALSE;
215 if (wsQualifier.IsEmpty()) {
216 wsNSAttribute = FX_WSTRC(L"xmlns");
217 bRet = TRUE;
218 } else {
219 wsNSAttribute = FX_WSTRC(L"xmlns:") + wsQualifier;
220 }
221 for (; pNode != pFakeRoot;
222 pNode = (IFDE_XMLElement*)pNode->GetNodeItem(IFDE_XMLNode::Parent)) {
223 if (pNode->GetType() != FDE_XMLNODE_Element) {
224 continue;
225 }
226 if (pNode->HasAttribute(wsNSAttribute)) {
227 pNode->GetString(wsNSAttribute, wsNamespaceURI);
228 return TRUE;
229 }
230 }
231 wsNamespaceURI.Empty();
232 return bRet;
233 }
234 static inline void XFA_FDEExtension_GetElementTagNamespaceURI(
235 IFDE_XMLElement* pElement,
236 CFX_WideString& wsNamespaceURI) {
237 CFX_WideString wsNodeStr;
238 pElement->GetNamespacePrefix(wsNodeStr);
239 if (!XFA_FDEExtension_ResolveNamespaceQualifier(pElement, wsNodeStr,
240 wsNamespaceURI)) {
241 wsNamespaceURI.Empty();
242 }
243 }
244 static FX_BOOL XFA_FDEExtension_MatchNodeName(
245 IFDE_XMLNode* pNode,
246 const CFX_WideStringC& wsLocalTagName,
247 const CFX_WideStringC& wsNamespaceURIPrefix,
248 FX_DWORD eMatchFlags = XFA_XDPPACKET_FLAGS_NOMATCH) {
249 if (!pNode || pNode->GetType() != FDE_XMLNODE_Element) {
250 return FALSE;
251 }
252 IFDE_XMLElement* pElement = reinterpret_cast<IFDE_XMLElement*>(pNode);
253 CFX_WideString wsNodeStr;
254 pElement->GetLocalTagName(wsNodeStr);
255 if (wsNodeStr != wsLocalTagName) {
256 return FALSE;
257 }
258 XFA_FDEExtension_GetElementTagNamespaceURI(pElement, wsNodeStr);
259 if (eMatchFlags & XFA_XDPPACKET_FLAGS_NOMATCH) {
260 return TRUE;
261 }
262 if (eMatchFlags & XFA_XDPPACKET_FLAGS_PREFIXMATCH) {
263 return wsNodeStr.Left(wsNamespaceURIPrefix.GetLength()) ==
264 wsNamespaceURIPrefix;
265 }
266 return wsNodeStr == wsNamespaceURIPrefix;
267 }
268 static FX_BOOL XFA_FDEExtension_GetAttributeLocalName(
269 const CFX_WideStringC& wsAttributeName,
270 CFX_WideString& wsLocalAttrName) {
271 CFX_WideString wsAttrName(wsAttributeName);
272 FX_STRSIZE iFind = wsAttrName.Find(L':', 0);
273 if (iFind < 0) {
274 wsLocalAttrName = wsAttrName;
275 return FALSE;
276 } else {
277 wsLocalAttrName = wsAttrName.Right(wsAttrName.GetLength() - iFind - 1);
278 return TRUE;
279 }
280 }
281 static FX_BOOL XFA_FDEExtension_ResolveAttribute(
282 IFDE_XMLElement* pElement,
283 const CFX_WideStringC& wsAttributeName,
284 CFX_WideString& wsLocalAttrName,
285 CFX_WideString& wsNamespaceURI) {
286 CFX_WideString wsAttrName(wsAttributeName);
287 CFX_WideString wsNSPrefix;
288 if (XFA_FDEExtension_GetAttributeLocalName(wsAttributeName,
289 wsLocalAttrName)) {
290 wsNSPrefix = wsAttrName.Left(wsAttributeName.GetLength() -
291 wsLocalAttrName.GetLength() - 1);
292 }
293 if (wsLocalAttrName == FX_WSTRC(L"xmlns") ||
294 wsNSPrefix == FX_WSTRC(L"xmlns") || wsNSPrefix == FX_WSTRC(L"xml")) {
295 return FALSE;
296 }
297 if (!XFA_FDEExtension_ResolveNamespaceQualifier(pElement, wsNSPrefix,
298 wsNamespaceURI)) {
299 wsNamespaceURI.Empty();
300 return FALSE;
301 }
302 return TRUE;
303 }
304 static FX_BOOL XFA_FDEExtension_FindAttributeWithNS(
305 IFDE_XMLElement* pElement,
306 const CFX_WideStringC& wsLocalAttributeName,
307 const CFX_WideStringC& wsNamespaceURIPrefix,
308 CFX_WideString& wsValue,
309 FX_BOOL bMatchNSAsPrefix = FALSE) {
310 if (!pElement) {
311 return FALSE;
312 }
313 CFX_WideString wsAttrName;
314 CFX_WideString wsAttrValue;
315 CFX_WideString wsAttrNS;
316 for (int32_t iAttrCount = pElement->CountAttributes(), i = 0; i < iAttrCount;
317 i++) {
318 pElement->GetAttribute(i, wsAttrName, wsAttrValue);
319 FX_STRSIZE iFind = wsAttrName.Find(L':', 0);
320 CFX_WideString wsNSPrefix;
321 if (iFind < 0) {
322 if (wsLocalAttributeName != wsAttrName) {
323 continue;
324 }
325 } else {
326 if (wsLocalAttributeName !=
327 wsAttrName.Right(wsAttrName.GetLength() - iFind - 1)) {
328 continue;
329 }
330 wsNSPrefix = wsAttrName.Left(iFind);
331 }
332 if (!XFA_FDEExtension_ResolveNamespaceQualifier(pElement, wsNSPrefix,
333 wsAttrNS)) {
334 continue;
335 }
336 if (bMatchNSAsPrefix) {
337 if (wsAttrNS.Left(wsNamespaceURIPrefix.GetLength()) !=
338 wsNamespaceURIPrefix) {
339 continue;
340 }
341 } else {
342 if (wsAttrNS != wsNamespaceURIPrefix) {
343 continue;
344 }
345 }
346 wsValue = wsAttrValue;
347 return TRUE;
348 }
349 return FALSE;
350 }
351 CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket(IFDE_XMLNode* pXMLDocumentNode,
352 XFA_XDPPACKET ePacketID) {
353 switch (ePacketID) {
354 case XFA_XDPPACKET_UNKNOWN:
355 return NULL;
356 case XFA_XDPPACKET_XDP:
357 return ParseAsXDPPacket_XDP(pXMLDocumentNode, ePacketID);
358 case XFA_XDPPACKET_Config:
359 return ParseAsXDPPacket_Config(pXMLDocumentNode, ePacketID);
360 case XFA_XDPPACKET_Template:
361 case XFA_XDPPACKET_Form:
362 return ParseAsXDPPacket_TemplateForm(pXMLDocumentNode, ePacketID);
363 case XFA_XDPPACKET_Datasets:
364 return ParseAsXDPPacket_Data(pXMLDocumentNode, ePacketID);
365 case XFA_XDPPACKET_Xdc:
366 return ParseAsXDPPacket_Xdc(pXMLDocumentNode, ePacketID);
367 case XFA_XDPPACKET_LocaleSet:
368 case XFA_XDPPACKET_ConnectionSet:
369 case XFA_XDPPACKET_SourceSet:
370 return ParseAsXDPPacket_LocaleConnectionSourceSet(pXMLDocumentNode,
371 ePacketID);
372 default:
373 return ParseAsXDPPacket_User(pXMLDocumentNode, ePacketID);
374 }
375 return NULL;
376 }
377 CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_XDP(
378 IFDE_XMLNode* pXMLDocumentNode,
379 XFA_XDPPACKET ePacketID) {
380 if (!XFA_FDEExtension_MatchNodeName(
381 pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_XDP)->pName,
382 XFA_GetPacketByIndex(XFA_PACKET_XDP)->pURI,
383 XFA_GetPacketByIndex(XFA_PACKET_XDP)->eFlags)) {
384 return nullptr;
385 }
386 CXFA_Node* pXFARootNode =
387 m_pFactory->CreateNode(XFA_XDPPACKET_XDP, XFA_ELEMENT_Xfa);
388 if (!pXFARootNode) {
389 return nullptr;
390 }
391 m_pRootNode = pXFARootNode;
392 pXFARootNode->SetCData(XFA_ATTRIBUTE_Name, FX_WSTRC(L"xfa"));
393 {
394 IFDE_XMLElement* pElement = (IFDE_XMLElement*)pXMLDocumentNode;
395 int32_t iAttributeCount = pElement->CountAttributes();
396 for (int32_t i = 0; i < iAttributeCount; i++) {
397 CFX_WideString wsAttriName, wsAttriValue;
398 pElement->GetAttribute(i, wsAttriName, wsAttriValue);
399 if (wsAttriName == FX_WSTRC(L"uuid")) {
400 pXFARootNode->SetCData(XFA_ATTRIBUTE_Uuid, wsAttriValue);
401 } else if (wsAttriName == FX_WSTRC(L"timeStamp")) {
402 pXFARootNode->SetCData(XFA_ATTRIBUTE_TimeStamp, wsAttriValue);
403 }
404 }
405 }
406 IFDE_XMLNode* pXMLConfigDOMRoot = nullptr;
407 CXFA_Node* pXFAConfigDOMRoot = nullptr;
408 {
409 for (IFDE_XMLNode* pChildItem =
410 pXMLDocumentNode->GetNodeItem(IFDE_XMLNode::FirstChild);
411 pChildItem;
412 pChildItem = pChildItem->GetNodeItem(IFDE_XMLNode::NextSibling)) {
413 const XFA_PACKETINFO* pPacketInfo =
414 XFA_GetPacketByIndex(XFA_PACKET_Config);
415 if (!XFA_FDEExtension_MatchNodeName(pChildItem, pPacketInfo->pName,
416 pPacketInfo->pURI,
417 pPacketInfo->eFlags)) {
418 continue;
419 }
420 if (pXFARootNode->GetFirstChildByName(pPacketInfo->uHash)) {
421 return nullptr;
422 }
423 pXMLConfigDOMRoot = pChildItem;
424 pXFAConfigDOMRoot =
425 ParseAsXDPPacket_Config(pXMLConfigDOMRoot, XFA_XDPPACKET_Config);
426 pXFARootNode->InsertChild(pXFAConfigDOMRoot, NULL);
427 }
428 }
429 IFDE_XMLNode* pXMLDatasetsDOMRoot = nullptr;
430 IFDE_XMLNode* pXMLFormDOMRoot = nullptr;
431 IFDE_XMLNode* pXMLTemplateDOMRoot = nullptr;
432 {
433 for (IFDE_XMLNode* pChildItem =
434 pXMLDocumentNode->GetNodeItem(IFDE_XMLNode::FirstChild);
435 pChildItem;
436 pChildItem = pChildItem->GetNodeItem(IFDE_XMLNode::NextSibling)) {
437 if (!pChildItem || pChildItem->GetType() != FDE_XMLNODE_Element) {
438 continue;
439 }
440 if (pChildItem == pXMLConfigDOMRoot) {
441 continue;
442 }
443 IFDE_XMLElement* pElement =
444 reinterpret_cast<IFDE_XMLElement*>(pChildItem);
445 CFX_WideString wsPacketName;
446 pElement->GetLocalTagName(wsPacketName);
447 const XFA_PACKETINFO* pPacketInfo = XFA_GetPacketByName(wsPacketName);
448 if (pPacketInfo && pPacketInfo->pURI) {
449 if (!XFA_FDEExtension_MatchNodeName(pElement, pPacketInfo->pName,
450 pPacketInfo->pURI,
451 pPacketInfo->eFlags)) {
452 pPacketInfo = nullptr;
453 }
454 }
455 XFA_XDPPACKET ePacket =
456 pPacketInfo ? pPacketInfo->eName : XFA_XDPPACKET_USER;
457 if (ePacket == XFA_XDPPACKET_XDP) {
458 continue;
459 }
460 if (ePacket == XFA_XDPPACKET_Datasets) {
461 if (pXMLDatasetsDOMRoot) {
462 return nullptr;
463 }
464 pXMLDatasetsDOMRoot = pElement;
465 } else if (ePacket == XFA_XDPPACKET_Form) {
466 if (pXMLFormDOMRoot) {
467 return nullptr;
468 }
469 pXMLFormDOMRoot = pElement;
470 } else if (ePacket == XFA_XDPPACKET_Template) {
471 if (pXMLTemplateDOMRoot) {
472 // Found a duplicate template packet.
473 return nullptr;
474 }
475 CXFA_Node* pPacketNode = ParseAsXDPPacket(pElement, ePacket);
476 if (pPacketNode) {
477 pXMLTemplateDOMRoot = pElement;
478 pXFARootNode->InsertChild(pPacketNode);
479 }
480 } else {
481 CXFA_Node* pPacketNode = ParseAsXDPPacket(pElement, ePacket);
482 if (pPacketNode) {
483 if (pPacketInfo &&
484 (pPacketInfo->eFlags & XFA_XDPPACKET_FLAGS_SUPPORTONE) &&
485 pXFARootNode->GetFirstChildByName(pPacketInfo->uHash)) {
486 return nullptr;
487 }
488 pXFARootNode->InsertChild(pPacketNode);
489 }
490 }
491 }
492 }
493 if (!pXMLTemplateDOMRoot) {
494 // No template is found.
495 return nullptr;
496 }
497 if (pXMLDatasetsDOMRoot) {
498 CXFA_Node* pPacketNode =
499 ParseAsXDPPacket(pXMLDatasetsDOMRoot, XFA_XDPPACKET_Datasets);
500 if (pPacketNode) {
501 pXFARootNode->InsertChild(pPacketNode);
502 }
503 }
504 if (pXMLFormDOMRoot) {
505 CXFA_Node* pPacketNode =
506 ParseAsXDPPacket(pXMLFormDOMRoot, XFA_XDPPACKET_Form);
507 if (pPacketNode) {
508 pXFARootNode->InsertChild(pPacketNode);
509 }
510 }
511 pXFARootNode->SetXMLMappingNode(pXMLDocumentNode);
512 return pXFARootNode;
513 }
514 CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_Config(
515 IFDE_XMLNode* pXMLDocumentNode,
516 XFA_XDPPACKET ePacketID) {
517 if (!XFA_FDEExtension_MatchNodeName(
518 pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_Config)->pName,
519 XFA_GetPacketByIndex(XFA_PACKET_Config)->pURI,
520 XFA_GetPacketByIndex(XFA_PACKET_Config)->eFlags)) {
521 return NULL;
522 }
523 CXFA_Node* pNode =
524 m_pFactory->CreateNode(XFA_XDPPACKET_Config, XFA_ELEMENT_Config);
525 if (!pNode) {
526 return NULL;
527 }
528 pNode->SetCData(XFA_ATTRIBUTE_Name,
529 XFA_GetPacketByIndex(XFA_PACKET_Config)->pName);
530 if (!NormalLoader(pNode, pXMLDocumentNode, ePacketID)) {
531 return NULL;
532 }
533 pNode->SetXMLMappingNode(pXMLDocumentNode);
534 return pNode;
535 }
536 CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_TemplateForm(
537 IFDE_XMLNode* pXMLDocumentNode,
538 XFA_XDPPACKET ePacketID) {
539 CXFA_Node* pNode = NULL;
540 if (ePacketID == XFA_XDPPACKET_Template) {
541 if (XFA_FDEExtension_MatchNodeName(
542 pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_Template)->pName,
543 XFA_GetPacketByIndex(XFA_PACKET_Template)->pURI,
544 XFA_GetPacketByIndex(XFA_PACKET_Template)->eFlags)) {
545 pNode =
546 m_pFactory->CreateNode(XFA_XDPPACKET_Template, XFA_ELEMENT_Template);
547 if (!pNode) {
548 return NULL;
549 }
550 pNode->SetCData(XFA_ATTRIBUTE_Name,
551 XFA_GetPacketByIndex(XFA_PACKET_Template)->pName);
552 if (m_bDocumentParser) {
553 CFX_WideString wsNamespaceURI;
554 IFDE_XMLElement* pXMLDocumentElement =
555 (IFDE_XMLElement*)pXMLDocumentNode;
556 pXMLDocumentElement->GetNamespaceURI(wsNamespaceURI);
557 if (wsNamespaceURI.IsEmpty()) {
558 pXMLDocumentElement->GetString(L"xmlns:xfa", wsNamespaceURI);
559 }
560 pNode->GetDocument()->RecognizeXFAVersionNumber(wsNamespaceURI);
561 }
562 if (!NormalLoader(pNode, pXMLDocumentNode, ePacketID)) {
563 return NULL;
564 }
565 }
566 } else if (ePacketID == XFA_XDPPACKET_Form) {
567 if (XFA_FDEExtension_MatchNodeName(
568 pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_Form)->pName,
569 XFA_GetPacketByIndex(XFA_PACKET_Form)->pURI,
570 XFA_GetPacketByIndex(XFA_PACKET_Form)->eFlags)) {
571 IFDE_XMLElement* pXMLDocumentElement = (IFDE_XMLElement*)pXMLDocumentNode;
572 CFX_WideString wsChecksum;
573 pXMLDocumentElement->GetString(L"checksum", wsChecksum);
574 if (wsChecksum.GetLength() != 28 ||
575 m_pXMLParser->m_dwCheckStatus != 0x03) {
576 return NULL;
577 }
578 IXFA_ChecksumContext* pChecksum = XFA_Checksum_Create();
579 pChecksum->StartChecksum();
580 pChecksum->UpdateChecksum(m_pFileRead, m_pXMLParser->m_nStart[0],
581 m_pXMLParser->m_nSize[0]);
582 pChecksum->UpdateChecksum(m_pFileRead, m_pXMLParser->m_nStart[1],
583 m_pXMLParser->m_nSize[1]);
584 pChecksum->FinishChecksum();
585 CFX_ByteString bsCheck;
586 pChecksum->GetChecksum(bsCheck);
587 pChecksum->Release();
588 if (bsCheck != wsChecksum.UTF8Encode()) {
589 return NULL;
590 }
591
592 pNode = m_pFactory->CreateNode(XFA_XDPPACKET_Form, XFA_ELEMENT_Form);
593 if (!pNode) {
594 return NULL;
595 }
596 pNode->SetCData(XFA_ATTRIBUTE_Name,
597 XFA_GetPacketByIndex(XFA_PACKET_Form)->pName);
598 pNode->SetAttribute(XFA_ATTRIBUTE_Checksum, wsChecksum);
599 CXFA_Node* pTemplateRoot =
600 m_pRootNode->GetFirstChildByClass(XFA_ELEMENT_Template);
601 CXFA_Node* pTemplateChosen =
602 pTemplateRoot
603 ? pTemplateRoot->GetFirstChildByClass(XFA_ELEMENT_Subform)
604 : NULL;
605 FX_BOOL bUseAttribute = TRUE;
606 if (pTemplateChosen &&
607 pTemplateChosen->GetEnum(XFA_ATTRIBUTE_RestoreState) !=
608 XFA_ATTRIBUTEENUM_Auto) {
609 bUseAttribute = FALSE;
610 }
611 if (!NormalLoader(pNode, pXMLDocumentNode, ePacketID, bUseAttribute)) {
612 return NULL;
613 }
614 }
615 }
616 if (pNode) {
617 pNode->SetXMLMappingNode(pXMLDocumentNode);
618 }
619 return pNode;
620 }
621 static IFDE_XMLNode* XFA_GetDataSetsFromXDP(IFDE_XMLNode* pXMLDocumentNode) {
622 if (XFA_FDEExtension_MatchNodeName(
623 pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_Datasets)->pName,
624 XFA_GetPacketByIndex(XFA_PACKET_Datasets)->pURI,
625 XFA_GetPacketByIndex(XFA_PACKET_Datasets)->eFlags)) {
626 return pXMLDocumentNode;
627 }
628 if (!XFA_FDEExtension_MatchNodeName(
629 pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_XDP)->pName,
630 XFA_GetPacketByIndex(XFA_PACKET_XDP)->pURI,
631 XFA_GetPacketByIndex(XFA_PACKET_XDP)->eFlags)) {
632 return NULL;
633 }
634 for (IFDE_XMLNode* pDatasetsNode =
635 pXMLDocumentNode->GetNodeItem(IFDE_XMLNode::FirstChild);
636 pDatasetsNode;
637 pDatasetsNode = pDatasetsNode->GetNodeItem(IFDE_XMLNode::NextSibling)) {
638 if (!XFA_FDEExtension_MatchNodeName(
639 pDatasetsNode, XFA_GetPacketByIndex(XFA_PACKET_Datasets)->pName,
640 XFA_GetPacketByIndex(XFA_PACKET_Datasets)->pURI,
641 XFA_GetPacketByIndex(XFA_PACKET_Datasets)->eFlags)) {
642 continue;
643 }
644 return pDatasetsNode;
645 }
646 return NULL;
647 }
648 CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_Data(
649 IFDE_XMLNode* pXMLDocumentNode,
650 XFA_XDPPACKET ePacketID) {
651 IFDE_XMLNode* pDatasetsXMLNode = XFA_GetDataSetsFromXDP(pXMLDocumentNode);
652 if (pDatasetsXMLNode) {
653 CXFA_Node* pNode =
654 m_pFactory->CreateNode(XFA_XDPPACKET_Datasets, XFA_ELEMENT_DataModel);
655 if (!pNode) {
656 return NULL;
657 }
658 pNode->SetCData(XFA_ATTRIBUTE_Name,
659 XFA_GetPacketByIndex(XFA_PACKET_Datasets)->pName);
660 if (!DataLoader(pNode, pDatasetsXMLNode, FALSE)) {
661 return NULL;
662 }
663 pNode->SetXMLMappingNode(pDatasetsXMLNode);
664 return pNode;
665 }
666 IFDE_XMLNode* pDataXMLNode = NULL;
667 if (XFA_FDEExtension_MatchNodeName(
668 pXMLDocumentNode, FX_WSTRC(L"data"),
669 XFA_GetPacketByIndex(XFA_PACKET_Datasets)->pURI,
670 XFA_GetPacketByIndex(XFA_PACKET_Datasets)->eFlags)) {
671 ((IFDE_XMLElement*)pXMLDocumentNode)->RemoveAttribute(L"xmlns:xfa");
672 pDataXMLNode = pXMLDocumentNode;
673 } else {
674 IFDE_XMLElement* pDataElement =
675 IFDE_XMLElement::Create(FX_WSTRC(L"xfa:data"));
676 IFDE_XMLNode* pParentXMLNode =
677 pXMLDocumentNode->GetNodeItem(IFDE_XMLNode::Parent);
678 if (pParentXMLNode) {
679 pParentXMLNode->RemoveChildNode(pXMLDocumentNode);
680 }
681 FXSYS_assert(pXMLDocumentNode->GetType() == FDE_XMLNODE_Element);
682 if (pXMLDocumentNode->GetType() == FDE_XMLNODE_Element) {
683 ((IFDE_XMLElement*)pXMLDocumentNode)->RemoveAttribute(L"xmlns:xfa");
684 }
685 pDataElement->InsertChildNode(pXMLDocumentNode);
686 pDataXMLNode = pDataElement;
687 }
688 if (pDataXMLNode) {
689 CXFA_Node* pNode =
690 m_pFactory->CreateNode(XFA_XDPPACKET_Datasets, XFA_ELEMENT_DataGroup);
691 if (!pNode) {
692 if (pDataXMLNode != pXMLDocumentNode) {
693 pDataXMLNode->Release();
694 }
695 return NULL;
696 }
697 CFX_WideString wsLocalName;
698 ((IFDE_XMLElement*)pDataXMLNode)->GetLocalTagName(wsLocalName);
699 pNode->SetCData(XFA_ATTRIBUTE_Name, wsLocalName);
700 if (!DataLoader(pNode, pDataXMLNode, TRUE)) {
701 return NULL;
702 }
703 pNode->SetXMLMappingNode(pDataXMLNode);
704 if (pDataXMLNode != pXMLDocumentNode) {
705 pNode->SetFlag(XFA_NODEFLAG_OwnXMLNode, TRUE, FALSE);
706 }
707 return pNode;
708 }
709 return NULL;
710 }
711 CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_LocaleConnectionSourceSet(
712 IFDE_XMLNode* pXMLDocumentNode,
713 XFA_XDPPACKET ePacketID) {
714 CXFA_Node* pNode = NULL;
715 if (ePacketID == XFA_XDPPACKET_LocaleSet) {
716 if (XFA_FDEExtension_MatchNodeName(
717 pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_LocaleSet)->pName,
718 XFA_GetPacketByIndex(XFA_PACKET_LocaleSet)->pURI,
719 XFA_GetPacketByIndex(XFA_PACKET_LocaleSet)->eFlags)) {
720 pNode = m_pFactory->CreateNode(XFA_XDPPACKET_LocaleSet,
721 XFA_ELEMENT_LocaleSet);
722 if (!pNode) {
723 return NULL;
724 }
725 pNode->SetCData(XFA_ATTRIBUTE_Name,
726 XFA_GetPacketByIndex(XFA_PACKET_LocaleSet)->pName);
727 if (!NormalLoader(pNode, pXMLDocumentNode, ePacketID)) {
728 return NULL;
729 }
730 }
731 } else if (ePacketID == XFA_XDPPACKET_ConnectionSet) {
732 if (XFA_FDEExtension_MatchNodeName(
733 pXMLDocumentNode,
734 XFA_GetPacketByIndex(XFA_PACKET_ConnectionSet)->pName,
735 XFA_GetPacketByIndex(XFA_PACKET_ConnectionSet)->pURI,
736 XFA_GetPacketByIndex(XFA_PACKET_ConnectionSet)->eFlags)) {
737 pNode = m_pFactory->CreateNode(XFA_XDPPACKET_ConnectionSet,
738 XFA_ELEMENT_ConnectionSet);
739 if (!pNode) {
740 return NULL;
741 }
742 pNode->SetCData(XFA_ATTRIBUTE_Name,
743 XFA_GetPacketByIndex(XFA_PACKET_ConnectionSet)->pName);
744 if (!NormalLoader(pNode, pXMLDocumentNode, ePacketID)) {
745 return NULL;
746 }
747 }
748 } else if (ePacketID == XFA_XDPPACKET_SourceSet) {
749 if (XFA_FDEExtension_MatchNodeName(
750 pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_SourceSet)->pName,
751 XFA_GetPacketByIndex(XFA_PACKET_SourceSet)->pURI,
752 XFA_GetPacketByIndex(XFA_PACKET_SourceSet)->eFlags)) {
753 pNode = m_pFactory->CreateNode(XFA_XDPPACKET_SourceSet,
754 XFA_ELEMENT_SourceSet);
755 if (!pNode) {
756 return NULL;
757 }
758 pNode->SetCData(XFA_ATTRIBUTE_Name,
759 XFA_GetPacketByIndex(XFA_PACKET_SourceSet)->pName);
760 if (!NormalLoader(pNode, pXMLDocumentNode, ePacketID)) {
761 return NULL;
762 }
763 }
764 }
765 if (pNode) {
766 pNode->SetXMLMappingNode(pXMLDocumentNode);
767 }
768 return pNode;
769 }
770 CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_Xdc(
771 IFDE_XMLNode* pXMLDocumentNode,
772 XFA_XDPPACKET ePacketID) {
773 if (XFA_FDEExtension_MatchNodeName(
774 pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_Xdc)->pName,
775 XFA_GetPacketByIndex(XFA_PACKET_Xdc)->pURI,
776 XFA_GetPacketByIndex(XFA_PACKET_Xdc)->eFlags)) {
777 CXFA_Node* pNode =
778 m_pFactory->CreateNode(XFA_XDPPACKET_Xdc, XFA_ELEMENT_Xdc);
779 if (!pNode) {
780 return NULL;
781 }
782 pNode->SetCData(XFA_ATTRIBUTE_Name,
783 XFA_GetPacketByIndex(XFA_PACKET_Xdc)->pName);
784 pNode->SetXMLMappingNode(pXMLDocumentNode);
785 return pNode;
786 }
787 return NULL;
788 }
789 CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_User(
790 IFDE_XMLNode* pXMLDocumentNode,
791 XFA_XDPPACKET ePacketID) {
792 CXFA_Node* pNode =
793 m_pFactory->CreateNode(XFA_XDPPACKET_XDP, XFA_ELEMENT_Packet);
794 if (!pNode) {
795 return NULL;
796 }
797 CFX_WideString wsName;
798 ((IFDE_XMLElement*)pXMLDocumentNode)->GetLocalTagName(wsName);
799 pNode->SetCData(XFA_ATTRIBUTE_Name, wsName);
800 if (!UserPacketLoader(pNode, pXMLDocumentNode)) {
801 return NULL;
802 }
803 pNode->SetXMLMappingNode(pXMLDocumentNode);
804 return pNode;
805 }
806 CXFA_Node* CXFA_SimpleParser::UserPacketLoader(CXFA_Node* pXFANode,
807 IFDE_XMLNode* pXMLDoc) {
808 return pXFANode;
809 }
810 static FX_BOOL XFA_FDEExtension_IsStringAllWhitespace(CFX_WideString wsText) {
811 wsText.TrimRight(L"\x20\x9\xD\xA");
812 return wsText.IsEmpty();
813 }
814 CXFA_Node* CXFA_SimpleParser::DataLoader(CXFA_Node* pXFANode,
815 IFDE_XMLNode* pXMLDoc,
816 FX_BOOL bDoTransform) {
817 ParseDataGroup(pXFANode, pXMLDoc, XFA_XDPPACKET_Datasets);
818 return pXFANode;
819 }
820 CXFA_Node* CXFA_SimpleParser::NormalLoader(CXFA_Node* pXFANode,
821 IFDE_XMLNode* pXMLDoc,
822 XFA_XDPPACKET ePacketID,
823 FX_BOOL bUseAttribute) {
824 FX_BOOL bOneOfPropertyFound = FALSE;
825 for (IFDE_XMLNode* pXMLChild = pXMLDoc->GetNodeItem(IFDE_XMLNode::FirstChild);
826 pXMLChild;
827 pXMLChild = pXMLChild->GetNodeItem(IFDE_XMLNode::NextSibling)) {
828 switch (pXMLChild->GetType()) {
829 case FDE_XMLNODE_Element: {
830 IFDE_XMLElement* pXMLElement = (IFDE_XMLElement*)pXMLChild;
831 CFX_WideString wsTagName;
832 pXMLElement->GetLocalTagName(wsTagName);
833 const XFA_ELEMENTINFO* pElemInfo = XFA_GetElementByName(wsTagName);
834 if (!pElemInfo) {
835 continue;
836 }
837 const XFA_PROPERTY* pPropertyInfo = XFA_GetPropertyOfElement(
838 pXFANode->GetClassID(), pElemInfo->eName, ePacketID);
839 if (pPropertyInfo &&
840 ((pPropertyInfo->uFlags &
841 (XFA_PROPERTYFLAG_OneOf | XFA_PROPERTYFLAG_DefaultOneOf)) != 0)) {
842 if (bOneOfPropertyFound) {
843 break;
844 }
845 bOneOfPropertyFound = TRUE;
846 }
847 CXFA_Node* pXFAChild =
848 m_pFactory->CreateNode(ePacketID, pElemInfo->eName);
849 if (pXFAChild == NULL) {
850 return NULL;
851 }
852 if (ePacketID == XFA_XDPPACKET_Config) {
853 pXFAChild->SetAttribute(XFA_ATTRIBUTE_Name, wsTagName);
854 }
855 FX_BOOL IsNeedValue = TRUE;
856 for (int32_t i = 0, count = pXMLElement->CountAttributes(); i < count;
857 i++) {
858 CFX_WideString wsAttrQualifiedName;
859 CFX_WideString wsAttrName;
860 CFX_WideString wsAttrValue;
861 pXMLElement->GetAttribute(i, wsAttrQualifiedName, wsAttrValue);
862 XFA_FDEExtension_GetAttributeLocalName(wsAttrQualifiedName,
863 wsAttrName);
864 if (wsAttrName == FX_WSTRC(L"nil") &&
865 wsAttrValue == FX_WSTRC(L"true")) {
866 IsNeedValue = FALSE;
867 }
868 const XFA_ATTRIBUTEINFO* lpAttrInfo =
869 XFA_GetAttributeByName(wsAttrName);
870 if (!lpAttrInfo) {
871 continue;
872 }
873 if (!bUseAttribute && lpAttrInfo->eName != XFA_ATTRIBUTE_Name &&
874 lpAttrInfo->eName != XFA_ATTRIBUTE_Save) {
875 continue;
876 }
877 pXFAChild->SetAttribute(lpAttrInfo->eName, wsAttrValue);
878 }
879 pXFANode->InsertChild(pXFAChild);
880 if (pElemInfo->eName == XFA_ELEMENT_Validate ||
881 pElemInfo->eName == XFA_ELEMENT_Locale) {
882 if (ePacketID == XFA_XDPPACKET_Config) {
883 ParseContentNode(pXFAChild, pXMLElement, ePacketID);
884 } else {
885 NormalLoader(pXFAChild, pXMLElement, ePacketID, bUseAttribute);
886 }
887 break;
888 }
889 switch (pXFAChild->GetObjectType()) {
890 case XFA_OBJECTTYPE_ContentNode:
891 case XFA_OBJECTTYPE_TextNode:
892 case XFA_OBJECTTYPE_NodeC:
893 case XFA_OBJECTTYPE_NodeV:
894 if (IsNeedValue) {
895 ParseContentNode(pXFAChild, pXMLElement, ePacketID);
896 }
897 break;
898 default:
899 NormalLoader(pXFAChild, pXMLElement, ePacketID, bUseAttribute);
900 break;
901 }
902 } break;
903 case FDE_XMLNODE_Instruction:
904 ParseInstruction(pXFANode, (IFDE_XMLInstruction*)pXMLChild, ePacketID);
905 break;
906 default:
907 break;
908 }
909 }
910 return pXFANode;
911 }
912 FX_BOOL XFA_RecognizeRichText(IFDE_XMLElement* pRichTextXMLNode) {
913 if (pRichTextXMLNode) {
914 CFX_WideString wsNamespaceURI;
915 XFA_FDEExtension_GetElementTagNamespaceURI(pRichTextXMLNode,
916 wsNamespaceURI);
917 if (wsNamespaceURI == FX_WSTRC(L"http://www.w3.org/1999/xhtml")) {
918 return TRUE;
919 }
920 }
921 return FALSE;
922 }
923 class RichTextNodeVisitor {
924 public:
925 static inline IFDE_XMLNode* GetFirstChild(IFDE_XMLNode* pNode) {
926 return pNode->GetNodeItem(IFDE_XMLNode::FirstChild);
927 }
928 static inline IFDE_XMLNode* GetNextSibling(IFDE_XMLNode* pNode) {
929 return pNode->GetNodeItem(IFDE_XMLNode::NextSibling);
930 }
931 static inline IFDE_XMLNode* GetParent(IFDE_XMLNode* pNode) {
932 return pNode->GetNodeItem(IFDE_XMLNode::Parent);
933 }
934 };
935
936 void XFA_ConvertXMLToPlainText(IFDE_XMLElement* pRootXMLNode,
937 CFX_WideString& wsOutput) {
938 for (IFDE_XMLNode* pXMLChild =
939 pRootXMLNode->GetNodeItem(IFDE_XMLNode::FirstChild);
940 pXMLChild;
941 pXMLChild = pXMLChild->GetNodeItem(IFDE_XMLNode::NextSibling)) {
942 switch (pXMLChild->GetType()) {
943 case FDE_XMLNODE_Element: {
944 CFX_WideString wsTextData;
945 ((IFDE_XMLElement*)pXMLChild)->GetTextData(wsTextData);
946 wsTextData += FX_WSTRC(L"\n");
947 wsOutput += wsTextData;
948 } break;
949 case FDE_XMLNODE_Text: {
950 CFX_WideString wsText;
951 ((IFDE_XMLText*)pXMLChild)->GetText(wsText);
952 if (XFA_FDEExtension_IsStringAllWhitespace(wsText)) {
953 continue;
954 } else {
955 wsOutput = wsText;
956 }
957 } break;
958 case FDE_XMLNODE_CharData: {
959 CFX_WideString wsCharData;
960 ((IFDE_XMLCharData*)pXMLChild)->GetCharData(wsCharData);
961 if (XFA_FDEExtension_IsStringAllWhitespace(wsCharData)) {
962 continue;
963 } else {
964 wsOutput = wsCharData;
965 }
966 } break;
967 default:
968 FXSYS_assert(FALSE);
969 break;
970 }
971 }
972 }
973
974 void CXFA_SimpleParser::ParseContentNode(CXFA_Node* pXFANode,
975 IFDE_XMLNode* pXMLNode,
976 XFA_XDPPACKET ePacketID) {
977 XFA_ELEMENT element = XFA_ELEMENT_Sharptext;
978 if (pXFANode->GetClassID() == XFA_ELEMENT_ExData) {
979 CFX_WideStringC wsContentType =
980 pXFANode->GetCData(XFA_ATTRIBUTE_ContentType);
981 if (wsContentType == FX_WSTRC(L"text/html"))
982 element = XFA_ELEMENT_SharpxHTML;
983 else if (wsContentType == FX_WSTRC(L"text/xml"))
984 element = XFA_ELEMENT_Sharpxml;
985 }
986 if (element == XFA_ELEMENT_SharpxHTML)
987 pXFANode->SetXMLMappingNode(pXMLNode);
988
989 CFX_WideString wsValue;
990 for (IFDE_XMLNode* pXMLChild =
991 pXMLNode->GetNodeItem(IFDE_XMLNode::FirstChild);
992 pXMLChild;
993 pXMLChild = pXMLChild->GetNodeItem(IFDE_XMLNode::NextSibling)) {
994 FDE_XMLNODETYPE eNodeType = pXMLChild->GetType();
995 if (eNodeType == FDE_XMLNODE_Instruction)
996 continue;
997
998 if (element == XFA_ELEMENT_SharpxHTML) {
999 if (eNodeType != FDE_XMLNODE_Element)
1000 break;
1001
1002 if (XFA_RecognizeRichText((IFDE_XMLElement*)pXMLChild))
1003 XFA_GetPlainTextFromRichText((IFDE_XMLElement*)pXMLChild, wsValue);
1004 } else if (element == XFA_ELEMENT_Sharpxml) {
1005 if (eNodeType != FDE_XMLNODE_Element)
1006 break;
1007 XFA_ConvertXMLToPlainText((IFDE_XMLElement*)pXMLChild, wsValue);
1008 } else {
1009 if (eNodeType == FDE_XMLNODE_Element)
1010 break;
1011 if (eNodeType == FDE_XMLNODE_Text)
1012 ((IFDE_XMLText*)pXMLChild)->GetText(wsValue);
1013 else if (eNodeType == FDE_XMLNODE_CharData)
1014 ((IFDE_XMLCharData*)pXMLChild)->GetCharData(wsValue);
1015 }
1016 break;
1017 }
1018 if (!wsValue.IsEmpty()) {
1019 if (pXFANode->GetObjectType() == XFA_OBJECTTYPE_ContentNode) {
1020 CXFA_Node* pContentRawDataNode =
1021 m_pFactory->CreateNode(ePacketID, element);
1022 FXSYS_assert(pContentRawDataNode);
1023 pContentRawDataNode->SetCData(XFA_ATTRIBUTE_Value, wsValue);
1024 pXFANode->InsertChild(pContentRawDataNode);
1025 } else {
1026 pXFANode->SetCData(XFA_ATTRIBUTE_Value, wsValue);
1027 }
1028 }
1029 }
1030
1031 void CXFA_SimpleParser::ParseDataGroup(CXFA_Node* pXFANode,
1032 IFDE_XMLNode* pXMLNode,
1033 XFA_XDPPACKET ePacketID) {
1034 for (IFDE_XMLNode* pXMLChild =
1035 pXMLNode->GetNodeItem(IFDE_XMLNode::FirstChild);
1036 pXMLChild;
1037 pXMLChild = pXMLChild->GetNodeItem(IFDE_XMLNode::NextSibling)) {
1038 switch (pXMLChild->GetType()) {
1039 case FDE_XMLNODE_Element: {
1040 IFDE_XMLElement* pXMLElement = (IFDE_XMLElement*)pXMLChild;
1041 {
1042 CFX_WideString wsNamespaceURI;
1043 XFA_FDEExtension_GetElementTagNamespaceURI(pXMLElement,
1044 wsNamespaceURI);
1045 if (wsNamespaceURI ==
1046 FX_WSTRC(L"http://www.xfa.com/schema/xfa-package/") ||
1047 wsNamespaceURI ==
1048 FX_WSTRC(L"http://www.xfa.org/schema/xfa-package/") ||
1049 wsNamespaceURI ==
1050 FX_WSTRC(L"http://www.w3.org/2001/XMLSchema-instance")) {
1051 continue;
1052 }
1053 if (0) {
1054 continue;
1055 }
1056 }
1057 XFA_ELEMENT eNodeType = XFA_ELEMENT_DataModel;
1058 if (eNodeType == XFA_ELEMENT_DataModel) {
1059 CFX_WideString wsDataNodeAttr;
1060 if (XFA_FDEExtension_FindAttributeWithNS(
1061 pXMLElement, FX_WSTRC(L"dataNode"),
1062 FX_WSTRC(L"http://www.xfa.org/schema/xfa-data/1.0/"),
1063 wsDataNodeAttr)) {
1064 if (wsDataNodeAttr == FX_WSTRC(L"dataGroup")) {
1065 eNodeType = XFA_ELEMENT_DataGroup;
1066 } else if (wsDataNodeAttr == FX_WSTRC(L"dataValue")) {
1067 eNodeType = XFA_ELEMENT_DataValue;
1068 }
1069 }
1070 }
1071 CFX_WideString wsContentType;
1072 if (eNodeType == XFA_ELEMENT_DataModel) {
1073 if (XFA_FDEExtension_FindAttributeWithNS(
1074 pXMLElement, FX_WSTRC(L"contentType"),
1075 FX_WSTRC(L"http://www.xfa.org/schema/xfa-data/1.0/"),
1076 wsContentType)) {
1077 if (!wsContentType.IsEmpty()) {
1078 eNodeType = XFA_ELEMENT_DataValue;
1079 }
1080 }
1081 }
1082 if (eNodeType == XFA_ELEMENT_DataModel) {
1083 for (IFDE_XMLNode* pXMLDataChild =
1084 pXMLElement->GetNodeItem(IFDE_XMLNode::FirstChild);
1085 pXMLDataChild; pXMLDataChild = pXMLDataChild->GetNodeItem(
1086 IFDE_XMLNode::NextSibling)) {
1087 if (pXMLDataChild->GetType() == FDE_XMLNODE_Element) {
1088 if (!XFA_RecognizeRichText((IFDE_XMLElement*)pXMLDataChild)) {
1089 eNodeType = XFA_ELEMENT_DataGroup;
1090 break;
1091 }
1092 }
1093 }
1094 }
1095 if (eNodeType == XFA_ELEMENT_DataModel) {
1096 eNodeType = XFA_ELEMENT_DataValue;
1097 }
1098 CXFA_Node* pXFAChild =
1099 m_pFactory->CreateNode(XFA_XDPPACKET_Datasets, eNodeType);
1100 if (pXFAChild == NULL) {
1101 return;
1102 }
1103 CFX_WideString wsNodeName;
1104 pXMLElement->GetLocalTagName(wsNodeName);
1105 pXFAChild->SetCData(XFA_ATTRIBUTE_Name, wsNodeName);
1106 FX_BOOL bNeedValue = TRUE;
1107 if (1) {
1108 for (int32_t i = 0, count = pXMLElement->CountAttributes(); i < count;
1109 i++) {
1110 CFX_WideString wsAttrQualifiedName;
1111 CFX_WideString wsAttrValue;
1112 CFX_WideString wsAttrName;
1113 CFX_WideString wsAttrNamespaceURI;
1114 pXMLElement->GetAttribute(i, wsAttrQualifiedName, wsAttrValue);
1115 if (!XFA_FDEExtension_ResolveAttribute(
1116 pXMLElement, wsAttrQualifiedName, wsAttrName,
1117 wsAttrNamespaceURI)) {
1118 continue;
1119 }
1120 if (wsAttrName == FX_WSTRC(L"nil") &&
1121 wsAttrValue == FX_WSTRC(L"true")) {
1122 bNeedValue = FALSE;
1123 continue;
1124 }
1125 if (wsAttrNamespaceURI ==
1126 FX_WSTRC(L"http://www.xfa.com/schema/xfa-package/") ||
1127 wsAttrNamespaceURI ==
1128 FX_WSTRC(L"http://www.xfa.org/schema/xfa-package/") ||
1129 wsAttrNamespaceURI ==
1130 FX_WSTRC(L"http://www.w3.org/2001/XMLSchema-instance") ||
1131 wsAttrNamespaceURI ==
1132 FX_WSTRC(L"http://www.xfa.org/schema/xfa-data/1.0/")) {
1133 continue;
1134 }
1135 if (0) {
1136 continue;
1137 }
1138 CXFA_Node* pXFAMetaData = m_pFactory->CreateNode(
1139 XFA_XDPPACKET_Datasets, XFA_ELEMENT_DataValue);
1140 if (pXFAMetaData == NULL) {
1141 return;
1142 }
1143 pXFAMetaData->SetCData(XFA_ATTRIBUTE_Name, wsAttrName);
1144 pXFAMetaData->SetCData(XFA_ATTRIBUTE_QualifiedName,
1145 wsAttrQualifiedName);
1146 pXFAMetaData->SetCData(XFA_ATTRIBUTE_Value, wsAttrValue);
1147 pXFAMetaData->SetEnum(XFA_ATTRIBUTE_Contains,
1148 XFA_ATTRIBUTEENUM_MetaData);
1149 pXFAChild->InsertChild(pXFAMetaData);
1150 pXFAMetaData->SetXMLMappingNode(pXMLElement);
1151 pXFAMetaData->SetFlag(XFA_NODEFLAG_Initialized, TRUE, FALSE);
1152 }
1153 if (!bNeedValue) {
1154 CFX_WideString wsNilName = FX_WSTRC(L"xsi:nil");
1155 pXMLElement->RemoveAttribute(wsNilName);
1156 }
1157 }
1158 pXFANode->InsertChild(pXFAChild);
1159 if (eNodeType == XFA_ELEMENT_DataGroup) {
1160 ParseDataGroup(pXFAChild, pXMLElement, ePacketID);
1161 } else {
1162 if (bNeedValue) {
1163 ParseDataValue(pXFAChild, pXMLChild, XFA_XDPPACKET_Datasets);
1164 }
1165 }
1166 pXFAChild->SetXMLMappingNode(pXMLElement);
1167 pXFAChild->SetFlag(XFA_NODEFLAG_Initialized, TRUE, FALSE);
1168 }
1169 continue;
1170 case FDE_XMLNODE_CharData: {
1171 IFDE_XMLCharData* pXMLCharData = (IFDE_XMLCharData*)pXMLChild;
1172 CFX_WideString wsCharData;
1173 pXMLCharData->GetCharData(wsCharData);
1174 if (XFA_FDEExtension_IsStringAllWhitespace(wsCharData)) {
1175 continue;
1176 }
1177 CXFA_Node* pXFAChild = m_pFactory->CreateNode(XFA_XDPPACKET_Datasets,
1178 XFA_ELEMENT_DataValue);
1179 if (pXFAChild == NULL) {
1180 return;
1181 }
1182 pXFAChild->SetCData(XFA_ATTRIBUTE_Value, wsCharData);
1183 pXFANode->InsertChild(pXFAChild);
1184 pXFAChild->SetXMLMappingNode(pXMLCharData);
1185 pXFAChild->SetFlag(XFA_NODEFLAG_Initialized, TRUE, FALSE);
1186 }
1187 continue;
1188 case FDE_XMLNODE_Text: {
1189 IFDE_XMLText* pXMLText = (IFDE_XMLText*)pXMLChild;
1190 CFX_WideString wsText;
1191 pXMLText->GetText(wsText);
1192 if (XFA_FDEExtension_IsStringAllWhitespace(wsText)) {
1193 continue;
1194 }
1195 CXFA_Node* pXFAChild = m_pFactory->CreateNode(XFA_XDPPACKET_Datasets,
1196 XFA_ELEMENT_DataValue);
1197 if (pXFAChild == NULL) {
1198 return;
1199 }
1200 pXFAChild->SetCData(XFA_ATTRIBUTE_Value, wsText);
1201 pXFANode->InsertChild(pXFAChild);
1202 pXFAChild->SetXMLMappingNode(pXMLText);
1203 pXFAChild->SetFlag(XFA_NODEFLAG_Initialized, TRUE, FALSE);
1204 }
1205 continue;
1206 case FDE_XMLNODE_Instruction:
1207 continue;
1208 default:
1209 continue;
1210 }
1211 }
1212 }
1213
1214 void CXFA_SimpleParser::ParseDataValue(CXFA_Node* pXFANode,
1215 IFDE_XMLNode* pXMLNode,
1216 XFA_XDPPACKET ePacketID) {
1217 CFX_WideTextBuf wsValueTextBuf;
1218 CFX_WideTextBuf wsCurValueTextBuf;
1219 FX_BOOL bMarkAsCompound = FALSE;
1220 IFDE_XMLNode* pXMLCurValueNode = nullptr;
1221 for (IFDE_XMLNode* pXMLChild =
1222 pXMLNode->GetNodeItem(IFDE_XMLNode::FirstChild);
1223 pXMLChild;
1224 pXMLChild = pXMLChild->GetNodeItem(IFDE_XMLNode::NextSibling)) {
1225 FDE_XMLNODETYPE eNodeType = pXMLChild->GetType();
1226 if (eNodeType == FDE_XMLNODE_Instruction)
1227 continue;
1228
1229 CFX_WideString wsText;
1230 if (eNodeType == FDE_XMLNODE_Text) {
1231 ((IFDE_XMLText*)pXMLChild)->GetText(wsText);
1232 if (!pXMLCurValueNode)
1233 pXMLCurValueNode = pXMLChild;
1234
1235 wsCurValueTextBuf << wsText;
1236 } else if (eNodeType == FDE_XMLNODE_CharData) {
1237 ((IFDE_XMLCharData*)pXMLChild)->GetCharData(wsText);
1238 if (!pXMLCurValueNode)
1239 pXMLCurValueNode = pXMLChild;
1240
1241 wsCurValueTextBuf << wsText;
1242 } else if (XFA_RecognizeRichText((IFDE_XMLElement*)pXMLChild)) {
1243 XFA_GetPlainTextFromRichText((IFDE_XMLElement*)pXMLChild, wsText);
1244 if (!pXMLCurValueNode)
1245 pXMLCurValueNode = pXMLChild;
1246
1247 wsCurValueTextBuf << wsText;
1248 } else {
1249 bMarkAsCompound = TRUE;
1250 if (pXMLCurValueNode) {
1251 CFX_WideStringC wsCurValue = wsCurValueTextBuf.GetWideString();
1252 if (!wsCurValue.IsEmpty()) {
1253 CXFA_Node* pXFAChild =
1254 m_pFactory->CreateNode(ePacketID, XFA_ELEMENT_DataValue);
1255 if (!pXFAChild)
1256 return;
1257
1258 pXFAChild->SetCData(XFA_ATTRIBUTE_Name, FX_WSTRC(L""));
1259 pXFAChild->SetCData(XFA_ATTRIBUTE_Value, wsCurValue);
1260 pXFANode->InsertChild(pXFAChild);
1261 pXFAChild->SetXMLMappingNode(pXMLCurValueNode);
1262 pXFAChild->SetFlag(XFA_NODEFLAG_Initialized, TRUE, FALSE);
1263 wsValueTextBuf << wsCurValue;
1264 wsCurValueTextBuf.Clear();
1265 }
1266 pXMLCurValueNode = nullptr;
1267 }
1268 CXFA_Node* pXFAChild =
1269 m_pFactory->CreateNode(ePacketID, XFA_ELEMENT_DataValue);
1270 if (!pXFAChild)
1271 return;
1272
1273 CFX_WideString wsNodeStr;
1274 ((IFDE_XMLElement*)pXMLChild)->GetLocalTagName(wsNodeStr);
1275 pXFAChild->SetCData(XFA_ATTRIBUTE_Name, wsNodeStr);
1276 ParseDataValue(pXFAChild, pXMLChild, ePacketID);
1277 pXFANode->InsertChild(pXFAChild);
1278 pXFAChild->SetXMLMappingNode(pXMLChild);
1279 pXFAChild->SetFlag(XFA_NODEFLAG_Initialized, TRUE, FALSE);
1280 CFX_WideStringC wsCurValue = pXFAChild->GetCData(XFA_ATTRIBUTE_Value);
1281 wsValueTextBuf << wsCurValue;
1282 }
1283 }
1284 if (pXMLCurValueNode) {
1285 CFX_WideStringC wsCurValue = wsCurValueTextBuf.GetWideString();
1286 if (!wsCurValue.IsEmpty()) {
1287 if (bMarkAsCompound) {
1288 CXFA_Node* pXFAChild =
1289 m_pFactory->CreateNode(ePacketID, XFA_ELEMENT_DataValue);
1290 if (!pXFAChild)
1291 return;
1292
1293 pXFAChild->SetCData(XFA_ATTRIBUTE_Name, FX_WSTRC(L""));
1294 pXFAChild->SetCData(XFA_ATTRIBUTE_Value, wsCurValue);
1295 pXFANode->InsertChild(pXFAChild);
1296 pXFAChild->SetXMLMappingNode(pXMLCurValueNode);
1297 pXFAChild->SetFlag(XFA_NODEFLAG_Initialized, TRUE, FALSE);
1298 }
1299 wsValueTextBuf << wsCurValue;
1300 wsCurValueTextBuf.Clear();
1301 }
1302 pXMLCurValueNode = nullptr;
1303 }
1304 CFX_WideStringC wsNodeValue = wsValueTextBuf.GetWideString();
1305 pXFANode->SetCData(XFA_ATTRIBUTE_Value, wsNodeValue);
1306 }
1307
1308 void CXFA_SimpleParser::ParseInstruction(CXFA_Node* pXFANode,
1309 IFDE_XMLInstruction* pXMLInstruction,
1310 XFA_XDPPACKET ePacketID) {
1311 if (!m_bDocumentParser) {
1312 return;
1313 }
1314 CFX_WideString wsTargetName;
1315 pXMLInstruction->GetTargetName(wsTargetName);
1316 if (wsTargetName == FX_WSTRC(L"originalXFAVersion")) {
1317 CFX_WideString wsData;
1318 if (pXMLInstruction->GetData(0, wsData) &&
1319 (pXFANode->GetDocument()->RecognizeXFAVersionNumber(wsData) !=
1320 XFA_VERSION_UNKNOWN)) {
1321 wsData.Empty();
1322 if (pXMLInstruction->GetData(1, wsData) &&
1323 wsData == FX_WSTRC(L"v2.7-scripting:1")) {
1324 pXFANode->GetDocument()->SetFlag(XFA_DOCFLAG_Scripting, TRUE);
1325 }
1326 }
1327 } else if (wsTargetName == FX_WSTRC(L"acrobat")) {
1328 CFX_WideString wsData;
1329 if (pXMLInstruction->GetData(0, wsData) &&
1330 wsData == FX_WSTRC(L"JavaScript")) {
1331 if (pXMLInstruction->GetData(1, wsData) &&
1332 wsData == FX_WSTRC(L"strictScoping")) {
1333 pXFANode->GetDocument()->SetFlag(XFA_DOCFLAG_StrictScoping, TRUE);
1334 }
1335 }
1336 }
1337 }
1338 void CXFA_SimpleParser::CloseParser() {
1339 if (m_pXMLDoc) {
1340 m_pXMLDoc->Release();
1341 m_pXMLDoc = NULL;
1342 }
1343 if (m_pStream) {
1344 m_pStream->Release();
1345 m_pStream = NULL;
1346 }
1347 }
1348 IXFA_DocParser* IXFA_DocParser::Create(IXFA_Notify* pNotify) {
1349 return new CXFA_DocumentParser(pNotify);
1350 }
1351 CXFA_DocumentParser::CXFA_DocumentParser(IXFA_Notify* pNotify)
1352 : m_nodeParser(NULL, TRUE), m_pNotify(pNotify), m_pDocument(NULL) {}
1353 CXFA_DocumentParser::~CXFA_DocumentParser() {
1354 CloseParser();
1355 }
1356 int32_t CXFA_DocumentParser::StartParse(IFX_FileRead* pStream,
1357 XFA_XDPPACKET ePacketID) {
1358 CloseParser();
1359 int32_t nRetStatus = m_nodeParser.StartParse(pStream, ePacketID);
1360 if (nRetStatus == XFA_PARSESTATUS_Ready) {
1361 m_pDocument = new CXFA_Document(this);
1362 m_nodeParser.SetFactory(m_pDocument);
1363 }
1364 return nRetStatus;
1365 }
1366 int32_t CXFA_DocumentParser::DoParse(IFX_Pause* pPause) {
1367 int32_t nRetStatus = m_nodeParser.DoParse(pPause);
1368 if (nRetStatus >= XFA_PARSESTATUS_Done) {
1369 FXSYS_assert(m_pDocument);
1370 m_pDocument->SetRoot(m_nodeParser.GetRootNode());
1371 }
1372 return nRetStatus;
1373 }
1374 int32_t CXFA_DocumentParser::ParseXMLData(const CFX_WideString& wsXML,
1375 IFDE_XMLNode*& pXMLNode,
1376 IFX_Pause* pPause) {
1377 CloseParser();
1378 int32_t nRetStatus = m_nodeParser.ParseXMLData(wsXML, pXMLNode, NULL);
1379 if (nRetStatus == XFA_PARSESTATUS_Done && pXMLNode) {
1380 m_pDocument = new CXFA_Document(this);
1381 m_nodeParser.SetFactory(m_pDocument);
1382 }
1383 return nRetStatus;
1384 }
1385 void CXFA_DocumentParser::ConstructXFANode(CXFA_Node* pXFANode,
1386 IFDE_XMLNode* pXMLNode) {
1387 if (!pXFANode || !pXMLNode) {
1388 return;
1389 }
1390 m_nodeParser.ConstructXFANode(pXFANode, pXMLNode);
1391 CXFA_Node* pRootNode = m_nodeParser.GetRootNode();
1392 if (m_pDocument && pRootNode) {
1393 m_pDocument->SetRoot(pRootNode);
1394 }
1395 }
1396 void CXFA_DocumentParser::CloseParser() {
1397 if (m_pDocument) {
1398 delete m_pDocument;
1399 m_pDocument = NULL;
1400 }
1401 m_nodeParser.CloseParser();
1402 }
1403 CXFA_XMLParser::CXFA_XMLParser(IFDE_XMLNode* pRoot, IFX_Stream* pStream)
1404 : m_nElementStart(0),
1405 m_dwCheckStatus(0),
1406 m_dwCurrentCheckStatus(0),
1407 m_pRoot(pRoot),
1408 m_pStream(pStream),
1409 m_pParser(nullptr),
1410 m_pParent(pRoot),
1411 m_pChild(nullptr),
1412 m_NodeStack(16),
1413 m_dwStatus(FDE_XMLSYNTAXSTATUS_None) {
1414 ASSERT(m_pParent && m_pStream);
1415 m_NodeStack.Push(m_pParent);
1416 m_pParser = IFDE_XMLSyntaxParser::Create();
1417 m_pParser->Init(m_pStream, 32 * 1024, 1024 * 1024);
1418 }
1419 CXFA_XMLParser::~CXFA_XMLParser() {
1420 if (m_pParser) {
1421 m_pParser->Release();
1422 }
1423 m_NodeStack.RemoveAll();
1424 m_ws1.Empty();
1425 m_ws2.Empty();
1426 }
1427 int32_t CXFA_XMLParser::DoParser(IFX_Pause* pPause) {
1428 if (m_dwStatus == FDE_XMLSYNTAXSTATUS_Error) {
1429 return -1;
1430 }
1431 if (m_dwStatus == FDE_XMLSYNTAXSTATUS_EOS) {
1432 return 100;
1433 }
1434 int32_t iCount = 0;
1435 while (TRUE) {
1436 m_dwStatus = m_pParser->DoSyntaxParse();
1437 switch (m_dwStatus) {
1438 case FDE_XMLSYNTAXSTATUS_InstructionOpen:
1439 break;
1440 case FDE_XMLSYNTAXSTATUS_InstructionClose:
1441 if (m_pChild) {
1442 if (m_pChild->GetType() != FDE_XMLNODE_Instruction) {
1443 m_dwStatus = FDE_XMLSYNTAXSTATUS_Error;
1444 break;
1445 }
1446 }
1447 m_pChild = m_pParent;
1448 break;
1449 case FDE_XMLSYNTAXSTATUS_ElementOpen:
1450 if (m_dwCheckStatus != 0x03 && m_NodeStack.GetSize() == 2) {
1451 m_nElementStart = m_pParser->GetCurrentPos() - 1;
1452 }
1453 break;
1454 case FDE_XMLSYNTAXSTATUS_ElementBreak:
1455 break;
1456 case FDE_XMLSYNTAXSTATUS_ElementClose:
1457 if (m_pChild->GetType() != FDE_XMLNODE_Element) {
1458 m_dwStatus = FDE_XMLSYNTAXSTATUS_Error;
1459 break;
1460 }
1461 m_pParser->GetTagName(m_ws1);
1462 ((IFDE_XMLElement*)m_pChild)->GetTagName(m_ws2);
1463 if (m_ws1.GetLength() > 0 && !m_ws1.Equal(m_ws2)) {
1464 m_dwStatus = FDE_XMLSYNTAXSTATUS_Error;
1465 break;
1466 }
1467 m_NodeStack.Pop();
1468 if (m_NodeStack.GetSize() < 1) {
1469 m_dwStatus = FDE_XMLSYNTAXSTATUS_Error;
1470 break;
1471 } else if (m_dwCurrentCheckStatus != 0 && m_NodeStack.GetSize() == 2) {
1472 m_nSize[m_dwCurrentCheckStatus - 1] =
1473 m_pParser->GetCurrentBinaryPos() -
1474 m_nStart[m_dwCurrentCheckStatus - 1];
1475 m_dwCurrentCheckStatus = 0;
1476 }
1477
1478 m_pParent = (IFDE_XMLNode*)*m_NodeStack.GetTopElement();
1479 m_pChild = m_pParent;
1480 iCount++;
1481 break;
1482 case FDE_XMLSYNTAXSTATUS_TargetName:
1483 m_pParser->GetTargetName(m_ws1);
1484 if (m_ws1 == FX_WSTRC(L"originalXFAVersion") ||
1485 m_ws1 == FX_WSTRC(L"acrobat")) {
1486 m_pChild = IFDE_XMLInstruction::Create(m_ws1);
1487 m_pParent->InsertChildNode(m_pChild);
1488 } else {
1489 m_pChild = NULL;
1490 }
1491 m_ws1.Empty();
1492 break;
1493 case FDE_XMLSYNTAXSTATUS_TagName:
1494 m_pParser->GetTagName(m_ws1);
1495 m_pChild = IFDE_XMLElement::Create(m_ws1);
1496 m_pParent->InsertChildNode(m_pChild);
1497 m_NodeStack.Push(m_pChild);
1498 m_pParent = m_pChild;
1499
1500 if (m_dwCheckStatus != 0x03 && m_NodeStack.GetSize() == 3) {
1501 CFX_WideString wsTag;
1502 ((IFDE_XMLElement*)m_pChild)->GetLocalTagName(wsTag);
1503 if (wsTag == FX_WSTRC(L"template")) {
1504 m_dwCheckStatus |= 0x01;
1505 m_dwCurrentCheckStatus = 0x01;
1506 m_nStart[0] = m_pParser->GetCurrentBinaryPos() -
1507 (m_pParser->GetCurrentPos() - m_nElementStart);
1508 } else if (wsTag == FX_WSTRC(L"datasets")) {
1509 m_dwCheckStatus |= 0x02;
1510 m_dwCurrentCheckStatus = 0x02;
1511 m_nStart[1] = m_pParser->GetCurrentBinaryPos() -
1512 (m_pParser->GetCurrentPos() - m_nElementStart);
1513 }
1514 }
1515 break;
1516 case FDE_XMLSYNTAXSTATUS_AttriName:
1517 m_pParser->GetAttributeName(m_ws1);
1518 break;
1519 case FDE_XMLSYNTAXSTATUS_AttriValue:
1520 if (m_pChild) {
1521 m_pParser->GetAttributeName(m_ws2);
1522 if (m_pChild->GetType() == FDE_XMLNODE_Element) {
1523 ((IFDE_XMLElement*)m_pChild)->SetString(m_ws1, m_ws2);
1524 }
1525 }
1526 m_ws1.Empty();
1527 break;
1528 case FDE_XMLSYNTAXSTATUS_Text:
1529 m_pParser->GetTextData(m_ws1);
1530 m_pChild = IFDE_XMLText::Create(m_ws1);
1531 m_pParent->InsertChildNode(m_pChild);
1532 m_pChild = m_pParent;
1533 break;
1534 case FDE_XMLSYNTAXSTATUS_CData:
1535 m_pParser->GetTextData(m_ws1);
1536 m_pChild = IFDE_XMLCharData::Create(m_ws1);
1537 m_pParent->InsertChildNode(m_pChild);
1538 m_pChild = m_pParent;
1539 break;
1540 case FDE_XMLSYNTAXSTATUS_TargetData:
1541 if (m_pChild) {
1542 if (m_pChild->GetType() != FDE_XMLNODE_Instruction) {
1543 m_dwStatus = FDE_XMLSYNTAXSTATUS_Error;
1544 break;
1545 }
1546 if (!m_ws1.IsEmpty()) {
1547 ((IFDE_XMLInstruction*)m_pChild)->AppendData(m_ws1);
1548 }
1549 m_pParser->GetTargetData(m_ws1);
1550 ((IFDE_XMLInstruction*)m_pChild)->AppendData(m_ws1);
1551 }
1552 m_ws1.Empty();
1553 break;
1554 default:
1555 break;
1556 }
1557 if (m_dwStatus == FDE_XMLSYNTAXSTATUS_Error ||
1558 m_dwStatus == FDE_XMLSYNTAXSTATUS_EOS) {
1559 break;
1560 }
1561 if (pPause && iCount > 500 && pPause->NeedToPauseNow()) {
1562 break;
1563 }
1564 }
1565 return (m_dwStatus == FDE_XMLSYNTAXSTATUS_Error || m_NodeStack.GetSize() != 1)
1566 ? -1
1567 : m_pParser->GetStatus();
1568 }
OLDNEW
« no previous file with comments | « xfa/src/fxfa/parser/xfa_parser_imp.h ('k') | xfa/src/fxfa/parser/xfa_parser_imp_embeddertest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698