зеркало из https://github.com/mozilla/pjs.git
Bug 282777 - Implement index() xpath function. Patch by aaronr@us.ibm.com, r=sicking, beaufour
This commit is contained in:
Родитель
82d3ed5f0a
Коммит
a36acd266d
|
@ -180,8 +180,34 @@ XFormsFunctionCall::evaluate(txIEvalContext* aContext, txAExprResult** aResult)
|
|||
// its index.
|
||||
if (!requireParams(1, 1, aContext))
|
||||
return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT;
|
||||
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
|
||||
nsAutoString indexId;
|
||||
evaluateToString((Expr*)iter.next(), aContext, indexId);
|
||||
|
||||
// here document is the XForms document
|
||||
nsCOMPtr<nsIDOMDocument> document;
|
||||
rv = mResolverNode->GetOwnerDocument(getter_AddRefs(document));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ENSURE_TRUE(document, NS_ERROR_NULL_POINTER);
|
||||
|
||||
// indexId should be the id of a nsIXFormsRepeatElement
|
||||
nsCOMPtr<nsIDOMElement> repeatEle;
|
||||
rv = document->GetElementById(indexId, getter_AddRefs(repeatEle));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// now get the index value from the xforms:repeat. Need to use the
|
||||
// service to do this work so that we don't have dependencies in
|
||||
// transformiix on XForms.
|
||||
nsCOMPtr<nsIXFormsUtilityService>xformsService =
|
||||
do_GetService("@mozilla.org/xforms-utility-service;1", &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
PRUint32 index;
|
||||
rv = xformsService->GetRepeatIndex(repeatEle, &index);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return aContext->recycler()->getNumberResult(index, aResult);
|
||||
|
||||
}
|
||||
case INSTANCE:
|
||||
{
|
||||
|
|
|
@ -65,7 +65,8 @@ class nsIXFormsModelElement; /* forward declaration */
|
|||
NS_IMETHOD GetModelFromNode(nsIDOMNode *node, nsIDOMNode **_retval); \
|
||||
NS_IMETHOD IsNodeAssocWithModel(nsIDOMNode *aNode, nsIDOMNode *aModel, PRBool *_retval); \
|
||||
NS_IMETHOD GetInstanceDocumentRoot(const nsAString & aID, nsIDOMNode *aModelNode, nsIDOMNode **_retval); \
|
||||
NS_IMETHOD ValidateString(const nsAString & aValue, const nsAString & aType, const nsAString & aNamespace, PRBool *_retval);
|
||||
NS_IMETHOD ValidateString(const nsAString & aValue, const nsAString & aType, const nsAString & aNamespace, PRBool *_retval); \
|
||||
NS_IMETHOD GetRepeatIndex(nsIDOMNode *aRepeat, PRUint32 *aIndex);
|
||||
|
||||
/**
|
||||
* Private interface implemented by the nsXFormsUtilityService in XForms extension.
|
||||
|
@ -116,6 +117,12 @@ class NS_NO_VTABLE nsIXFormsUtilityService : public nsISupports {
|
|||
/* boolean validateString (in AString aValue, in AString aType, in AString aNamespace); */
|
||||
NS_IMETHOD ValidateString(const nsAString & aValue, const nsAString & aType, const nsAString & aNamespace, PRBool *_retval) = 0;
|
||||
|
||||
/**
|
||||
* Function to retrieve the index from the given repeat element.
|
||||
*/
|
||||
/* unsigned long getRepeatIndex (in nsIDOMNode aRepeat); */
|
||||
NS_IMETHOD GetRepeatIndex(nsIDOMNode *aRepeat, PRUint32 *aIndex) = 0;
|
||||
|
||||
};
|
||||
|
||||
#define NS_ERROR_XFORMS_CALCUATION_EXCEPTION \
|
||||
|
|
|
@ -211,7 +211,9 @@ nsXFormsXPathEvaluator::XFormsParseContextImpl::resolveFunctionCall(
|
|||
aFnCall = new XFormsFunctionCall(XFormsFunctionCall::IF);
|
||||
}
|
||||
else if (aName == txXPathAtoms::index) {
|
||||
aFnCall = new XFormsFunctionCall(XFormsFunctionCall::INDEX);
|
||||
NS_ENSURE_TRUE(mResolverNode, NS_ERROR_FAILURE);
|
||||
aFnCall = new XFormsFunctionCall(XFormsFunctionCall::INDEX,
|
||||
mResolverNode);
|
||||
}
|
||||
else if (aName == txXPathAtoms::instance) {
|
||||
NS_ENSURE_TRUE(mResolverNode, NS_ERROR_FAILURE);
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
#include "nsIXFormsModelElement.h"
|
||||
#include "nsIDOMNodeList.h"
|
||||
#include "nsIInstanceElementPrivate.h"
|
||||
#include "nsIXFormsRepeatElement.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsXFormsUtilityService, nsIXFormsUtilityService)
|
||||
|
||||
|
@ -223,3 +224,15 @@ nsXFormsUtilityService::ValidateString(const nsAString & aValue,
|
|||
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXFormsUtilityService::GetRepeatIndex(nsIDOMNode *aRepeat, PRUint32 *aIndex)
|
||||
{
|
||||
NS_ASSERTION(aIndex, "no return buffer for index, we'll crash soon");
|
||||
*aIndex = 0;
|
||||
|
||||
nsCOMPtr<nsIXFormsRepeatElement> repeatEle = do_QueryInterface(aRepeat);
|
||||
NS_ENSURE_TRUE(repeatEle, NS_ERROR_NULL_POINTER);
|
||||
|
||||
return repeatEle->GetIndex(aIndex);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче