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

Side by Side Diff: xfa/fxfa/parser/xfa_document_serialize.cpp

Issue 2123133004: Remove IXFA_Parser, cleanup XFA parser code. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase to master Created 4 years, 5 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
« no previous file with comments | « xfa/fxfa/parser/xfa_document_layout_imp.cpp ('k') | xfa/fxfa/parser/xfa_layout_appadapter.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "xfa/fxfa/parser/xfa_document_serialize.h" 7 #include "xfa/fxfa/parser/xfa_document_serialize.h"
8 8
9 #include "xfa/fde/xml/fde_xml_imp.h" 9 #include "xfa/fde/xml/fde_xml_imp.h"
10 #include "xfa/fgas/crt/fgas_codepage.h" 10 #include "xfa/fgas/crt/fgas_codepage.h"
11 #include "xfa/fxfa/parser/xfa_doclayout.h" 11 #include "xfa/fxfa/parser/xfa_doclayout.h"
12 #include "xfa/fxfa/parser/xfa_document.h" 12 #include "xfa/fxfa/parser/xfa_document.h"
13 #include "xfa/fxfa/parser/xfa_localemgr.h" 13 #include "xfa/fxfa/parser/xfa_localemgr.h"
14 #include "xfa/fxfa/parser/xfa_object.h" 14 #include "xfa/fxfa/parser/xfa_object.h"
15 #include "xfa/fxfa/parser/xfa_parser.h"
16 #include "xfa/fxfa/parser/xfa_parser_imp.h" 15 #include "xfa/fxfa/parser/xfa_parser_imp.h"
17 #include "xfa/fxfa/parser/xfa_script.h" 16 #include "xfa/fxfa/parser/xfa_script.h"
18 #include "xfa/fxfa/parser/xfa_utils.h" 17 #include "xfa/fxfa/parser/xfa_utils.h"
19 18
20 CXFA_DataImporter::CXFA_DataImporter(CXFA_Document* pDocument) 19 CXFA_DataImporter::CXFA_DataImporter(CXFA_Document* pDocument)
21 : m_pDocument(pDocument) { 20 : m_pDocument(pDocument) {
22 ASSERT(m_pDocument); 21 ASSERT(m_pDocument);
23 } 22 }
24 FX_BOOL CXFA_DataImporter::ImportData(IFX_FileRead* pDataDocument) { 23 FX_BOOL CXFA_DataImporter::ImportData(IFX_FileRead* pDataDocument) {
25 IXFA_Parser* pDataDocumentParser = IXFA_Parser::Create(m_pDocument); 24 std::unique_ptr<CXFA_SimpleParser> pDataDocumentParser(
26 if (!pDataDocumentParser) { 25 new CXFA_SimpleParser(m_pDocument, false));
26 if (!pDataDocumentParser)
27 return FALSE;
28
29 if (pDataDocumentParser->StartParse(pDataDocument, XFA_XDPPACKET_Datasets) !=
30 XFA_PARSESTATUS_Ready) {
27 return FALSE; 31 return FALSE;
28 } 32 }
29 if (pDataDocumentParser->StartParse(pDataDocument, XFA_XDPPACKET_Datasets) != 33 if (pDataDocumentParser->DoParse(nullptr) < XFA_PARSESTATUS_Done)
30 XFA_PARSESTATUS_Ready) {
31 pDataDocumentParser->Release();
32 return FALSE; 34 return FALSE;
33 } 35
34 if (pDataDocumentParser->DoParse(nullptr) < XFA_PARSESTATUS_Done) { 36 CXFA_Node* pImportDataRoot = pDataDocumentParser->GetRootNode();
35 pDataDocumentParser->Release(); 37 if (!pImportDataRoot)
36 return FALSE; 38 return FALSE;
37 } 39
38 CXFA_Node* pImportDataRoot = pDataDocumentParser->GetRootNode();
39 if (!pImportDataRoot) {
40 pDataDocumentParser->Release();
41 return FALSE;
42 }
43 CXFA_Node* pDataModel = 40 CXFA_Node* pDataModel =
44 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets)); 41 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets));
45 if (!pDataModel) { 42 if (!pDataModel)
46 pDataDocumentParser->Release();
47 return FALSE; 43 return FALSE;
48 } 44
49 CXFA_Node* pDataNode = ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Data)); 45 CXFA_Node* pDataNode = ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Data));
50 if (pDataNode) { 46 if (pDataNode)
51 pDataModel->RemoveChild(pDataNode); 47 pDataModel->RemoveChild(pDataNode);
52 } 48
53 if (pImportDataRoot->GetElementType() == XFA_Element::DataModel) { 49 if (pImportDataRoot->GetElementType() == XFA_Element::DataModel) {
54 while (CXFA_Node* pChildNode = 50 while (CXFA_Node* pChildNode =
55 pImportDataRoot->GetNodeItem(XFA_NODEITEM_FirstChild)) { 51 pImportDataRoot->GetNodeItem(XFA_NODEITEM_FirstChild)) {
56 pImportDataRoot->RemoveChild(pChildNode); 52 pImportDataRoot->RemoveChild(pChildNode);
57 pDataModel->InsertChild(pChildNode); 53 pDataModel->InsertChild(pChildNode);
58 } 54 }
59 } else { 55 } else {
60 CFDE_XMLNode* pXMLNode = pImportDataRoot->GetXMLMappingNode(); 56 CFDE_XMLNode* pXMLNode = pImportDataRoot->GetXMLMappingNode();
61 CFDE_XMLNode* pParentXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::Parent); 57 CFDE_XMLNode* pParentXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::Parent);
62 if (pParentXMLNode) { 58 if (pParentXMLNode)
63 pParentXMLNode->RemoveChildNode(pXMLNode); 59 pParentXMLNode->RemoveChildNode(pXMLNode);
64 }
65 pDataModel->InsertChild(pImportDataRoot); 60 pDataModel->InsertChild(pImportDataRoot);
66 } 61 }
67 m_pDocument->DoDataRemerge(FALSE); 62 m_pDocument->DoDataRemerge(FALSE);
68 pDataDocumentParser->Release();
69 return TRUE; 63 return TRUE;
70 } 64 }
65
71 CFX_WideString XFA_ExportEncodeAttribute(const CFX_WideString& str) { 66 CFX_WideString XFA_ExportEncodeAttribute(const CFX_WideString& str) {
72 CFX_WideTextBuf textBuf; 67 CFX_WideTextBuf textBuf;
73 int32_t iLen = str.GetLength(); 68 int32_t iLen = str.GetLength();
74 for (int32_t i = 0; i < iLen; i++) { 69 for (int32_t i = 0; i < iLen; i++) {
75 switch (str[i]) { 70 switch (str[i]) {
76 case '&': 71 case '&':
77 textBuf << FX_WSTRC(L"&amp;"); 72 textBuf << FX_WSTRC(L"&amp;");
78 break; 73 break;
79 case '<': 74 case '<':
80 textBuf << FX_WSTRC(L"&lt;"); 75 textBuf << FX_WSTRC(L"&lt;");
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 } 475 }
481 pStream->SetCodePage(FX_CODEPAGE_UTF8); 476 pStream->SetCodePage(FX_CODEPAGE_UTF8);
482 FX_BOOL bRet = Export(pStream, pNode, dwFlag, pChecksum); 477 FX_BOOL bRet = Export(pStream, pNode, dwFlag, pChecksum);
483 pStream->Release(); 478 pStream->Release();
484 return bRet; 479 return bRet;
485 } 480 }
486 FX_BOOL CXFA_DataExporter::Export(IFX_Stream* pStream, 481 FX_BOOL CXFA_DataExporter::Export(IFX_Stream* pStream,
487 CXFA_Node* pNode, 482 CXFA_Node* pNode,
488 uint32_t dwFlag, 483 uint32_t dwFlag,
489 const FX_CHAR* pChecksum) { 484 const FX_CHAR* pChecksum) {
490 CFDE_XMLDoc* pXMLDoc = m_pDocument->GetParser()->GetXMLDoc(); 485 CFDE_XMLDoc* pXMLDoc = m_pDocument->GetXMLDoc();
491 if (pNode->IsModelNode()) { 486 if (pNode->IsModelNode()) {
492 switch (pNode->GetPacketID()) { 487 switch (pNode->GetPacketID()) {
493 case XFA_XDPPACKET_XDP: { 488 case XFA_XDPPACKET_XDP: {
494 static const FX_WCHAR s_pwsPreamble[] = 489 static const FX_WCHAR s_pwsPreamble[] =
495 L"<xdp:xdp xmlns:xdp=\"http://ns.adobe.com/xdp/\">"; 490 L"<xdp:xdp xmlns:xdp=\"http://ns.adobe.com/xdp/\">";
496 pStream->WriteString(s_pwsPreamble, FXSYS_wcslen(s_pwsPreamble)); 491 pStream->WriteString(s_pwsPreamble, FXSYS_wcslen(s_pwsPreamble));
497 for (CXFA_Node* pChild = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); 492 for (CXFA_Node* pChild = pNode->GetNodeItem(XFA_NODEITEM_FirstChild);
498 pChild; pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { 493 pChild; pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
499 Export(pStream, pChild, dwFlag, pChecksum); 494 Export(pStream, pChild, dwFlag, pChecksum);
500 } 495 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 pXMLElement->RemoveAttribute(L"xfa:dataNode"); 565 pXMLElement->RemoveAttribute(L"xfa:dataNode");
571 } 566 }
572 } else { 567 } else {
573 CFDE_XMLNode* pXMLNode = pDataNode->GetXMLMappingNode(); 568 CFDE_XMLNode* pXMLNode = pDataNode->GetXMLMappingNode();
574 ASSERT(pXMLNode->GetType() == FDE_XMLNODE_Element); 569 ASSERT(pXMLNode->GetType() == FDE_XMLNODE_Element);
575 static_cast<CFDE_XMLElement*>(pXMLNode)->SetString(L"xfa:dataNode", 570 static_cast<CFDE_XMLElement*>(pXMLNode)->SetString(L"xfa:dataNode",
576 L"dataGroup"); 571 L"dataGroup");
577 } 572 }
578 } 573 }
579 } 574 }
OLDNEW
« no previous file with comments | « xfa/fxfa/parser/xfa_document_layout_imp.cpp ('k') | xfa/fxfa/parser/xfa_layout_appadapter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698