blob: 28d0a8ce2a231b213fb269322a8ca6046dce1c71 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
// 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/fx_stream.h"
#include "core/fxcrt/xml/cfx_xmlnode.h"
#include "third_party/base/ptr_util.h"
#include "xfa/fxfa/fxfa.h"
#include "xfa/fxfa/fxfa_basic.h"
#include "xfa/fxfa/parser/cxfa_document.h"
#include "xfa/fxfa/parser/cxfa_node.h"
#include "xfa/fxfa/parser/cxfa_simple_parser.h"
CXFA_DataImporter::CXFA_DataImporter(CXFA_Document* pDocument)
: m_pDocument(pDocument) {
ASSERT(m_pDocument);
}
CXFA_DataImporter::~CXFA_DataImporter() {}
bool CXFA_DataImporter::ImportData(
const RetainPtr<IFX_SeekableStream>& pDataDocument) {
auto pDataDocumentParser =
pdfium::MakeUnique<CXFA_SimpleParser>(m_pDocument.Get(), false);
if (pDataDocumentParser->StartParse(
pDataDocument, XFA_PacketType::Datasets) != XFA_PARSESTATUS_Ready) {
return false;
}
if (pDataDocumentParser->DoParse() < 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, true);
if (pImportDataRoot->GetElementType() == XFA_Element::DataModel) {
while (CXFA_Node* pChildNode =
pImportDataRoot->GetNodeItem(XFA_NODEITEM_FirstChild)) {
pImportDataRoot->RemoveChild(pChildNode, true);
pDataModel->InsertChild(pChildNode, nullptr);
}
} else {
CFX_XMLNode* pXMLNode = pImportDataRoot->GetXMLMappingNode();
CFX_XMLNode* pParentXMLNode = pXMLNode->GetNodeItem(CFX_XMLNode::Parent);
if (pParentXMLNode)
pParentXMLNode->RemoveChildNode(pXMLNode);
pDataModel->InsertChild(pImportDataRoot, nullptr);
}
m_pDocument->DoDataRemerge(false);
return true;
}
|