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