CXFA_Node* XFA_DataDescription_MaybeCreateDataNode( CXFA_Document* pDocument, CXFA_Node* pDataParent, XFA_Element eNodeType, const CFX_WideString& wsName) { if (!pDataParent) { return nullptr; } CXFA_Node* pParentDDNode = pDataParent->GetDataDescriptionNode(); if (!pParentDDNode) { CXFA_Node* pDataNode = pDocument->CreateNode(XFA_XDPPACKET_Datasets, eNodeType); ASSERT(pDataNode); pDataNode->SetCData(XFA_ATTRIBUTE_Name, wsName); pDataNode->CreateXMLMappingNode(); pDataParent->InsertChild(pDataNode); pDataNode->SetFlag(XFA_NodeFlag_Initialized, false); return pDataNode; } else { CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_DDGroup> sIterator(pParentDDNode); for (CXFA_Node* pDDGroupNode = sIterator.GetCurrent(); pDDGroupNode; pDDGroupNode = sIterator.MoveToNext()) { if (pDDGroupNode != pParentDDNode) { if (pDDGroupNode->GetElementType() != XFA_Element::DataGroup) { continue; } CFX_WideString wsNamespace; if (!pDDGroupNode->TryNamespace(wsNamespace) || wsNamespace != FX_WSTRC(L"http://ns.adobe.com/data-description/")) { continue; } } CXFA_Node* pDDNode = pDDGroupNode->GetFirstChildByName(wsName.AsStringC()); if (!pDDNode) { continue; } if (pDDNode->GetElementType() != eNodeType) { break; } CXFA_Node* pDataNode = pDocument->CreateNode(XFA_XDPPACKET_Datasets, eNodeType); ASSERT(pDataNode); pDataNode->SetCData(XFA_ATTRIBUTE_Name, wsName); pDataNode->CreateXMLMappingNode(); if (eNodeType == XFA_Element::DataValue && pDDNode->GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData) { pDataNode->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_MetaData); } pDataParent->InsertChild(pDataNode); pDataNode->SetDataDescriptionNode(pDDNode); pDataNode->SetFlag(XFA_NodeFlag_Initialized, false); return pDataNode; } return nullptr; } }
void CXFA_ScriptContext::NormalPropertySetter(CFXJSE_Value* pOriginalValue, const CFX_ByteStringC& szPropName, CFXJSE_Value* pReturnValue) { CXFA_Object* pOriginalObject = ToObject(pOriginalValue, nullptr); if (!pOriginalObject) return; CXFA_ScriptContext* lpScriptContext = pOriginalObject->GetDocument()->GetScriptContext(); CXFA_Object* pObject = lpScriptContext->GetVariablesThis(pOriginalObject); CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = XFA_GetScriptAttributeByName( pObject->GetElementType(), wsPropName.AsStringC()); if (lpAttributeInfo) { (pObject->*(lpAttributeInfo->lpfnCallback))( pReturnValue, TRUE, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); } else { if (pObject->IsNode()) { if (wsPropName.GetAt(0) == '#') { wsPropName = wsPropName.Right(wsPropName.GetLength() - 1); } CXFA_Node* pNode = ToNode(pObject); CXFA_Node* pPropOrChild = nullptr; XFA_Element eType = XFA_GetElementTypeForName(wsPropName.AsStringC()); if (eType != XFA_Element::Unknown) pPropOrChild = pNode->GetProperty(0, eType); else pPropOrChild = pNode->GetFirstChildByName(wsPropName.AsStringC()); if (pPropOrChild) { CFX_WideString wsDefaultName(L"{default}"); const XFA_SCRIPTATTRIBUTEINFO* lpAttrInfo = XFA_GetScriptAttributeByName(pPropOrChild->GetElementType(), wsDefaultName.AsStringC()); if (lpAttrInfo) { (pPropOrChild->*(lpAttrInfo->lpfnCallback))( pReturnValue, TRUE, (XFA_ATTRIBUTE)lpAttrInfo->eAttribute); return; } } } CXFA_Object* pScriptObject = lpScriptContext->GetVariablesThis(pOriginalObject, TRUE); if (pScriptObject) { lpScriptContext->QueryVariableValue(ToNode(pScriptObject), szPropName, pReturnValue, FALSE); } } }
void XFA_DataDescription_UpdateDataRelation(CXFA_Node* pDataNode, CXFA_Node* pDataDescriptionNode) { ASSERT(pDataDescriptionNode); for (CXFA_Node* pDataChild = pDataNode->GetNodeItem(XFA_NODEITEM_FirstChild); pDataChild; pDataChild = pDataChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { uint32_t dwNameHash = pDataChild->GetNameHash(); if (!dwNameHash) continue; CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_DDGroup> sIterator(pDataDescriptionNode); for (CXFA_Node* pDDGroupNode = sIterator.GetCurrent(); pDDGroupNode; pDDGroupNode = sIterator.MoveToNext()) { if (pDDGroupNode != pDataDescriptionNode) { if (pDDGroupNode->GetElementType() != XFA_Element::DataGroup) continue; CFX_WideString wsNamespace; if (!pDDGroupNode->TryNamespace(wsNamespace) || wsNamespace != FX_WSTRC(L"http://ns.adobe.com/data-description/")) { continue; } } CXFA_Node* pDDNode = pDDGroupNode->GetFirstChildByName(dwNameHash); if (!pDDNode) continue; if (pDDNode->GetElementType() != pDataChild->GetElementType()) break; pDataChild->SetDataDescriptionNode(pDDNode); XFA_DataDescription_UpdateDataRelation(pDataChild, pDDNode); break; } } }
void CXFA_FFDocView::RunBindItems() { int32_t iCount = m_bindItems.GetSize(); for (int32_t i = 0; i < iCount; i++) { if (reinterpret_cast<CXFA_Node*>(m_bindItems[i]) ->HasFlag(XFA_NODEFLAG_HasRemoved)) { continue; } CXFA_Node* pWidgetNode = reinterpret_cast<CXFA_Node*>(m_bindItems[i]) ->GetNodeItem(XFA_NODEITEM_Parent); CXFA_WidgetAcc* pAcc = (CXFA_WidgetAcc*)pWidgetNode->GetWidgetData(); if (!pAcc) { continue; } CXFA_BindItems binditems(reinterpret_cast<CXFA_Node*>(m_bindItems[i])); IXFA_ScriptContext* pScriptContext = pWidgetNode->GetDocument()->GetScriptContext(); CFX_WideStringC wsRef; binditems.GetRef(wsRef); FX_DWORD dwStyle = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_ALL; XFA_RESOLVENODE_RS rs; pScriptContext->ResolveObjects(pWidgetNode, wsRef, rs, dwStyle); int32_t iCount = rs.nodes.GetSize(); pAcc->DeleteItem(-1); if (rs.dwFlags != XFA_RESOVENODE_RSTYPE_Nodes || iCount < 1) { continue; } CFX_WideStringC wsValueRef, wsLabelRef; binditems.GetValueRef(wsValueRef); binditems.GetLabelRef(wsLabelRef); FX_BOOL bUseValue = wsLabelRef.IsEmpty() || wsLabelRef == wsValueRef; FX_BOOL bLabelUseContent = wsLabelRef.IsEmpty() || wsLabelRef == FX_WSTRC(L"$"); FX_BOOL bValueUseContent = wsValueRef.IsEmpty() || wsValueRef == FX_WSTRC(L"$"); CFX_WideString wsValue, wsLabel; FX_DWORD uValueHash = FX_HashCode_String_GetW(CFX_WideString(wsValueRef), wsValueRef.GetLength()); for (int32_t i = 0; i < iCount; i++) { CXFA_Object* refObj = rs.nodes[i]; if (!refObj->IsNode()) { continue; } CXFA_Node* refNode = refObj->AsNode(); if (bValueUseContent) { wsValue = refNode->GetContent(); } else { CXFA_Node* nodeValue = refNode->GetFirstChildByName(uValueHash); if (nodeValue == NULL) { wsValue = refNode->GetContent(); } else { wsValue = nodeValue->GetContent(); } } if (!bUseValue) { if (bLabelUseContent) { wsLabel = refNode->GetContent(); } else { CXFA_Node* nodeLabel = refNode->GetFirstChildByName(wsLabelRef); if (nodeLabel != NULL) { wsLabel = nodeLabel->GetContent(); } } } else { wsLabel = wsValue; } pAcc->InsertItem(wsLabel, wsValue); } } m_bindItems.RemoveAll(); }
void CXFA_FFDocView::RunBindItems() { for (int32_t i = 0; i < m_BindItems.GetSize(); i++) { if (m_BindItems[i]->HasRemovedChildren()) continue; CXFA_Node* pWidgetNode = m_BindItems[i]->GetNodeItem(XFA_NODEITEM_Parent); CXFA_WidgetAcc* pAcc = static_cast<CXFA_WidgetAcc*>(pWidgetNode->GetWidgetData()); if (!pAcc) continue; CXFA_BindItems binditems(m_BindItems[i]); CXFA_ScriptContext* pScriptContext = pWidgetNode->GetDocument()->GetScriptContext(); CFX_WideStringC wsRef; binditems.GetRef(wsRef); uint32_t dwStyle = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_ALL; XFA_RESOLVENODE_RS rs; pScriptContext->ResolveObjects(pWidgetNode, wsRef, rs, dwStyle); int32_t iCount = rs.nodes.GetSize(); pAcc->DeleteItem(-1); if (rs.dwFlags != XFA_RESOVENODE_RSTYPE_Nodes || iCount < 1) continue; CFX_WideStringC wsValueRef, wsLabelRef; binditems.GetValueRef(wsValueRef); binditems.GetLabelRef(wsLabelRef); const bool bUseValue = wsLabelRef.IsEmpty() || wsLabelRef == wsValueRef; const bool bLabelUseContent = wsLabelRef.IsEmpty() || wsLabelRef == FX_WSTRC(L"$"); const bool bValueUseContent = wsValueRef.IsEmpty() || wsValueRef == FX_WSTRC(L"$"); CFX_WideString wsValue; CFX_WideString wsLabel; uint32_t uValueHash = FX_HashCode_GetW(wsValueRef, false); for (int32_t j = 0; j < iCount; j++) { CXFA_Object* refObj = rs.nodes[j]; if (!refObj->IsNode()) { continue; } CXFA_Node* refNode = refObj->AsNode(); if (bValueUseContent) { wsValue = refNode->GetContent(); } else { CXFA_Node* nodeValue = refNode->GetFirstChildByName(uValueHash); wsValue = nodeValue ? nodeValue->GetContent() : refNode->GetContent(); } if (!bUseValue) { if (bLabelUseContent) { wsLabel = refNode->GetContent(); } else { CXFA_Node* nodeLabel = refNode->GetFirstChildByName(wsLabelRef); if (nodeLabel) wsLabel = nodeLabel->GetContent(); } } else { wsLabel = wsValue; } pAcc->InsertItem(wsLabel, wsValue); } } m_BindItems.RemoveAll(); }