mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 15:23:51 +00:00
[XForms] Add support for XPath function current(). Bug 342857, r=doronr+olli
This commit is contained in:
parent
67ce3c3059
commit
12f49cb385
@ -153,6 +153,7 @@ XPIDLSRCS = \
|
||||
nsIXFormsNSEditableElement.idl \
|
||||
nsIXFormsComboboxUIWidget.idl \
|
||||
nsIXFormsXPathFunctions.idl \
|
||||
nsIXFormsXPathState.idl \
|
||||
$(NULL)
|
||||
|
||||
# XForms source files
|
||||
@ -215,6 +216,7 @@ CPPSRCS = \
|
||||
nsXFormsCopyElement.cpp \
|
||||
nsXFormsRangeConditionAccessors.cpp \
|
||||
nsXFormsXPathFunctions.cpp \
|
||||
nsXFormsXPathState.cpp \
|
||||
$(NULL)
|
||||
|
||||
# Standard Mozilla make rules
|
||||
|
@ -40,7 +40,7 @@
|
||||
#include "nsISupports.idl"
|
||||
#include "txIFunctionEvaluationContext.idl"
|
||||
|
||||
[scriptable, uuid(cc846954-69a0-11d9-9791-000a95dc234c)]
|
||||
[scriptable, uuid(d3c957be-9f59-42f3-8ca9-7a22edf0e231)]
|
||||
interface nsIXFormsXPathFunctions : nsISupports
|
||||
{
|
||||
double avg(in txINodeSet aNodeSet);
|
||||
@ -57,4 +57,5 @@ interface nsIXFormsXPathFunctions : nsISupports
|
||||
DOMString property(in DOMString aProperty);
|
||||
double seconds(in DOMString aDuration);
|
||||
double secondsFromDateTime(in DOMString aDateTime);
|
||||
txINodeSet current(in txIFunctionEvaluationContext aContext);
|
||||
};
|
||||
|
69
extensions/xforms/nsIXFormsXPathState.idl
Normal file
69
extensions/xforms/nsIXFormsXPathState.idl
Normal file
@ -0,0 +1,69 @@
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla XForms support.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* IBM Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2007
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Aaron Reed <aaronr@us.ibm.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIDOMNode.idl"
|
||||
|
||||
/**
|
||||
* The nsIXFormsXPathState interface is used to define the methods and
|
||||
* and attributes that are necessary for the class nsXFormsXPathState. Objects
|
||||
* of that class are passed into our XPath expression evaluations to specify
|
||||
* the state to use. Basically the 'state' is like a property object, so that
|
||||
* we can pass information from our side of the expression evaluation to the
|
||||
* XForms XPath functions so that they can behave correctly.
|
||||
*/
|
||||
|
||||
[uuid(5c5eb4e7-5693-46e2-aa05-f630d33217e5)]
|
||||
interface nsIXFormsXPathState : nsISupports
|
||||
{
|
||||
/**
|
||||
* The XForms control upon which the XPath expression appears. Used inside
|
||||
* some of our XForms XPath functions to access to the XForms document.
|
||||
*/
|
||||
readonly attribute nsIDOMNode xformsNode;
|
||||
|
||||
/**
|
||||
* The original context node used to build and evaluate the XPath expression.
|
||||
* This can be useful to remember since this is the context node used
|
||||
* for the parse context part of XPath. But the context that our
|
||||
* XFormsXPath functions has access to is the evaluation context.
|
||||
* The context node for the evaluation context can change as XPath
|
||||
* works its way through the expression.
|
||||
*/
|
||||
readonly attribute nsIDOMNode originalContextNode;
|
||||
};
|
@ -2321,8 +2321,11 @@ nsXFormsModelElement::ProcessBind(nsIDOMXPathEvaluator *aEvaluator,
|
||||
exprString = NS_LITERAL_STRING(".");
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIXFormsXPathState> state = new nsXFormsXPathState(aBindElement,
|
||||
aContextNode);
|
||||
NS_ENSURE_TRUE(state, NS_ERROR_OUT_OF_MEMORY);
|
||||
rv = nsXFormsUtils::EvaluateXPath(eval, exprString, aContextNode, resolver,
|
||||
aBindElement,
|
||||
state,
|
||||
nsIDOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE,
|
||||
aContextPosition, aContextSize,
|
||||
nsnull, getter_AddRefs(result));
|
||||
@ -2410,9 +2413,14 @@ nsXFormsModelElement::ProcessBind(nsIDOMXPathEvaluator *aEvaluator,
|
||||
// bind contains (aka nested binds).
|
||||
while (node && snapItem < snapLen) {
|
||||
|
||||
// set the context node for the expression that is being analyzed.
|
||||
nsCOMPtr<nsIXFormsXPathState> stateForMIP =
|
||||
new nsXFormsXPathState(aBindElement, node);
|
||||
NS_ENSURE_TRUE(stateForMIP, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
// Apply MIPs
|
||||
nsXFormsXPathParser parser;
|
||||
nsXFormsXPathAnalyzer analyzer(eval, resolver, aBindElement);
|
||||
nsXFormsXPathAnalyzer analyzer(eval, resolver, stateForMIP);
|
||||
PRBool multiMIP = PR_FALSE;
|
||||
for (PRUint32 j = 0; j < eModel__count; ++j) {
|
||||
if (propStrings[j].IsEmpty())
|
||||
@ -2441,15 +2449,15 @@ nsXFormsModelElement::ProcessBind(nsIDOMXPathEvaluator *aEvaluator,
|
||||
if (j == eModel_type) {
|
||||
// Inform MDG that it needs to check type. The only arguments
|
||||
// actually used are |eModel_constraint| and |node|.
|
||||
rv = mMDG.AddMIP(eModel_constraint, nsnull, nsnull, PR_FALSE, node, 1,
|
||||
1);
|
||||
rv = mMDG.AddMIP(eModel_constraint, nsnull, nsnull, PR_FALSE, node,
|
||||
1, 1);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
} else {
|
||||
|
||||
rv = nsXFormsUtils::CreateExpression(nodesetEvalInternal,
|
||||
propStrings[j], resolver,
|
||||
aBindElement,
|
||||
stateForMIP,
|
||||
getter_AddRefs(props[j]));
|
||||
if (NS_FAILED(rv)) {
|
||||
const PRUnichar *strings[] = { propStrings[j].get() };
|
||||
|
@ -112,6 +112,8 @@ UnregisterXFormsModule(nsIComponentManager *aCompMgr,
|
||||
printf("XFORMS Module: Unregistering\n");
|
||||
#endif
|
||||
|
||||
nsXFormsUtils::Shutdown();
|
||||
|
||||
nsCOMPtr<nsICategoryManager> catman =
|
||||
do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
|
||||
|
||||
|
@ -808,17 +808,9 @@ nsXFormsSubmissionElement::SerializeDataXML(nsIDOMDocument *data,
|
||||
mElement->GetAttribute(NS_LITERAL_STRING("mediatype"), mediaType);
|
||||
|
||||
// Check for preference, disabling SOAP requests
|
||||
PRBool enableExperimental = PR_FALSE;
|
||||
nsCOMPtr<nsIPrefBranch> pref = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
|
||||
if (NS_SUCCEEDED(rv) && pref) {
|
||||
PRBool val;
|
||||
if (NS_SUCCEEDED(pref->GetBoolPref("xforms.enableExperimentalFeatures",
|
||||
&val)))
|
||||
enableExperimental = val;
|
||||
}
|
||||
if (nsXFormsUtils::ExperimentalFeaturesEnabled()) {
|
||||
|
||||
// Check for SOAP Envelope and handle SOAP
|
||||
if (enableExperimental) {
|
||||
// Check for SOAP Envelope and handle SOAP
|
||||
nsAutoString nodeName, nodeNS;
|
||||
data->GetLocalName(nodeName);
|
||||
data->GetNamespaceURI(nodeNS);
|
||||
|
@ -212,6 +212,27 @@ struct EventItem
|
||||
nsCOMPtr<nsIDOMElement> srcElement;
|
||||
};
|
||||
|
||||
static PRBool gExperimentalFeaturesEnabled = PR_FALSE;
|
||||
|
||||
PR_STATIC_CALLBACK(int) PrefChangedCallback(const char* aPref, void* aData)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPrefBranch> pref = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
|
||||
if (NS_SUCCEEDED(rv) && pref) {
|
||||
|
||||
// if our experimental pref changed, make sure to update our static
|
||||
// variable.
|
||||
if (strcmp(aPref, PREF_EXPERIMENTAL_FEATURES) == 0) {
|
||||
PRBool val;
|
||||
if (NS_SUCCEEDED(pref->GetBoolPref(PREF_EXPERIMENTAL_FEATURES, &val))) {
|
||||
gExperimentalFeaturesEnabled = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0; // PREF_OK
|
||||
}
|
||||
|
||||
/* static */ nsresult
|
||||
nsXFormsUtils::Init()
|
||||
{
|
||||
@ -241,6 +262,40 @@ nsXFormsUtils::Init()
|
||||
sEventDefaults.Put(NS_ConvertUTF8toUTF16(sEventDefaultsEntries[i].name),
|
||||
flag);
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPrefBranch> prefBranch =
|
||||
do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
|
||||
if (NS_SUCCEEDED(rv) && prefBranch) {
|
||||
PRBool val;
|
||||
rv = prefBranch->GetBoolPref(PREF_EXPERIMENTAL_FEATURES, &val);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
gExperimentalFeaturesEnabled = val;
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPref> pref = do_GetService(NS_PREF_CONTRACTID, &rv);
|
||||
NS_ENSURE_STATE(pref);
|
||||
rv = pref->RegisterCallback(PREF_EXPERIMENTAL_FEATURES,
|
||||
PrefChangedCallback, nsnull);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* static */ nsresult
|
||||
nsXFormsUtils::Shutdown()
|
||||
{
|
||||
// unregister our pref listeners
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPref> pref = do_GetService(NS_PREF_CONTRACTID, &rv);
|
||||
NS_ENSURE_STATE(pref);
|
||||
rv = pref->UnregisterCallback(PREF_EXPERIMENTAL_FEATURES,
|
||||
PrefChangedCallback, nsnull);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
gExperimentalFeaturesEnabled = PR_FALSE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -426,7 +481,7 @@ nsXFormsUtils::GetModel(nsIDOMElement *aElement,
|
||||
nsXFormsUtils::CreateExpression(nsIXPathEvaluatorInternal *aEvaluator,
|
||||
const nsAString &aExpression,
|
||||
nsIDOMXPathNSResolver *aResolver,
|
||||
nsISupports *aState,
|
||||
nsIXFormsXPathState *aState,
|
||||
nsIDOMXPathExpression **aResult)
|
||||
{
|
||||
nsStringArray ns;
|
||||
@ -469,8 +524,12 @@ nsXFormsUtils::EvaluateXPath(const nsAString &aExpression,
|
||||
nsresult rv = eval->CreateNSResolver(aResolverNode, getter_AddRefs(resolver));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIXFormsXPathState> state = new nsXFormsXPathState(aResolverNode,
|
||||
aContextNode);
|
||||
NS_ENSURE_TRUE(state, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
nsCOMPtr<nsIDOMXPathExpression> expression;
|
||||
rv = CreateExpression(evalInternal, aExpression, resolver, aResolverNode,
|
||||
rv = CreateExpression(evalInternal, aExpression, resolver, state,
|
||||
getter_AddRefs(expression));
|
||||
|
||||
PRBool throwException = PR_FALSE;
|
||||
@ -499,7 +558,7 @@ nsXFormsUtils::EvaluateXPath(const nsAString &aExpression,
|
||||
/// @see http://bugzilla.mozilla.org/show_bug.cgi?id=265212
|
||||
if (aSet) {
|
||||
nsXFormsXPathParser parser;
|
||||
nsXFormsXPathAnalyzer analyzer(evalInternal, resolver, aResolverNode);
|
||||
nsXFormsXPathAnalyzer analyzer(evalInternal, resolver, state);
|
||||
nsAutoPtr<nsXFormsXPathNode> xNode(parser.Parse(aExpression));
|
||||
rv = analyzer.Analyze(aContextNode,
|
||||
xNode,
|
||||
@ -545,7 +604,7 @@ nsXFormsUtils::EvaluateXPath(nsIXPathEvaluatorInternal *aEvaluator,
|
||||
const nsAString &aExpression,
|
||||
nsIDOMNode *aContextNode,
|
||||
nsIDOMXPathNSResolver *aResolver,
|
||||
nsISupports *aState,
|
||||
nsIXFormsXPathState *aState,
|
||||
PRUint16 aResultType,
|
||||
PRInt32 aContextPosition,
|
||||
PRInt32 aContextSize,
|
||||
@ -562,7 +621,9 @@ nsXFormsUtils::EvaluateXPath(nsIXPathEvaluatorInternal *aEvaluator,
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// if somehow the contextNode and the evaluator weren't spawned from the same
|
||||
// document, this could fail with NS_ERROR_DOM_WRONG_DOCUMENT_ERR
|
||||
// document, this could fail with NS_ERROR_DOM_WRONG_DOCUMENT_ERR. We are
|
||||
// NOT setting the state's original context node here. We'll assume that
|
||||
// the state was set up correctly prior to this function being called.
|
||||
nsCOMPtr<nsISupports> supResult;
|
||||
rv = nsExpression->EvaluateWithContext(aContextNode, aContextPosition,
|
||||
aContextSize, aResultType,
|
||||
@ -2751,3 +2812,10 @@ nsXFormsUtils::NodeHasItemset(nsIDOMNode *aNode)
|
||||
return hasItemset;
|
||||
}
|
||||
|
||||
/* static */ PRBool
|
||||
nsXFormsUtils::ExperimentalFeaturesEnabled()
|
||||
{
|
||||
// Return the value of the preference that surrounds all of our
|
||||
// 'not yet standardized' XForms work.
|
||||
return gExperimentalFeaturesEnabled;
|
||||
}
|
||||
|
@ -50,6 +50,7 @@
|
||||
#include "nsIScriptError.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsIDOMWindowInternal.h"
|
||||
#include "nsXFormsXPathState.h"
|
||||
|
||||
class nsIDOMElement;
|
||||
class nsIXFormsModelElement;
|
||||
@ -70,6 +71,8 @@ class nsIXPathEvaluatorInternal;
|
||||
#define NS_NAMESPACE_SOAP_ENVELOPE "http://schemas.xmlsoap.org/soap/envelope/"
|
||||
#define NS_NAMESPACE_MOZ_XFORMS_LAZY "http://www.mozilla.org/projects/xforms/2005/lazy"
|
||||
|
||||
#define PREF_EXPERIMENTAL_FEATURES "xforms.enableExperimentalFeatures"
|
||||
|
||||
#define NS_ERROR_XFORMS_CALCULATION_EXCEPTION \
|
||||
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 3001)
|
||||
|
||||
@ -183,6 +186,12 @@ public:
|
||||
static NS_HIDDEN_(nsresult)
|
||||
Init();
|
||||
|
||||
/**
|
||||
* Shutdown nsXFormsUtils.
|
||||
*/
|
||||
static NS_HIDDEN_(nsresult)
|
||||
Shutdown();
|
||||
|
||||
/**
|
||||
* Locate the model that is a parent of |aBindElement|. This method walks
|
||||
* up the content tree looking for the containing model.
|
||||
@ -266,7 +275,7 @@ public:
|
||||
CreateExpression(nsIXPathEvaluatorInternal *aEvaluator,
|
||||
const nsAString &aExpression,
|
||||
nsIDOMXPathNSResolver *aResolver,
|
||||
nsISupports *aState,
|
||||
nsIXFormsXPathState *aState,
|
||||
nsIDOMXPathExpression **aResult);
|
||||
|
||||
/**
|
||||
@ -291,7 +300,7 @@ public:
|
||||
const nsAString &aExpression,
|
||||
nsIDOMNode *aContextNode,
|
||||
nsIDOMXPathNSResolver *aResolver,
|
||||
nsISupports *aState,
|
||||
nsIXFormsXPathState *aState,
|
||||
PRUint16 aResultType,
|
||||
PRInt32 aContextPosition,
|
||||
PRInt32 aContextSize,
|
||||
@ -713,6 +722,22 @@ public:
|
||||
*/
|
||||
static NS_HIDDEN_(PRBool) NodeHasItemset(nsIDOMNode *aNode);
|
||||
|
||||
/**
|
||||
* Variable is true if the 'xforms.enableExperimentalFeatures' preference has
|
||||
* been enabled in the browser. We currently use this preference to surround
|
||||
* code that implements features from future XForms specs. Specs that have
|
||||
* not yet reached recommendation.
|
||||
*/
|
||||
static NS_HIDDEN_(PRBool) experimentalFeaturesEnabled;
|
||||
|
||||
/**
|
||||
* Returns true if the 'xforms.enableExperimentalFeatures' preference has
|
||||
* been enabled in the browser. We currently use this preference to surround
|
||||
* code that implements features from future XForms specs. Specs that have
|
||||
* not yet reached recommendation.
|
||||
*/
|
||||
static NS_HIDDEN_(PRBool) ExperimentalFeaturesEnabled();
|
||||
|
||||
private:
|
||||
/**
|
||||
* Do same origin checks on aBaseDocument and aTestURI. Hosts can be
|
||||
|
@ -50,7 +50,7 @@
|
||||
|
||||
nsXFormsXPathAnalyzer::nsXFormsXPathAnalyzer(nsIXPathEvaluatorInternal *aEvaluator,
|
||||
nsIDOMXPathNSResolver *aResolver,
|
||||
nsISupports *aState)
|
||||
nsIXFormsXPathState *aState)
|
||||
: mEvaluator(aEvaluator),
|
||||
mResolver(aResolver),
|
||||
mState(aState)
|
||||
|
@ -48,6 +48,7 @@
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsIXFormsXPathState.h"
|
||||
|
||||
/**
|
||||
* This class analyzes an XPath Expression parse tree (nsXFormsXPathNode), and
|
||||
@ -60,7 +61,7 @@ class nsXFormsXPathAnalyzer {
|
||||
private:
|
||||
nsCOMPtr<nsIXPathEvaluatorInternal> mEvaluator;
|
||||
nsCOMPtr<nsIDOMXPathNSResolver> mResolver;
|
||||
nsCOMPtr<nsISupports> mState;
|
||||
nsCOMPtr<nsIXFormsXPathState> mState;
|
||||
|
||||
nsCOMArray<nsIDOMNode> *mCurSet;
|
||||
nsCOMPtr<nsIDOMNSXPathExpression> mCurExpression;
|
||||
@ -77,7 +78,7 @@ private:
|
||||
public:
|
||||
nsXFormsXPathAnalyzer(nsIXPathEvaluatorInternal *aEvaluator,
|
||||
nsIDOMXPathNSResolver *aResolver,
|
||||
nsISupports *aState);
|
||||
nsIXFormsXPathState *aState);
|
||||
~nsXFormsXPathAnalyzer();
|
||||
|
||||
nsresult Analyze(nsIDOMNode *aContextNode,
|
||||
|
@ -154,9 +154,10 @@ nsXFormsXPathFunctions::Index(txIFunctionEvaluationContext *aContext,
|
||||
// make sure that it is a xforms:repeat node. Given that, must query
|
||||
// its index.
|
||||
|
||||
nsCOMPtr<nsISupports> state;
|
||||
nsCOMPtr<nsIXFormsXPathState> state;
|
||||
aContext->GetState(getter_AddRefs(state));
|
||||
nsCOMPtr<nsIDOMNode> resolverNode = do_QueryInterface(state);
|
||||
nsCOMPtr<nsIDOMNode> resolverNode;
|
||||
state->GetXformsNode(getter_AddRefs(resolverNode));
|
||||
NS_ENSURE_TRUE(resolverNode, NS_ERROR_FAILURE);
|
||||
|
||||
// here document is the XForms document
|
||||
@ -197,9 +198,10 @@ nsXFormsXPathFunctions::Instance(txIFunctionEvaluationContext *aContext,
|
||||
// The state is the node in the XForms document that contained
|
||||
// the expression we are evaluating. We'll use this to get the
|
||||
// document. If this isn't here, then something is wrong. Bail.
|
||||
nsCOMPtr<nsISupports> state;
|
||||
nsCOMPtr<nsIXFormsXPathState> state;
|
||||
aContext->GetState(getter_AddRefs(state));
|
||||
nsCOMPtr<nsIDOMNode> resolverNode = do_QueryInterface(state);
|
||||
nsCOMPtr<nsIDOMNode> resolverNode;
|
||||
state->GetXformsNode(getter_AddRefs(resolverNode));
|
||||
NS_ENSURE_TRUE(resolverNode, NS_ERROR_FAILURE);
|
||||
|
||||
// here document is the XForms document
|
||||
@ -427,3 +429,31 @@ nsXFormsXPathFunctions::SecondsFromDateTime(const nsAString &aDateTime,
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXFormsXPathFunctions::Current(txIFunctionEvaluationContext *aContext,
|
||||
txINodeSet **aResult)
|
||||
{
|
||||
*aResult = nsnull;
|
||||
|
||||
if (!nsXFormsUtils::ExperimentalFeaturesEnabled()) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
// now get the contextNode passed in to the evaluation
|
||||
nsCOMPtr<nsIXFormsXPathState> state;
|
||||
aContext->GetState(getter_AddRefs(state));
|
||||
nsCOMPtr<nsIDOMNode> origContextNode;
|
||||
state->GetOriginalContextNode(getter_AddRefs(origContextNode));
|
||||
NS_ENSURE_STATE(origContextNode);
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<txINodeSet> result =
|
||||
do_CreateInstance("@mozilla.org/transformiix-nodeset;1", &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
result->Add(origContextNode);
|
||||
result.swap(*aResult);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -37,6 +37,9 @@
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsIXFormsXPathFunctions.h"
|
||||
#include "nsIXFormsXPathState.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
class nsXFormsXPathFunctions : public nsIXFormsXPathFunctions
|
||||
{
|
||||
|
59
extensions/xforms/nsXFormsXPathState.cpp
Normal file
59
extensions/xforms/nsXFormsXPathState.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla XForms support.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* IBM Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2007
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Aaron Reed <aaronr@us.ibm.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsXFormsXPathState.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsXFormsXPathState, nsIXFormsXPathState)
|
||||
|
||||
// nsXFormsXPathState methods
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXFormsXPathState::GetXformsNode(nsIDOMNode **aResolverNode)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aResolverNode);
|
||||
NS_IF_ADDREF(*aResolverNode = mXFormsNode);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXFormsXPathState::GetOriginalContextNode(nsIDOMNode **aContextNode)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aContextNode);
|
||||
NS_IF_ADDREF(*aContextNode = mOriginalContextNode);
|
||||
return NS_OK;
|
||||
}
|
74
extensions/xforms/nsXFormsXPathState.h
Normal file
74
extensions/xforms/nsXFormsXPathState.h
Normal file
@ -0,0 +1,74 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla XForms support.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* IBM Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2007
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Aaron Reed <aaronr@us.ibm.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsIXFormsXPathState.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
class nsXFormsXPathState : public nsIXFormsXPathState
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIXFORMSXPATHSTATE
|
||||
|
||||
/**
|
||||
* Constructors.
|
||||
*
|
||||
* @param aXFormsNode The XForms control upon which the expression
|
||||
* appears. Used to allow our XForms XPath functions
|
||||
* access to the XForms document.
|
||||
* @param aContextNode The original context node used to build and
|
||||
* evaluate the XPath expression. This can be useful
|
||||
* to remember since this is the context node used
|
||||
* for the parse context part of XPath. But the
|
||||
* context that our XFormsXPath functions has access
|
||||
* to is the evaluation context. The context node
|
||||
* for the evaluation context can chnage as XPath
|
||||
* works its way through the expression.
|
||||
*/
|
||||
|
||||
nsXFormsXPathState(nsIDOMNode *aXFormsNode,
|
||||
nsIDOMNode *aContextNode)
|
||||
: mXFormsNode(aXFormsNode),
|
||||
mOriginalContextNode(aContextNode) {};
|
||||
|
||||
private:
|
||||
|
||||
nsCOMPtr<nsIDOMNode> mXFormsNode;
|
||||
nsCOMPtr<nsIDOMNode> mOriginalContextNode;
|
||||
};
|
Loading…
Reference in New Issue
Block a user