OLD | NEW |
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 <memory> |
| 10 |
9 #include "xfa/fde/xml/fde_xml_imp.h" | 11 #include "xfa/fde/xml/fde_xml_imp.h" |
10 #include "xfa/fgas/crt/fgas_codepage.h" | 12 #include "xfa/fgas/crt/fgas_codepage.h" |
11 #include "xfa/fxfa/fm2js/xfa_fm2jsapi.h" | 13 #include "xfa/fxfa/fm2js/xfa_fm2jsapi.h" |
12 #include "xfa/fxfa/parser/xfa_doclayout.h" | 14 #include "xfa/fxfa/parser/xfa_doclayout.h" |
13 #include "xfa/fxfa/parser/xfa_document.h" | 15 #include "xfa/fxfa/parser/xfa_document.h" |
14 #include "xfa/fxfa/parser/xfa_localemgr.h" | 16 #include "xfa/fxfa/parser/xfa_localemgr.h" |
15 #include "xfa/fxfa/parser/xfa_object.h" | 17 #include "xfa/fxfa/parser/xfa_object.h" |
16 #include "xfa/fxfa/parser/xfa_parser.h" | 18 #include "xfa/fxfa/parser/xfa_parser.h" |
17 #include "xfa/fxfa/parser/xfa_parser_imp.h" | 19 #include "xfa/fxfa/parser/xfa_parser_imp.h" |
18 #include "xfa/fxfa/parser/xfa_script.h" | 20 #include "xfa/fxfa/parser/xfa_script.h" |
19 #include "xfa/fxfa/parser/xfa_utils.h" | 21 #include "xfa/fxfa/parser/xfa_utils.h" |
20 | 22 |
21 CXFA_DataImporter::CXFA_DataImporter(CXFA_Document* pDocument) | 23 CXFA_DataImporter::CXFA_DataImporter(CXFA_Document* pDocument) |
22 : m_pDocument(pDocument) { | 24 : m_pDocument(pDocument) { |
23 ASSERT(m_pDocument); | 25 ASSERT(m_pDocument); |
24 } | 26 } |
| 27 |
25 FX_BOOL CXFA_DataImporter::ImportData(IFX_FileRead* pDataDocument) { | 28 FX_BOOL CXFA_DataImporter::ImportData(IFX_FileRead* pDataDocument) { |
26 IXFA_Parser* pDataDocumentParser = IXFA_Parser::Create(m_pDocument); | 29 std::unique_ptr<IXFA_Parser> pDataDocumentParser( |
27 if (!pDataDocumentParser) { | 30 IXFA_Parser::Create(m_pDocument)); |
| 31 if (pDataDocumentParser->StartParse(pDataDocument, XFA_XDPPACKET_Datasets) != |
| 32 XFA_PARSESTATUS_Ready) { |
28 return FALSE; | 33 return FALSE; |
29 } | 34 } |
30 if (pDataDocumentParser->StartParse(pDataDocument, XFA_XDPPACKET_Datasets) != | 35 if (pDataDocumentParser->DoParse(nullptr) < XFA_PARSESTATUS_Done) |
31 XFA_PARSESTATUS_Ready) { | |
32 pDataDocumentParser->Release(); | |
33 return FALSE; | 36 return FALSE; |
34 } | 37 |
35 if (pDataDocumentParser->DoParse(NULL) < XFA_PARSESTATUS_Done) { | 38 CXFA_Node* pImportDataRoot = pDataDocumentParser->GetRootNode(); |
36 pDataDocumentParser->Release(); | 39 if (!pImportDataRoot) |
37 return FALSE; | 40 return FALSE; |
38 } | 41 |
39 CXFA_Node* pImportDataRoot = pDataDocumentParser->GetRootNode(); | |
40 if (!pImportDataRoot) { | |
41 pDataDocumentParser->Release(); | |
42 return FALSE; | |
43 } | |
44 CXFA_Node* pDataModel = | 42 CXFA_Node* pDataModel = |
45 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets)); | 43 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets)); |
46 if (!pDataModel) { | 44 if (!pDataModel) |
47 pDataDocumentParser->Release(); | |
48 return FALSE; | 45 return FALSE; |
49 } | 46 |
50 CXFA_Node* pDataNode = ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Data)); | 47 CXFA_Node* pDataNode = ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Data)); |
51 if (pDataNode) { | 48 if (pDataNode) { |
52 pDataModel->RemoveChild(pDataNode); | 49 pDataModel->RemoveChild(pDataNode); |
53 } | 50 } |
54 if (pImportDataRoot->GetClassID() == XFA_ELEMENT_DataModel) { | 51 if (pImportDataRoot->GetClassID() == XFA_ELEMENT_DataModel) { |
55 while (CXFA_Node* pChildNode = | 52 while (CXFA_Node* pChildNode = |
56 pImportDataRoot->GetNodeItem(XFA_NODEITEM_FirstChild)) { | 53 pImportDataRoot->GetNodeItem(XFA_NODEITEM_FirstChild)) { |
57 pImportDataRoot->RemoveChild(pChildNode); | 54 pImportDataRoot->RemoveChild(pChildNode); |
58 pDataModel->InsertChild(pChildNode); | 55 pDataModel->InsertChild(pChildNode); |
59 } | 56 } |
60 } else { | 57 } else { |
61 CFDE_XMLNode* pXMLNode = pImportDataRoot->GetXMLMappingNode(); | 58 CFDE_XMLNode* pXMLNode = pImportDataRoot->GetXMLMappingNode(); |
62 CFDE_XMLNode* pParentXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::Parent); | 59 CFDE_XMLNode* pParentXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::Parent); |
63 if (pParentXMLNode) { | 60 if (pParentXMLNode) { |
64 pParentXMLNode->RemoveChildNode(pXMLNode); | 61 pParentXMLNode->RemoveChildNode(pXMLNode); |
65 } | 62 } |
66 pDataModel->InsertChild(pImportDataRoot); | 63 pDataModel->InsertChild(pImportDataRoot); |
67 } | 64 } |
68 m_pDocument->DoDataRemerge(FALSE); | 65 m_pDocument->DoDataRemerge(FALSE); |
69 pDataDocumentParser->Release(); | |
70 return TRUE; | 66 return TRUE; |
71 } | 67 } |
| 68 |
72 CFX_WideString XFA_ExportEncodeAttribute(const CFX_WideString& str) { | 69 CFX_WideString XFA_ExportEncodeAttribute(const CFX_WideString& str) { |
73 CFX_WideTextBuf textBuf; | 70 CFX_WideTextBuf textBuf; |
74 int32_t iLen = str.GetLength(); | 71 int32_t iLen = str.GetLength(); |
75 for (int32_t i = 0; i < iLen; i++) { | 72 for (int32_t i = 0; i < iLen; i++) { |
76 switch (str[i]) { | 73 switch (str[i]) { |
77 case '&': | 74 case '&': |
78 textBuf << FX_WSTRC(L"&"); | 75 textBuf << FX_WSTRC(L"&"); |
79 break; | 76 break; |
80 case '<': | 77 case '<': |
81 textBuf << FX_WSTRC(L"<"); | 78 textBuf << FX_WSTRC(L"<"); |
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 pXMLElement->RemoveAttribute(L"xfa:dataNode"); | 571 pXMLElement->RemoveAttribute(L"xfa:dataNode"); |
575 } | 572 } |
576 } else { | 573 } else { |
577 CFDE_XMLNode* pXMLNode = pDataNode->GetXMLMappingNode(); | 574 CFDE_XMLNode* pXMLNode = pDataNode->GetXMLMappingNode(); |
578 ASSERT(pXMLNode->GetType() == FDE_XMLNODE_Element); | 575 ASSERT(pXMLNode->GetType() == FDE_XMLNODE_Element); |
579 static_cast<CFDE_XMLElement*>(pXMLNode)->SetString(L"xfa:dataNode", | 576 static_cast<CFDE_XMLElement*>(pXMLNode)->SetString(L"xfa:dataNode", |
580 L"dataGroup"); | 577 L"dataGroup"); |
581 } | 578 } |
582 } | 579 } |
583 } | 580 } |
OLD | NEW |