summaryrefslogtreecommitdiff
path: root/xfa/fxfa/parser/cxfa_dataimporter.cpp
diff options
context:
space:
mode:
authordsinclair <dsinclair@chromium.org>2016-07-21 12:04:34 -0700
committerCommit bot <commit-bot@chromium.org>2016-07-21 12:04:34 -0700
commit3a7cc7382305e2d1f2793d9fea923f2428a87e64 (patch)
tree7e84a6a6d0e577a2fd736e4125c6078bb3860cbc /xfa/fxfa/parser/cxfa_dataimporter.cpp
parent16280245cab39fe646a97030940771bc105a1115 (diff)
downloadpdfium-3a7cc7382305e2d1f2793d9fea923f2428a87e64.tar.xz
Split xfa_document_serialize into class files
This CL moves CXFA_DataImporter and CXFA_DataExporter into their own files and moves code to an anonymous namespace as necessary. Review-Url: https://codereview.chromium.org/2164663004
Diffstat (limited to 'xfa/fxfa/parser/cxfa_dataimporter.cpp')
-rw-r--r--xfa/fxfa/parser/cxfa_dataimporter.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/xfa/fxfa/parser/cxfa_dataimporter.cpp b/xfa/fxfa/parser/cxfa_dataimporter.cpp
new file mode 100644
index 0000000000..87848ddebb
--- /dev/null
+++ b/xfa/fxfa/parser/cxfa_dataimporter.cpp
@@ -0,0 +1,62 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "xfa/fxfa/parser/cxfa_dataimporter.h"
+
+#include <memory>
+
+#include "core/fxcrt/include/fx_stream.h"
+#include "xfa/fde/xml/fde_xml_imp.h"
+#include "xfa/fxfa/include/fxfa.h"
+#include "xfa/fxfa/include/fxfa_basic.h"
+#include "xfa/fxfa/parser/cxfa_document.h"
+#include "xfa/fxfa/parser/cxfa_simple_parser.h"
+#include "xfa/fxfa/parser/xfa_object.h"
+
+CXFA_DataImporter::CXFA_DataImporter(CXFA_Document* pDocument)
+ : m_pDocument(pDocument) {
+ ASSERT(m_pDocument);
+}
+
+FX_BOOL CXFA_DataImporter::ImportData(IFX_FileRead* pDataDocument) {
+ std::unique_ptr<CXFA_SimpleParser> pDataDocumentParser(
+ new CXFA_SimpleParser(m_pDocument, false));
+ if (pDataDocumentParser->StartParse(pDataDocument, XFA_XDPPACKET_Datasets) !=
+ XFA_PARSESTATUS_Ready) {
+ return FALSE;
+ }
+ if (pDataDocumentParser->DoParse(nullptr) < XFA_PARSESTATUS_Done)
+ return FALSE;
+
+ CXFA_Node* pImportDataRoot = pDataDocumentParser->GetRootNode();
+ if (!pImportDataRoot)
+ return FALSE;
+
+ CXFA_Node* pDataModel =
+ ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets));
+ if (!pDataModel)
+ return FALSE;
+
+ CXFA_Node* pDataNode = ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Data));
+ if (pDataNode)
+ pDataModel->RemoveChild(pDataNode);
+
+ if (pImportDataRoot->GetElementType() == XFA_Element::DataModel) {
+ while (CXFA_Node* pChildNode =
+ pImportDataRoot->GetNodeItem(XFA_NODEITEM_FirstChild)) {
+ pImportDataRoot->RemoveChild(pChildNode);
+ pDataModel->InsertChild(pChildNode);
+ }
+ } else {
+ CFDE_XMLNode* pXMLNode = pImportDataRoot->GetXMLMappingNode();
+ CFDE_XMLNode* pParentXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::Parent);
+ if (pParentXMLNode)
+ pParentXMLNode->RemoveChildNode(pXMLNode);
+ pDataModel->InsertChild(pImportDataRoot);
+ }
+ m_pDocument->DoDataRemerge(FALSE);
+ return TRUE;
+}