Support context size and position in ns(XForms)XPathExpression. Bug 292841, r=sicking, sr=peterv, a=mkaply

This commit is contained in:
allan%beaufour.dk 2005-06-02 06:53:42 +00:00
Родитель d4d13d935b
Коммит 673396fbbb
7 изменённых файлов: 71 добавлений и 675 удалений

Просмотреть файл

@ -52,6 +52,7 @@ XPIDLSRCS = \
nsIDOMXPathNamespace.idl \
nsIDOMXPathNSResolver.idl \
nsIDOMXPathResult.idl \
nsIDOMNSXPathExpression.idl \
$(NULL)
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -0,0 +1,68 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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.org code.
*
* The Initial Developer of the Original Code is
* Novell, inc.
* Portions created by the Initial Developer are Copyright (C) 2005
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Allan Beaufour <allan@beaufour.dk> (original author)
*
* 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 "domstubs.idl"
interface nsIDOMXPathResult;
interface XPathException;
/**
* Interface for Mozilla specific XPathExpression functions.
*/
[scriptable, uuid(ce600ca8-e98a-4419-ad61-2f6d0cb0ecc8)]
interface nsIDOMNSXPathExpression : nsISupports
{
/**
* Evaluate the expression with the given context. Similar to
* nsIDOMXPathExpression::evaluate(), except that this takes the context
* position and size too.
*
* @param contextNode The context node
* @param contextPosition The context position
* @param contextSize The context size
* @param type The needed result type
* @param result The result
*/
nsISupports evaluateWithContext(in nsIDOMNode contextNode,
in unsigned long contextPosition,
in unsigned long contextSize,
in unsigned short type,
in nsISupports result)
raises(XPathException,
DOMException);
};

Просмотреть файл

@ -38,6 +38,7 @@
#include "nsICategoryManager.h"
#include "nsIDOMClassInfo.h"
#include "nsIDOMNSXPathExpression.h"
#include "nsIDOMXPathExpression.h"
#include "nsIDOMXPathNSResolver.h"
#include "nsIDOMXPathResult.h"
@ -98,6 +99,7 @@ NS_DOMCI_EXTENSION(Transformiix)
NS_DOMCI_EXTENSION_ENTRY_BEGIN(XPathExpression)
NS_DOMCI_EXTENSION_ENTRY_INTERFACE(nsIDOMXPathExpression)
NS_DOMCI_EXTENSION_ENTRY_INTERFACE(nsIDOMNSXPathExpression)
NS_DOMCI_EXTENSION_ENTRY_END(XPathExpression, nsIDOMXPathExpression,
PR_TRUE, nsnull)

Просмотреть файл

@ -1,97 +0,0 @@
/* -*- 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) 2004
* 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 ***** */
#ifndef nsIXFormsXPathEvaluator_h
#define nsIXFormsXPathEvaluator_h
#include "nsISupports.h"
/* For IDL files that don't want to include root IDL files. */
#ifndef NS_NO_VTABLE
#define NS_NO_VTABLE
#endif
class nsIDOMNode; /* forward declaration */
class nsIDOMXPathExpression; /* forward declaration */
/* starting interface: nsIXFormsXPathEvaluator */
#define NS_XFORMS_XPATH_EVALUATOR_CONTRACTID "@mozilla.org/dom/xforms-xpath-evaluator;1"
/* a7e127c6-31ff-40b4-8780-15d6938b33d3 */
#define TRANSFORMIIX_XFORMS_XPATH_EVALUATOR_CID \
{ 0xa7e127c6, 0x31ff, 0x40b4, { 0x87, 0x80, 0x15, 0xd6, 0x93, 0x8b, 0x33, 0xd3 } }
/* 60050a4a-4c99-4bad-8c47-3b9b96caf2b4 */
#define TRANSFORMIIX_XFORMS_XPATH_EVALUATOR_IID \
{ 0x60050a4a, 0x4c99, 0x4bad, { 0x8c, 0x47, 0x3b, 0x9b, 0x96, 0xca, 0xf2, 0xb4 } }
/* Use this macro when declaring classes that implement this interface. */
#define NS_DECL_NSIXFORMXPATHEVALUATOR \
NS_IMETHOD CreateExpression(const nsAString & aExpression, nsIDOMNode *aResolverNode,nsIDOMXPathExpression **aResult); \
NS_IMETHOD Evaluate(const nsAString & aExpression, nsIDOMNode *aContextNode, nsIDOMNode *aResolverNode, PRUint16 aType, nsISupports *aInResult, nsISupports **aResult);
/**
* Private interface implemented by the nsXFormsXPathEvaluator in Transformiix
* and will move to the XForms extension when XPath is made extensible. We
* are using this interface instead of nsIDOMXPathEvaluator since we can
* don't really need all of that overhead. For example, this interface uses
* a resolver node from the xforms document rather than forcing XForms to
* create a namespace resolver node prior to creating the expression or
* running an evaluation.
*/
class NS_NO_VTABLE nsIXFormsXPathEvaluator : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(TRANSFORMIIX_XFORMS_XPATH_EVALUATOR_IID)
/**
* Function to create a nsIDOMXPathExpression from the provided expression
* string. aResolverNode is the xforms node that the expression is
* associated with.
*/
NS_IMETHOD CreateExpression(const nsAString & aExpression, nsIDOMNode *aResolverNode, nsIDOMXPathExpression **aResult) = 0;
/**
* Function to evaluate the given expression. aResolverNode is the xforms
* node that the expression is associated with. The other parameters are as
* required by DOM's XPathEvaluator.
*/
NS_IMETHOD Evaluate(const nsAString & aExpression, nsIDOMNode *aContextNode, nsIDOMNode *aResolverNode, PRUint16 aType, nsISupports *aInResult, nsISupports **aResult) = 0;
};
#endif /* nsIXFormsXPathEvaluator_h */

