NS_IMETHODIMP nsXFormsInstanceElement::AttributeSet(nsIAtom *aName, const nsAString &aNewValue) { if (!mInitialized || mLazy) return NS_OK; // @src has precedence over inline content which has precedence // over @resource. if (aName == nsXFormsAtoms::src) { LoadExternalInstance(aNewValue); } else if (aName == nsXFormsAtoms::resource) { // If @resource is set or changed, it only matters if there is // no @src or inline content. nsAutoString src; mElement->GetAttribute(NS_LITERAL_STRING("src"), src); if (src.IsEmpty()) { // Check for inline content. nsCOMPtr<nsIDOMNode> child; GetFirstChildElement(getter_AddRefs(child)); if (!child) { LoadExternalInstance(aNewValue); } } } return NS_OK; }
AXMLElement* AXMLElement::GetElement(const VString &pElementname) { AXMLElement *elem = NULL; elem = GetFirstChildElement(); while (elem) { if (elem->GetName() == pElementname) break; elem = elem->GetNextElement(); } return elem; }
NS_IMETHODIMP nsXFormsInstanceElement::AttributeRemoved(nsIAtom *aName) { if (!mInitialized || mLazy) return NS_OK; // @src has precdence over inline content which has precedence // over @resource. if (aName == nsXFormsAtoms::src) { PRBool restart = PR_FALSE; if (mChannel) { // looks like we are trying to remove the src attribute while we are // already trying to load the external instance document. We'll stop // the current load effort. restart = PR_TRUE; mChannel->Cancel(NS_BINDING_ABORTED); mChannel = nsnull; mListener = nsnull; } // We no longer have an external (@src) instance to use. Next in precedence // would be inline content so we'll use that if it exists. If there is no // inline content, then we'll look for @resource (the instance may have had // both @src and @resource and no inline content). nsresult rv; nsCOMPtr<nsIDOMNode> child; GetFirstChildElement(getter_AddRefs(child)); if (child) { // Reset our instance document to whatever inline content we have. rv = CloneInlineInstance(child); } else { nsAutoString resource; mElement->GetAttribute(NS_LITERAL_STRING("resource"), resource); if (!resource.IsEmpty()) { LoadExternalInstance(resource); } } // if we had already started to load an external instance document, then // as part of that we would have told the model to wait for that external // document to load before it finishes the model construction. Since we // aren't loading from an external document any longer, tell the model that // there is no need to wait for us anymore. if (restart) { nsCOMPtr<nsIModelElementPrivate> model = GetModel(); if (model) { model->InstanceLoadFinished(PR_TRUE, EmptyString()); } } return rv; } return NS_OK; }
AXMLElement* AXMLElement::GetNextElement(AXMLElement* pAfterElem) { AXMLElement *elem = NULL; elem = GetFirstChildElement(); if (pAfterElem) { while (elem) { if (elem == pAfterElem) break; elem = elem->GetNextElement(); } if (elem) elem = elem->GetNextElement(); } return elem; }
void nsSOAPUtils::GetSpecificChildElement(nsISOAPEncoding * aEncoding, nsIDOMElement * aParent, const nsAString & aNamespace, const nsAString & aType, nsIDOMElement * *aElement) { nsCOMPtr<nsIDOMElement> sibling; *aElement = nsnull; GetFirstChildElement(aParent, getter_AddRefs(sibling)); if (sibling) { GetSpecificSiblingElement(aEncoding, sibling, aNamespace, aType, aElement); } }
NS_IMETHODIMP nsXFormsInstanceElement::ParentChanged(nsIDOMElement *aNewParent) { nsCOMPtr<nsIModelElementPrivate> model = GetModel(); if (!model) return NS_OK; if (mInitialized || !mElement) { return NS_OK; } mInitialized = PR_TRUE; model->AddInstanceElement(this); // If model isn't loaded entirely (It means xforms-ready event hasn't been // fired) then the instance will be initialized by model and will be backed up // when xforms-ready event is fired. PRBool isready; model->GetIsReady(&isready); if (!isready) return NS_OK; // If the model is loaded and ready then the instance is inserted dynamically. // The instance should create instance document and back it up. // Probably dynamic instances should be handled too when model isn't loaded // entirely (for more information see a comment 29 of bug 320081 // https://bugzilla.mozilla.org/show_bug.cgi?id=320081#c29). nsAutoString src; mElement->GetAttribute(NS_LITERAL_STRING("src"), src); if (!src.IsEmpty()) { // XXX: external dynamic instances isn't handled (see a bug 325684 // https://bugzilla.mozilla.org/show_bug.cgi?id=325684) return NS_OK; } // If we don't have a linked external instance, use our inline data. nsCOMPtr<nsIDOMNode> child; GetFirstChildElement(getter_AddRefs(child)); nsresult rv = CloneInlineInstance(child); if (NS_FAILED(rv)) return rv; return BackupOriginalDocument(); }
AXMLElement* AXMLElement::GetNextElement(AXMLElement* pAfterElem,const VString &pElementname) { AXMLElement *elem = NULL; elem = GetFirstChildElement(); if (pAfterElem) { while (elem) { if (elem == pAfterElem) break; elem = elem->GetNextElement(); } if (elem) elem = elem->GetNextElement(); } while (elem) { if (elem->GetName() == pElementname) break; elem = elem->GetNextElement(); } return elem; }
NS_IMETHODIMP nsXFormsInstanceElement::Initialize() { mElement->HasAttributeNS(NS_LITERAL_STRING(NS_NAMESPACE_MOZ_XFORMS_LAZY), NS_LITERAL_STRING("lazy"), &mLazy); if (mLazy) { // Lazy instance return CreateInstanceDocument(NS_LITERAL_STRING("instanceData")); } // Normal instance // If the src attribute is given, then it takes precedence over inline // content and the resource attribute, and the XML data for the instance // is obtained from the link. If the src attribute is omitted, then the // data for the instance is obtained from inline content if it is given // or the resource attribute otherwise. If both the resource attribute // and inline content are provided, the inline content takes precedence. nsresult rv = NS_OK; nsAutoString src, resource; mElement->GetAttribute(NS_LITERAL_STRING("src"), src); if (!src.IsEmpty()) { LoadExternalInstance(src); } else { // If we have a first child element then we have inline content. nsCOMPtr<nsIDOMNode> child; GetFirstChildElement(getter_AddRefs(child)); if (child) { rv = CloneInlineInstance(child); } else { // No @src or inline content, better have @resource mElement->GetAttribute(NS_LITERAL_STRING("resource"), resource); LoadExternalInstance(resource); } } return rv; }
HRESULT CXmlHelper::Initialize(IXMLDOMElement *lpRootElem) { TNktComPtr<IXMLDOMElement> cCurrElem, cNextElem; CNktComBStr cElemAttrIdBStr, cNameBstr; HRESULT hRes; SIZE_T i; LONG k; nktMemSet(aFundTypesIndexes, 0, sizeof(aFundTypesIndexes)); hRes = GetFirstChildElement(lpRootElem, &cCurrElem); if (FAILED(hRes)) return hRes; while (cCurrElem != NULL) { cElemAttrIdBStr.Reset(); hRes = GetAttributeValue(cCurrElem, L"id", &cElemAttrIdBStr); if (FAILED(hRes)) { init_on_error: Reset(); return hRes; } if (cElemAttrIdBStr[0] != 0) { //add this element if (nIdElemMapEntriesCount >= nIdElemMapEntriesSize) { ID_ELEM_MAP_ENTRY *lpNew; lpNew = (ID_ELEM_MAP_ENTRY*)nktMemMalloc((nIdElemMapEntriesSize+10240)*sizeof(ID_ELEM_MAP_ENTRY)); if (lpNew == NULL) { hRes = E_OUTOFMEMORY; goto init_on_error; } nIdElemMapEntriesSize += 10240; if (lpIdElemMapEntries != NULL) { nktMemCopy(lpNew, lpIdElemMapEntries, nIdElemMapEntriesCount*sizeof(ID_ELEM_MAP_ENTRY)); nktMemFree(lpIdElemMapEntries); } lpIdElemMapEntries = lpNew; } wcsncpy_s(lpIdElemMapEntries[nIdElemMapEntriesCount].szIdW, cElemAttrIdBStr, 16); lpIdElemMapEntries[nIdElemMapEntriesCount].szIdW[15] = 0; k = GetDbObjectClass(cCurrElem, 1); if (k == -1) { hRes = E_OUTOFMEMORY; goto init_on_error; } if (k == NKT_DBOBJCLASS_Fundamental) { cNameBstr.Reset(); hRes = GetAttributeValue(cCurrElem, L"name", &cNameBstr); if (FAILED(hRes)) goto init_on_error; if (_wcsicmp((LPWSTR)cNameBstr, L"signed char") == 0) k = NKT_DBFUNDTYPE_SignedByte; else if (_wcsicmp((LPWSTR)cNameBstr, L"char") == 0) k = NKT_DBFUNDTYPE_AnsiChar; else if (_wcsicmp((LPWSTR)cNameBstr, L"unsigned char") == 0) k = NKT_DBFUNDTYPE_UnsignedByte; else if (_wcsicmp((LPWSTR)cNameBstr, L"short int") == 0) k = NKT_DBFUNDTYPE_SignedWord; else if (_wcsicmp((LPWSTR)cNameBstr, L"short unsigned int") == 0) k = NKT_DBFUNDTYPE_UnsignedWord; else if (_wcsicmp((LPWSTR)cNameBstr, L"int") == 0 || _wcsicmp((LPWSTR)cNameBstr, L"long int") == 0 || _wcsicmp((LPWSTR)cNameBstr, L"bool") == 0) k = NKT_DBFUNDTYPE_SignedDoubleWord; else if (_wcsicmp((LPWSTR)cNameBstr, L"unsigned int") == 0 || _wcsicmp((LPWSTR)cNameBstr, L"long unsigned int") == 0) k = NKT_DBFUNDTYPE_UnsignedDoubleWord; else if (_wcsicmp((LPWSTR)cNameBstr, L"long long int") == 0) k = NKT_DBFUNDTYPE_SignedQuadWord; else if (_wcsicmp((LPWSTR)cNameBstr, L"long long unsigned int") == 0) k = NKT_DBFUNDTYPE_UnsignedQuadWord; else if (_wcsicmp((LPWSTR)cNameBstr, L"float") == 0) k = NKT_DBFUNDTYPE_Float; else if (_wcsicmp((LPWSTR)cNameBstr, L"double") == 0) k = NKT_DBFUNDTYPE_Double; else if (_wcsicmp((LPWSTR)cNameBstr, L"long double") == 0) k = NKT_DBFUNDTYPE_LongDouble; else if (_wcsicmp((LPWSTR)cNameBstr, L"wchar_t") == 0) k = NKT_DBFUNDTYPE_WideChar; else if (_wcsicmp((LPWSTR)cNameBstr, L"void") == 0) k = NKT_DBFUNDTYPE_Void; else { hRes = E_FAIL; goto init_on_error; } aFundTypesIndexes[k-NKT_DBFUNDTYPE_MIN] = 1; } else k = 0; lpIdElemMapEntries[nIdElemMapEntriesCount].nFundamentalType = (ULONG)k; lpIdElemMapEntries[nIdElemMapEntriesCount].lpElem = cCurrElem; lpIdElemMapEntries[nIdElemMapEntriesCount].lpElem->AddRef(); nIdElemMapEntriesCount++; } //get next element hRes = GetNextElement(cCurrElem, &cNextElem); if (FAILED(hRes)) goto init_on_error; cCurrElem.Attach(cNextElem.Detach()); } //fast fundamental quick check for (k=0; k<X_ARRAYLEN(aFundTypesIndexes); k++) { if (aFundTypesIndexes[k] == 0) { hRes = E_FAIL; goto init_on_error; } } //sort elements by id qsort_s(lpIdElemMapEntries, nIdElemMapEntriesCount, sizeof(ID_ELEM_MAP_ENTRY), IdElemMapEntry_Compare, NULL); //find each fundamental nktMemSet(aFundTypesIndexes, 0, sizeof(aFundTypesIndexes)); for (i=0; i<nIdElemMapEntriesCount; i++) { if (lpIdElemMapEntries[i].nFundamentalType != 0) aFundTypesIndexes[lpIdElemMapEntries[i].nFundamentalType - NKT_DBFUNDTYPE_MIN] = i; } //fast fundamental quick check (should not happen) for (k=0; k<X_ARRAYLEN(aFundTypesIndexes); k++) { if (aFundTypesIndexes[k] == 0) { hRes = E_FAIL; goto init_on_error; } } return S_OK; }