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