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 namespace { | |
16 | |
17 class RichTextNodeVisitor { | |
Wei Li
2016/07/11 17:53:38
Is this used?
dsinclair
2016/07/11 18:55:01
Nice catch, removed.
| |
18 public: | |
19 static CFDE_XMLNode* GetFirstChild(CFDE_XMLNode* pNode) { | |
20 return pNode->GetNodeItem(CFDE_XMLNode::FirstChild); | |
21 } | |
22 static CFDE_XMLNode* GetNextSibling(CFDE_XMLNode* pNode) { | |
23 return pNode->GetNodeItem(CFDE_XMLNode::NextSibling); | |
24 } | |
25 static CFDE_XMLNode* GetParent(CFDE_XMLNode* pNode) { | |
26 return pNode->GetNodeItem(CFDE_XMLNode::Parent); | |
27 } | |
28 }; | |
29 | |
30 CFDE_XMLNode* GetDocumentNode(CFDE_XMLDoc* pXMLDoc, | |
31 FX_BOOL bVerifyWellFormness = FALSE) { | |
32 if (!pXMLDoc) | |
33 return nullptr; | |
34 | |
35 CFDE_XMLNode* pXMLFakeRoot = pXMLDoc->GetRoot(); | |
36 for (CFDE_XMLNode* pXMLNode = | |
37 pXMLFakeRoot->GetNodeItem(CFDE_XMLNode::FirstChild); | |
Wei Li
2016/07/11 17:53:38
Nit: no need for |pXMLFakeRoot|
dsinclair
2016/07/11 18:55:01
Done.
| |
38 pXMLNode; pXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::NextSibling)) { | |
39 if (pXMLNode->GetType() != FDE_XMLNODE_Element) | |
40 continue; | |
41 | |
42 if (!bVerifyWellFormness) | |
43 return pXMLNode; | |
44 | |
45 for (CFDE_XMLNode* pNextNode = | |
46 pXMLNode->GetNodeItem(CFDE_XMLNode::NextSibling); | |
47 pNextNode; | |
48 pNextNode = pNextNode->GetNodeItem(CFDE_XMLNode::NextSibling)) { | |
49 if (pNextNode->GetType() == FDE_XMLNODE_Element) | |
50 return FALSE; | |
51 } | |
52 return pXMLNode; | |
53 } | |
54 return nullptr; | |
55 } | |
56 | |
57 void GetElementTagNamespaceURI(CFDE_XMLElement* pElement, | |
58 CFX_WideString& wsNamespaceURI) { | |
59 CFX_WideString wsNodeStr; | |
60 pElement->GetNamespacePrefix(wsNodeStr); | |
61 if (!XFA_FDEExtension_ResolveNamespaceQualifier( | |
62 pElement, wsNodeStr.AsStringC(), wsNamespaceURI)) { | |
63 wsNamespaceURI.clear(); | |
64 } | |
65 } | |
66 | |
67 FX_BOOL MatchNodeName(CFDE_XMLNode* pNode, | |
68 const CFX_WideStringC& wsLocalTagName, | |
69 const CFX_WideStringC& wsNamespaceURIPrefix, | |
70 uint32_t eMatchFlags = XFA_XDPPACKET_FLAGS_NOMATCH) { | |
71 if (!pNode || pNode->GetType() != FDE_XMLNODE_Element) | |
72 return FALSE; | |
73 | |
74 CFDE_XMLElement* pElement = reinterpret_cast<CFDE_XMLElement*>(pNode); | |
75 CFX_WideString wsNodeStr; | |
76 pElement->GetLocalTagName(wsNodeStr); | |
77 if (wsNodeStr != wsLocalTagName) | |
78 return FALSE; | |
79 | |
80 GetElementTagNamespaceURI(pElement, wsNodeStr); | |
81 if (eMatchFlags & XFA_XDPPACKET_FLAGS_NOMATCH) | |
82 return TRUE; | |
83 if (eMatchFlags & XFA_XDPPACKET_FLAGS_PREFIXMATCH) { | |
84 return wsNodeStr.Left(wsNamespaceURIPrefix.GetLength()) == | |
85 wsNamespaceURIPrefix; | |
86 } | |
87 return wsNodeStr == wsNamespaceURIPrefix; | |
88 } | |
89 | |
90 FX_BOOL GetAttributeLocalName(const CFX_WideStringC& wsAttributeName, | |
91 CFX_WideString& wsLocalAttrName) { | |
92 CFX_WideString wsAttrName(wsAttributeName); | |
93 FX_STRSIZE iFind = wsAttrName.Find(L':', 0); | |
94 if (iFind < 0) { | |
95 wsLocalAttrName = wsAttrName; | |
96 return FALSE; | |
97 } | |
98 wsLocalAttrName = wsAttrName.Right(wsAttrName.GetLength() - iFind - 1); | |
99 return TRUE; | |
100 } | |
101 | |
102 FX_BOOL ResolveAttribute(CFDE_XMLElement* pElement, | |
103 const CFX_WideStringC& wsAttributeName, | |
104 CFX_WideString& wsLocalAttrName, | |
105 CFX_WideString& wsNamespaceURI) { | |
106 CFX_WideString wsAttrName(wsAttributeName); | |
107 CFX_WideString wsNSPrefix; | |
108 if (GetAttributeLocalName(wsAttributeName, wsLocalAttrName)) { | |
109 wsNSPrefix = wsAttrName.Left(wsAttributeName.GetLength() - | |
110 wsLocalAttrName.GetLength() - 1); | |
111 } | |
112 if (wsLocalAttrName == FX_WSTRC(L"xmlns") || | |
113 wsNSPrefix == FX_WSTRC(L"xmlns") || wsNSPrefix == FX_WSTRC(L"xml")) { | |
114 return FALSE; | |
115 } | |
116 if (!XFA_FDEExtension_ResolveNamespaceQualifier( | |
117 pElement, wsNSPrefix.AsStringC(), wsNamespaceURI)) { | |
118 wsNamespaceURI.clear(); | |
119 return FALSE; | |
120 } | |
121 return TRUE; | |
122 } | |
123 | |
124 FX_BOOL FindAttributeWithNS(CFDE_XMLElement* pElement, | |
125 const CFX_WideStringC& wsLocalAttributeName, | |
126 const CFX_WideStringC& wsNamespaceURIPrefix, | |
127 CFX_WideString& wsValue, | |
128 FX_BOOL bMatchNSAsPrefix = FALSE) { | |
129 if (!pElement) | |
130 return FALSE; | |
131 | |
132 CFX_WideString wsAttrName; | |
133 CFX_WideString wsAttrValue; | |
134 CFX_WideString wsAttrNS; | |
135 for (int32_t iAttrCount = pElement->CountAttributes(), i = 0; i < iAttrCount; | |
136 i++) { | |
137 pElement->GetAttribute(i, wsAttrName, wsAttrValue); | |
138 FX_STRSIZE iFind = wsAttrName.Find(L':', 0); | |
139 CFX_WideString wsNSPrefix; | |
140 if (iFind < 0) { | |
141 if (wsLocalAttributeName != wsAttrName) | |
142 continue; | |
143 } else { | |
144 if (wsLocalAttributeName != | |
145 wsAttrName.Right(wsAttrName.GetLength() - iFind - 1)) { | |
146 continue; | |
147 } | |
148 wsNSPrefix = wsAttrName.Left(iFind); | |
149 } | |
150 if (!XFA_FDEExtension_ResolveNamespaceQualifier( | |
151 pElement, wsNSPrefix.AsStringC(), wsAttrNS)) { | |
152 continue; | |
153 } | |
154 if (bMatchNSAsPrefix) { | |
155 if (wsAttrNS.Left(wsNamespaceURIPrefix.GetLength()) != | |
156 wsNamespaceURIPrefix) { | |
157 continue; | |
158 } | |
159 } else { | |
160 if (wsAttrNS != wsNamespaceURIPrefix) | |
161 continue; | |
162 } | |
163 wsValue = wsAttrValue; | |
164 return TRUE; | |
165 } | |
166 return FALSE; | |
167 } | |
168 | |
169 CFDE_XMLNode* GetDataSetsFromXDP(CFDE_XMLNode* pXMLDocumentNode) { | |
170 if (MatchNodeName(pXMLDocumentNode, | |
171 XFA_GetPacketByIndex(XFA_PACKET_Datasets)->pName, | |
172 XFA_GetPacketByIndex(XFA_PACKET_Datasets)->pURI, | |
173 XFA_GetPacketByIndex(XFA_PACKET_Datasets)->eFlags)) { | |
174 return pXMLDocumentNode; | |
175 } | |
176 if (!MatchNodeName(pXMLDocumentNode, | |
177 XFA_GetPacketByIndex(XFA_PACKET_XDP)->pName, | |
178 XFA_GetPacketByIndex(XFA_PACKET_XDP)->pURI, | |
179 XFA_GetPacketByIndex(XFA_PACKET_XDP)->eFlags)) { | |
180 return nullptr; | |
181 } | |
182 for (CFDE_XMLNode* pDatasetsNode = | |
183 pXMLDocumentNode->GetNodeItem(CFDE_XMLNode::FirstChild); | |
184 pDatasetsNode; | |
185 pDatasetsNode = pDatasetsNode->GetNodeItem(CFDE_XMLNode::NextSibling)) { | |
186 if (!MatchNodeName(pDatasetsNode, | |
187 XFA_GetPacketByIndex(XFA_PACKET_Datasets)->pName, | |
188 XFA_GetPacketByIndex(XFA_PACKET_Datasets)->pURI, | |
189 XFA_GetPacketByIndex(XFA_PACKET_Datasets)->eFlags)) { | |
190 continue; | |
191 } | |
192 return pDatasetsNode; | |
193 } | |
194 return nullptr; | |
195 } | |
196 | |
197 FX_BOOL IsStringAllWhitespace(CFX_WideString wsText) { | |
198 wsText.TrimRight(L"\x20\x9\xD\xA"); | |
199 return wsText.IsEmpty(); | |
200 } | |
201 | |
202 void ConvertXMLToPlainText(CFDE_XMLElement* pRootXMLNode, | |
203 CFX_WideString& wsOutput) { | |
204 for (CFDE_XMLNode* pXMLChild = | |
205 pRootXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild); | |
206 pXMLChild; | |
207 pXMLChild = pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling)) { | |
208 switch (pXMLChild->GetType()) { | |
209 case FDE_XMLNODE_Element: { | |
210 CFX_WideString wsTextData; | |
211 static_cast<CFDE_XMLElement*>(pXMLChild)->GetTextData(wsTextData); | |
212 wsTextData += FX_WSTRC(L"\n"); | |
213 wsOutput += wsTextData; | |
214 break; | |
215 } | |
216 case FDE_XMLNODE_Text: { | |
217 CFX_WideString wsText; | |
218 static_cast<CFDE_XMLText*>(pXMLChild)->GetText(wsText); | |
219 if (IsStringAllWhitespace(wsText)) | |
220 continue; | |
221 | |
222 wsOutput = wsText; | |
223 break; | |
224 } | |
225 case FDE_XMLNODE_CharData: { | |
226 CFX_WideString wsCharData; | |
227 static_cast<CFDE_XMLCharData*>(pXMLChild)->GetCharData(wsCharData); | |
228 if (IsStringAllWhitespace(wsCharData)) | |
229 continue; | |
230 | |
231 wsOutput = wsCharData; | |
232 break; | |
233 } | |
234 default: | |
235 ASSERT(FALSE); | |
236 break; | |
237 } | |
238 } | |
239 } | |
240 | |
241 } // namespace | |
242 | |
243 FX_BOOL XFA_RecognizeRichText(CFDE_XMLElement* pRichTextXMLNode) { | |
244 if (pRichTextXMLNode) { | |
245 CFX_WideString wsNamespaceURI; | |
246 GetElementTagNamespaceURI(pRichTextXMLNode, wsNamespaceURI); | |
247 if (wsNamespaceURI == FX_WSTRC(L"http://www.w3.org/1999/xhtml")) | |
248 return TRUE; | |
249 } | |
250 return FALSE; | |
251 } | |
252 | |
15 CXFA_SimpleParser::CXFA_SimpleParser(CXFA_Document* pFactory, | 253 CXFA_SimpleParser::CXFA_SimpleParser(CXFA_Document* pFactory, |
16 bool bDocumentParser) | 254 bool bDocumentParser) |
17 : m_pXMLParser(nullptr), | 255 : m_pXMLParser(nullptr), |
18 m_pXMLDoc(nullptr), | 256 m_pXMLDoc(nullptr), |
19 m_pStream(nullptr), | 257 m_pStream(nullptr), |
20 m_pFileRead(nullptr), | 258 m_pFileRead(nullptr), |
21 m_pFactory(pFactory), | 259 m_pFactory(pFactory), |
22 m_pRootNode(nullptr), | 260 m_pRootNode(nullptr), |
23 m_ePacketID(XFA_XDPPACKET_UNKNOWN), | 261 m_ePacketID(XFA_XDPPACKET_UNKNOWN), |
24 m_bDocumentParser(bDocumentParser) {} | 262 m_bDocumentParser(bDocumentParser) {} |
25 | 263 |
26 CXFA_SimpleParser::~CXFA_SimpleParser() { | 264 CXFA_SimpleParser::~CXFA_SimpleParser() {} |
27 } | |
28 | 265 |
29 void CXFA_SimpleParser::SetFactory(CXFA_Document* pFactory) { | 266 void CXFA_SimpleParser::SetFactory(CXFA_Document* pFactory) { |
30 m_pFactory = pFactory; | 267 m_pFactory = pFactory; |
31 } | 268 } |
32 | 269 |
33 static CFDE_XMLNode* XFA_FDEExtension_GetDocumentNode( | |
34 CFDE_XMLDoc* pXMLDoc, | |
35 FX_BOOL bVerifyWellFormness = FALSE) { | |
36 if (!pXMLDoc) { | |
37 return nullptr; | |
38 } | |
39 CFDE_XMLNode* pXMLFakeRoot = pXMLDoc->GetRoot(); | |
40 for (CFDE_XMLNode* pXMLNode = | |
41 pXMLFakeRoot->GetNodeItem(CFDE_XMLNode::FirstChild); | |
42 pXMLNode; pXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::NextSibling)) { | |
43 if (pXMLNode->GetType() == FDE_XMLNODE_Element) { | |
44 if (bVerifyWellFormness) { | |
45 for (CFDE_XMLNode* pNextNode = | |
46 pXMLNode->GetNodeItem(CFDE_XMLNode::NextSibling); | |
47 pNextNode; | |
48 pNextNode = pNextNode->GetNodeItem(CFDE_XMLNode::NextSibling)) { | |
49 if (pNextNode->GetType() == FDE_XMLNODE_Element) { | |
50 return FALSE; | |
51 } | |
52 } | |
53 } | |
54 return pXMLNode; | |
55 } | |
56 } | |
57 return nullptr; | |
58 } | |
59 | |
60 int32_t CXFA_SimpleParser::StartParse(IFX_FileRead* pStream, | 270 int32_t CXFA_SimpleParser::StartParse(IFX_FileRead* pStream, |
61 XFA_XDPPACKET ePacketID) { | 271 XFA_XDPPACKET ePacketID) { |
62 CloseParser(); | 272 CloseParser(); |
63 m_pFileRead = pStream; | 273 m_pFileRead = pStream; |
64 m_pStream.reset(IFX_Stream::CreateStream( | 274 m_pStream.reset(IFX_Stream::CreateStream( |
65 pStream, FX_STREAMACCESS_Read | FX_STREAMACCESS_Text)); | 275 pStream, FX_STREAMACCESS_Read | FX_STREAMACCESS_Text)); |
66 if (!m_pStream) | 276 if (!m_pStream) |
67 return XFA_PARSESTATUS_StreamErr; | 277 return XFA_PARSESTATUS_StreamErr; |
68 | 278 |
69 uint16_t wCodePage = m_pStream->GetCodePage(); | 279 uint16_t wCodePage = m_pStream->GetCodePage(); |
(...skipping 13 matching lines...) Expand all Loading... | |
83 int32_t CXFA_SimpleParser::DoParse(IFX_Pause* pPause) { | 293 int32_t CXFA_SimpleParser::DoParse(IFX_Pause* pPause) { |
84 if (!m_pXMLDoc || m_ePacketID == XFA_XDPPACKET_UNKNOWN) | 294 if (!m_pXMLDoc || m_ePacketID == XFA_XDPPACKET_UNKNOWN) |
85 return XFA_PARSESTATUS_StatusErr; | 295 return XFA_PARSESTATUS_StatusErr; |
86 | 296 |
87 int32_t iRet = m_pXMLDoc->DoLoad(pPause); | 297 int32_t iRet = m_pXMLDoc->DoLoad(pPause); |
88 if (iRet < 0) | 298 if (iRet < 0) |
89 return XFA_PARSESTATUS_SyntaxErr; | 299 return XFA_PARSESTATUS_SyntaxErr; |
90 if (iRet < 100) | 300 if (iRet < 100) |
91 return iRet / 2; | 301 return iRet / 2; |
92 | 302 |
93 m_pRootNode = ParseAsXDPPacket( | 303 m_pRootNode = ParseAsXDPPacket(GetDocumentNode(m_pXMLDoc.get()), m_ePacketID); |
94 XFA_FDEExtension_GetDocumentNode(m_pXMLDoc.get()), m_ePacketID); | |
95 m_pXMLDoc->CloseXML(); | 304 m_pXMLDoc->CloseXML(); |
96 m_pStream.reset(); | 305 m_pStream.reset(); |
97 | 306 |
98 if (!m_pRootNode) | 307 if (!m_pRootNode) |
99 return XFA_PARSESTATUS_StatusErr; | 308 return XFA_PARSESTATUS_StatusErr; |
100 return XFA_PARSESTATUS_Done; | 309 return XFA_PARSESTATUS_Done; |
101 } | 310 } |
102 | 311 |
103 int32_t CXFA_SimpleParser::ParseXMLData(const CFX_WideString& wsXML, | 312 int32_t CXFA_SimpleParser::ParseXMLData(const CFX_WideString& wsXML, |
104 CFDE_XMLNode*& pXMLNode, | 313 CFDE_XMLNode*& pXMLNode, |
(...skipping 13 matching lines...) Expand all Loading... | |
118 return XFA_PARSESTATUS_StatusErr; | 327 return XFA_PARSESTATUS_StatusErr; |
119 | 328 |
120 int32_t iRet = m_pXMLDoc->DoLoad(pPause); | 329 int32_t iRet = m_pXMLDoc->DoLoad(pPause); |
121 if (iRet < 0 || iRet >= 100) | 330 if (iRet < 0 || iRet >= 100) |
122 m_pXMLDoc->CloseXML(); | 331 m_pXMLDoc->CloseXML(); |
123 if (iRet < 0) | 332 if (iRet < 0) |
124 return XFA_PARSESTATUS_SyntaxErr; | 333 return XFA_PARSESTATUS_SyntaxErr; |
125 if (iRet < 100) | 334 if (iRet < 100) |
126 return iRet / 2; | 335 return iRet / 2; |
127 | 336 |
128 pXMLNode = XFA_FDEExtension_GetDocumentNode(m_pXMLDoc.get()); | 337 pXMLNode = GetDocumentNode(m_pXMLDoc.get()); |
129 return XFA_PARSESTATUS_Done; | 338 return XFA_PARSESTATUS_Done; |
130 } | 339 } |
131 | 340 |
132 void CXFA_SimpleParser::ConstructXFANode(CXFA_Node* pXFANode, | 341 void CXFA_SimpleParser::ConstructXFANode(CXFA_Node* pXFANode, |
133 CFDE_XMLNode* pXMLNode) { | 342 CFDE_XMLNode* pXMLNode) { |
134 XFA_XDPPACKET ePacketID = (XFA_XDPPACKET)pXFANode->GetPacketID(); | 343 XFA_XDPPACKET ePacketID = (XFA_XDPPACKET)pXFANode->GetPacketID(); |
135 if (ePacketID == XFA_XDPPACKET_Datasets) { | 344 if (ePacketID == XFA_XDPPACKET_Datasets) { |
136 if (pXFANode->GetElementType() == XFA_Element::DataValue) { | 345 if (pXFANode->GetElementType() == XFA_Element::DataValue) { |
137 for (CFDE_XMLNode* pXMLChild = | 346 for (CFDE_XMLNode* pXMLChild = |
138 pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild); | 347 pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 } | 389 } |
181 | 390 |
182 CFDE_XMLDoc* CXFA_SimpleParser::GetXMLDoc() const { | 391 CFDE_XMLDoc* CXFA_SimpleParser::GetXMLDoc() const { |
183 return m_pXMLDoc.get(); | 392 return m_pXMLDoc.get(); |
184 } | 393 } |
185 | 394 |
186 FX_BOOL XFA_FDEExtension_ResolveNamespaceQualifier( | 395 FX_BOOL XFA_FDEExtension_ResolveNamespaceQualifier( |
187 CFDE_XMLElement* pNode, | 396 CFDE_XMLElement* pNode, |
188 const CFX_WideStringC& wsQualifier, | 397 const CFX_WideStringC& wsQualifier, |
189 CFX_WideString& wsNamespaceURI) { | 398 CFX_WideString& wsNamespaceURI) { |
190 if (!pNode) { | 399 if (!pNode) |
191 return FALSE; | 400 return FALSE; |
192 } | 401 |
193 CFDE_XMLNode* pFakeRoot = pNode->GetNodeItem(CFDE_XMLNode::Root); | 402 CFDE_XMLNode* pFakeRoot = pNode->GetNodeItem(CFDE_XMLNode::Root); |
194 CFX_WideString wsNSAttribute; | 403 CFX_WideString wsNSAttribute; |
195 FX_BOOL bRet = FALSE; | 404 FX_BOOL bRet = FALSE; |
196 if (wsQualifier.IsEmpty()) { | 405 if (wsQualifier.IsEmpty()) { |
197 wsNSAttribute = FX_WSTRC(L"xmlns"); | 406 wsNSAttribute = FX_WSTRC(L"xmlns"); |
198 bRet = TRUE; | 407 bRet = TRUE; |
199 } else { | 408 } else { |
200 wsNSAttribute = FX_WSTRC(L"xmlns:") + wsQualifier; | 409 wsNSAttribute = FX_WSTRC(L"xmlns:") + wsQualifier; |
201 } | 410 } |
202 for (; pNode != pFakeRoot; pNode = static_cast<CFDE_XMLElement*>( | 411 for (; pNode != pFakeRoot; pNode = static_cast<CFDE_XMLElement*>( |
203 pNode->GetNodeItem(CFDE_XMLNode::Parent))) { | 412 pNode->GetNodeItem(CFDE_XMLNode::Parent))) { |
204 if (pNode->GetType() != FDE_XMLNODE_Element) { | 413 if (pNode->GetType() != FDE_XMLNODE_Element) |
205 continue; | 414 continue; |
206 } | 415 |
207 if (pNode->HasAttribute(wsNSAttribute.c_str())) { | 416 if (pNode->HasAttribute(wsNSAttribute.c_str())) { |
208 pNode->GetString(wsNSAttribute.c_str(), wsNamespaceURI); | 417 pNode->GetString(wsNSAttribute.c_str(), wsNamespaceURI); |
209 return TRUE; | 418 return TRUE; |
210 } | 419 } |
211 } | 420 } |
212 wsNamespaceURI.clear(); | 421 wsNamespaceURI.clear(); |
213 return bRet; | 422 return bRet; |
214 } | 423 } |
215 | 424 |
216 static inline void XFA_FDEExtension_GetElementTagNamespaceURI( | |
217 CFDE_XMLElement* pElement, | |
218 CFX_WideString& wsNamespaceURI) { | |
219 CFX_WideString wsNodeStr; | |
220 pElement->GetNamespacePrefix(wsNodeStr); | |
221 if (!XFA_FDEExtension_ResolveNamespaceQualifier( | |
222 pElement, wsNodeStr.AsStringC(), wsNamespaceURI)) { | |
223 wsNamespaceURI.clear(); | |
224 } | |
225 } | |
226 | |
227 static FX_BOOL XFA_FDEExtension_MatchNodeName( | |
228 CFDE_XMLNode* pNode, | |
229 const CFX_WideStringC& wsLocalTagName, | |
230 const CFX_WideStringC& wsNamespaceURIPrefix, | |
231 uint32_t eMatchFlags = XFA_XDPPACKET_FLAGS_NOMATCH) { | |
232 if (!pNode || pNode->GetType() != FDE_XMLNODE_Element) { | |
233 return FALSE; | |
234 } | |
235 CFDE_XMLElement* pElement = reinterpret_cast<CFDE_XMLElement*>(pNode); | |
236 CFX_WideString wsNodeStr; | |
237 pElement->GetLocalTagName(wsNodeStr); | |
238 if (wsNodeStr != wsLocalTagName) { | |
239 return FALSE; | |
240 } | |
241 XFA_FDEExtension_GetElementTagNamespaceURI(pElement, wsNodeStr); | |
242 if (eMatchFlags & XFA_XDPPACKET_FLAGS_NOMATCH) { | |
243 return TRUE; | |
244 } | |
245 if (eMatchFlags & XFA_XDPPACKET_FLAGS_PREFIXMATCH) { | |
246 return wsNodeStr.Left(wsNamespaceURIPrefix.GetLength()) == | |
247 wsNamespaceURIPrefix; | |
248 } | |
249 return wsNodeStr == wsNamespaceURIPrefix; | |
250 } | |
251 | |
252 static FX_BOOL XFA_FDEExtension_GetAttributeLocalName( | |
253 const CFX_WideStringC& wsAttributeName, | |
254 CFX_WideString& wsLocalAttrName) { | |
255 CFX_WideString wsAttrName(wsAttributeName); | |
256 FX_STRSIZE iFind = wsAttrName.Find(L':', 0); | |
257 if (iFind < 0) { | |
258 wsLocalAttrName = wsAttrName; | |
259 return FALSE; | |
260 } else { | |
261 wsLocalAttrName = wsAttrName.Right(wsAttrName.GetLength() - iFind - 1); | |
262 return TRUE; | |
263 } | |
264 } | |
265 | |
266 static FX_BOOL XFA_FDEExtension_ResolveAttribute( | |
267 CFDE_XMLElement* pElement, | |
268 const CFX_WideStringC& wsAttributeName, | |
269 CFX_WideString& wsLocalAttrName, | |
270 CFX_WideString& wsNamespaceURI) { | |
271 CFX_WideString wsAttrName(wsAttributeName); | |
272 CFX_WideString wsNSPrefix; | |
273 if (XFA_FDEExtension_GetAttributeLocalName(wsAttributeName, | |
274 wsLocalAttrName)) { | |
275 wsNSPrefix = wsAttrName.Left(wsAttributeName.GetLength() - | |
276 wsLocalAttrName.GetLength() - 1); | |
277 } | |
278 if (wsLocalAttrName == FX_WSTRC(L"xmlns") || | |
279 wsNSPrefix == FX_WSTRC(L"xmlns") || wsNSPrefix == FX_WSTRC(L"xml")) { | |
280 return FALSE; | |
281 } | |
282 if (!XFA_FDEExtension_ResolveNamespaceQualifier( | |
283 pElement, wsNSPrefix.AsStringC(), wsNamespaceURI)) { | |
284 wsNamespaceURI.clear(); | |
285 return FALSE; | |
286 } | |
287 return TRUE; | |
288 } | |
289 | |
290 static FX_BOOL XFA_FDEExtension_FindAttributeWithNS( | |
291 CFDE_XMLElement* pElement, | |
292 const CFX_WideStringC& wsLocalAttributeName, | |
293 const CFX_WideStringC& wsNamespaceURIPrefix, | |
294 CFX_WideString& wsValue, | |
295 FX_BOOL bMatchNSAsPrefix = FALSE) { | |
296 if (!pElement) { | |
297 return FALSE; | |
298 } | |
299 CFX_WideString wsAttrName; | |
300 CFX_WideString wsAttrValue; | |
301 CFX_WideString wsAttrNS; | |
302 for (int32_t iAttrCount = pElement->CountAttributes(), i = 0; i < iAttrCount; | |
303 i++) { | |
304 pElement->GetAttribute(i, wsAttrName, wsAttrValue); | |
305 FX_STRSIZE iFind = wsAttrName.Find(L':', 0); | |
306 CFX_WideString wsNSPrefix; | |
307 if (iFind < 0) { | |
308 if (wsLocalAttributeName != wsAttrName) { | |
309 continue; | |
310 } | |
311 } else { | |
312 if (wsLocalAttributeName != | |
313 wsAttrName.Right(wsAttrName.GetLength() - iFind - 1)) { | |
314 continue; | |
315 } | |
316 wsNSPrefix = wsAttrName.Left(iFind); | |
317 } | |
318 if (!XFA_FDEExtension_ResolveNamespaceQualifier( | |
319 pElement, wsNSPrefix.AsStringC(), wsAttrNS)) { | |
320 continue; | |
321 } | |
322 if (bMatchNSAsPrefix) { | |
323 if (wsAttrNS.Left(wsNamespaceURIPrefix.GetLength()) != | |
324 wsNamespaceURIPrefix) { | |
325 continue; | |
326 } | |
327 } else { | |
328 if (wsAttrNS != wsNamespaceURIPrefix) { | |
329 continue; | |
330 } | |
331 } | |
332 wsValue = wsAttrValue; | |
333 return TRUE; | |
334 } | |
335 return FALSE; | |
336 } | |
337 | |
338 CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket(CFDE_XMLNode* pXMLDocumentNode, | 425 CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket(CFDE_XMLNode* pXMLDocumentNode, |
339 XFA_XDPPACKET ePacketID) { | 426 XFA_XDPPACKET ePacketID) { |
340 switch (ePacketID) { | 427 switch (ePacketID) { |
341 case XFA_XDPPACKET_UNKNOWN: | 428 case XFA_XDPPACKET_UNKNOWN: |
342 return nullptr; | 429 return nullptr; |
343 case XFA_XDPPACKET_XDP: | 430 case XFA_XDPPACKET_XDP: |
344 return ParseAsXDPPacket_XDP(pXMLDocumentNode, ePacketID); | 431 return ParseAsXDPPacket_XDP(pXMLDocumentNode, ePacketID); |
345 case XFA_XDPPACKET_Config: | 432 case XFA_XDPPACKET_Config: |
346 return ParseAsXDPPacket_Config(pXMLDocumentNode, ePacketID); | 433 return ParseAsXDPPacket_Config(pXMLDocumentNode, ePacketID); |
347 case XFA_XDPPACKET_Template: | 434 case XFA_XDPPACKET_Template: |
348 case XFA_XDPPACKET_Form: | 435 case XFA_XDPPACKET_Form: |
349 return ParseAsXDPPacket_TemplateForm(pXMLDocumentNode, ePacketID); | 436 return ParseAsXDPPacket_TemplateForm(pXMLDocumentNode, ePacketID); |
350 case XFA_XDPPACKET_Datasets: | 437 case XFA_XDPPACKET_Datasets: |
351 return ParseAsXDPPacket_Data(pXMLDocumentNode, ePacketID); | 438 return ParseAsXDPPacket_Data(pXMLDocumentNode, ePacketID); |
352 case XFA_XDPPACKET_Xdc: | 439 case XFA_XDPPACKET_Xdc: |
353 return ParseAsXDPPacket_Xdc(pXMLDocumentNode, ePacketID); | 440 return ParseAsXDPPacket_Xdc(pXMLDocumentNode, ePacketID); |
354 case XFA_XDPPACKET_LocaleSet: | 441 case XFA_XDPPACKET_LocaleSet: |
355 case XFA_XDPPACKET_ConnectionSet: | 442 case XFA_XDPPACKET_ConnectionSet: |
356 case XFA_XDPPACKET_SourceSet: | 443 case XFA_XDPPACKET_SourceSet: |
357 return ParseAsXDPPacket_LocaleConnectionSourceSet(pXMLDocumentNode, | 444 return ParseAsXDPPacket_LocaleConnectionSourceSet(pXMLDocumentNode, |
358 ePacketID); | 445 ePacketID); |
359 default: | 446 default: |
360 return ParseAsXDPPacket_User(pXMLDocumentNode, ePacketID); | 447 return ParseAsXDPPacket_User(pXMLDocumentNode, ePacketID); |
361 } | 448 } |
362 } | 449 } |
363 | 450 |
364 CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_XDP( | 451 CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_XDP( |
365 CFDE_XMLNode* pXMLDocumentNode, | 452 CFDE_XMLNode* pXMLDocumentNode, |
366 XFA_XDPPACKET ePacketID) { | 453 XFA_XDPPACKET ePacketID) { |
367 if (!XFA_FDEExtension_MatchNodeName( | 454 if (!MatchNodeName(pXMLDocumentNode, |
368 pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_XDP)->pName, | 455 XFA_GetPacketByIndex(XFA_PACKET_XDP)->pName, |
369 XFA_GetPacketByIndex(XFA_PACKET_XDP)->pURI, | 456 XFA_GetPacketByIndex(XFA_PACKET_XDP)->pURI, |
370 XFA_GetPacketByIndex(XFA_PACKET_XDP)->eFlags)) { | 457 XFA_GetPacketByIndex(XFA_PACKET_XDP)->eFlags)) { |
371 return nullptr; | 458 return nullptr; |
372 } | 459 } |
373 CXFA_Node* pXFARootNode = | 460 CXFA_Node* pXFARootNode = |
374 m_pFactory->CreateNode(XFA_XDPPACKET_XDP, XFA_Element::Xfa); | 461 m_pFactory->CreateNode(XFA_XDPPACKET_XDP, XFA_Element::Xfa); |
375 if (!pXFARootNode) { | 462 if (!pXFARootNode) |
376 return nullptr; | 463 return nullptr; |
377 } | 464 |
378 m_pRootNode = pXFARootNode; | 465 m_pRootNode = pXFARootNode; |
379 pXFARootNode->SetCData(XFA_ATTRIBUTE_Name, L"xfa"); | 466 pXFARootNode->SetCData(XFA_ATTRIBUTE_Name, L"xfa"); |
380 { | 467 { |
381 CFDE_XMLElement* pElement = static_cast<CFDE_XMLElement*>(pXMLDocumentNode); | 468 CFDE_XMLElement* pElement = static_cast<CFDE_XMLElement*>(pXMLDocumentNode); |
382 int32_t iAttributeCount = pElement->CountAttributes(); | 469 int32_t iAttributeCount = pElement->CountAttributes(); |
383 for (int32_t i = 0; i < iAttributeCount; i++) { | 470 for (int32_t i = 0; i < iAttributeCount; i++) { |
384 CFX_WideString wsAttriName, wsAttriValue; | 471 CFX_WideString wsAttriName, wsAttriValue; |
385 pElement->GetAttribute(i, wsAttriName, wsAttriValue); | 472 pElement->GetAttribute(i, wsAttriName, wsAttriValue); |
386 if (wsAttriName == FX_WSTRC(L"uuid")) { | 473 if (wsAttriName == FX_WSTRC(L"uuid")) |
387 pXFARootNode->SetCData(XFA_ATTRIBUTE_Uuid, wsAttriValue); | 474 pXFARootNode->SetCData(XFA_ATTRIBUTE_Uuid, wsAttriValue); |
388 } else if (wsAttriName == FX_WSTRC(L"timeStamp")) { | 475 else if (wsAttriName == FX_WSTRC(L"timeStamp")) |
389 pXFARootNode->SetCData(XFA_ATTRIBUTE_TimeStamp, wsAttriValue); | 476 pXFARootNode->SetCData(XFA_ATTRIBUTE_TimeStamp, wsAttriValue); |
390 } | |
391 } | 477 } |
392 } | 478 } |
479 | |
393 CFDE_XMLNode* pXMLConfigDOMRoot = nullptr; | 480 CFDE_XMLNode* pXMLConfigDOMRoot = nullptr; |
394 CXFA_Node* pXFAConfigDOMRoot = nullptr; | 481 CXFA_Node* pXFAConfigDOMRoot = nullptr; |
395 { | 482 { |
396 for (CFDE_XMLNode* pChildItem = | 483 for (CFDE_XMLNode* pChildItem = |
397 pXMLDocumentNode->GetNodeItem(CFDE_XMLNode::FirstChild); | 484 pXMLDocumentNode->GetNodeItem(CFDE_XMLNode::FirstChild); |
398 pChildItem; | 485 pChildItem; |
399 pChildItem = pChildItem->GetNodeItem(CFDE_XMLNode::NextSibling)) { | 486 pChildItem = pChildItem->GetNodeItem(CFDE_XMLNode::NextSibling)) { |
400 const XFA_PACKETINFO* pPacketInfo = | 487 const XFA_PACKETINFO* pPacketInfo = |
401 XFA_GetPacketByIndex(XFA_PACKET_Config); | 488 XFA_GetPacketByIndex(XFA_PACKET_Config); |
402 if (!XFA_FDEExtension_MatchNodeName(pChildItem, pPacketInfo->pName, | 489 if (!MatchNodeName(pChildItem, pPacketInfo->pName, pPacketInfo->pURI, |
403 pPacketInfo->pURI, | 490 pPacketInfo->eFlags)) { |
404 pPacketInfo->eFlags)) { | |
405 continue; | 491 continue; |
406 } | 492 } |
407 if (pXFARootNode->GetFirstChildByName(pPacketInfo->uHash)) { | 493 if (pXFARootNode->GetFirstChildByName(pPacketInfo->uHash)) { |
408 return nullptr; | 494 return nullptr; |
409 } | 495 } |
410 pXMLConfigDOMRoot = pChildItem; | 496 pXMLConfigDOMRoot = pChildItem; |
411 pXFAConfigDOMRoot = | 497 pXFAConfigDOMRoot = |
412 ParseAsXDPPacket_Config(pXMLConfigDOMRoot, XFA_XDPPACKET_Config); | 498 ParseAsXDPPacket_Config(pXMLConfigDOMRoot, XFA_XDPPACKET_Config); |
413 pXFARootNode->InsertChild(pXFAConfigDOMRoot, nullptr); | 499 pXFARootNode->InsertChild(pXFAConfigDOMRoot, nullptr); |
414 } | 500 } |
415 } | 501 } |
502 | |
416 CFDE_XMLNode* pXMLDatasetsDOMRoot = nullptr; | 503 CFDE_XMLNode* pXMLDatasetsDOMRoot = nullptr; |
417 CFDE_XMLNode* pXMLFormDOMRoot = nullptr; | 504 CFDE_XMLNode* pXMLFormDOMRoot = nullptr; |
418 CFDE_XMLNode* pXMLTemplateDOMRoot = nullptr; | 505 CFDE_XMLNode* pXMLTemplateDOMRoot = nullptr; |
419 { | 506 { |
420 for (CFDE_XMLNode* pChildItem = | 507 for (CFDE_XMLNode* pChildItem = |
421 pXMLDocumentNode->GetNodeItem(CFDE_XMLNode::FirstChild); | 508 pXMLDocumentNode->GetNodeItem(CFDE_XMLNode::FirstChild); |
422 pChildItem; | 509 pChildItem; |
423 pChildItem = pChildItem->GetNodeItem(CFDE_XMLNode::NextSibling)) { | 510 pChildItem = pChildItem->GetNodeItem(CFDE_XMLNode::NextSibling)) { |
424 if (!pChildItem || pChildItem->GetType() != FDE_XMLNODE_Element) { | 511 if (!pChildItem || pChildItem->GetType() != FDE_XMLNODE_Element) |
425 continue; | 512 continue; |
426 } | 513 if (pChildItem == pXMLConfigDOMRoot) |
427 if (pChildItem == pXMLConfigDOMRoot) { | |
428 continue; | 514 continue; |
429 } | 515 |
430 CFDE_XMLElement* pElement = | 516 CFDE_XMLElement* pElement = |
431 reinterpret_cast<CFDE_XMLElement*>(pChildItem); | 517 reinterpret_cast<CFDE_XMLElement*>(pChildItem); |
432 CFX_WideString wsPacketName; | 518 CFX_WideString wsPacketName; |
433 pElement->GetLocalTagName(wsPacketName); | 519 pElement->GetLocalTagName(wsPacketName); |
434 const XFA_PACKETINFO* pPacketInfo = | 520 const XFA_PACKETINFO* pPacketInfo = |
435 XFA_GetPacketByName(wsPacketName.AsStringC()); | 521 XFA_GetPacketByName(wsPacketName.AsStringC()); |
436 if (pPacketInfo && pPacketInfo->pURI) { | 522 if (pPacketInfo && pPacketInfo->pURI) { |
437 if (!XFA_FDEExtension_MatchNodeName(pElement, pPacketInfo->pName, | 523 if (!MatchNodeName(pElement, pPacketInfo->pName, pPacketInfo->pURI, |
438 pPacketInfo->pURI, | 524 pPacketInfo->eFlags)) { |
439 pPacketInfo->eFlags)) { | |
440 pPacketInfo = nullptr; | 525 pPacketInfo = nullptr; |
441 } | 526 } |
442 } | 527 } |
443 XFA_XDPPACKET ePacket = | 528 XFA_XDPPACKET ePacket = |
444 pPacketInfo ? pPacketInfo->eName : XFA_XDPPACKET_USER; | 529 pPacketInfo ? pPacketInfo->eName : XFA_XDPPACKET_USER; |
445 if (ePacket == XFA_XDPPACKET_XDP) { | 530 if (ePacket == XFA_XDPPACKET_XDP) |
446 continue; | 531 continue; |
447 } | |
448 if (ePacket == XFA_XDPPACKET_Datasets) { | 532 if (ePacket == XFA_XDPPACKET_Datasets) { |
449 if (pXMLDatasetsDOMRoot) { | 533 if (pXMLDatasetsDOMRoot) |
450 return nullptr; | 534 return nullptr; |
451 } | 535 |
452 pXMLDatasetsDOMRoot = pElement; | 536 pXMLDatasetsDOMRoot = pElement; |
453 } else if (ePacket == XFA_XDPPACKET_Form) { | 537 } else if (ePacket == XFA_XDPPACKET_Form) { |
454 if (pXMLFormDOMRoot) { | 538 if (pXMLFormDOMRoot) |
455 return nullptr; | 539 return nullptr; |
456 } | 540 |
457 pXMLFormDOMRoot = pElement; | 541 pXMLFormDOMRoot = pElement; |
458 } else if (ePacket == XFA_XDPPACKET_Template) { | 542 } else if (ePacket == XFA_XDPPACKET_Template) { |
459 if (pXMLTemplateDOMRoot) { | 543 if (pXMLTemplateDOMRoot) { |
460 // Found a duplicate template packet. | 544 // Found a duplicate template packet. |
461 return nullptr; | 545 return nullptr; |
462 } | 546 } |
463 CXFA_Node* pPacketNode = ParseAsXDPPacket(pElement, ePacket); | 547 CXFA_Node* pPacketNode = ParseAsXDPPacket(pElement, ePacket); |
464 if (pPacketNode) { | 548 if (pPacketNode) { |
465 pXMLTemplateDOMRoot = pElement; | 549 pXMLTemplateDOMRoot = pElement; |
466 pXFARootNode->InsertChild(pPacketNode); | 550 pXFARootNode->InsertChild(pPacketNode); |
467 } | 551 } |
468 } else { | 552 } else { |
469 CXFA_Node* pPacketNode = ParseAsXDPPacket(pElement, ePacket); | 553 CXFA_Node* pPacketNode = ParseAsXDPPacket(pElement, ePacket); |
470 if (pPacketNode) { | 554 if (pPacketNode) { |
471 if (pPacketInfo && | 555 if (pPacketInfo && |
472 (pPacketInfo->eFlags & XFA_XDPPACKET_FLAGS_SUPPORTONE) && | 556 (pPacketInfo->eFlags & XFA_XDPPACKET_FLAGS_SUPPORTONE) && |
473 pXFARootNode->GetFirstChildByName(pPacketInfo->uHash)) { | 557 pXFARootNode->GetFirstChildByName(pPacketInfo->uHash)) { |
474 return nullptr; | 558 return nullptr; |
475 } | 559 } |
476 pXFARootNode->InsertChild(pPacketNode); | 560 pXFARootNode->InsertChild(pPacketNode); |
477 } | 561 } |
478 } | 562 } |
479 } | 563 } |
480 } | 564 } |
565 | |
481 if (!pXMLTemplateDOMRoot) { | 566 if (!pXMLTemplateDOMRoot) { |
482 // No template is found. | 567 // No template is found. |
483 return nullptr; | 568 return nullptr; |
484 } | 569 } |
485 if (pXMLDatasetsDOMRoot) { | 570 if (pXMLDatasetsDOMRoot) { |
486 CXFA_Node* pPacketNode = | 571 CXFA_Node* pPacketNode = |
487 ParseAsXDPPacket(pXMLDatasetsDOMRoot, XFA_XDPPACKET_Datasets); | 572 ParseAsXDPPacket(pXMLDatasetsDOMRoot, XFA_XDPPACKET_Datasets); |
488 if (pPacketNode) { | 573 if (pPacketNode) |
489 pXFARootNode->InsertChild(pPacketNode); | 574 pXFARootNode->InsertChild(pPacketNode); |
490 } | |
491 } | 575 } |
492 if (pXMLFormDOMRoot) { | 576 if (pXMLFormDOMRoot) { |
493 CXFA_Node* pPacketNode = | 577 CXFA_Node* pPacketNode = |
494 ParseAsXDPPacket(pXMLFormDOMRoot, XFA_XDPPACKET_Form); | 578 ParseAsXDPPacket(pXMLFormDOMRoot, XFA_XDPPACKET_Form); |
495 if (pPacketNode) { | 579 if (pPacketNode) |
496 pXFARootNode->InsertChild(pPacketNode); | 580 pXFARootNode->InsertChild(pPacketNode); |
497 } | |
498 } | 581 } |
499 pXFARootNode->SetXMLMappingNode(pXMLDocumentNode); | 582 pXFARootNode->SetXMLMappingNode(pXMLDocumentNode); |
500 return pXFARootNode; | 583 return pXFARootNode; |
501 } | 584 } |
502 | 585 |
503 CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_Config( | 586 CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_Config( |
504 CFDE_XMLNode* pXMLDocumentNode, | 587 CFDE_XMLNode* pXMLDocumentNode, |
505 XFA_XDPPACKET ePacketID) { | 588 XFA_XDPPACKET ePacketID) { |
506 if (!XFA_FDEExtension_MatchNodeName( | 589 if (!MatchNodeName(pXMLDocumentNode, |
507 pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_Config)->pName, | 590 XFA_GetPacketByIndex(XFA_PACKET_Config)->pName, |
508 XFA_GetPacketByIndex(XFA_PACKET_Config)->pURI, | 591 XFA_GetPacketByIndex(XFA_PACKET_Config)->pURI, |
509 XFA_GetPacketByIndex(XFA_PACKET_Config)->eFlags)) { | 592 XFA_GetPacketByIndex(XFA_PACKET_Config)->eFlags)) { |
510 return nullptr; | 593 return nullptr; |
511 } | 594 } |
512 CXFA_Node* pNode = | 595 CXFA_Node* pNode = |
513 m_pFactory->CreateNode(XFA_XDPPACKET_Config, XFA_Element::Config); | 596 m_pFactory->CreateNode(XFA_XDPPACKET_Config, XFA_Element::Config); |
514 if (!pNode) { | 597 if (!pNode) |
515 return nullptr; | 598 return nullptr; |
516 } | 599 |
517 pNode->SetCData(XFA_ATTRIBUTE_Name, | 600 pNode->SetCData(XFA_ATTRIBUTE_Name, |
518 XFA_GetPacketByIndex(XFA_PACKET_Config)->pName); | 601 XFA_GetPacketByIndex(XFA_PACKET_Config)->pName); |
519 if (!NormalLoader(pNode, pXMLDocumentNode, ePacketID)) { | 602 if (!NormalLoader(pNode, pXMLDocumentNode, ePacketID)) |
520 return nullptr; | 603 return nullptr; |
521 } | 604 |
522 pNode->SetXMLMappingNode(pXMLDocumentNode); | 605 pNode->SetXMLMappingNode(pXMLDocumentNode); |
523 return pNode; | 606 return pNode; |
524 } | 607 } |
525 | 608 |
526 CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_TemplateForm( | 609 CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_TemplateForm( |
527 CFDE_XMLNode* pXMLDocumentNode, | 610 CFDE_XMLNode* pXMLDocumentNode, |
528 XFA_XDPPACKET ePacketID) { | 611 XFA_XDPPACKET ePacketID) { |
529 CXFA_Node* pNode = nullptr; | 612 CXFA_Node* pNode = nullptr; |
530 if (ePacketID == XFA_XDPPACKET_Template) { | 613 if (ePacketID == XFA_XDPPACKET_Template) { |
531 if (XFA_FDEExtension_MatchNodeName( | 614 if (MatchNodeName(pXMLDocumentNode, |
532 pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_Template)->pName, | 615 XFA_GetPacketByIndex(XFA_PACKET_Template)->pName, |
533 XFA_GetPacketByIndex(XFA_PACKET_Template)->pURI, | 616 XFA_GetPacketByIndex(XFA_PACKET_Template)->pURI, |
534 XFA_GetPacketByIndex(XFA_PACKET_Template)->eFlags)) { | 617 XFA_GetPacketByIndex(XFA_PACKET_Template)->eFlags)) { |
535 pNode = | 618 pNode = |
536 m_pFactory->CreateNode(XFA_XDPPACKET_Template, XFA_Element::Template); | 619 m_pFactory->CreateNode(XFA_XDPPACKET_Template, XFA_Element::Template); |
537 if (!pNode) { | 620 if (!pNode) |
538 return nullptr; | 621 return nullptr; |
539 } | 622 |
540 pNode->SetCData(XFA_ATTRIBUTE_Name, | 623 pNode->SetCData(XFA_ATTRIBUTE_Name, |
541 XFA_GetPacketByIndex(XFA_PACKET_Template)->pName); | 624 XFA_GetPacketByIndex(XFA_PACKET_Template)->pName); |
542 if (m_bDocumentParser) { | 625 if (m_bDocumentParser) { |
543 CFX_WideString wsNamespaceURI; | 626 CFX_WideString wsNamespaceURI; |
544 CFDE_XMLElement* pXMLDocumentElement = | 627 CFDE_XMLElement* pXMLDocumentElement = |
545 static_cast<CFDE_XMLElement*>(pXMLDocumentNode); | 628 static_cast<CFDE_XMLElement*>(pXMLDocumentNode); |
546 pXMLDocumentElement->GetNamespaceURI(wsNamespaceURI); | 629 pXMLDocumentElement->GetNamespaceURI(wsNamespaceURI); |
547 if (wsNamespaceURI.IsEmpty()) { | 630 if (wsNamespaceURI.IsEmpty()) |
548 pXMLDocumentElement->GetString(L"xmlns:xfa", wsNamespaceURI); | 631 pXMLDocumentElement->GetString(L"xmlns:xfa", wsNamespaceURI); |
549 } | 632 |
550 pNode->GetDocument()->RecognizeXFAVersionNumber(wsNamespaceURI); | 633 pNode->GetDocument()->RecognizeXFAVersionNumber(wsNamespaceURI); |
551 } | 634 } |
552 if (!NormalLoader(pNode, pXMLDocumentNode, ePacketID)) { | 635 if (!NormalLoader(pNode, pXMLDocumentNode, ePacketID)) |
553 return nullptr; | 636 return nullptr; |
554 } | |
555 } | 637 } |
556 } else if (ePacketID == XFA_XDPPACKET_Form) { | 638 } else if (ePacketID == XFA_XDPPACKET_Form) { |
557 if (XFA_FDEExtension_MatchNodeName( | 639 if (MatchNodeName(pXMLDocumentNode, |
558 pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_Form)->pName, | 640 XFA_GetPacketByIndex(XFA_PACKET_Form)->pName, |
559 XFA_GetPacketByIndex(XFA_PACKET_Form)->pURI, | 641 XFA_GetPacketByIndex(XFA_PACKET_Form)->pURI, |
560 XFA_GetPacketByIndex(XFA_PACKET_Form)->eFlags)) { | 642 XFA_GetPacketByIndex(XFA_PACKET_Form)->eFlags)) { |
561 CFDE_XMLElement* pXMLDocumentElement = | 643 CFDE_XMLElement* pXMLDocumentElement = |
562 static_cast<CFDE_XMLElement*>(pXMLDocumentNode); | 644 static_cast<CFDE_XMLElement*>(pXMLDocumentNode); |
563 CFX_WideString wsChecksum; | 645 CFX_WideString wsChecksum; |
564 pXMLDocumentElement->GetString(L"checksum", wsChecksum); | 646 pXMLDocumentElement->GetString(L"checksum", wsChecksum); |
565 if (wsChecksum.GetLength() != 28 || | 647 if (wsChecksum.GetLength() != 28 || |
566 m_pXMLParser->m_dwCheckStatus != 0x03) { | 648 m_pXMLParser->m_dwCheckStatus != 0x03) { |
567 return nullptr; | 649 return nullptr; |
568 } | 650 } |
569 std::unique_ptr<CXFA_ChecksumContext> pChecksum(new CXFA_ChecksumContext); | 651 std::unique_ptr<CXFA_ChecksumContext> pChecksum(new CXFA_ChecksumContext); |
570 pChecksum->StartChecksum(); | 652 pChecksum->StartChecksum(); |
(...skipping 18 matching lines...) Expand all Loading... | |
589 CXFA_Node* pTemplateChosen = | 671 CXFA_Node* pTemplateChosen = |
590 pTemplateRoot | 672 pTemplateRoot |
591 ? pTemplateRoot->GetFirstChildByClass(XFA_Element::Subform) | 673 ? pTemplateRoot->GetFirstChildByClass(XFA_Element::Subform) |
592 : nullptr; | 674 : nullptr; |
593 FX_BOOL bUseAttribute = TRUE; | 675 FX_BOOL bUseAttribute = TRUE; |
594 if (pTemplateChosen && | 676 if (pTemplateChosen && |
595 pTemplateChosen->GetEnum(XFA_ATTRIBUTE_RestoreState) != | 677 pTemplateChosen->GetEnum(XFA_ATTRIBUTE_RestoreState) != |
596 XFA_ATTRIBUTEENUM_Auto) { | 678 XFA_ATTRIBUTEENUM_Auto) { |
597 bUseAttribute = FALSE; | 679 bUseAttribute = FALSE; |
598 } | 680 } |
599 if (!NormalLoader(pNode, pXMLDocumentNode, ePacketID, bUseAttribute)) { | 681 if (!NormalLoader(pNode, pXMLDocumentNode, ePacketID, bUseAttribute)) |
600 return nullptr; | 682 return nullptr; |
601 } | |
602 } | 683 } |
603 } | 684 } |
604 if (pNode) { | 685 if (pNode) |
605 pNode->SetXMLMappingNode(pXMLDocumentNode); | 686 pNode->SetXMLMappingNode(pXMLDocumentNode); |
606 } | 687 |
607 return pNode; | 688 return pNode; |
608 } | 689 } |
609 | 690 |
610 static CFDE_XMLNode* XFA_GetDataSetsFromXDP(CFDE_XMLNode* pXMLDocumentNode) { | |
611 if (XFA_FDEExtension_MatchNodeName( | |
612 pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_Datasets)->pName, | |
613 XFA_GetPacketByIndex(XFA_PACKET_Datasets)->pURI, | |
614 XFA_GetPacketByIndex(XFA_PACKET_Datasets)->eFlags)) { | |
615 return pXMLDocumentNode; | |
616 } | |
617 if (!XFA_FDEExtension_MatchNodeName( | |
618 pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_XDP)->pName, | |
619 XFA_GetPacketByIndex(XFA_PACKET_XDP)->pURI, | |
620 XFA_GetPacketByIndex(XFA_PACKET_XDP)->eFlags)) { | |
621 return nullptr; | |
622 } | |
623 for (CFDE_XMLNode* pDatasetsNode = | |
624 pXMLDocumentNode->GetNodeItem(CFDE_XMLNode::FirstChild); | |
625 pDatasetsNode; | |
626 pDatasetsNode = pDatasetsNode->GetNodeItem(CFDE_XMLNode::NextSibling)) { | |
627 if (!XFA_FDEExtension_MatchNodeName( | |
628 pDatasetsNode, XFA_GetPacketByIndex(XFA_PACKET_Datasets)->pName, | |
629 XFA_GetPacketByIndex(XFA_PACKET_Datasets)->pURI, | |
630 XFA_GetPacketByIndex(XFA_PACKET_Datasets)->eFlags)) { | |
631 continue; | |
632 } | |
633 return pDatasetsNode; | |
634 } | |
635 return nullptr; | |
636 } | |
637 | |
638 CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_Data( | 691 CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_Data( |
639 CFDE_XMLNode* pXMLDocumentNode, | 692 CFDE_XMLNode* pXMLDocumentNode, |
640 XFA_XDPPACKET ePacketID) { | 693 XFA_XDPPACKET ePacketID) { |
641 CFDE_XMLNode* pDatasetsXMLNode = XFA_GetDataSetsFromXDP(pXMLDocumentNode); | 694 CFDE_XMLNode* pDatasetsXMLNode = GetDataSetsFromXDP(pXMLDocumentNode); |
642 if (pDatasetsXMLNode) { | 695 if (pDatasetsXMLNode) { |
643 CXFA_Node* pNode = | 696 CXFA_Node* pNode = |
644 m_pFactory->CreateNode(XFA_XDPPACKET_Datasets, XFA_Element::DataModel); | 697 m_pFactory->CreateNode(XFA_XDPPACKET_Datasets, XFA_Element::DataModel); |
645 if (!pNode) { | 698 if (!pNode) |
646 return nullptr; | 699 return nullptr; |
647 } | 700 |
648 pNode->SetCData(XFA_ATTRIBUTE_Name, | 701 pNode->SetCData(XFA_ATTRIBUTE_Name, |
649 XFA_GetPacketByIndex(XFA_PACKET_Datasets)->pName); | 702 XFA_GetPacketByIndex(XFA_PACKET_Datasets)->pName); |
650 if (!DataLoader(pNode, pDatasetsXMLNode, FALSE)) { | 703 if (!DataLoader(pNode, pDatasetsXMLNode, FALSE)) |
651 return nullptr; | 704 return nullptr; |
652 } | 705 |
653 pNode->SetXMLMappingNode(pDatasetsXMLNode); | 706 pNode->SetXMLMappingNode(pDatasetsXMLNode); |
654 return pNode; | 707 return pNode; |
655 } | 708 } |
709 | |
656 CFDE_XMLNode* pDataXMLNode = nullptr; | 710 CFDE_XMLNode* pDataXMLNode = nullptr; |
657 if (XFA_FDEExtension_MatchNodeName( | 711 if (MatchNodeName(pXMLDocumentNode, FX_WSTRC(L"data"), |
658 pXMLDocumentNode, FX_WSTRC(L"data"), | 712 XFA_GetPacketByIndex(XFA_PACKET_Datasets)->pURI, |
659 XFA_GetPacketByIndex(XFA_PACKET_Datasets)->pURI, | 713 XFA_GetPacketByIndex(XFA_PACKET_Datasets)->eFlags)) { |
660 XFA_GetPacketByIndex(XFA_PACKET_Datasets)->eFlags)) { | |
661 static_cast<CFDE_XMLElement*>(pXMLDocumentNode) | 714 static_cast<CFDE_XMLElement*>(pXMLDocumentNode) |
662 ->RemoveAttribute(L"xmlns:xfa"); | 715 ->RemoveAttribute(L"xmlns:xfa"); |
663 pDataXMLNode = pXMLDocumentNode; | 716 pDataXMLNode = pXMLDocumentNode; |
664 } else { | 717 } else { |
665 CFDE_XMLElement* pDataElement = new CFDE_XMLElement(L"xfa:data"); | 718 CFDE_XMLElement* pDataElement = new CFDE_XMLElement(L"xfa:data"); |
666 CFDE_XMLNode* pParentXMLNode = | 719 CFDE_XMLNode* pParentXMLNode = |
667 pXMLDocumentNode->GetNodeItem(CFDE_XMLNode::Parent); | 720 pXMLDocumentNode->GetNodeItem(CFDE_XMLNode::Parent); |
668 if (pParentXMLNode) { | 721 if (pParentXMLNode) |
669 pParentXMLNode->RemoveChildNode(pXMLDocumentNode); | 722 pParentXMLNode->RemoveChildNode(pXMLDocumentNode); |
670 } | 723 |
671 ASSERT(pXMLDocumentNode->GetType() == FDE_XMLNODE_Element); | 724 ASSERT(pXMLDocumentNode->GetType() == FDE_XMLNODE_Element); |
672 if (pXMLDocumentNode->GetType() == FDE_XMLNODE_Element) { | 725 if (pXMLDocumentNode->GetType() == FDE_XMLNODE_Element) { |
673 static_cast<CFDE_XMLElement*>(pXMLDocumentNode) | 726 static_cast<CFDE_XMLElement*>(pXMLDocumentNode) |
674 ->RemoveAttribute(L"xmlns:xfa"); | 727 ->RemoveAttribute(L"xmlns:xfa"); |
675 } | 728 } |
676 pDataElement->InsertChildNode(pXMLDocumentNode); | 729 pDataElement->InsertChildNode(pXMLDocumentNode); |
677 pDataXMLNode = pDataElement; | 730 pDataXMLNode = pDataElement; |
678 } | 731 } |
732 | |
679 if (pDataXMLNode) { | 733 if (pDataXMLNode) { |
680 CXFA_Node* pNode = | 734 CXFA_Node* pNode = |
681 m_pFactory->CreateNode(XFA_XDPPACKET_Datasets, XFA_Element::DataGroup); | 735 m_pFactory->CreateNode(XFA_XDPPACKET_Datasets, XFA_Element::DataGroup); |
682 if (!pNode) { | 736 if (!pNode) { |
683 if (pDataXMLNode != pXMLDocumentNode) { | 737 if (pDataXMLNode != pXMLDocumentNode) |
684 pDataXMLNode->Release(); | 738 pDataXMLNode->Release(); |
685 } | |
686 return nullptr; | 739 return nullptr; |
687 } | 740 } |
688 CFX_WideString wsLocalName; | 741 CFX_WideString wsLocalName; |
689 static_cast<CFDE_XMLElement*>(pDataXMLNode)->GetLocalTagName(wsLocalName); | 742 static_cast<CFDE_XMLElement*>(pDataXMLNode)->GetLocalTagName(wsLocalName); |
690 pNode->SetCData(XFA_ATTRIBUTE_Name, wsLocalName); | 743 pNode->SetCData(XFA_ATTRIBUTE_Name, wsLocalName); |
691 if (!DataLoader(pNode, pDataXMLNode, TRUE)) { | 744 if (!DataLoader(pNode, pDataXMLNode, TRUE)) |
692 return nullptr; | 745 return nullptr; |
693 } | 746 |
694 pNode->SetXMLMappingNode(pDataXMLNode); | 747 pNode->SetXMLMappingNode(pDataXMLNode); |
695 if (pDataXMLNode != pXMLDocumentNode) { | 748 if (pDataXMLNode != pXMLDocumentNode) |
696 pNode->SetFlag(XFA_NodeFlag_OwnXMLNode, false); | 749 pNode->SetFlag(XFA_NodeFlag_OwnXMLNode, false); |
697 } | |
698 return pNode; | 750 return pNode; |
699 } | 751 } |
700 return nullptr; | 752 return nullptr; |
701 } | 753 } |
702 | 754 |
703 CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_LocaleConnectionSourceSet( | 755 CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_LocaleConnectionSourceSet( |
704 CFDE_XMLNode* pXMLDocumentNode, | 756 CFDE_XMLNode* pXMLDocumentNode, |
705 XFA_XDPPACKET ePacketID) { | 757 XFA_XDPPACKET ePacketID) { |
706 CXFA_Node* pNode = nullptr; | 758 CXFA_Node* pNode = nullptr; |
707 if (ePacketID == XFA_XDPPACKET_LocaleSet) { | 759 if (ePacketID == XFA_XDPPACKET_LocaleSet) { |
708 if (XFA_FDEExtension_MatchNodeName( | 760 if (MatchNodeName(pXMLDocumentNode, |
709 pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_LocaleSet)->pName, | 761 XFA_GetPacketByIndex(XFA_PACKET_LocaleSet)->pName, |
710 XFA_GetPacketByIndex(XFA_PACKET_LocaleSet)->pURI, | 762 XFA_GetPacketByIndex(XFA_PACKET_LocaleSet)->pURI, |
711 XFA_GetPacketByIndex(XFA_PACKET_LocaleSet)->eFlags)) { | 763 XFA_GetPacketByIndex(XFA_PACKET_LocaleSet)->eFlags)) { |
712 pNode = m_pFactory->CreateNode(XFA_XDPPACKET_LocaleSet, | 764 pNode = m_pFactory->CreateNode(XFA_XDPPACKET_LocaleSet, |
713 XFA_Element::LocaleSet); | 765 XFA_Element::LocaleSet); |
714 if (!pNode) { | 766 if (!pNode) |
715 return nullptr; | 767 return nullptr; |
716 } | 768 |
717 pNode->SetCData(XFA_ATTRIBUTE_Name, | 769 pNode->SetCData(XFA_ATTRIBUTE_Name, |
718 XFA_GetPacketByIndex(XFA_PACKET_LocaleSet)->pName); | 770 XFA_GetPacketByIndex(XFA_PACKET_LocaleSet)->pName); |
719 if (!NormalLoader(pNode, pXMLDocumentNode, ePacketID)) { | 771 if (!NormalLoader(pNode, pXMLDocumentNode, ePacketID)) |
720 return nullptr; | 772 return nullptr; |
721 } | |
722 } | 773 } |
723 } else if (ePacketID == XFA_XDPPACKET_ConnectionSet) { | 774 } else if (ePacketID == XFA_XDPPACKET_ConnectionSet) { |
724 if (XFA_FDEExtension_MatchNodeName( | 775 if (MatchNodeName(pXMLDocumentNode, |
725 pXMLDocumentNode, | 776 XFA_GetPacketByIndex(XFA_PACKET_ConnectionSet)->pName, |
726 XFA_GetPacketByIndex(XFA_PACKET_ConnectionSet)->pName, | 777 XFA_GetPacketByIndex(XFA_PACKET_ConnectionSet)->pURI, |
727 XFA_GetPacketByIndex(XFA_PACKET_ConnectionSet)->pURI, | 778 XFA_GetPacketByIndex(XFA_PACKET_ConnectionSet)->eFlags)) { |
728 XFA_GetPacketByIndex(XFA_PACKET_ConnectionSet)->eFlags)) { | |
729 pNode = m_pFactory->CreateNode(XFA_XDPPACKET_ConnectionSet, | 779 pNode = m_pFactory->CreateNode(XFA_XDPPACKET_ConnectionSet, |
730 XFA_Element::ConnectionSet); | 780 XFA_Element::ConnectionSet); |
731 if (!pNode) { | 781 if (!pNode) |
732 return nullptr; | 782 return nullptr; |
733 } | 783 |
734 pNode->SetCData(XFA_ATTRIBUTE_Name, | 784 pNode->SetCData(XFA_ATTRIBUTE_Name, |
735 XFA_GetPacketByIndex(XFA_PACKET_ConnectionSet)->pName); | 785 XFA_GetPacketByIndex(XFA_PACKET_ConnectionSet)->pName); |
736 if (!NormalLoader(pNode, pXMLDocumentNode, ePacketID)) { | 786 if (!NormalLoader(pNode, pXMLDocumentNode, ePacketID)) |
737 return nullptr; | 787 return nullptr; |
738 } | |
739 } | 788 } |
740 } else if (ePacketID == XFA_XDPPACKET_SourceSet) { | 789 } else if (ePacketID == XFA_XDPPACKET_SourceSet) { |
741 if (XFA_FDEExtension_MatchNodeName( | 790 if (MatchNodeName(pXMLDocumentNode, |
742 pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_SourceSet)->pName, | 791 XFA_GetPacketByIndex(XFA_PACKET_SourceSet)->pName, |
743 XFA_GetPacketByIndex(XFA_PACKET_SourceSet)->pURI, | 792 XFA_GetPacketByIndex(XFA_PACKET_SourceSet)->pURI, |
744 XFA_GetPacketByIndex(XFA_PACKET_SourceSet)->eFlags)) { | 793 XFA_GetPacketByIndex(XFA_PACKET_SourceSet)->eFlags)) { |
745 pNode = m_pFactory->CreateNode(XFA_XDPPACKET_SourceSet, | 794 pNode = m_pFactory->CreateNode(XFA_XDPPACKET_SourceSet, |
746 XFA_Element::SourceSet); | 795 XFA_Element::SourceSet); |
747 if (!pNode) { | 796 if (!pNode) |
748 return nullptr; | 797 return nullptr; |
749 } | 798 |
750 pNode->SetCData(XFA_ATTRIBUTE_Name, | 799 pNode->SetCData(XFA_ATTRIBUTE_Name, |
751 XFA_GetPacketByIndex(XFA_PACKET_SourceSet)->pName); | 800 XFA_GetPacketByIndex(XFA_PACKET_SourceSet)->pName); |
752 if (!NormalLoader(pNode, pXMLDocumentNode, ePacketID)) { | 801 if (!NormalLoader(pNode, pXMLDocumentNode, ePacketID)) |
753 return nullptr; | 802 return nullptr; |
754 } | |
755 } | 803 } |
756 } | 804 } |
757 if (pNode) { | 805 if (pNode) |
758 pNode->SetXMLMappingNode(pXMLDocumentNode); | 806 pNode->SetXMLMappingNode(pXMLDocumentNode); |
759 } | |
760 return pNode; | 807 return pNode; |
761 } | 808 } |
762 | 809 |
763 CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_Xdc( | 810 CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_Xdc( |
764 CFDE_XMLNode* pXMLDocumentNode, | 811 CFDE_XMLNode* pXMLDocumentNode, |
765 XFA_XDPPACKET ePacketID) { | 812 XFA_XDPPACKET ePacketID) { |
766 if (XFA_FDEExtension_MatchNodeName( | 813 if (!MatchNodeName(pXMLDocumentNode, |
767 pXMLDocumentNode, XFA_GetPacketByIndex(XFA_PACKET_Xdc)->pName, | 814 XFA_GetPacketByIndex(XFA_PACKET_Xdc)->pName, |
768 XFA_GetPacketByIndex(XFA_PACKET_Xdc)->pURI, | 815 XFA_GetPacketByIndex(XFA_PACKET_Xdc)->pURI, |
769 XFA_GetPacketByIndex(XFA_PACKET_Xdc)->eFlags)) { | 816 XFA_GetPacketByIndex(XFA_PACKET_Xdc)->eFlags)) |
770 CXFA_Node* pNode = | 817 return nullptr; |
771 m_pFactory->CreateNode(XFA_XDPPACKET_Xdc, XFA_Element::Xdc); | 818 |
772 if (!pNode) { | 819 CXFA_Node* pNode = |
773 return nullptr; | 820 m_pFactory->CreateNode(XFA_XDPPACKET_Xdc, XFA_Element::Xdc); |
774 } | 821 if (!pNode) |
775 pNode->SetCData(XFA_ATTRIBUTE_Name, | 822 return nullptr; |
776 XFA_GetPacketByIndex(XFA_PACKET_Xdc)->pName); | 823 |
777 pNode->SetXMLMappingNode(pXMLDocumentNode); | 824 pNode->SetCData(XFA_ATTRIBUTE_Name, |
778 return pNode; | 825 XFA_GetPacketByIndex(XFA_PACKET_Xdc)->pName); |
779 } | 826 pNode->SetXMLMappingNode(pXMLDocumentNode); |
780 return nullptr; | 827 return pNode; |
781 } | 828 } |
782 | 829 |
783 CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_User( | 830 CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_User( |
784 CFDE_XMLNode* pXMLDocumentNode, | 831 CFDE_XMLNode* pXMLDocumentNode, |
785 XFA_XDPPACKET ePacketID) { | 832 XFA_XDPPACKET ePacketID) { |
786 CXFA_Node* pNode = | 833 CXFA_Node* pNode = |
787 m_pFactory->CreateNode(XFA_XDPPACKET_XDP, XFA_Element::Packet); | 834 m_pFactory->CreateNode(XFA_XDPPACKET_XDP, XFA_Element::Packet); |
788 if (!pNode) { | 835 if (!pNode) |
789 return nullptr; | 836 return nullptr; |
790 } | 837 |
791 CFX_WideString wsName; | 838 CFX_WideString wsName; |
792 static_cast<CFDE_XMLElement*>(pXMLDocumentNode)->GetLocalTagName(wsName); | 839 static_cast<CFDE_XMLElement*>(pXMLDocumentNode)->GetLocalTagName(wsName); |
793 pNode->SetCData(XFA_ATTRIBUTE_Name, wsName); | 840 pNode->SetCData(XFA_ATTRIBUTE_Name, wsName); |
794 if (!UserPacketLoader(pNode, pXMLDocumentNode)) { | 841 if (!UserPacketLoader(pNode, pXMLDocumentNode)) |
795 return nullptr; | 842 return nullptr; |
796 } | 843 |
797 pNode->SetXMLMappingNode(pXMLDocumentNode); | 844 pNode->SetXMLMappingNode(pXMLDocumentNode); |
798 return pNode; | 845 return pNode; |
799 } | 846 } |
800 | 847 |
801 CXFA_Node* CXFA_SimpleParser::UserPacketLoader(CXFA_Node* pXFANode, | 848 CXFA_Node* CXFA_SimpleParser::UserPacketLoader(CXFA_Node* pXFANode, |
802 CFDE_XMLNode* pXMLDoc) { | 849 CFDE_XMLNode* pXMLDoc) { |
803 return pXFANode; | 850 return pXFANode; |
804 } | 851 } |
805 | 852 |
806 static FX_BOOL XFA_FDEExtension_IsStringAllWhitespace(CFX_WideString wsText) { | |
807 wsText.TrimRight(L"\x20\x9\xD\xA"); | |
808 return wsText.IsEmpty(); | |
809 } | |
810 | |
811 CXFA_Node* CXFA_SimpleParser::DataLoader(CXFA_Node* pXFANode, | 853 CXFA_Node* CXFA_SimpleParser::DataLoader(CXFA_Node* pXFANode, |
812 CFDE_XMLNode* pXMLDoc, | 854 CFDE_XMLNode* pXMLDoc, |
813 FX_BOOL bDoTransform) { | 855 FX_BOOL bDoTransform) { |
814 ParseDataGroup(pXFANode, pXMLDoc, XFA_XDPPACKET_Datasets); | 856 ParseDataGroup(pXFANode, pXMLDoc, XFA_XDPPACKET_Datasets); |
815 return pXFANode; | 857 return pXFANode; |
816 } | 858 } |
817 | 859 |
818 CXFA_Node* CXFA_SimpleParser::NormalLoader(CXFA_Node* pXFANode, | 860 CXFA_Node* CXFA_SimpleParser::NormalLoader(CXFA_Node* pXFANode, |
819 CFDE_XMLNode* pXMLDoc, | 861 CFDE_XMLNode* pXMLDoc, |
820 XFA_XDPPACKET ePacketID, | 862 XFA_XDPPACKET ePacketID, |
821 FX_BOOL bUseAttribute) { | 863 FX_BOOL bUseAttribute) { |
822 FX_BOOL bOneOfPropertyFound = FALSE; | 864 FX_BOOL bOneOfPropertyFound = FALSE; |
823 for (CFDE_XMLNode* pXMLChild = pXMLDoc->GetNodeItem(CFDE_XMLNode::FirstChild); | 865 for (CFDE_XMLNode* pXMLChild = pXMLDoc->GetNodeItem(CFDE_XMLNode::FirstChild); |
824 pXMLChild; | 866 pXMLChild; |
825 pXMLChild = pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling)) { | 867 pXMLChild = pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling)) { |
826 switch (pXMLChild->GetType()) { | 868 switch (pXMLChild->GetType()) { |
827 case FDE_XMLNODE_Element: { | 869 case FDE_XMLNODE_Element: { |
828 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLChild); | 870 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLChild); |
829 CFX_WideString wsTagName; | 871 CFX_WideString wsTagName; |
830 pXMLElement->GetLocalTagName(wsTagName); | 872 pXMLElement->GetLocalTagName(wsTagName); |
831 XFA_Element eType = XFA_GetElementTypeForName(wsTagName.AsStringC()); | 873 XFA_Element eType = XFA_GetElementTypeForName(wsTagName.AsStringC()); |
832 if (eType == XFA_Element::Unknown) | 874 if (eType == XFA_Element::Unknown) |
833 continue; | 875 continue; |
834 | 876 |
835 const XFA_PROPERTY* pPropertyInfo = XFA_GetPropertyOfElement( | 877 const XFA_PROPERTY* pPropertyInfo = XFA_GetPropertyOfElement( |
836 pXFANode->GetElementType(), eType, ePacketID); | 878 pXFANode->GetElementType(), eType, ePacketID); |
837 if (pPropertyInfo && | 879 if (pPropertyInfo && |
838 ((pPropertyInfo->uFlags & | 880 ((pPropertyInfo->uFlags & |
839 (XFA_PROPERTYFLAG_OneOf | XFA_PROPERTYFLAG_DefaultOneOf)) != 0)) { | 881 (XFA_PROPERTYFLAG_OneOf | XFA_PROPERTYFLAG_DefaultOneOf)) != 0)) { |
840 if (bOneOfPropertyFound) { | 882 if (bOneOfPropertyFound) |
841 break; | 883 break; |
842 } | 884 |
843 bOneOfPropertyFound = TRUE; | 885 bOneOfPropertyFound = TRUE; |
844 } | 886 } |
845 CXFA_Node* pXFAChild = m_pFactory->CreateNode(ePacketID, eType); | 887 CXFA_Node* pXFAChild = m_pFactory->CreateNode(ePacketID, eType); |
846 if (!pXFAChild) | 888 if (!pXFAChild) |
847 return nullptr; | 889 return nullptr; |
848 if (ePacketID == XFA_XDPPACKET_Config) | 890 if (ePacketID == XFA_XDPPACKET_Config) |
849 pXFAChild->SetAttribute(XFA_ATTRIBUTE_Name, wsTagName.AsStringC()); | 891 pXFAChild->SetAttribute(XFA_ATTRIBUTE_Name, wsTagName.AsStringC()); |
850 | 892 |
851 FX_BOOL IsNeedValue = TRUE; | 893 FX_BOOL IsNeedValue = TRUE; |
852 for (int32_t i = 0, count = pXMLElement->CountAttributes(); i < count; | 894 for (int32_t i = 0, count = pXMLElement->CountAttributes(); i < count; |
853 i++) { | 895 i++) { |
854 CFX_WideString wsAttrQualifiedName; | 896 CFX_WideString wsAttrQualifiedName; |
855 CFX_WideString wsAttrName; | 897 CFX_WideString wsAttrName; |
856 CFX_WideString wsAttrValue; | 898 CFX_WideString wsAttrValue; |
857 pXMLElement->GetAttribute(i, wsAttrQualifiedName, wsAttrValue); | 899 pXMLElement->GetAttribute(i, wsAttrQualifiedName, wsAttrValue); |
858 XFA_FDEExtension_GetAttributeLocalName( | 900 GetAttributeLocalName(wsAttrQualifiedName.AsStringC(), wsAttrName); |
859 wsAttrQualifiedName.AsStringC(), wsAttrName); | |
860 if (wsAttrName == FX_WSTRC(L"nil") && | 901 if (wsAttrName == FX_WSTRC(L"nil") && |
861 wsAttrValue == FX_WSTRC(L"true")) { | 902 wsAttrValue == FX_WSTRC(L"true")) { |
862 IsNeedValue = FALSE; | 903 IsNeedValue = FALSE; |
863 } | 904 } |
864 const XFA_ATTRIBUTEINFO* lpAttrInfo = | 905 const XFA_ATTRIBUTEINFO* lpAttrInfo = |
865 XFA_GetAttributeByName(wsAttrName.AsStringC()); | 906 XFA_GetAttributeByName(wsAttrName.AsStringC()); |
866 if (!lpAttrInfo) { | 907 if (!lpAttrInfo) |
867 continue; | 908 continue; |
868 } | 909 |
869 if (!bUseAttribute && lpAttrInfo->eName != XFA_ATTRIBUTE_Name && | 910 if (!bUseAttribute && lpAttrInfo->eName != XFA_ATTRIBUTE_Name && |
870 lpAttrInfo->eName != XFA_ATTRIBUTE_Save) { | 911 lpAttrInfo->eName != XFA_ATTRIBUTE_Save) { |
871 continue; | 912 continue; |
872 } | 913 } |
873 pXFAChild->SetAttribute(lpAttrInfo->eName, wsAttrValue.AsStringC()); | 914 pXFAChild->SetAttribute(lpAttrInfo->eName, wsAttrValue.AsStringC()); |
874 } | 915 } |
875 pXFANode->InsertChild(pXFAChild); | 916 pXFANode->InsertChild(pXFAChild); |
876 if (eType == XFA_Element::Validate || eType == XFA_Element::Locale) { | 917 if (eType == XFA_Element::Validate || eType == XFA_Element::Locale) { |
877 if (ePacketID == XFA_XDPPACKET_Config) { | 918 if (ePacketID == XFA_XDPPACKET_Config) |
878 ParseContentNode(pXFAChild, pXMLElement, ePacketID); | 919 ParseContentNode(pXFAChild, pXMLElement, ePacketID); |
879 } else { | 920 else |
880 NormalLoader(pXFAChild, pXMLElement, ePacketID, bUseAttribute); | 921 NormalLoader(pXFAChild, pXMLElement, ePacketID, bUseAttribute); |
881 } | 922 |
882 break; | 923 break; |
883 } | 924 } |
884 switch (pXFAChild->GetObjectType()) { | 925 switch (pXFAChild->GetObjectType()) { |
885 case XFA_ObjectType::ContentNode: | 926 case XFA_ObjectType::ContentNode: |
886 case XFA_ObjectType::TextNode: | 927 case XFA_ObjectType::TextNode: |
887 case XFA_ObjectType::NodeC: | 928 case XFA_ObjectType::NodeC: |
888 case XFA_ObjectType::NodeV: | 929 case XFA_ObjectType::NodeV: |
889 if (IsNeedValue) { | 930 if (IsNeedValue) |
890 ParseContentNode(pXFAChild, pXMLElement, ePacketID); | 931 ParseContentNode(pXFAChild, pXMLElement, ePacketID); |
891 } | |
892 break; | 932 break; |
893 default: | 933 default: |
894 NormalLoader(pXFAChild, pXMLElement, ePacketID, bUseAttribute); | 934 NormalLoader(pXFAChild, pXMLElement, ePacketID, bUseAttribute); |
895 break; | 935 break; |
896 } | 936 } |
897 } break; | 937 } break; |
898 case FDE_XMLNODE_Instruction: | 938 case FDE_XMLNODE_Instruction: |
899 ParseInstruction(pXFANode, static_cast<CFDE_XMLInstruction*>(pXMLChild), | 939 ParseInstruction(pXFANode, static_cast<CFDE_XMLInstruction*>(pXMLChild), |
900 ePacketID); | 940 ePacketID); |
901 break; | 941 break; |
902 default: | 942 default: |
903 break; | 943 break; |
904 } | 944 } |
905 } | 945 } |
906 return pXFANode; | 946 return pXFANode; |
907 } | 947 } |
908 | 948 |
909 FX_BOOL XFA_RecognizeRichText(CFDE_XMLElement* pRichTextXMLNode) { | |
910 if (pRichTextXMLNode) { | |
911 CFX_WideString wsNamespaceURI; | |
912 XFA_FDEExtension_GetElementTagNamespaceURI(pRichTextXMLNode, | |
913 wsNamespaceURI); | |
914 if (wsNamespaceURI == FX_WSTRC(L"http://www.w3.org/1999/xhtml")) { | |
915 return TRUE; | |
916 } | |
917 } | |
918 return FALSE; | |
919 } | |
920 | |
921 class RichTextNodeVisitor { | |
922 public: | |
923 static inline CFDE_XMLNode* GetFirstChild(CFDE_XMLNode* pNode) { | |
924 return pNode->GetNodeItem(CFDE_XMLNode::FirstChild); | |
925 } | |
926 static inline CFDE_XMLNode* GetNextSibling(CFDE_XMLNode* pNode) { | |
927 return pNode->GetNodeItem(CFDE_XMLNode::NextSibling); | |
928 } | |
929 static inline CFDE_XMLNode* GetParent(CFDE_XMLNode* pNode) { | |
930 return pNode->GetNodeItem(CFDE_XMLNode::Parent); | |
931 } | |
932 }; | |
933 | |
934 void XFA_ConvertXMLToPlainText(CFDE_XMLElement* pRootXMLNode, | |
935 CFX_WideString& wsOutput) { | |
936 for (CFDE_XMLNode* pXMLChild = | |
937 pRootXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild); | |
938 pXMLChild; | |
939 pXMLChild = pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling)) { | |
940 switch (pXMLChild->GetType()) { | |
941 case FDE_XMLNODE_Element: { | |
942 CFX_WideString wsTextData; | |
943 static_cast<CFDE_XMLElement*>(pXMLChild)->GetTextData(wsTextData); | |
944 wsTextData += FX_WSTRC(L"\n"); | |
945 wsOutput += wsTextData; | |
946 } break; | |
947 case FDE_XMLNODE_Text: { | |
948 CFX_WideString wsText; | |
949 static_cast<CFDE_XMLText*>(pXMLChild)->GetText(wsText); | |
950 if (XFA_FDEExtension_IsStringAllWhitespace(wsText)) { | |
951 continue; | |
952 } else { | |
953 wsOutput = wsText; | |
954 } | |
955 } break; | |
956 case FDE_XMLNODE_CharData: { | |
957 CFX_WideString wsCharData; | |
958 static_cast<CFDE_XMLCharData*>(pXMLChild)->GetCharData(wsCharData); | |
959 if (XFA_FDEExtension_IsStringAllWhitespace(wsCharData)) { | |
960 continue; | |
961 } else { | |
962 wsOutput = wsCharData; | |
963 } | |
964 } break; | |
965 default: | |
966 ASSERT(FALSE); | |
967 break; | |
968 } | |
969 } | |
970 } | |
971 | |
972 void CXFA_SimpleParser::ParseContentNode(CXFA_Node* pXFANode, | 949 void CXFA_SimpleParser::ParseContentNode(CXFA_Node* pXFANode, |
973 CFDE_XMLNode* pXMLNode, | 950 CFDE_XMLNode* pXMLNode, |
974 XFA_XDPPACKET ePacketID) { | 951 XFA_XDPPACKET ePacketID) { |
975 XFA_Element element = XFA_Element::Sharptext; | 952 XFA_Element element = XFA_Element::Sharptext; |
976 if (pXFANode->GetElementType() == XFA_Element::ExData) { | 953 if (pXFANode->GetElementType() == XFA_Element::ExData) { |
977 CFX_WideStringC wsContentType = | 954 CFX_WideStringC wsContentType = |
978 pXFANode->GetCData(XFA_ATTRIBUTE_ContentType); | 955 pXFANode->GetCData(XFA_ATTRIBUTE_ContentType); |
979 if (wsContentType == FX_WSTRC(L"text/html")) | 956 if (wsContentType == FX_WSTRC(L"text/html")) |
980 element = XFA_Element::SharpxHTML; | 957 element = XFA_Element::SharpxHTML; |
981 else if (wsContentType == FX_WSTRC(L"text/xml")) | 958 else if (wsContentType == FX_WSTRC(L"text/xml")) |
(...skipping 14 matching lines...) Expand all Loading... | |
996 if (element == XFA_Element::SharpxHTML) { | 973 if (element == XFA_Element::SharpxHTML) { |
997 if (eNodeType != FDE_XMLNODE_Element) | 974 if (eNodeType != FDE_XMLNODE_Element) |
998 break; | 975 break; |
999 | 976 |
1000 if (XFA_RecognizeRichText(static_cast<CFDE_XMLElement*>(pXMLChild))) | 977 if (XFA_RecognizeRichText(static_cast<CFDE_XMLElement*>(pXMLChild))) |
1001 XFA_GetPlainTextFromRichText(static_cast<CFDE_XMLElement*>(pXMLChild), | 978 XFA_GetPlainTextFromRichText(static_cast<CFDE_XMLElement*>(pXMLChild), |
1002 wsValue); | 979 wsValue); |
1003 } else if (element == XFA_Element::Sharpxml) { | 980 } else if (element == XFA_Element::Sharpxml) { |
1004 if (eNodeType != FDE_XMLNODE_Element) | 981 if (eNodeType != FDE_XMLNODE_Element) |
1005 break; | 982 break; |
1006 XFA_ConvertXMLToPlainText(static_cast<CFDE_XMLElement*>(pXMLChild), | 983 |
1007 wsValue); | 984 ConvertXMLToPlainText(static_cast<CFDE_XMLElement*>(pXMLChild), wsValue); |
1008 } else { | 985 } else { |
1009 if (eNodeType == FDE_XMLNODE_Element) | 986 if (eNodeType == FDE_XMLNODE_Element) |
1010 break; | 987 break; |
1011 if (eNodeType == FDE_XMLNODE_Text) | 988 if (eNodeType == FDE_XMLNODE_Text) |
1012 static_cast<CFDE_XMLText*>(pXMLChild)->GetText(wsValue); | 989 static_cast<CFDE_XMLText*>(pXMLChild)->GetText(wsValue); |
1013 else if (eNodeType == FDE_XMLNODE_CharData) | 990 else if (eNodeType == FDE_XMLNODE_CharData) |
1014 static_cast<CFDE_XMLCharData*>(pXMLChild)->GetCharData(wsValue); | 991 static_cast<CFDE_XMLCharData*>(pXMLChild)->GetCharData(wsValue); |
1015 } | 992 } |
1016 break; | 993 break; |
1017 } | 994 } |
(...skipping 15 matching lines...) Expand all Loading... | |
1033 XFA_XDPPACKET ePacketID) { | 1010 XFA_XDPPACKET ePacketID) { |
1034 for (CFDE_XMLNode* pXMLChild = | 1011 for (CFDE_XMLNode* pXMLChild = |
1035 pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild); | 1012 pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild); |
1036 pXMLChild; | 1013 pXMLChild; |
1037 pXMLChild = pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling)) { | 1014 pXMLChild = pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling)) { |
1038 switch (pXMLChild->GetType()) { | 1015 switch (pXMLChild->GetType()) { |
1039 case FDE_XMLNODE_Element: { | 1016 case FDE_XMLNODE_Element: { |
1040 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLChild); | 1017 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLChild); |
1041 { | 1018 { |
1042 CFX_WideString wsNamespaceURI; | 1019 CFX_WideString wsNamespaceURI; |
1043 XFA_FDEExtension_GetElementTagNamespaceURI(pXMLElement, | 1020 GetElementTagNamespaceURI(pXMLElement, wsNamespaceURI); |
1044 wsNamespaceURI); | |
1045 if (wsNamespaceURI == | 1021 if (wsNamespaceURI == |
1046 FX_WSTRC(L"http://www.xfa.com/schema/xfa-package/") || | 1022 FX_WSTRC(L"http://www.xfa.com/schema/xfa-package/") || |
1047 wsNamespaceURI == | 1023 wsNamespaceURI == |
1048 FX_WSTRC(L"http://www.xfa.org/schema/xfa-package/") || | 1024 FX_WSTRC(L"http://www.xfa.org/schema/xfa-package/") || |
1049 wsNamespaceURI == | 1025 wsNamespaceURI == |
1050 FX_WSTRC(L"http://www.w3.org/2001/XMLSchema-instance")) { | 1026 FX_WSTRC(L"http://www.w3.org/2001/XMLSchema-instance")) { |
1051 continue; | 1027 continue; |
1052 } | 1028 } |
1053 } | 1029 } |
1030 | |
1054 XFA_Element eNodeType = XFA_Element::DataModel; | 1031 XFA_Element eNodeType = XFA_Element::DataModel; |
1055 if (eNodeType == XFA_Element::DataModel) { | 1032 if (eNodeType == XFA_Element::DataModel) { |
1056 CFX_WideString wsDataNodeAttr; | 1033 CFX_WideString wsDataNodeAttr; |
1057 if (XFA_FDEExtension_FindAttributeWithNS( | 1034 if (FindAttributeWithNS( |
1058 pXMLElement, FX_WSTRC(L"dataNode"), | 1035 pXMLElement, FX_WSTRC(L"dataNode"), |
1059 FX_WSTRC(L"http://www.xfa.org/schema/xfa-data/1.0/"), | 1036 FX_WSTRC(L"http://www.xfa.org/schema/xfa-data/1.0/"), |
1060 wsDataNodeAttr)) { | 1037 wsDataNodeAttr)) { |
1061 if (wsDataNodeAttr == FX_WSTRC(L"dataGroup")) { | 1038 if (wsDataNodeAttr == FX_WSTRC(L"dataGroup")) |
1062 eNodeType = XFA_Element::DataGroup; | 1039 eNodeType = XFA_Element::DataGroup; |
1063 } else if (wsDataNodeAttr == FX_WSTRC(L"dataValue")) { | 1040 else if (wsDataNodeAttr == FX_WSTRC(L"dataValue")) |
1064 eNodeType = XFA_Element::DataValue; | 1041 eNodeType = XFA_Element::DataValue; |
1065 } | |
1066 } | 1042 } |
1067 } | 1043 } |
1068 CFX_WideString wsContentType; | 1044 CFX_WideString wsContentType; |
1069 if (eNodeType == XFA_Element::DataModel) { | 1045 if (eNodeType == XFA_Element::DataModel) { |
1070 if (XFA_FDEExtension_FindAttributeWithNS( | 1046 if (FindAttributeWithNS( |
1071 pXMLElement, FX_WSTRC(L"contentType"), | 1047 pXMLElement, FX_WSTRC(L"contentType"), |
1072 FX_WSTRC(L"http://www.xfa.org/schema/xfa-data/1.0/"), | 1048 FX_WSTRC(L"http://www.xfa.org/schema/xfa-data/1.0/"), |
1073 wsContentType)) { | 1049 wsContentType)) { |
1074 if (!wsContentType.IsEmpty()) { | 1050 if (!wsContentType.IsEmpty()) |
1075 eNodeType = XFA_Element::DataValue; | 1051 eNodeType = XFA_Element::DataValue; |
1076 } | |
1077 } | 1052 } |
1078 } | 1053 } |
1079 if (eNodeType == XFA_Element::DataModel) { | 1054 if (eNodeType == XFA_Element::DataModel) { |
1080 for (CFDE_XMLNode* pXMLDataChild = | 1055 for (CFDE_XMLNode* pXMLDataChild = |
1081 pXMLElement->GetNodeItem(CFDE_XMLNode::FirstChild); | 1056 pXMLElement->GetNodeItem(CFDE_XMLNode::FirstChild); |
1082 pXMLDataChild; pXMLDataChild = pXMLDataChild->GetNodeItem( | 1057 pXMLDataChild; pXMLDataChild = pXMLDataChild->GetNodeItem( |
1083 CFDE_XMLNode::NextSibling)) { | 1058 CFDE_XMLNode::NextSibling)) { |
1084 if (pXMLDataChild->GetType() == FDE_XMLNODE_Element) { | 1059 if (pXMLDataChild->GetType() == FDE_XMLNODE_Element) { |
1085 if (!XFA_RecognizeRichText( | 1060 if (!XFA_RecognizeRichText( |
1086 static_cast<CFDE_XMLElement*>(pXMLDataChild))) { | 1061 static_cast<CFDE_XMLElement*>(pXMLDataChild))) { |
1087 eNodeType = XFA_Element::DataGroup; | 1062 eNodeType = XFA_Element::DataGroup; |
1088 break; | 1063 break; |
1089 } | 1064 } |
1090 } | 1065 } |
1091 } | 1066 } |
1092 } | 1067 } |
1093 if (eNodeType == XFA_Element::DataModel) { | 1068 if (eNodeType == XFA_Element::DataModel) |
1094 eNodeType = XFA_Element::DataValue; | 1069 eNodeType = XFA_Element::DataValue; |
1095 } | 1070 |
1096 CXFA_Node* pXFAChild = | 1071 CXFA_Node* pXFAChild = |
1097 m_pFactory->CreateNode(XFA_XDPPACKET_Datasets, eNodeType); | 1072 m_pFactory->CreateNode(XFA_XDPPACKET_Datasets, eNodeType); |
1098 if (!pXFAChild) { | 1073 if (!pXFAChild) |
1099 return; | 1074 return; |
1100 } | 1075 |
1101 CFX_WideString wsNodeName; | 1076 CFX_WideString wsNodeName; |
1102 pXMLElement->GetLocalTagName(wsNodeName); | 1077 pXMLElement->GetLocalTagName(wsNodeName); |
1103 pXFAChild->SetCData(XFA_ATTRIBUTE_Name, wsNodeName); | 1078 pXFAChild->SetCData(XFA_ATTRIBUTE_Name, wsNodeName); |
1104 bool bNeedValue = true; | 1079 bool bNeedValue = true; |
1105 for (int32_t i = 0; i < pXMLElement->CountAttributes(); ++i) { | 1080 for (int32_t i = 0; i < pXMLElement->CountAttributes(); ++i) { |
1106 CFX_WideString wsQualifiedName; | 1081 CFX_WideString wsQualifiedName; |
1107 CFX_WideString wsValue; | 1082 CFX_WideString wsValue; |
1108 CFX_WideString wsName; | 1083 CFX_WideString wsName; |
1109 CFX_WideString wsNS; | 1084 CFX_WideString wsNS; |
1110 pXMLElement->GetAttribute(i, wsQualifiedName, wsValue); | 1085 pXMLElement->GetAttribute(i, wsQualifiedName, wsValue); |
1111 if (!XFA_FDEExtension_ResolveAttribute( | 1086 if (!ResolveAttribute(pXMLElement, wsQualifiedName.AsStringC(), |
1112 pXMLElement, wsQualifiedName.AsStringC(), wsName, wsNS)) { | 1087 wsName, wsNS)) { |
1113 continue; | 1088 continue; |
1114 } | 1089 } |
1115 if (wsName == FX_WSTRC(L"nil") && wsValue == FX_WSTRC(L"true")) { | 1090 if (wsName == FX_WSTRC(L"nil") && wsValue == FX_WSTRC(L"true")) { |
1116 bNeedValue = false; | 1091 bNeedValue = false; |
1117 continue; | 1092 continue; |
1118 } | 1093 } |
1119 if (wsNS == FX_WSTRC(L"http://www.xfa.com/schema/xfa-package/") || | 1094 if (wsNS == FX_WSTRC(L"http://www.xfa.com/schema/xfa-package/") || |
1120 wsNS == FX_WSTRC(L"http://www.xfa.org/schema/xfa-package/") || | 1095 wsNS == FX_WSTRC(L"http://www.xfa.org/schema/xfa-package/") || |
1121 wsNS == FX_WSTRC(L"http://www.w3.org/2001/XMLSchema-instance") || | 1096 wsNS == FX_WSTRC(L"http://www.w3.org/2001/XMLSchema-instance") || |
1122 wsNS == FX_WSTRC(L"http://www.xfa.org/schema/xfa-data/1.0/")) { | 1097 wsNS == FX_WSTRC(L"http://www.xfa.org/schema/xfa-data/1.0/")) { |
1123 continue; | 1098 continue; |
1124 } | 1099 } |
1125 CXFA_Node* pXFAMetaData = m_pFactory->CreateNode( | 1100 CXFA_Node* pXFAMetaData = m_pFactory->CreateNode( |
1126 XFA_XDPPACKET_Datasets, XFA_Element::DataValue); | 1101 XFA_XDPPACKET_Datasets, XFA_Element::DataValue); |
1127 if (!pXFAMetaData) { | 1102 if (!pXFAMetaData) |
1128 return; | 1103 return; |
1129 } | 1104 |
1130 pXFAMetaData->SetCData(XFA_ATTRIBUTE_Name, wsName); | 1105 pXFAMetaData->SetCData(XFA_ATTRIBUTE_Name, wsName); |
1131 pXFAMetaData->SetCData(XFA_ATTRIBUTE_QualifiedName, wsQualifiedName); | 1106 pXFAMetaData->SetCData(XFA_ATTRIBUTE_QualifiedName, wsQualifiedName); |
1132 pXFAMetaData->SetCData(XFA_ATTRIBUTE_Value, wsValue); | 1107 pXFAMetaData->SetCData(XFA_ATTRIBUTE_Value, wsValue); |
1133 pXFAMetaData->SetEnum(XFA_ATTRIBUTE_Contains, | 1108 pXFAMetaData->SetEnum(XFA_ATTRIBUTE_Contains, |
1134 XFA_ATTRIBUTEENUM_MetaData); | 1109 XFA_ATTRIBUTEENUM_MetaData); |
1135 pXFAChild->InsertChild(pXFAMetaData); | 1110 pXFAChild->InsertChild(pXFAMetaData); |
1136 pXFAMetaData->SetXMLMappingNode(pXMLElement); | 1111 pXFAMetaData->SetXMLMappingNode(pXMLElement); |
1137 pXFAMetaData->SetFlag(XFA_NodeFlag_Initialized, false); | 1112 pXFAMetaData->SetFlag(XFA_NodeFlag_Initialized, false); |
1138 } | 1113 } |
1114 | |
1139 if (!bNeedValue) { | 1115 if (!bNeedValue) { |
1140 CFX_WideString wsNilName(L"xsi:nil"); | 1116 CFX_WideString wsNilName(L"xsi:nil"); |
1141 pXMLElement->RemoveAttribute(wsNilName.c_str()); | 1117 pXMLElement->RemoveAttribute(wsNilName.c_str()); |
1142 } | 1118 } |
1143 pXFANode->InsertChild(pXFAChild); | 1119 pXFANode->InsertChild(pXFAChild); |
1144 if (eNodeType == XFA_Element::DataGroup) { | 1120 if (eNodeType == XFA_Element::DataGroup) |
1145 ParseDataGroup(pXFAChild, pXMLElement, ePacketID); | 1121 ParseDataGroup(pXFAChild, pXMLElement, ePacketID); |
1146 } else if (bNeedValue) { | 1122 else if (bNeedValue) |
1147 ParseDataValue(pXFAChild, pXMLChild, XFA_XDPPACKET_Datasets); | 1123 ParseDataValue(pXFAChild, pXMLChild, XFA_XDPPACKET_Datasets); |
1148 } | 1124 |
1149 pXFAChild->SetXMLMappingNode(pXMLElement); | 1125 pXFAChild->SetXMLMappingNode(pXMLElement); |
1150 pXFAChild->SetFlag(XFA_NodeFlag_Initialized, false); | 1126 pXFAChild->SetFlag(XFA_NodeFlag_Initialized, false); |
1151 continue; | 1127 continue; |
1152 } | 1128 } |
1153 case FDE_XMLNODE_CharData: { | 1129 case FDE_XMLNODE_CharData: { |
1154 CFDE_XMLCharData* pXMLCharData = | 1130 CFDE_XMLCharData* pXMLCharData = |
1155 static_cast<CFDE_XMLCharData*>(pXMLChild); | 1131 static_cast<CFDE_XMLCharData*>(pXMLChild); |
1156 CFX_WideString wsCharData; | 1132 CFX_WideString wsCharData; |
1157 pXMLCharData->GetCharData(wsCharData); | 1133 pXMLCharData->GetCharData(wsCharData); |
1158 if (XFA_FDEExtension_IsStringAllWhitespace(wsCharData)) { | 1134 if (IsStringAllWhitespace(wsCharData)) |
1159 continue; | 1135 continue; |
1160 } | 1136 |
1161 CXFA_Node* pXFAChild = m_pFactory->CreateNode(XFA_XDPPACKET_Datasets, | 1137 CXFA_Node* pXFAChild = m_pFactory->CreateNode(XFA_XDPPACKET_Datasets, |
1162 XFA_Element::DataValue); | 1138 XFA_Element::DataValue); |
1163 if (!pXFAChild) { | 1139 if (!pXFAChild) |
1164 return; | 1140 return; |
1165 } | 1141 |
1166 pXFAChild->SetCData(XFA_ATTRIBUTE_Value, wsCharData); | 1142 pXFAChild->SetCData(XFA_ATTRIBUTE_Value, wsCharData); |
1167 pXFANode->InsertChild(pXFAChild); | 1143 pXFANode->InsertChild(pXFAChild); |
1168 pXFAChild->SetXMLMappingNode(pXMLCharData); | 1144 pXFAChild->SetXMLMappingNode(pXMLCharData); |
1169 pXFAChild->SetFlag(XFA_NodeFlag_Initialized, false); | 1145 pXFAChild->SetFlag(XFA_NodeFlag_Initialized, false); |
1170 continue; | 1146 continue; |
1171 } | 1147 } |
1172 case FDE_XMLNODE_Text: { | 1148 case FDE_XMLNODE_Text: { |
1173 CFDE_XMLText* pXMLText = static_cast<CFDE_XMLText*>(pXMLChild); | 1149 CFDE_XMLText* pXMLText = static_cast<CFDE_XMLText*>(pXMLChild); |
1174 CFX_WideString wsText; | 1150 CFX_WideString wsText; |
1175 pXMLText->GetText(wsText); | 1151 pXMLText->GetText(wsText); |
1176 if (XFA_FDEExtension_IsStringAllWhitespace(wsText)) { | 1152 if (IsStringAllWhitespace(wsText)) |
1177 continue; | 1153 continue; |
1178 } | 1154 |
1179 CXFA_Node* pXFAChild = m_pFactory->CreateNode(XFA_XDPPACKET_Datasets, | 1155 CXFA_Node* pXFAChild = m_pFactory->CreateNode(XFA_XDPPACKET_Datasets, |
1180 XFA_Element::DataValue); | 1156 XFA_Element::DataValue); |
1181 if (!pXFAChild) { | 1157 if (!pXFAChild) |
1182 return; | 1158 return; |
1183 } | 1159 |
1184 pXFAChild->SetCData(XFA_ATTRIBUTE_Value, wsText); | 1160 pXFAChild->SetCData(XFA_ATTRIBUTE_Value, wsText); |
1185 pXFANode->InsertChild(pXFAChild); | 1161 pXFANode->InsertChild(pXFAChild); |
1186 pXFAChild->SetXMLMappingNode(pXMLText); | 1162 pXFAChild->SetXMLMappingNode(pXMLText); |
1187 pXFAChild->SetFlag(XFA_NodeFlag_Initialized, false); | 1163 pXFAChild->SetFlag(XFA_NodeFlag_Initialized, false); |
1188 continue; | 1164 continue; |
1189 } | 1165 } |
1190 default: | 1166 default: |
1191 continue; | 1167 continue; |
1192 } | 1168 } |
1193 } | 1169 } |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1285 } | 1261 } |
1286 pXMLCurValueNode = nullptr; | 1262 pXMLCurValueNode = nullptr; |
1287 } | 1263 } |
1288 CFX_WideString wsNodeValue = wsValueTextBuf.MakeString(); | 1264 CFX_WideString wsNodeValue = wsValueTextBuf.MakeString(); |
1289 pXFANode->SetCData(XFA_ATTRIBUTE_Value, wsNodeValue); | 1265 pXFANode->SetCData(XFA_ATTRIBUTE_Value, wsNodeValue); |
1290 } | 1266 } |
1291 | 1267 |
1292 void CXFA_SimpleParser::ParseInstruction(CXFA_Node* pXFANode, | 1268 void CXFA_SimpleParser::ParseInstruction(CXFA_Node* pXFANode, |
1293 CFDE_XMLInstruction* pXMLInstruction, | 1269 CFDE_XMLInstruction* pXMLInstruction, |
1294 XFA_XDPPACKET ePacketID) { | 1270 XFA_XDPPACKET ePacketID) { |
1295 if (!m_bDocumentParser) { | 1271 if (!m_bDocumentParser) |
1296 return; | 1272 return; |
1297 } | 1273 |
1298 CFX_WideString wsTargetName; | 1274 CFX_WideString wsTargetName; |
1299 pXMLInstruction->GetTargetName(wsTargetName); | 1275 pXMLInstruction->GetTargetName(wsTargetName); |
1300 if (wsTargetName == FX_WSTRC(L"originalXFAVersion")) { | 1276 if (wsTargetName == FX_WSTRC(L"originalXFAVersion")) { |
1301 CFX_WideString wsData; | 1277 CFX_WideString wsData; |
1302 if (pXMLInstruction->GetData(0, wsData) && | 1278 if (pXMLInstruction->GetData(0, wsData) && |
1303 (pXFANode->GetDocument()->RecognizeXFAVersionNumber(wsData) != | 1279 (pXFANode->GetDocument()->RecognizeXFAVersionNumber(wsData) != |
1304 XFA_VERSION_UNKNOWN)) { | 1280 XFA_VERSION_UNKNOWN)) { |
1305 wsData.clear(); | 1281 wsData.clear(); |
1306 if (pXMLInstruction->GetData(1, wsData) && | 1282 if (pXMLInstruction->GetData(1, wsData) && |
1307 wsData == FX_WSTRC(L"v2.7-scripting:1")) { | 1283 wsData == FX_WSTRC(L"v2.7-scripting:1")) { |
1308 pXFANode->GetDocument()->SetFlag(XFA_DOCFLAG_Scripting, TRUE); | 1284 pXFANode->GetDocument()->SetFlag(XFA_DOCFLAG_Scripting, TRUE); |
1309 } | 1285 } |
1310 } | 1286 } |
1311 } else if (wsTargetName == FX_WSTRC(L"acrobat")) { | 1287 } else if (wsTargetName == FX_WSTRC(L"acrobat")) { |
1312 CFX_WideString wsData; | 1288 CFX_WideString wsData; |
1313 if (pXMLInstruction->GetData(0, wsData) && | 1289 if (pXMLInstruction->GetData(0, wsData) && |
1314 wsData == FX_WSTRC(L"JavaScript")) { | 1290 wsData == FX_WSTRC(L"JavaScript")) { |
1315 if (pXMLInstruction->GetData(1, wsData) && | 1291 if (pXMLInstruction->GetData(1, wsData) && |
1316 wsData == FX_WSTRC(L"strictScoping")) { | 1292 wsData == FX_WSTRC(L"strictScoping")) { |
1317 pXFANode->GetDocument()->SetFlag(XFA_DOCFLAG_StrictScoping, TRUE); | 1293 pXFANode->GetDocument()->SetFlag(XFA_DOCFLAG_StrictScoping, TRUE); |
1318 } | 1294 } |
1319 } | 1295 } |
1320 } | 1296 } |
1321 } | 1297 } |
1322 | 1298 |
1323 void CXFA_SimpleParser::CloseParser() { | 1299 void CXFA_SimpleParser::CloseParser() { |
1324 m_pXMLDoc.reset(); | 1300 m_pXMLDoc.reset(); |
1325 m_pStream.reset(); | 1301 m_pStream.reset(); |
1326 } | 1302 } |
OLD | NEW |