OLD | NEW |
---|---|
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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/cxfa_simple_parser.h" | 7 #include "xfa/fxfa/parser/cxfa_simple_parser.h" |
8 | 8 |
9 #include "xfa/fgas/crt/fgas_codepage.h" | 9 #include "xfa/fgas/crt/fgas_codepage.h" |
10 #include "xfa/fxfa/include/fxfa.h" | 10 #include "xfa/fxfa/include/fxfa.h" |
11 #include "xfa/fxfa/include/xfa_checksum.h" | 11 #include "xfa/fxfa/include/xfa_checksum.h" |
12 #include "xfa/fxfa/parser/cxfa_xml_parser.h" | 12 #include "xfa/fxfa/parser/cxfa_xml_parser.h" |
13 #include "xfa/fxfa/parser/xfa_document.h" | 13 #include "xfa/fxfa/parser/xfa_document.h" |
14 | 14 |
15 CXFA_SimpleParser::CXFA_SimpleParser(CXFA_Document* pFactory, | 15 CXFA_SimpleParser::CXFA_SimpleParser(CXFA_Document* pFactory, |
16 bool bDocumentParser) | 16 bool bDocumentParser) |
17 : m_pXMLParser(nullptr), | 17 : m_pXMLParser(nullptr), |
18 m_pXMLDoc(nullptr), | 18 m_pXMLDoc(nullptr), |
19 m_pStream(nullptr), | 19 m_pStream(nullptr), |
20 m_pFileRead(nullptr), | 20 m_pFileRead(nullptr), |
21 m_pFactory(pFactory), | 21 m_pFactory(pFactory), |
22 m_pRootNode(nullptr), | 22 m_pRootNode(nullptr), |
23 m_ePacketID(XFA_XDPPACKET_UNKNOWN), | 23 m_ePacketID(XFA_XDPPACKET_UNKNOWN), |
24 m_bDocumentParser(bDocumentParser) {} | 24 m_bDocumentParser(bDocumentParser) {} |
25 | 25 |
26 CXFA_SimpleParser::~CXFA_SimpleParser() { | 26 CXFA_SimpleParser::~CXFA_SimpleParser() { |
27 CloseParser(); | |
28 } | 27 } |
29 | 28 |
30 void CXFA_SimpleParser::SetFactory(CXFA_Document* pFactory) { | 29 void CXFA_SimpleParser::SetFactory(CXFA_Document* pFactory) { |
31 m_pFactory = pFactory; | 30 m_pFactory = pFactory; |
32 } | 31 } |
33 | 32 |
34 static CFDE_XMLNode* XFA_FDEExtension_GetDocumentNode( | 33 static CFDE_XMLNode* XFA_FDEExtension_GetDocumentNode( |
35 CFDE_XMLDoc* pXMLDoc, | 34 CFDE_XMLDoc* pXMLDoc, |
36 FX_BOOL bVerifyWellFormness = FALSE) { | 35 FX_BOOL bVerifyWellFormness = FALSE) { |
37 if (!pXMLDoc) { | 36 if (!pXMLDoc) { |
(...skipping 16 matching lines...) Expand all Loading... | |
54 } | 53 } |
55 return pXMLNode; | 54 return pXMLNode; |
56 } | 55 } |
57 } | 56 } |
58 return nullptr; | 57 return nullptr; |
59 } | 58 } |
60 int32_t CXFA_SimpleParser::StartParse(IFX_FileRead* pStream, | 59 int32_t CXFA_SimpleParser::StartParse(IFX_FileRead* pStream, |
61 XFA_XDPPACKET ePacketID) { | 60 XFA_XDPPACKET ePacketID) { |
62 CloseParser(); | 61 CloseParser(); |
63 m_pFileRead = pStream; | 62 m_pFileRead = pStream; |
64 m_pStream = IFX_Stream::CreateStream( | 63 m_pStream.reset(IFX_Stream::CreateStream( |
65 pStream, FX_STREAMACCESS_Read | FX_STREAMACCESS_Text); | 64 pStream, FX_STREAMACCESS_Read | FX_STREAMACCESS_Text)); |
66 if (!m_pStream) { | 65 if (!m_pStream) |
67 return XFA_PARSESTATUS_StreamErr; | 66 return XFA_PARSESTATUS_StreamErr; |
68 } | 67 |
69 uint16_t wCodePage = m_pStream->GetCodePage(); | 68 uint16_t wCodePage = m_pStream->GetCodePage(); |
70 if (wCodePage != FX_CODEPAGE_UTF16LE && wCodePage != FX_CODEPAGE_UTF16BE && | 69 if (wCodePage != FX_CODEPAGE_UTF16LE && wCodePage != FX_CODEPAGE_UTF16BE && |
71 wCodePage != FX_CODEPAGE_UTF8) { | 70 wCodePage != FX_CODEPAGE_UTF8) { |
72 m_pStream->SetCodePage(FX_CODEPAGE_UTF8); | 71 m_pStream->SetCodePage(FX_CODEPAGE_UTF8); |
73 } | 72 } |
74 m_pXMLDoc = new CFDE_XMLDoc; | 73 m_pXMLDoc.reset(new CFDE_XMLDoc); |
75 m_pXMLParser = new CXFA_XMLParser(m_pXMLDoc->GetRoot(), m_pStream); | 74 m_pXMLParser = new CXFA_XMLParser(m_pXMLDoc->GetRoot(), m_pStream.get()); |
76 if (!m_pXMLDoc->LoadXML(m_pXMLParser)) { | 75 if (!m_pXMLDoc->LoadXML(m_pXMLParser)) |
77 return XFA_PARSESTATUS_StatusErr; | 76 return XFA_PARSESTATUS_StatusErr; |
78 } | 77 |
79 m_ePacketID = ePacketID; | 78 m_ePacketID = ePacketID; |
80 return XFA_PARSESTATUS_Ready; | 79 return XFA_PARSESTATUS_Ready; |
81 } | 80 } |
Wei Li
2016/07/07 22:22:11
Blank line here? Ditto.
dsinclair
2016/07/11 13:41:29
Done.
| |
82 int32_t CXFA_SimpleParser::DoParse(IFX_Pause* pPause) { | 81 int32_t CXFA_SimpleParser::DoParse(IFX_Pause* pPause) { |
83 if (!m_pXMLDoc || m_ePacketID == XFA_XDPPACKET_UNKNOWN) { | 82 if (!m_pXMLDoc || m_ePacketID == XFA_XDPPACKET_UNKNOWN) |
84 return XFA_PARSESTATUS_StatusErr; | 83 return XFA_PARSESTATUS_StatusErr; |
85 } | 84 |
86 int32_t iRet = m_pXMLDoc->DoLoad(pPause); | 85 int32_t iRet = m_pXMLDoc->DoLoad(pPause); |
87 if (iRet < 0) { | 86 if (iRet < 0) |
88 return XFA_PARSESTATUS_SyntaxErr; | 87 return XFA_PARSESTATUS_SyntaxErr; |
89 } | 88 if (iRet < 100) |
90 if (iRet < 100) { | |
91 return iRet / 2; | 89 return iRet / 2; |
92 } | 90 |
93 m_pRootNode = ParseAsXDPPacket(XFA_FDEExtension_GetDocumentNode(m_pXMLDoc), | 91 m_pRootNode = ParseAsXDPPacket( |
94 m_ePacketID); | 92 XFA_FDEExtension_GetDocumentNode(m_pXMLDoc.get()), m_ePacketID); |
95 m_pXMLDoc->CloseXML(); | 93 m_pXMLDoc->CloseXML(); |
96 if (m_pStream) { | 94 m_pStream.reset(); |
97 m_pStream->Release(); | 95 |
98 m_pStream = nullptr; | 96 if (!m_pRootNode) |
99 } | |
100 if (!m_pRootNode) { | |
101 return XFA_PARSESTATUS_StatusErr; | 97 return XFA_PARSESTATUS_StatusErr; |
102 } | |
103 return XFA_PARSESTATUS_Done; | 98 return XFA_PARSESTATUS_Done; |
104 } | 99 } |
105 int32_t CXFA_SimpleParser::ParseXMLData(const CFX_WideString& wsXML, | 100 int32_t CXFA_SimpleParser::ParseXMLData(const CFX_WideString& wsXML, |
106 CFDE_XMLNode*& pXMLNode, | 101 CFDE_XMLNode*& pXMLNode, |
107 IFX_Pause* pPause) { | 102 IFX_Pause* pPause) { |
108 CloseParser(); | 103 CloseParser(); |
109 pXMLNode = nullptr; | 104 pXMLNode = nullptr; |
110 IFX_Stream* pStream = XFA_CreateWideTextRead(wsXML); | 105 IFX_Stream* pStream = XFA_CreateWideTextRead(wsXML); |
111 if (!pStream) { | 106 if (!pStream) |
112 return XFA_PARSESTATUS_StreamErr; | 107 return XFA_PARSESTATUS_StreamErr; |
113 } | 108 |
114 m_pStream = pStream; | 109 m_pStream.reset(pStream); |
Wei Li
2016/07/07 22:22:11
Is |m_pStream| needed here? Having a unique_ptr of
dsinclair
2016/07/11 13:41:29
Done.
| |
115 m_pXMLDoc = new CFDE_XMLDoc; | 110 m_pXMLDoc.reset(new CFDE_XMLDoc); |
116 CXFA_XMLParser* pParser = new CXFA_XMLParser(m_pXMLDoc->GetRoot(), m_pStream); | 111 CXFA_XMLParser* pParser = |
112 new CXFA_XMLParser(m_pXMLDoc->GetRoot(), m_pStream.get()); | |
117 pParser->m_dwCheckStatus = 0x03; | 113 pParser->m_dwCheckStatus = 0x03; |
118 if (!m_pXMLDoc->LoadXML(pParser)) { | 114 if (!m_pXMLDoc->LoadXML(pParser)) |
119 return XFA_PARSESTATUS_StatusErr; | 115 return XFA_PARSESTATUS_StatusErr; |
120 } | 116 |
121 int32_t iRet = m_pXMLDoc->DoLoad(pPause); | 117 int32_t iRet = m_pXMLDoc->DoLoad(pPause); |
122 if (iRet < 0 || iRet >= 100) { | 118 if (iRet < 0 || iRet >= 100) |
123 m_pXMLDoc->CloseXML(); | 119 m_pXMLDoc->CloseXML(); |
124 } | 120 if (iRet < 0) |
125 if (iRet < 0) { | |
126 return XFA_PARSESTATUS_SyntaxErr; | 121 return XFA_PARSESTATUS_SyntaxErr; |
127 } | 122 if (iRet < 100) |
128 if (iRet < 100) { | |
129 return iRet / 2; | 123 return iRet / 2; |
130 } | 124 |
131 if (m_pStream) { | 125 m_pStream.reset(); |
132 m_pStream->Release(); | 126 |
133 m_pStream = nullptr; | 127 pXMLNode = XFA_FDEExtension_GetDocumentNode(m_pXMLDoc.get()); |
134 } | |
135 pXMLNode = XFA_FDEExtension_GetDocumentNode(m_pXMLDoc); | |
136 return XFA_PARSESTATUS_Done; | 128 return XFA_PARSESTATUS_Done; |
137 } | 129 } |
138 | 130 |
139 void CXFA_SimpleParser::ConstructXFANode(CXFA_Node* pXFANode, | 131 void CXFA_SimpleParser::ConstructXFANode(CXFA_Node* pXFANode, |
140 CFDE_XMLNode* pXMLNode) { | 132 CFDE_XMLNode* pXMLNode) { |
141 XFA_XDPPACKET ePacketID = (XFA_XDPPACKET)pXFANode->GetPacketID(); | 133 XFA_XDPPACKET ePacketID = (XFA_XDPPACKET)pXFANode->GetPacketID(); |
142 if (ePacketID == XFA_XDPPACKET_Datasets) { | 134 if (ePacketID == XFA_XDPPACKET_Datasets) { |
143 if (pXFANode->GetElementType() == XFA_Element::DataValue) { | 135 if (pXFANode->GetElementType() == XFA_Element::DataValue) { |
144 for (CFDE_XMLNode* pXMLChild = | 136 for (CFDE_XMLNode* pXMLChild = |
145 pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild); | 137 pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 } else { | 172 } else { |
181 m_pRootNode = NormalLoader(pXFANode, pXMLNode, ePacketID); | 173 m_pRootNode = NormalLoader(pXFANode, pXMLNode, ePacketID); |
182 } | 174 } |
183 } | 175 } |
184 | 176 |
185 CXFA_Node* CXFA_SimpleParser::GetRootNode() const { | 177 CXFA_Node* CXFA_SimpleParser::GetRootNode() const { |
186 return m_pRootNode; | 178 return m_pRootNode; |
187 } | 179 } |
188 | 180 |
189 CFDE_XMLDoc* CXFA_SimpleParser::GetXMLDoc() const { | 181 CFDE_XMLDoc* CXFA_SimpleParser::GetXMLDoc() const { |
190 return m_pXMLDoc; | 182 return m_pXMLDoc.get(); |
191 } | 183 } |
192 | 184 |
193 FX_BOOL XFA_FDEExtension_ResolveNamespaceQualifier( | 185 FX_BOOL XFA_FDEExtension_ResolveNamespaceQualifier( |
194 CFDE_XMLElement* pNode, | 186 CFDE_XMLElement* pNode, |
195 const CFX_WideStringC& wsQualifier, | 187 const CFX_WideStringC& wsQualifier, |
196 CFX_WideString& wsNamespaceURI) { | 188 CFX_WideString& wsNamespaceURI) { |
197 if (!pNode) { | 189 if (!pNode) { |
198 return FALSE; | 190 return FALSE; |
199 } | 191 } |
200 CFDE_XMLNode* pFakeRoot = pNode->GetNodeItem(CFDE_XMLNode::Root); | 192 CFDE_XMLNode* pFakeRoot = pNode->GetNodeItem(CFDE_XMLNode::Root); |
(...skipping 1099 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1300 if (pXMLInstruction->GetData(0, wsData) && | 1292 if (pXMLInstruction->GetData(0, wsData) && |
1301 wsData == FX_WSTRC(L"JavaScript")) { | 1293 wsData == FX_WSTRC(L"JavaScript")) { |
1302 if (pXMLInstruction->GetData(1, wsData) && | 1294 if (pXMLInstruction->GetData(1, wsData) && |
1303 wsData == FX_WSTRC(L"strictScoping")) { | 1295 wsData == FX_WSTRC(L"strictScoping")) { |
1304 pXFANode->GetDocument()->SetFlag(XFA_DOCFLAG_StrictScoping, TRUE); | 1296 pXFANode->GetDocument()->SetFlag(XFA_DOCFLAG_StrictScoping, TRUE); |
1305 } | 1297 } |
1306 } | 1298 } |
1307 } | 1299 } |
1308 } | 1300 } |
1309 void CXFA_SimpleParser::CloseParser() { | 1301 void CXFA_SimpleParser::CloseParser() { |
1310 if (m_pXMLDoc) { | 1302 m_pXMLDoc.reset(); |
1311 m_pXMLDoc->Release(); | 1303 m_pStream.reset(); |
1312 m_pXMLDoc = nullptr; | |
1313 } | |
1314 if (m_pStream) { | |
1315 m_pStream->Release(); | |
1316 m_pStream = nullptr; | |
1317 } | |
1318 } | 1304 } |
OLD | NEW |