Просмотреть файл

@ -1,271 +0,0 @@
/* -*- 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) 2004
* 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 "nsXFormsXPathEvaluator.h"
#include "nsCOMPtr.h"
#include "nsIAtom.h"
#include "nsIDOMClassInfo.h"
#include "nsXPathException.h"
#include "nsXPathExpression.h"
#include "nsXPathNSResolver.h"
#include "nsXPathResult.h"
#include "nsContentCID.h"
#include "Expr.h"
#include "ExprParser.h"
#include "nsDOMError.h"
#include "txURIUtils.h"
#include "nsIDocument.h"
#include "nsIDOMDocument.h"
#include "nsDOMString.h"
#include "nsINameSpaceManager.h"
#include "txError.h"
#include "txAtoms.h"
#include "XFormsFunctions.h"
#include "nsIDOM3Node.h"
extern nsINameSpaceManager* gTxNameSpaceManager;
NS_IMPL_ADDREF(nsXFormsXPathEvaluator)
NS_IMPL_RELEASE(nsXFormsXPathEvaluator)
NS_INTERFACE_MAP_BEGIN(nsXFormsXPathEvaluator)
NS_INTERFACE_MAP_ENTRY(nsIXFormsXPathEvaluator)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXFormsXPathEvaluator)
NS_INTERFACE_MAP_END
nsXFormsXPathEvaluator::nsXFormsXPathEvaluator()
{
}
nsXFormsXPathEvaluator::~nsXFormsXPathEvaluator()
{
}
NS_IMETHODIMP
nsXFormsXPathEvaluator::CreateExpression(const nsAString & aExpression,
nsIDOMNode *aResolverNode,
nsIDOMXPathExpression **aResult)
{
nsresult rv = NS_OK;
if (!mRecycler) {
nsRefPtr<txResultRecycler> recycler = new txResultRecycler;
NS_ENSURE_TRUE(recycler, NS_ERROR_OUT_OF_MEMORY);
rv = recycler->init();
NS_ENSURE_SUCCESS(rv, rv);
mRecycler = recycler;
}
XFormsParseContextImpl pContext(aResolverNode);
nsAutoPtr<Expr> expression;
rv = txExprParser::createExpr(PromiseFlatString(aExpression), &pContext,
getter_Transfers(expression));
if (NS_FAILED(rv)) {
if (rv == NS_ERROR_DOM_NAMESPACE_ERR) {
return NS_ERROR_DOM_NAMESPACE_ERR;
}
return NS_ERROR_DOM_INVALID_EXPRESSION_ERR;
}
*aResult = new nsXPathExpression(expression, mRecycler);
if (!*aResult) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(*aResult);
return NS_OK;
}
NS_IMETHODIMP
nsXFormsXPathEvaluator::Evaluate(const nsAString & aExpression,
nsIDOMNode *aContextNode,
nsIDOMNode *aResolverNode,
PRUint16 aType,
nsISupports *aInResult,
nsISupports **aResult)
{
// XXX Need to check document of aContextNode if created by
// QI'ing a document.
nsCOMPtr<nsIDOMXPathExpression> expression;
nsresult rv = CreateExpression(aExpression, aResolverNode,
getter_AddRefs(expression));
NS_ENSURE_SUCCESS(rv, rv);
return expression->Evaluate(aContextNode, aType, aInResult, aResult);
}
/*
* Implementation of txIParseContext private to nsXFormsXPathEvaluator
* XFormsParseContextImpl bases on a nsIDOMXPathNSResolver
*/
nsresult nsXFormsXPathEvaluator::XFormsParseContextImpl::resolveNamespacePrefix
(nsIAtom* aPrefix, PRInt32& aID)
{
aID = kNameSpaceID_Unknown;
if (!mResolverNode) {
return NS_ERROR_DOM_NAMESPACE_ERR;
}
nsAutoString prefix;
if (aPrefix) {
aPrefix->ToString(prefix);
}
nsVoidableString ns;
nsresult rv;
// begin - taken directly from nsXPathNSResolver::LookupNamespaceURI
if (prefix.EqualsLiteral("xml")) {
ns.AssignLiteral("http://www.w3.org/XML/1998/namespace");
rv = NS_OK;
}
else {
nsCOMPtr<nsIDOM3Node> dom3Node = do_QueryInterface(mResolverNode);
NS_ASSERTION(dom3Node, "Need a node to resolve namespaces.");
if( dom3Node ) {
rv = dom3Node->LookupNamespaceURI(prefix, ns);
}
else {
SetDOMStringToNull(ns);
rv = NS_OK;
}
}
// end - taken directly from nsXPathNSResolver::LookupNamespaceURI
NS_ENSURE_SUCCESS(rv, rv);
if (DOMStringIsNull(ns)) {
return NS_ERROR_DOM_NAMESPACE_ERR;
}
if (ns.IsEmpty()) {
aID = kNameSpaceID_None;
return NS_OK;
}
// get the namespaceID for the URI
return gTxNameSpaceManager->RegisterNameSpace(ns, aID);
}
nsresult
nsXFormsXPathEvaluator::XFormsParseContextImpl::resolveFunctionCall(
nsIAtom* aName,
PRInt32 aNamespaceID,
FunctionCall*& aFnCall)
{
if (aNamespaceID == kNameSpaceID_None) {
PRBool isOutOfMem = PR_TRUE;
if (aName == txXPathAtoms::avg) {
aFnCall = new XFormsFunctionCall(XFormsFunctionCall::AVG);
}
else if (aName == txXPathAtoms::booleanFromString) {
aFnCall = new XFormsFunctionCall(XFormsFunctionCall::BOOLEANFROMSTRING);
}
else if (aName == txXPathAtoms::countNonEmpty) {
aFnCall = new XFormsFunctionCall(XFormsFunctionCall::COUNTNONEMPTY);
}
else if (aName == txXPathAtoms::daysFromDate) {
aFnCall = new XFormsFunctionCall(XFormsFunctionCall::DAYSFROMDATE);
}
else if (aName == txXPathAtoms::ifFunc) {
aFnCall = new XFormsFunctionCall(XFormsFunctionCall::IF);
}
else if (aName == txXPathAtoms::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);
aFnCall = new XFormsFunctionCall(XFormsFunctionCall::INSTANCE,
mResolverNode);
}
else if (aName == txXPathAtoms::max) {
aFnCall = new XFormsFunctionCall(XFormsFunctionCall::MAX);
}
else if (aName == txXPathAtoms::min) {
aFnCall = new XFormsFunctionCall(XFormsFunctionCall::MIN);
}
else if (aName == txXPathAtoms::months) {
aFnCall = new XFormsFunctionCall(XFormsFunctionCall::MONTHS);
}
else if (aName == txXPathAtoms::now) {
aFnCall = new XFormsFunctionCall(XFormsFunctionCall::NOW);
}
else if (aName == txXPathAtoms::property) {
aFnCall = new XFormsFunctionCall(XFormsFunctionCall::PROPERTY);
}
else if (aName == txXPathAtoms::seconds) {
aFnCall = new XFormsFunctionCall(XFormsFunctionCall::SECONDS);
}
else if (aName == txXPathAtoms::secondsFromDateTime) {
aFnCall = new XFormsFunctionCall(XFormsFunctionCall::SECONDSFROMDATETIME);
}
else {
// didn't find functioncall here, aFnCall should be null
isOutOfMem = PR_FALSE;
}
if (aFnCall)
{
return NS_OK;
}
else if (isOutOfMem) {
NS_ERROR("XPath FunctionLib failed on out-of-memory");
return NS_ERROR_OUT_OF_MEMORY;
}
}
return NS_ERROR_XPATH_UNKNOWN_FUNCTION;
}
PRBool nsXFormsXPathEvaluator::XFormsParseContextImpl::caseInsensitiveNameTests()
{
// This will always be false since this handles XForms, which is XML-based,
// so case sensitive.
return PR_FALSE;
}
void
nsXFormsXPathEvaluator::XFormsParseContextImpl::SetErrorOffset(PRUint32 aOffset)
{
}

