OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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/fxfa/parser/cxfa_dataimporter.h" | |
8 | |
9 #include <memory> | |
10 | |
11 #include "core/fxcrt/include/fx_stream.h" | |
12 #include "xfa/fxfa/include/fxfa.h" | |
13 #include "xfa/fxfa/include/fxfa_basic.h" | |
14 #include "xfa/fxfa/parser/cxfa_document.h" | |
15 #include "xfa/fxfa/parser/cxfa_simple_parser.h" | |
16 #include "xfa/fxfa/parser/xfa_object.h" | |
Wei Li
2016/07/20 22:36:47
still need fde_xml_imp.h?
dsinclair
2016/07/21 13:34:37
Done.
| |
17 | |
18 CXFA_DataImporter::CXFA_DataImporter(CXFA_Document* pDocument) | |
19 : m_pDocument(pDocument) { | |
20 ASSERT(m_pDocument); | |
21 } | |
22 | |
23 FX_BOOL CXFA_DataImporter::ImportData(IFX_FileRead* pDataDocument) { | |
24 std::unique_ptr<CXFA_SimpleParser> pDataDocumentParser( | |
25 new CXFA_SimpleParser(m_pDocument, false)); | |
26 if (!pDataDocumentParser) | |
Wei Li
2016/07/20 22:36:47
Do we need to check this?
dsinclair
2016/07/21 13:34:37
Done.
| |
27 return FALSE; | |
28 | |
29 if (pDataDocumentParser->StartParse(pDataDocument, XFA_XDPPACKET_Datasets) != | |
30 XFA_PARSESTATUS_Ready) { | |
31 return FALSE; | |
32 } | |
33 if (pDataDocumentParser->DoParse(nullptr) < XFA_PARSESTATUS_Done) | |
34 return FALSE; | |
35 | |
36 CXFA_Node* pImportDataRoot = pDataDocumentParser->GetRootNode(); | |
37 if (!pImportDataRoot) | |
38 return FALSE; | |
39 | |
40 CXFA_Node* pDataModel = | |
41 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets)); | |
42 if (!pDataModel) | |
43 return FALSE; | |
44 | |
45 CXFA_Node* pDataNode = ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Data)); | |
46 if (pDataNode) | |
47 pDataModel->RemoveChild(pDataNode); | |
48 | |
49 if (pImportDataRoot->GetElementType() == XFA_Element::DataModel) { | |
50 while (CXFA_Node* pChildNode = | |
51 pImportDataRoot->GetNodeItem(XFA_NODEITEM_FirstChild)) { | |
52 pImportDataRoot->RemoveChild(pChildNode); | |
53 pDataModel->InsertChild(pChildNode); | |
54 } | |
55 } else { | |
56 CFDE_XMLNode* pXMLNode = pImportDataRoot->GetXMLMappingNode(); | |
57 CFDE_XMLNode* pParentXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::Parent); | |
58 if (pParentXMLNode) | |
59 pParentXMLNode->RemoveChildNode(pXMLNode); | |
60 pDataModel->InsertChild(pImportDataRoot); | |
61 } | |
62 m_pDocument->DoDataRemerge(FALSE); | |
63 return TRUE; | |
64 } | |
OLD | NEW |