| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "xfa/fxfa/parser/xfa_document_datamerger_imp.h" | 7 #include "xfa/fxfa/parser/xfa_document_datamerger_imp.h" |
| 8 | 8 |
| 9 #include "core/fxcrt/include/fx_ext.h" | 9 #include "core/fxcrt/include/fx_ext.h" |
| 10 #include "xfa/fde/xml/fde_xml_imp.h" |
| 10 #include "xfa/fxfa/fm2js/xfa_fm2jsapi.h" | 11 #include "xfa/fxfa/fm2js/xfa_fm2jsapi.h" |
| 11 #include "xfa/fxfa/parser/xfa_basic_imp.h" | 12 #include "xfa/fxfa/parser/xfa_basic_imp.h" |
| 12 #include "xfa/fxfa/parser/xfa_docdata.h" | 13 #include "xfa/fxfa/parser/xfa_docdata.h" |
| 13 #include "xfa/fxfa/parser/xfa_doclayout.h" | 14 #include "xfa/fxfa/parser/xfa_doclayout.h" |
| 14 #include "xfa/fxfa/parser/xfa_document.h" | 15 #include "xfa/fxfa/parser/xfa_document.h" |
| 15 #include "xfa/fxfa/parser/xfa_document_datadescription_imp.h" | 16 #include "xfa/fxfa/parser/xfa_document_datadescription_imp.h" |
| 16 #include "xfa/fxfa/parser/xfa_document_layout_imp.h" | 17 #include "xfa/fxfa/parser/xfa_document_layout_imp.h" |
| 17 #include "xfa/fxfa/parser/xfa_localemgr.h" | 18 #include "xfa/fxfa/parser/xfa_localemgr.h" |
| 18 #include "xfa/fxfa/parser/xfa_object.h" | 19 #include "xfa/fxfa/parser/xfa_object.h" |
| 19 #include "xfa/fxfa/parser/xfa_parser.h" | 20 #include "xfa/fxfa/parser/xfa_parser.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 switch (eUIType) { | 119 switch (eUIType) { |
| 119 case XFA_ELEMENT_ImageEdit: { | 120 case XFA_ELEMENT_ImageEdit: { |
| 120 CXFA_Image image = defValue.GetImage(); | 121 CXFA_Image image = defValue.GetImage(); |
| 121 CFX_WideString wsContentType; | 122 CFX_WideString wsContentType; |
| 122 CFX_WideString wsHref; | 123 CFX_WideString wsHref; |
| 123 if (image) { | 124 if (image) { |
| 124 image.GetContent(wsValue); | 125 image.GetContent(wsValue); |
| 125 image.GetContentType(wsContentType); | 126 image.GetContentType(wsContentType); |
| 126 image.GetHref(wsHref); | 127 image.GetHref(wsHref); |
| 127 } | 128 } |
| 128 IFDE_XMLElement* pXMLDataElement = | 129 CFDE_XMLElement* pXMLDataElement = |
| 129 (IFDE_XMLElement*)(pDataNode->GetXMLMappingNode()); | 130 static_cast<CFDE_XMLElement*>(pDataNode->GetXMLMappingNode()); |
| 130 FXSYS_assert(pXMLDataElement); | 131 FXSYS_assert(pXMLDataElement); |
| 131 pWidgetData->GetFormatDataValue(wsValue, wsFormatedValue); | 132 pWidgetData->GetFormatDataValue(wsValue, wsFormatedValue); |
| 132 pDataNode->SetAttributeValue(wsValue, wsFormatedValue); | 133 pDataNode->SetAttributeValue(wsValue, wsFormatedValue); |
| 133 pDataNode->SetCData(XFA_ATTRIBUTE_ContentType, wsContentType); | 134 pDataNode->SetCData(XFA_ATTRIBUTE_ContentType, wsContentType); |
| 134 if (!wsHref.IsEmpty()) { | 135 if (!wsHref.IsEmpty()) { |
| 135 pXMLDataElement->SetString(FX_WSTRC(L"href"), wsHref); | 136 pXMLDataElement->SetString(FX_WSTRC(L"href"), wsHref); |
| 136 } | 137 } |
| 137 } break; | 138 } break; |
| 138 case XFA_ELEMENT_ChoiceList: | 139 case XFA_ELEMENT_ChoiceList: |
| 139 defValue.GetChildValueContent(wsValue); | 140 defValue.GetChildValueContent(wsValue); |
| 140 if (pWidgetData->GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) { | 141 if (pWidgetData->GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) { |
| 141 CFX_WideStringArray wsSelTextArray; | 142 CFX_WideStringArray wsSelTextArray; |
| 142 pWidgetData->GetSelectedItemsValue(wsSelTextArray); | 143 pWidgetData->GetSelectedItemsValue(wsSelTextArray); |
| 143 int32_t iSize = wsSelTextArray.GetSize(); | 144 int32_t iSize = wsSelTextArray.GetSize(); |
| 144 if (iSize >= 1) { | 145 if (iSize >= 1) { |
| 145 CXFA_Node* pValue = NULL; | 146 CXFA_Node* pValue = NULL; |
| 146 for (int32_t i = 0; i < iSize; i++) { | 147 for (int32_t i = 0; i < iSize; i++) { |
| 147 pValue = pDataNode->CreateSamePacketNode(XFA_ELEMENT_DataValue); | 148 pValue = pDataNode->CreateSamePacketNode(XFA_ELEMENT_DataValue); |
| 148 pValue->SetCData(XFA_ATTRIBUTE_Name, FX_WSTRC(L"value")); | 149 pValue->SetCData(XFA_ATTRIBUTE_Name, FX_WSTRC(L"value")); |
| 149 pValue->CreateXMLMappingNode(); | 150 pValue->CreateXMLMappingNode(); |
| 150 pDataNode->InsertChild(pValue); | 151 pDataNode->InsertChild(pValue); |
| 151 pValue->SetCData(XFA_ATTRIBUTE_Value, wsSelTextArray[i]); | 152 pValue->SetCData(XFA_ATTRIBUTE_Value, wsSelTextArray[i]); |
| 152 } | 153 } |
| 153 } else { | 154 } else { |
| 154 IFDE_XMLNode* pXMLNode = pDataNode->GetXMLMappingNode(); | 155 CFDE_XMLNode* pXMLNode = pDataNode->GetXMLMappingNode(); |
| 155 FXSYS_assert(pXMLNode->GetType() == FDE_XMLNODE_Element); | 156 FXSYS_assert(pXMLNode->GetType() == FDE_XMLNODE_Element); |
| 156 ((IFDE_XMLElement*)pXMLNode) | 157 static_cast<CFDE_XMLElement*>(pXMLNode) |
| 157 ->SetString(FX_WSTRC(L"xfa:dataNode"), FX_WSTRC(L"dataGroup")); | 158 ->SetString(FX_WSTRC(L"xfa:dataNode"), FX_WSTRC(L"dataGroup")); |
| 158 } | 159 } |
| 159 } else if (!wsValue.IsEmpty()) { | 160 } else if (!wsValue.IsEmpty()) { |
| 160 pWidgetData->GetFormatDataValue(wsValue, wsFormatedValue); | 161 pWidgetData->GetFormatDataValue(wsValue, wsFormatedValue); |
| 161 pDataNode->SetAttributeValue(wsValue, wsFormatedValue); | 162 pDataNode->SetAttributeValue(wsValue, wsFormatedValue); |
| 162 } | 163 } |
| 163 break; | 164 break; |
| 164 case XFA_ELEMENT_CheckButton: | 165 case XFA_ELEMENT_CheckButton: |
| 165 defValue.GetChildValueContent(wsValue); | 166 defValue.GetChildValueContent(wsValue); |
| 166 if (wsValue.IsEmpty()) { | 167 if (wsValue.IsEmpty()) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 pDataNode->TryContent(wsXMLValue); | 257 pDataNode->TryContent(wsXMLValue); |
| 257 CFX_WideString wsNormailizeValue; | 258 CFX_WideString wsNormailizeValue; |
| 258 pWidgetData->GetNormalizeDataValue(wsXMLValue, wsNormailizeValue); | 259 pWidgetData->GetNormalizeDataValue(wsXMLValue, wsNormailizeValue); |
| 259 pDataNode->SetAttributeValue(wsNormailizeValue, wsXMLValue); | 260 pDataNode->SetAttributeValue(wsNormailizeValue, wsXMLValue); |
| 260 switch (eUIType) { | 261 switch (eUIType) { |
| 261 case XFA_ELEMENT_ImageEdit: { | 262 case XFA_ELEMENT_ImageEdit: { |
| 262 XFA_DataMerge_FormValueNode_SetChildContent( | 263 XFA_DataMerge_FormValueNode_SetChildContent( |
| 263 defValue.GetNode(), wsNormailizeValue, XFA_ELEMENT_Image); | 264 defValue.GetNode(), wsNormailizeValue, XFA_ELEMENT_Image); |
| 264 CXFA_Image image = defValue.GetImage(); | 265 CXFA_Image image = defValue.GetImage(); |
| 265 if (image) { | 266 if (image) { |
| 266 IFDE_XMLElement* pXMLDataElement = | 267 CFDE_XMLElement* pXMLDataElement = |
| 267 (IFDE_XMLElement*)(pDataNode->GetXMLMappingNode()); | 268 static_cast<CFDE_XMLElement*>(pDataNode->GetXMLMappingNode()); |
| 268 FXSYS_assert(pXMLDataElement); | 269 FXSYS_assert(pXMLDataElement); |
| 269 CFX_WideString wsContentType; | 270 CFX_WideString wsContentType; |
| 270 CFX_WideString wsHref; | 271 CFX_WideString wsHref; |
| 271 pXMLDataElement->GetString(L"xfa:contentType", wsContentType); | 272 pXMLDataElement->GetString(L"xfa:contentType", wsContentType); |
| 272 if (!wsContentType.IsEmpty()) { | 273 if (!wsContentType.IsEmpty()) { |
| 273 pDataNode->SetCData(XFA_ATTRIBUTE_ContentType, wsContentType); | 274 pDataNode->SetCData(XFA_ATTRIBUTE_ContentType, wsContentType); |
| 274 image.SetContentType(wsContentType); | 275 image.SetContentType(wsContentType); |
| 275 } | 276 } |
| 276 pXMLDataElement->GetString(L"href", wsHref); | 277 pXMLDataElement->GetString(L"href", wsHref); |
| 277 if (!wsHref.IsEmpty()) { | 278 if (!wsHref.IsEmpty()) { |
| (...skipping 976 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1254 for (int32_t i = 0; i < arrayNodes.GetSize(); i++) { | 1255 for (int32_t i = 0; i < arrayNodes.GetSize(); i++) { |
| 1255 CXFA_Node* pNode = arrayNodes[i]->AsNode(); | 1256 CXFA_Node* pNode = arrayNodes[i]->AsNode(); |
| 1256 if (pNode && !pNode->HasBindItem()) | 1257 if (pNode && !pNode->HasBindItem()) |
| 1257 return pNode; | 1258 return pNode; |
| 1258 } | 1259 } |
| 1259 return nullptr; | 1260 return nullptr; |
| 1260 } | 1261 } |
| 1261 void CXFA_Document::DoDataMerge() { | 1262 void CXFA_Document::DoDataMerge() { |
| 1262 CXFA_Node* pDatasetsRoot = ToNode(GetXFAObject(XFA_HASHCODE_Datasets)); | 1263 CXFA_Node* pDatasetsRoot = ToNode(GetXFAObject(XFA_HASHCODE_Datasets)); |
| 1263 if (!pDatasetsRoot) { | 1264 if (!pDatasetsRoot) { |
| 1264 IFDE_XMLElement* pDatasetsXMLNode = | 1265 CFDE_XMLElement* pDatasetsXMLNode = |
| 1265 IFDE_XMLElement::Create(FX_WSTRC(L"xfa:datasets")); | 1266 new CFDE_XMLElement(FX_WSTRC(L"xfa:datasets")); |
| 1266 FXSYS_assert(pDatasetsXMLNode); | 1267 |
| 1267 pDatasetsXMLNode->SetString( | 1268 pDatasetsXMLNode->SetString( |
| 1268 FX_WSTRC(L"xmlns:xfa"), | 1269 FX_WSTRC(L"xmlns:xfa"), |
| 1269 FX_WSTRC(L"http://www.xfa.org/schema/xfa-data/1.0/")); | 1270 FX_WSTRC(L"http://www.xfa.org/schema/xfa-data/1.0/")); |
| 1270 pDatasetsRoot = CreateNode(XFA_XDPPACKET_Datasets, XFA_ELEMENT_DataModel); | 1271 pDatasetsRoot = CreateNode(XFA_XDPPACKET_Datasets, XFA_ELEMENT_DataModel); |
| 1271 pDatasetsRoot->SetCData(XFA_ATTRIBUTE_Name, FX_WSTRC(L"datasets")); | 1272 pDatasetsRoot->SetCData(XFA_ATTRIBUTE_Name, FX_WSTRC(L"datasets")); |
| 1272 m_pRootNode->GetXMLMappingNode()->InsertChildNode(pDatasetsXMLNode); | 1273 m_pRootNode->GetXMLMappingNode()->InsertChildNode(pDatasetsXMLNode); |
| 1273 m_pRootNode->InsertChild(pDatasetsRoot); | 1274 m_pRootNode->InsertChild(pDatasetsRoot); |
| 1274 pDatasetsRoot->SetXMLMappingNode(pDatasetsXMLNode); | 1275 pDatasetsRoot->SetXMLMappingNode(pDatasetsXMLNode); |
| 1275 } | 1276 } |
| 1276 CXFA_Node *pDataRoot = NULL, *pDDRoot = NULL; | 1277 CXFA_Node *pDataRoot = NULL, *pDDRoot = NULL; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1298 } | 1299 } |
| 1299 if (wsNamespaceURI == wsDatasetsURI) { | 1300 if (wsNamespaceURI == wsDatasetsURI) { |
| 1300 pDataRoot = pChildNode; | 1301 pDataRoot = pChildNode; |
| 1301 } | 1302 } |
| 1302 } | 1303 } |
| 1303 if (pDataRoot && pDDRoot) { | 1304 if (pDataRoot && pDDRoot) { |
| 1304 break; | 1305 break; |
| 1305 } | 1306 } |
| 1306 } | 1307 } |
| 1307 if (!pDataRoot) { | 1308 if (!pDataRoot) { |
| 1308 IFDE_XMLElement* pDataRootXMLNode = | 1309 CFDE_XMLElement* pDataRootXMLNode = |
| 1309 IFDE_XMLElement::Create(FX_WSTRC(L"xfa:data")); | 1310 new CFDE_XMLElement(FX_WSTRC(L"xfa:data")); |
| 1310 FXSYS_assert(pDataRootXMLNode); | 1311 |
| 1311 pDataRoot = CreateNode(XFA_XDPPACKET_Datasets, XFA_ELEMENT_DataGroup); | 1312 pDataRoot = CreateNode(XFA_XDPPACKET_Datasets, XFA_ELEMENT_DataGroup); |
| 1312 pDataRoot->SetCData(XFA_ATTRIBUTE_Name, FX_WSTRC(L"data")); | 1313 pDataRoot->SetCData(XFA_ATTRIBUTE_Name, FX_WSTRC(L"data")); |
| 1313 pDataRoot->SetXMLMappingNode(pDataRootXMLNode); | 1314 pDataRoot->SetXMLMappingNode(pDataRootXMLNode); |
| 1314 pDatasetsRoot->InsertChild(pDataRoot); | 1315 pDatasetsRoot->InsertChild(pDataRoot); |
| 1315 } | 1316 } |
| 1316 CXFA_Node* pDataTopLevel = | 1317 CXFA_Node* pDataTopLevel = |
| 1317 pDataRoot->GetFirstChildByClass(XFA_ELEMENT_DataGroup); | 1318 pDataRoot->GetFirstChildByClass(XFA_ELEMENT_DataGroup); |
| 1318 uint32_t dwNameHash = pDataTopLevel ? pDataTopLevel->GetNameHash() : 0; | 1319 uint32_t dwNameHash = pDataTopLevel ? pDataTopLevel->GetNameHash() : 0; |
| 1319 CXFA_Node* pTemplateRoot = | 1320 CXFA_Node* pTemplateRoot = |
| 1320 m_pRootNode->GetFirstChildByClass(XFA_ELEMENT_Template); | 1321 m_pRootNode->GetFirstChildByClass(XFA_ELEMENT_Template); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1346 pNode->SetFlag(XFA_NODEFLAG_UnusedNode); | 1347 pNode->SetFlag(XFA_NODEFLAG_UnusedNode); |
| 1347 } | 1348 } |
| 1348 } | 1349 } |
| 1349 CXFA_Node* pSubformSetNode = XFA_NodeMerge_CloneOrMergeContainer( | 1350 CXFA_Node* pSubformSetNode = XFA_NodeMerge_CloneOrMergeContainer( |
| 1350 this, pFormRoot, pTemplateChosen, FALSE); | 1351 this, pFormRoot, pTemplateChosen, FALSE); |
| 1351 FXSYS_assert(pSubformSetNode); | 1352 FXSYS_assert(pSubformSetNode); |
| 1352 if (!pDataTopLevel) { | 1353 if (!pDataTopLevel) { |
| 1353 CFX_WideStringC wsFormName = pSubformSetNode->GetCData(XFA_ATTRIBUTE_Name); | 1354 CFX_WideStringC wsFormName = pSubformSetNode->GetCData(XFA_ATTRIBUTE_Name); |
| 1354 CFX_WideString wsDataTopLevelName = | 1355 CFX_WideString wsDataTopLevelName = |
| 1355 wsFormName.IsEmpty() ? FX_WSTRC(L"form") : wsFormName; | 1356 wsFormName.IsEmpty() ? FX_WSTRC(L"form") : wsFormName; |
| 1356 IFDE_XMLElement* pDataTopLevelXMLNode = | 1357 CFDE_XMLElement* pDataTopLevelXMLNode = |
| 1357 IFDE_XMLElement::Create(wsDataTopLevelName); | 1358 new CFDE_XMLElement(wsDataTopLevelName); |
| 1358 FXSYS_assert(pDataTopLevelXMLNode); | 1359 |
| 1359 pDataTopLevel = CreateNode(XFA_XDPPACKET_Datasets, XFA_ELEMENT_DataGroup); | 1360 pDataTopLevel = CreateNode(XFA_XDPPACKET_Datasets, XFA_ELEMENT_DataGroup); |
| 1360 pDataTopLevel->SetCData(XFA_ATTRIBUTE_Name, wsDataTopLevelName); | 1361 pDataTopLevel->SetCData(XFA_ATTRIBUTE_Name, wsDataTopLevelName); |
| 1361 pDataTopLevel->SetXMLMappingNode(pDataTopLevelXMLNode); | 1362 pDataTopLevel->SetXMLMappingNode(pDataTopLevelXMLNode); |
| 1362 CXFA_Node* pBeforeNode = pDataRoot->GetNodeItem(XFA_NODEITEM_FirstChild); | 1363 CXFA_Node* pBeforeNode = pDataRoot->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 1363 pDataRoot->InsertChild(pDataTopLevel, pBeforeNode); | 1364 pDataRoot->InsertChild(pDataTopLevel, pBeforeNode); |
| 1364 } | 1365 } |
| 1365 FXSYS_assert(pDataTopLevel); | 1366 FXSYS_assert(pDataTopLevel); |
| 1366 XFA_DataMerge_CreateDataBinding(pSubformSetNode, pDataTopLevel); | 1367 XFA_DataMerge_CreateDataBinding(pSubformSetNode, pDataTopLevel); |
| 1367 for (CXFA_Node* pTemplateChild = | 1368 for (CXFA_Node* pTemplateChild = |
| 1368 pTemplateChosen->GetNodeItem(XFA_NODEITEM_FirstChild); | 1369 pTemplateChosen->GetNodeItem(XFA_NODEITEM_FirstChild); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1420 } | 1421 } |
| 1421 pFormRoot->SetObject(XFA_ATTRIBUTE_BindingNode, NULL); | 1422 pFormRoot->SetObject(XFA_ATTRIBUTE_BindingNode, NULL); |
| 1422 } | 1423 } |
| 1423 XFA_DataMerge_ClearGlobalBinding(this); | 1424 XFA_DataMerge_ClearGlobalBinding(this); |
| 1424 if (bDoDataMerge) { | 1425 if (bDoDataMerge) { |
| 1425 DoDataMerge(); | 1426 DoDataMerge(); |
| 1426 } | 1427 } |
| 1427 CXFA_LayoutProcessor* pLayoutProcessor = GetLayoutProcessor(); | 1428 CXFA_LayoutProcessor* pLayoutProcessor = GetLayoutProcessor(); |
| 1428 pLayoutProcessor->SetForceReLayout(TRUE); | 1429 pLayoutProcessor->SetForceReLayout(TRUE); |
| 1429 } | 1430 } |
| OLD | NEW |