Просмотреть файл

@ -1,209 +0,0 @@
/* -*- 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 TransforMiiX XSLT processor code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Peter Van der Beken <peterv@propagandism.org>
*
* 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 "nsXPathExpression.h"
#include "Expr.h"
#include "ExprResult.h"
#include "nsDOMError.h"
#include "nsIDOMCharacterData.h"
#include "nsIDOMClassInfo.h"
#include "nsIDOMDocument.h"
#include "nsIDOMXPathNamespace.h"
#include "nsXPathResult.h"
#include "nsDOMError.h"
#include "txURIUtils.h"
#include "txXPathTreeWalker.h"
NS_IMPL_ADDREF(nsXPathExpression)
NS_IMPL_RELEASE(nsXPathExpression)
NS_INTERFACE_MAP_BEGIN(nsXPathExpression)
NS_INTERFACE_MAP_ENTRY(nsIDOMXPathExpression)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMXPathExpression)
NS_INTERFACE_MAP_ENTRY_EXTERNAL_DOM_CLASSINFO(XPathExpression)
NS_INTERFACE_MAP_END
nsXPathExpression::nsXPathExpression(nsAutoPtr<Expr>& aExpression,
txResultRecycler* aRecycler)
: mExpression(aExpression),
mRecycler(aRecycler)
{
}
nsXPathExpression::~nsXPathExpression()
{
}
NS_IMETHODIMP
nsXPathExpression::Evaluate(nsIDOMNode *aContextNode,
PRUint16 aType,
nsISupports *aInResult,
nsISupports **aResult)
{
NS_ENSURE_ARG(aContextNode);
if (!URIUtils::CanCallerAccess(aContextNode))
return NS_ERROR_DOM_SECURITY_ERR;
nsresult rv;
PRUint16 nodeType;
rv = aContextNode->GetNodeType(&nodeType);
NS_ENSURE_SUCCESS(rv, rv);
if (nodeType == nsIDOMNode::TEXT_NODE ||
nodeType == nsIDOMNode::CDATA_SECTION_NODE) {
nsCOMPtr<nsIDOMCharacterData> textNode = do_QueryInterface(aContextNode);
NS_ENSURE_TRUE(textNode, NS_ERROR_FAILURE);
if (textNode) {
PRUint32 textLength;
textNode->GetLength(&textLength);
if (textLength == 0)
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
}
// XXX Need to get logical XPath text node for CDATASection
// and Text nodes.
}
else if (nodeType != nsIDOMNode::DOCUMENT_NODE &&
nodeType != nsIDOMNode::ELEMENT_NODE &&
nodeType != nsIDOMNode::ATTRIBUTE_NODE &&
nodeType != nsIDOMNode::COMMENT_NODE &&
nodeType != nsIDOMNode::PROCESSING_INSTRUCTION_NODE &&
nodeType != nsIDOMXPathNamespace::XPATH_NAMESPACE_NODE) {
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
}
NS_ENSURE_ARG(aResult);
*aResult = nsnull;
nsAutoPtr<txXPathNode> contextNode(txXPathNativeNode::createXPathNode(aContextNode));
if (!contextNode) {
return NS_ERROR_OUT_OF_MEMORY;
}
EvalContextImpl eContext(*contextNode, mRecycler);
nsRefPtr<txAExprResult> exprResult;
rv = mExpression->evaluate(&eContext, getter_AddRefs(exprResult));
NS_ENSURE_SUCCESS(rv, rv);
PRUint16 resultType = aType;
if (aType == nsIDOMXPathResult::ANY_TYPE) {
short exprResultType = exprResult->getResultType();
switch (exprResultType) {
case txAExprResult::NUMBER:
resultType = nsIDOMXPathResult::NUMBER_TYPE;
break;
case txAExprResult::STRING:
resultType = nsIDOMXPathResult::STRING_TYPE;
break;
case txAExprResult::BOOLEAN:
resultType = nsIDOMXPathResult::BOOLEAN_TYPE;
break;
case txAExprResult::NODESET:
resultType = nsIDOMXPathResult::UNORDERED_NODE_ITERATOR_TYPE;
break;
case txAExprResult::RESULT_TREE_FRAGMENT:
NS_ERROR("Can't return a tree fragment!");
return NS_ERROR_FAILURE;
}
}
// We need a result object and it must be our implementation.
nsCOMPtr<nsIXPathResult> xpathResult = do_QueryInterface(aInResult);
if (!xpathResult) {
// Either no aInResult or not one of ours.
xpathResult = new nsXPathResult();
NS_ENSURE_TRUE(xpathResult, NS_ERROR_OUT_OF_MEMORY);
}
rv = xpathResult->SetExprResult(exprResult, resultType);
NS_ENSURE_SUCCESS(rv, rv);
return CallQueryInterface(xpathResult, aResult);
}
/*
* Implementation of the txIEvalContext private to nsXPathExpression
* EvalContextImpl bases on only one context node and no variables
*/
nsresult
nsXPathExpression::EvalContextImpl::getVariable(PRInt32 aNamespace,
nsIAtom* aLName,
txAExprResult*& aResult)
{
aResult = 0;
return NS_ERROR_INVALID_ARG;
}
MBool nsXPathExpression::EvalContextImpl::isStripSpaceAllowed(const txXPathNode& aNode)
{
return MB_FALSE;
}
void* nsXPathExpression::EvalContextImpl::getPrivateContext()
{
// we don't have a private context here.
return nsnull;
}
txResultRecycler* nsXPathExpression::EvalContextImpl::recycler()
{
return mRecycler;
}
void nsXPathExpression::EvalContextImpl::receiveError(const nsAString& aMsg,
nsresult aRes)
{
mLastError = aRes;
// forward aMsg to console service?
}
const txXPathNode& nsXPathExpression::EvalContextImpl::getContextNode()
{
return mContextNode;
}
PRUint32 nsXPathExpression::EvalContextImpl::size()
{
return 1;
}
PRUint32 nsXPathExpression::EvalContextImpl::position()
{
return 1;
}

