| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "xfa/fxfa/parser/xfa_parser_imp.h" | 7 #include "xfa/fxfa/parser/xfa_parser_imp.h" |
| 8 | 8 |
| 9 #include "xfa/fde/xml/fde_xml_imp.h" | 9 #include "xfa/fde/xml/fde_xml_imp.h" |
| 10 #include "xfa/fgas/crt/fgas_codepage.h" | 10 #include "xfa/fgas/crt/fgas_codepage.h" |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 XFA_GetPacketByIndex(XFA_PACKET_XDP)->pURI, | 370 XFA_GetPacketByIndex(XFA_PACKET_XDP)->pURI, |
| 371 XFA_GetPacketByIndex(XFA_PACKET_XDP)->eFlags)) { | 371 XFA_GetPacketByIndex(XFA_PACKET_XDP)->eFlags)) { |
| 372 return nullptr; | 372 return nullptr; |
| 373 } | 373 } |
| 374 CXFA_Node* pXFARootNode = | 374 CXFA_Node* pXFARootNode = |
| 375 m_pFactory->CreateNode(XFA_XDPPACKET_XDP, XFA_ELEMENT_Xfa); | 375 m_pFactory->CreateNode(XFA_XDPPACKET_XDP, XFA_ELEMENT_Xfa); |
| 376 if (!pXFARootNode) { | 376 if (!pXFARootNode) { |
| 377 return nullptr; | 377 return nullptr; |
| 378 } | 378 } |
| 379 m_pRootNode = pXFARootNode; | 379 m_pRootNode = pXFARootNode; |
| 380 pXFARootNode->SetCData(XFA_ATTRIBUTE_Name, FX_WSTRC(L"xfa")); | 380 pXFARootNode->SetCData(XFA_ATTRIBUTE_Name, L"xfa"); |
| 381 { | 381 { |
| 382 CFDE_XMLElement* pElement = static_cast<CFDE_XMLElement*>(pXMLDocumentNode); | 382 CFDE_XMLElement* pElement = static_cast<CFDE_XMLElement*>(pXMLDocumentNode); |
| 383 int32_t iAttributeCount = pElement->CountAttributes(); | 383 int32_t iAttributeCount = pElement->CountAttributes(); |
| 384 for (int32_t i = 0; i < iAttributeCount; i++) { | 384 for (int32_t i = 0; i < iAttributeCount; i++) { |
| 385 CFX_WideString wsAttriName, wsAttriValue; | 385 CFX_WideString wsAttriName, wsAttriValue; |
| 386 pElement->GetAttribute(i, wsAttriName, wsAttriValue); | 386 pElement->GetAttribute(i, wsAttriName, wsAttriValue); |
| 387 if (wsAttriName == FX_WSTRC(L"uuid")) { | 387 if (wsAttriName == FX_WSTRC(L"uuid")) { |
| 388 pXFARootNode->SetCData(XFA_ATTRIBUTE_Uuid, wsAttriValue); | 388 pXFARootNode->SetCData(XFA_ATTRIBUTE_Uuid, wsAttriValue); |
| 389 } else if (wsAttriName == FX_WSTRC(L"timeStamp")) { | 389 } else if (wsAttriName == FX_WSTRC(L"timeStamp")) { |
| 390 pXFARootNode->SetCData(XFA_ATTRIBUTE_TimeStamp, wsAttriValue); | 390 pXFARootNode->SetCData(XFA_ATTRIBUTE_TimeStamp, wsAttriValue); |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 } | 655 } |
| 656 CFDE_XMLNode* pDataXMLNode = NULL; | 656 CFDE_XMLNode* pDataXMLNode = NULL; |
| 657 if (XFA_FDEExtension_MatchNodeName( | 657 if (XFA_FDEExtension_MatchNodeName( |
| 658 pXMLDocumentNode, FX_WSTRC(L"data"), | 658 pXMLDocumentNode, FX_WSTRC(L"data"), |
| 659 XFA_GetPacketByIndex(XFA_PACKET_Datasets)->pURI, | 659 XFA_GetPacketByIndex(XFA_PACKET_Datasets)->pURI, |
| 660 XFA_GetPacketByIndex(XFA_PACKET_Datasets)->eFlags)) { | 660 XFA_GetPacketByIndex(XFA_PACKET_Datasets)->eFlags)) { |
| 661 static_cast<CFDE_XMLElement*>(pXMLDocumentNode) | 661 static_cast<CFDE_XMLElement*>(pXMLDocumentNode) |
| 662 ->RemoveAttribute(L"xmlns:xfa"); | 662 ->RemoveAttribute(L"xmlns:xfa"); |
| 663 pDataXMLNode = pXMLDocumentNode; | 663 pDataXMLNode = pXMLDocumentNode; |
| 664 } else { | 664 } else { |
| 665 CFDE_XMLElement* pDataElement = new CFDE_XMLElement(FX_WSTRC(L"xfa:data")); | 665 CFDE_XMLElement* pDataElement = new CFDE_XMLElement(L"xfa:data"); |
| 666 CFDE_XMLNode* pParentXMLNode = | 666 CFDE_XMLNode* pParentXMLNode = |
| 667 pXMLDocumentNode->GetNodeItem(CFDE_XMLNode::Parent); | 667 pXMLDocumentNode->GetNodeItem(CFDE_XMLNode::Parent); |
| 668 if (pParentXMLNode) { | 668 if (pParentXMLNode) { |
| 669 pParentXMLNode->RemoveChildNode(pXMLDocumentNode); | 669 pParentXMLNode->RemoveChildNode(pXMLDocumentNode); |
| 670 } | 670 } |
| 671 ASSERT(pXMLDocumentNode->GetType() == FDE_XMLNODE_Element); | 671 ASSERT(pXMLDocumentNode->GetType() == FDE_XMLNODE_Element); |
| 672 if (pXMLDocumentNode->GetType() == FDE_XMLNODE_Element) { | 672 if (pXMLDocumentNode->GetType() == FDE_XMLNODE_Element) { |
| 673 static_cast<CFDE_XMLElement*>(pXMLDocumentNode) | 673 static_cast<CFDE_XMLElement*>(pXMLDocumentNode) |
| 674 ->RemoveAttribute(L"xmlns:xfa"); | 674 ->RemoveAttribute(L"xmlns:xfa"); |
| 675 } | 675 } |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1140 pXFAMetaData->SetCData(XFA_ATTRIBUTE_QualifiedName, | 1140 pXFAMetaData->SetCData(XFA_ATTRIBUTE_QualifiedName, |
| 1141 wsAttrQualifiedName); | 1141 wsAttrQualifiedName); |
| 1142 pXFAMetaData->SetCData(XFA_ATTRIBUTE_Value, wsAttrValue); | 1142 pXFAMetaData->SetCData(XFA_ATTRIBUTE_Value, wsAttrValue); |
| 1143 pXFAMetaData->SetEnum(XFA_ATTRIBUTE_Contains, | 1143 pXFAMetaData->SetEnum(XFA_ATTRIBUTE_Contains, |
| 1144 XFA_ATTRIBUTEENUM_MetaData); | 1144 XFA_ATTRIBUTEENUM_MetaData); |
| 1145 pXFAChild->InsertChild(pXFAMetaData); | 1145 pXFAChild->InsertChild(pXFAMetaData); |
| 1146 pXFAMetaData->SetXMLMappingNode(pXMLElement); | 1146 pXFAMetaData->SetXMLMappingNode(pXMLElement); |
| 1147 pXFAMetaData->SetFlag(XFA_NODEFLAG_Initialized, false); | 1147 pXFAMetaData->SetFlag(XFA_NODEFLAG_Initialized, false); |
| 1148 } | 1148 } |
| 1149 if (!bNeedValue) { | 1149 if (!bNeedValue) { |
| 1150 CFX_WideString wsNilName = FX_WSTRC(L"xsi:nil"); | 1150 CFX_WideString wsNilName(L"xsi:nil"); |
| 1151 pXMLElement->RemoveAttribute(wsNilName.c_str()); | 1151 pXMLElement->RemoveAttribute(wsNilName.c_str()); |
| 1152 } | 1152 } |
| 1153 } | 1153 } |
| 1154 pXFANode->InsertChild(pXFAChild); | 1154 pXFANode->InsertChild(pXFAChild); |
| 1155 if (eNodeType == XFA_ELEMENT_DataGroup) { | 1155 if (eNodeType == XFA_ELEMENT_DataGroup) { |
| 1156 ParseDataGroup(pXFAChild, pXMLElement, ePacketID); | 1156 ParseDataGroup(pXFAChild, pXMLElement, ePacketID); |
| 1157 } else { | 1157 } else { |
| 1158 if (bNeedValue) { | 1158 if (bNeedValue) { |
| 1159 ParseDataValue(pXFAChild, pXMLChild, XFA_XDPPACKET_Datasets); | 1159 ParseDataValue(pXFAChild, pXMLChild, XFA_XDPPACKET_Datasets); |
| 1160 } | 1160 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1240 static_cast<CFDE_XMLElement*>(pXMLChild))) { | 1240 static_cast<CFDE_XMLElement*>(pXMLChild))) { |
| 1241 XFA_GetPlainTextFromRichText(static_cast<CFDE_XMLElement*>(pXMLChild), | 1241 XFA_GetPlainTextFromRichText(static_cast<CFDE_XMLElement*>(pXMLChild), |
| 1242 wsText); | 1242 wsText); |
| 1243 if (!pXMLCurValueNode) | 1243 if (!pXMLCurValueNode) |
| 1244 pXMLCurValueNode = pXMLChild; | 1244 pXMLCurValueNode = pXMLChild; |
| 1245 | 1245 |
| 1246 wsCurValueTextBuf << wsText; | 1246 wsCurValueTextBuf << wsText; |
| 1247 } else { | 1247 } else { |
| 1248 bMarkAsCompound = TRUE; | 1248 bMarkAsCompound = TRUE; |
| 1249 if (pXMLCurValueNode) { | 1249 if (pXMLCurValueNode) { |
| 1250 CFX_WideStringC wsCurValue = wsCurValueTextBuf.AsStringC(); | 1250 CFX_WideString wsCurValue = wsCurValueTextBuf.MakeString(); |
| 1251 if (!wsCurValue.IsEmpty()) { | 1251 if (!wsCurValue.IsEmpty()) { |
| 1252 CXFA_Node* pXFAChild = | 1252 CXFA_Node* pXFAChild = |
| 1253 m_pFactory->CreateNode(ePacketID, XFA_ELEMENT_DataValue); | 1253 m_pFactory->CreateNode(ePacketID, XFA_ELEMENT_DataValue); |
| 1254 if (!pXFAChild) | 1254 if (!pXFAChild) |
| 1255 return; | 1255 return; |
| 1256 | 1256 |
| 1257 pXFAChild->SetCData(XFA_ATTRIBUTE_Name, FX_WSTRC(L"")); | 1257 pXFAChild->SetCData(XFA_ATTRIBUTE_Name, L""); |
| 1258 pXFAChild->SetCData(XFA_ATTRIBUTE_Value, wsCurValue); | 1258 pXFAChild->SetCData(XFA_ATTRIBUTE_Value, wsCurValue); |
| 1259 pXFANode->InsertChild(pXFAChild); | 1259 pXFANode->InsertChild(pXFAChild); |
| 1260 pXFAChild->SetXMLMappingNode(pXMLCurValueNode); | 1260 pXFAChild->SetXMLMappingNode(pXMLCurValueNode); |
| 1261 pXFAChild->SetFlag(XFA_NODEFLAG_Initialized, false); | 1261 pXFAChild->SetFlag(XFA_NODEFLAG_Initialized, false); |
| 1262 wsValueTextBuf << wsCurValue; | 1262 wsValueTextBuf << wsCurValue; |
| 1263 wsCurValueTextBuf.Clear(); | 1263 wsCurValueTextBuf.Clear(); |
| 1264 } | 1264 } |
| 1265 pXMLCurValueNode = nullptr; | 1265 pXMLCurValueNode = nullptr; |
| 1266 } | 1266 } |
| 1267 CXFA_Node* pXFAChild = | 1267 CXFA_Node* pXFAChild = |
| 1268 m_pFactory->CreateNode(ePacketID, XFA_ELEMENT_DataValue); | 1268 m_pFactory->CreateNode(ePacketID, XFA_ELEMENT_DataValue); |
| 1269 if (!pXFAChild) | 1269 if (!pXFAChild) |
| 1270 return; | 1270 return; |
| 1271 | 1271 |
| 1272 CFX_WideString wsNodeStr; | 1272 CFX_WideString wsNodeStr; |
| 1273 static_cast<CFDE_XMLElement*>(pXMLChild)->GetLocalTagName(wsNodeStr); | 1273 static_cast<CFDE_XMLElement*>(pXMLChild)->GetLocalTagName(wsNodeStr); |
| 1274 pXFAChild->SetCData(XFA_ATTRIBUTE_Name, wsNodeStr); | 1274 pXFAChild->SetCData(XFA_ATTRIBUTE_Name, wsNodeStr); |
| 1275 ParseDataValue(pXFAChild, pXMLChild, ePacketID); | 1275 ParseDataValue(pXFAChild, pXMLChild, ePacketID); |
| 1276 pXFANode->InsertChild(pXFAChild); | 1276 pXFANode->InsertChild(pXFAChild); |
| 1277 pXFAChild->SetXMLMappingNode(pXMLChild); | 1277 pXFAChild->SetXMLMappingNode(pXMLChild); |
| 1278 pXFAChild->SetFlag(XFA_NODEFLAG_Initialized, false); | 1278 pXFAChild->SetFlag(XFA_NODEFLAG_Initialized, false); |
| 1279 CFX_WideStringC wsCurValue = pXFAChild->GetCData(XFA_ATTRIBUTE_Value); | 1279 CFX_WideStringC wsCurValue = pXFAChild->GetCData(XFA_ATTRIBUTE_Value); |
| 1280 wsValueTextBuf << wsCurValue; | 1280 wsValueTextBuf << wsCurValue; |
| 1281 } | 1281 } |
| 1282 } | 1282 } |
| 1283 if (pXMLCurValueNode) { | 1283 if (pXMLCurValueNode) { |
| 1284 CFX_WideStringC wsCurValue = wsCurValueTextBuf.AsStringC(); | 1284 CFX_WideString wsCurValue = wsCurValueTextBuf.MakeString(); |
| 1285 if (!wsCurValue.IsEmpty()) { | 1285 if (!wsCurValue.IsEmpty()) { |
| 1286 if (bMarkAsCompound) { | 1286 if (bMarkAsCompound) { |
| 1287 CXFA_Node* pXFAChild = | 1287 CXFA_Node* pXFAChild = |
| 1288 m_pFactory->CreateNode(ePacketID, XFA_ELEMENT_DataValue); | 1288 m_pFactory->CreateNode(ePacketID, XFA_ELEMENT_DataValue); |
| 1289 if (!pXFAChild) | 1289 if (!pXFAChild) |
| 1290 return; | 1290 return; |
| 1291 | 1291 |
| 1292 pXFAChild->SetCData(XFA_ATTRIBUTE_Name, FX_WSTRC(L"")); | 1292 pXFAChild->SetCData(XFA_ATTRIBUTE_Name, L""); |
| 1293 pXFAChild->SetCData(XFA_ATTRIBUTE_Value, wsCurValue); | 1293 pXFAChild->SetCData(XFA_ATTRIBUTE_Value, wsCurValue); |
| 1294 pXFANode->InsertChild(pXFAChild); | 1294 pXFANode->InsertChild(pXFAChild); |
| 1295 pXFAChild->SetXMLMappingNode(pXMLCurValueNode); | 1295 pXFAChild->SetXMLMappingNode(pXMLCurValueNode); |
| 1296 pXFAChild->SetFlag(XFA_NODEFLAG_Initialized, false); | 1296 pXFAChild->SetFlag(XFA_NODEFLAG_Initialized, false); |
| 1297 } | 1297 } |
| 1298 wsValueTextBuf << wsCurValue; | 1298 wsValueTextBuf << wsCurValue; |
| 1299 wsCurValueTextBuf.Clear(); | 1299 wsCurValueTextBuf.Clear(); |
| 1300 } | 1300 } |
| 1301 pXMLCurValueNode = nullptr; | 1301 pXMLCurValueNode = nullptr; |
| 1302 } | 1302 } |
| 1303 CFX_WideStringC wsNodeValue = wsValueTextBuf.AsStringC(); | 1303 CFX_WideString wsNodeValue = wsValueTextBuf.MakeString(); |
| 1304 pXFANode->SetCData(XFA_ATTRIBUTE_Value, wsNodeValue); | 1304 pXFANode->SetCData(XFA_ATTRIBUTE_Value, wsNodeValue); |
| 1305 } | 1305 } |
| 1306 | 1306 |
| 1307 void CXFA_SimpleParser::ParseInstruction(CXFA_Node* pXFANode, | 1307 void CXFA_SimpleParser::ParseInstruction(CXFA_Node* pXFANode, |
| 1308 CFDE_XMLInstruction* pXMLInstruction, | 1308 CFDE_XMLInstruction* pXMLInstruction, |
| 1309 XFA_XDPPACKET ePacketID) { | 1309 XFA_XDPPACKET ePacketID) { |
| 1310 if (!m_bDocumentParser) { | 1310 if (!m_bDocumentParser) { |
| 1311 return; | 1311 return; |
| 1312 } | 1312 } |
| 1313 CFX_WideString wsTargetName; | 1313 CFX_WideString wsTargetName; |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1556 } | 1556 } |
| 1557 if (pPause && iCount > 500 && pPause->NeedToPauseNow()) { | 1557 if (pPause && iCount > 500 && pPause->NeedToPauseNow()) { |
| 1558 break; | 1558 break; |
| 1559 } | 1559 } |
| 1560 } | 1560 } |
| 1561 return (m_syntaxParserResult == FDE_XmlSyntaxResult::Error || | 1561 return (m_syntaxParserResult == FDE_XmlSyntaxResult::Error || |
| 1562 m_NodeStack.GetSize() != 1) | 1562 m_NodeStack.GetSize() != 1) |
| 1563 ? -1 | 1563 ? -1 |
| 1564 : m_pParser->GetStatus(); | 1564 : m_pParser->GetStatus(); |
| 1565 } | 1565 } |
| OLD | NEW |