Просмотреть файл

@ -1,98 +0,0 @@
/* -*- 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 TransforMiiX XSLT processor code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Peter Van der Beken <peterv@propagandism.org>
*
* 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 ***** */
#ifndef nsXPathExpression_h__
#define nsXPathExpression_h__
#include "nsIDOMXPathExpression.h"
#include "txIXPathContext.h"
#include "txResultRecycler.h"
#include "nsAutoPtr.h"
class Expr;
class txXPathNode;
/**
* A class for evaluating an XPath expression string
*/
class nsXPathExpression : public nsIDOMXPathExpression
{
public:
nsXPathExpression(nsAutoPtr<Expr>& aExpression,
txResultRecycler* aRecycler);
virtual ~nsXPathExpression();
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIDOMXPathExpression interface
NS_DECL_NSIDOMXPATHEXPRESSION
private:
nsAutoPtr<Expr> mExpression;
nsRefPtr<txResultRecycler> mRecycler;
class EvalContextImpl : public txIEvalContext
{
public:
EvalContextImpl(const txXPathNode& aContextNode, txResultRecycler* aRecycler)
: mContextNode(aContextNode),
mLastError(NS_OK),
mRecycler(aRecycler)
{
}
~EvalContextImpl()
{
}
nsresult getError()
{
return mLastError;
}
TX_DECL_EVAL_CONTEXT;
private:
const txXPathNode& mContextNode;
nsresult mLastError;
nsRefPtr<txResultRecycler> mRecycler;
};
};
#endif