New files for bug 103235 (Implement DOM Level 3 XPath WD). r=sicking, sr=jst, a=dbaron.

This commit is contained in:
peterv%netscape.com 2002-03-14 11:12:51 +00:00
Родитель 45c64478b8
Коммит f16c40594e
23 изменённых файлов: 2255 добавлений и 0 удалений

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

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

@ -0,0 +1 @@
Makefile

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

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

@ -0,0 +1,57 @@
# ***** 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
# 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@netscape.com> (original author)
#
# 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 *****
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = dom
XPIDL_MODULE = dom_xpath
XPIDLSRCS = \
nsIDOMXPathEvaluator.idl \
nsIDOMXPathException.idl \
nsIDOMXPathExpression.idl \
nsIDOMXPathNamespace.idl \
nsIDOMXPathNSResolver.idl \
nsIDOMXPathResult.idl \
$(NULL)
include $(topsrcdir)/config/rules.mk

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

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

@ -0,0 +1,66 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Peter Van der Beken <peterv@netscape.com> (original author)
*
*
* 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 NPL, 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 NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/**
* Corresponds to http://www.w3.org/TR/2002/WD-DOM-Level-3-XPath-20020208
*/
#include "domstubs.idl"
interface nsIDOMXPathNSResolver;
interface nsIDOMXPathResult;
interface nsIDOMXPathExpression;
interface XPathException;
[scriptable, uuid(75506f8a-b504-11d5-a7f2-ca108ab8b6fc)]
interface nsIDOMXPathEvaluator : nsISupports
{
nsIDOMXPathExpression createExpression(in DOMString expression,
in nsIDOMXPathNSResolver resolver)
raises(XPathException,
DOMException);
nsIDOMXPathNSResolver createNSResolver(in nsIDOMNode nodeResolver);
nsIDOMXPathResult evaluate(in DOMString expression,
in nsIDOMNode contextNode,
in nsIDOMXPathNSResolver resolver,
in unsigned short type,
in nsIDOMXPathResult result)
raises(XPathException,
DOMException);
};

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

@ -0,0 +1,54 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Peter Van der Beken <peterv@netscape.com> (original author)
*
*
* 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 NPL, 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 NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/**
* Corresponds to http://www.w3.org/TR/2002/WD-DOM-Level-3-XPath-20020208
*/
#include "domstubs.idl"
[scriptable, uuid(75506f89-b504-11d5-a7f2-ca108ab8b6fc)]
interface nsIDOMXPathException : nsISupports
{
// XPathExceptionCode
const unsigned short INVALID_EXPRESSION_ERR = 1;
const unsigned short TYPE_ERR = 2;
readonly attribute unsigned short code;
};

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

@ -0,0 +1,57 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Peter Van der Beken <peterv@netscape.com> (original author)
*
*
* 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 NPL, 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 NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/**
* Corresponds to http://www.w3.org/TR/2002/WD-DOM-Level-3-XPath-20020208
*/
#include "domstubs.idl"
interface nsIDOMXPathResult;
interface XPathException;
[scriptable, uuid(75506f82-b504-11d5-a7f2-ca108ab8b6fc)]
interface nsIDOMXPathExpression : nsISupports
{
nsIDOMXPathResult evaluate(in nsIDOMNode contextNode,
in unsigned short type,
in nsIDOMXPathResult result)
raises(XPathException,
DOMException);
};

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

@ -0,0 +1,50 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Peter Van der Beken <peterv@netscape.com> (original author)
*
*
* 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 NPL, 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 NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/**
* Corresponds to http://www.w3.org/TR/2002/WD-DOM-Level-3-XPath-20020208
*/
#include "domstubs.idl"
[scriptable, function, uuid(75506f83-b504-11d5-a7f2-ca108ab8b6fc)]
interface nsIDOMXPathNSResolver : nsISupports
{
DOMString lookupNamespaceURI(in DOMString prefix);
};

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

@ -0,0 +1,53 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Peter Van der Beken <peterv@netscape.com> (original author)
*
*
* 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 NPL, 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 NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/**
* Corresponds to http://www.w3.org/TR/2002/WD-DOM-Level-3-XPath-20020208
*/
#include "nsIDOMNode.idl"
[scriptable, uuid(75506f87-b504-11d5-a7f2-ca108ab8b6fc)]
interface nsIDOMXPathNamespace : nsIDOMNode
{
// XPathNodeType
const unsigned short XPATH_NAMESPACE_NODE = 13;
readonly attribute nsIDOMElement ownerElement;
};

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

@ -0,0 +1,85 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Peter Van der Beken <peterv@netscape.com> (original author)
*
*
* 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 NPL, 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 NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/**
* Corresponds to http://www.w3.org/TR/2002/WD-DOM-Level-3-XPath-20020208
*/
#include "domstubs.idl"
interface XPathException;
[scriptable, uuid(75506f84-b504-11d5-a7f2-ca108ab8b6fc)]
interface nsIDOMXPathResult : nsISupports
{
// XPathResultType
const unsigned short ANY_TYPE = 0;
const unsigned short NUMBER_TYPE = 1;
const unsigned short STRING_TYPE = 2;
const unsigned short BOOLEAN_TYPE = 3;
const unsigned short UNORDERED_NODE_ITERATOR_TYPE = 4;
const unsigned short ORDERED_NODE_ITERATOR_TYPE = 5;
const unsigned short UNORDERED_NODE_SNAPSHOT_TYPE = 6;
const unsigned short ORDERED_NODE_SNAPSHOT_TYPE = 7;
const unsigned short ANY_UNORDERED_NODE_TYPE = 8;
const unsigned short FIRST_ORDERED_NODE_TYPE = 9;
readonly attribute unsigned short resultType;
readonly attribute double numberValue;
// raises(XPathException) on retrieval
readonly attribute DOMString stringValue;
// raises(XPathException) on retrieval
readonly attribute boolean booleanValue;
// raises(XPathException) on retrieval
readonly attribute nsIDOMNode singleNodeValue;
// raises(XPathException) on retrieval
readonly attribute boolean invalidIteratorState;
readonly attribute unsigned long snapshotLength;
// raises(XPathException) on retrieval
nsIDOMNode iterateNext()
raises(XPathException,
DOMException);
nsIDOMNode snapshotItem(in unsigned long index)
raises(XPathException);
};

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

@ -0,0 +1,116 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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
* 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@netscape.com> (original author)
*
*
* 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 NPL, 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 NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsXPathEvaluator.h"
#include "nsCOMPtr.h"
#include "nsIDOMClassInfo.h"
#include "nsXPathException.h"
#include "nsXPathExpression.h"
#include "nsXPathNSResolver.h"
#include "nsXPathResult.h"
#include "ProcessorState.h"
NS_IMPL_ADDREF(nsXPathEvaluator)
NS_IMPL_RELEASE(nsXPathEvaluator)
NS_INTERFACE_MAP_BEGIN(nsXPathEvaluator)
NS_INTERFACE_MAP_ENTRY(nsIDOMXPathEvaluator)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMXPathEvaluator)
NS_INTERFACE_MAP_ENTRY_EXTERNAL_DOM_CLASSINFO(XPathEvaluator)
NS_INTERFACE_MAP_END
nsXPathEvaluator::nsXPathEvaluator()
{
NS_INIT_ISUPPORTS();
}
nsXPathEvaluator::~nsXPathEvaluator()
{
}
NS_IMETHODIMP
nsXPathEvaluator::CreateExpression(const nsAReadableString & aExpression,
nsIDOMXPathNSResolver *aResolver,
nsIDOMXPathExpression **aResult)
{
String expressionString(PromiseFlatString(aExpression).get());
// XXX (pvdb) TODO Set the right resolver on the ExprParser
Expr* expression = mParser.createExpr(expressionString);
if (!expression)
return NS_ERROR_DOM_INVALID_EXPRESSION_ERR;
*aResult = new nsXPathExpression(expression);
if (!*aResult) {
delete expression;
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(*aResult);
return NS_OK;
}
NS_IMETHODIMP
nsXPathEvaluator::CreateNSResolver(nsIDOMNode *aNodeResolver,
nsIDOMXPathNSResolver **aResult)
{
NS_ENSURE_ARG(aNodeResolver);
*aResult = new nsXPathNSResolver(aNodeResolver);
NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY);
NS_ADDREF(*aResult);
return NS_OK;
}
NS_IMETHODIMP
nsXPathEvaluator::Evaluate(const nsAString & aExpression,
nsIDOMNode *aContextNode,
nsIDOMXPathNSResolver *aResolver,
PRUint16 aType,
nsIDOMXPathResult *aInResult,
nsIDOMXPathResult **aResult)
{
// XXX Need to check document of aContextNode if created by
// QI'ing a document.
nsCOMPtr<nsIDOMXPathExpression> expression;
nsresult rv = CreateExpression(aExpression, aResolver,
getter_AddRefs(expression));
NS_ENSURE_SUCCESS(rv, rv);
return expression->Evaluate(aContextNode, aType, aInResult, aResult);
}

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

@ -0,0 +1,72 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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
* 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@netscape.com> (original author)
*
*
* 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 NPL, 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 NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsXPathEvaluator_h__
#define nsXPathEvaluator_h__
#include "nsIDOMXPathEvaluator.h"
#include "ExprParser.h"
/**
* A class for evaluating an XPath expression string
*/
class nsXPathEvaluator : public nsIDOMXPathEvaluator
{
public:
nsXPathEvaluator();
virtual ~nsXPathEvaluator();
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIDOMXPathEvaluator interface
NS_DECL_NSIDOMXPATHEVALUATOR
private:
ExprParser mParser;
};
/* d0a75e02-b5e7-11d5-a7f2-df109fb8a1fc */
#define TRANSFORMIIX_XPATH_EVALUATOR_CID \
{ 0xd0a75e02, 0xb5e7, 0x11d5, { 0xa7, 0xf2, 0xdf, 0x10, 0x9f, 0xb8, 0xa1, 0xfc } }
#define TRANSFORMIIX_XPATH_EVALUATOR_CONTRACTID \
"@mozilla.org/transformiix/xpath-evaluator;1"
#endif

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

@ -0,0 +1,282 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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
* 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@netscape.com> (original author)
*
*
* 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 NPL, 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 NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsXPathException.h"
#include "nsCRT.h"
#include "nsIDOMClassInfo.h"
#include "nsString.h"
#include "prprf.h"
NS_IMPL_ISUPPORTS1(nsXPathExceptionProvider, nsIExceptionProvider)
nsXPathExceptionProvider::nsXPathExceptionProvider()
{
NS_INIT_ISUPPORTS();
}
nsXPathExceptionProvider::~nsXPathExceptionProvider()
{
}
NS_IMETHODIMP
nsXPathExceptionProvider::GetException(nsresult aNSResult,
nsIException *aDefaultException,
nsIException **aException)
{
NS_ENSURE_ARG_POINTER(aException);
*aException = new nsXPathException(aNSResult, aDefaultException);
NS_ENSURE_TRUE(*aException, NS_ERROR_OUT_OF_MEMORY);
NS_IF_ADDREF(*aException);
return NS_OK;
}
NS_IMPL_ADDREF(nsXPathException)
NS_IMPL_RELEASE(nsXPathException)
NS_INTERFACE_MAP_BEGIN(nsXPathException)
NS_INTERFACE_MAP_ENTRY(nsIException)
NS_INTERFACE_MAP_ENTRY(nsIDOMXPathException)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIException)
NS_INTERFACE_MAP_ENTRY_EXTERNAL_DOM_CLASSINFO(XPathException)
NS_INTERFACE_MAP_END
nsXPathException::nsXPathException(nsresult aNSResult, nsIException* aInner)
: mResult(aNSResult),
mInner(aInner)
{
NS_INIT_ISUPPORTS();
}
nsXPathException::~nsXPathException()
{
}
NS_IMETHODIMP
nsXPathException::GetCode(PRUint16* aCode)
{
NS_ENSURE_ARG_POINTER(aCode);
if (NS_ERROR_GET_MODULE(mResult) == NS_ERROR_MODULE_DOM_XPATH) {
*aCode = NS_ERROR_GET_CODE(mResult);
} else {
NS_WARNING("Non DOM nsresult passed to a DOM exception!");
*aCode = (PRUint32)mResult;
}
return NS_OK;
}
NS_IMETHODIMP
nsXPathException::GetMessage(char **aMessage)
{
NS_ENSURE_ARG_POINTER(aMessage);
if (mResult == NS_ERROR_DOM_INVALID_EXPRESSION_ERR) {
*aMessage = nsCRT::strdup(NS_ERROR_DOM_INVALID_EXPRESSION_MSG);
}
else if (mResult == NS_ERROR_DOM_TYPE_ERR) {
*aMessage = nsCRT::strdup(NS_ERROR_DOM_TYPE_MSG);
}
else {
*aMessage = nsnull;
}
return NS_OK;
}
NS_IMETHODIMP
nsXPathException::GetResult(PRUint32* aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = mResult;
return NS_OK;
}
NS_IMETHODIMP
nsXPathException::GetName(char **aName)
{
NS_ENSURE_ARG_POINTER(aName);
if (mResult == NS_ERROR_DOM_INVALID_EXPRESSION_ERR) {
*aName = nsCRT::strdup("NS_ERROR_DOM_INVALID_EXPRESSION_ERR");
}
else if (mResult == NS_ERROR_DOM_TYPE_ERR) {
*aName = nsCRT::strdup("NS_ERROR_DOM_TYPE_ERR");
}
else {
*aName = nsnull;
}
return NS_OK;
}
NS_IMETHODIMP
nsXPathException::GetFilename(char **aFilename)
{
if (mInner) {
return mInner->GetFilename(aFilename);
}
NS_ENSURE_ARG_POINTER(aFilename);
*aFilename = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsXPathException::GetLineNumber(PRUint32 *aLineNumber)
{
if (mInner) {
return mInner->GetLineNumber(aLineNumber);
}
NS_ENSURE_ARG_POINTER(aLineNumber);
*aLineNumber = 0;
return NS_OK;
}
NS_IMETHODIMP
nsXPathException::GetColumnNumber(PRUint32 *aColumnNumber)
{
if (mInner) {
return mInner->GetColumnNumber(aColumnNumber);
}
NS_ENSURE_ARG_POINTER(aColumnNumber);
*aColumnNumber = 0;
return NS_OK;
}
NS_IMETHODIMP
nsXPathException::GetLocation(nsIStackFrame **aLocation)
{
if (mInner) {
return mInner->GetLocation(aLocation);
}
NS_ENSURE_ARG_POINTER(aLocation);
*aLocation = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsXPathException::GetInner(nsIException **aInner)
{
NS_ENSURE_ARG_POINTER(aInner);
*aInner = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsXPathException::GetData(nsISupports **aData)
{
if (mInner) {
return mInner->GetData(aData);
}
NS_ENSURE_ARG_POINTER(aData);
*aData = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsXPathException::ToString(char **aReturn)
{
*aReturn = nsnull;
static const char defaultMsg[] = "<no message>";
static const char defaultLocation[] = "<unknown>";
static const char defaultName[] = "<unknown>";
static const char format[] =
"[Exception... \"%s\" code: \"%d\" nsresult: \"0x%x (%s)\" location: \"%s\"]";
nsCAutoString location;
if (mInner) {
nsXPIDLCString filename;
mInner->GetFilename(getter_Copies(filename));
if (!filename.IsEmpty()) {
PRUint32 line_nr = 0;
mInner->GetLineNumber(&line_nr);
char *temp = PR_smprintf("%s Line: %d", filename.get(), line_nr);
if (temp) {
location.Assign(temp);
PR_smprintf_free(temp);
}
}
}
if (location.IsEmpty()) {
location = defaultLocation;
}
char* msg;
char* resultName;
PRUint16 code;
GetMessage(&msg);
GetName(&resultName);
GetCode(&code);
*aReturn = PR_smprintf(format, (msg ? msg : defaultMsg), code, mResult,
(resultName ? resultName : defaultName), location.get());
return *aReturn ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}

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

@ -0,0 +1,93 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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
* 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@netscape.com> (original author)
*
*
* 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 NPL, 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 NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsXPathException_h__
#define nsXPathException_h__
#include "nsCOMPtr.h"
#include "nsIDOMXPathException.h"
#include "nsIException.h"
#include "nsIExceptionService.h"
/* DOM error codes from http://www.w3.org/TR/DOM-Level-3-XPath */
#define NS_ERROR_DOM_INVALID_EXPRESSION_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_XPATH, 1)
#define NS_ERROR_DOM_TYPE_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_XPATH, 2)
#define NS_ERROR_DOM_INVALID_EXPRESSION_MSG "The expression is not a legal expression or it contains namespace prefixes that can't be resolved."
#define NS_ERROR_DOM_TYPE_MSG "The expression cannot be converted to return the specified type."
class nsXPathExceptionProvider : public nsIExceptionProvider
{
public:
nsXPathExceptionProvider();
virtual ~nsXPathExceptionProvider();
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIExceptionProvider interface
NS_DECL_NSIEXCEPTIONPROVIDER
};
/**
* A class for evaluating an XPath expression string
*/
class nsXPathException : public nsIException,
public nsIDOMXPathException
{
public:
nsXPathException(nsresult aNSResult, nsIException* aInner);
virtual ~nsXPathException();
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIException interface
NS_DECL_NSIEXCEPTION
// nsIDOMXPathException interface
NS_DECL_NSIDOMXPATHEXCEPTION
private:
nsresult mResult;
nsCOMPtr<nsIException> mInner;
};
#endif

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

@ -0,0 +1,154 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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
* 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@netscape.com> (original author)
*
*
* 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 NPL, 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 NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsXPathExpression.h"
#include "Expr.h"
#include "nsDOMError.h"
#include "nsIDOMClassInfo.h"
#include "nsIDOMXPathNamespace.h"
#include "nsXPathResult.h"
#include "ProcessorState.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(Expr* aExpression) : mExpression(aExpression)
{
NS_INIT_ISUPPORTS();
}
nsXPathExpression::~nsXPathExpression()
{
delete mExpression;
}
NS_IMETHODIMP
nsXPathExpression::Evaluate(nsIDOMNode *aContextNode,
PRUint16 aType,
nsIDOMXPathResult *aInResult,
nsIDOMXPathResult **aResult)
{
NS_ENSURE_ARG(aContextNode);
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;
nsCOMPtr<nsIDOMDocument> ownerDOMDocument;
aContextNode->GetOwnerDocument(getter_AddRefs(ownerDOMDocument));
if (!ownerDOMDocument) {
ownerDOMDocument = do_QueryInterface(aContextNode);
NS_ENSURE_TRUE(ownerDOMDocument, NS_ERROR_FAILURE);
}
Document document(ownerDOMDocument);
Node* node = document.createWrapper(aContextNode);
ProcessorState processorState;
ExprResult* exprResult = mExpression->evaluate(node, &processorState);
NS_ENSURE_TRUE(exprResult, NS_ERROR_OUT_OF_MEMORY);
PRUint16 resultType = aType;
if (aType == nsIDOMXPathResult::ANY_TYPE) {
short exprResultType = exprResult->getResultType();
switch (exprResultType) {
case ExprResult::NUMBER:
resultType = nsIDOMXPathResult::NUMBER_TYPE;
break;
case ExprResult::STRING:
resultType = nsIDOMXPathResult::STRING_TYPE;
break;
case ExprResult::BOOLEAN:
resultType = nsIDOMXPathResult::BOOLEAN_TYPE;
break;
case ExprResult::NODESET:
resultType = nsIDOMXPathResult::UNORDERED_NODE_ITERATOR_TYPE;
break;
case ExprResult::TREE_FRAGMENT:
NS_ERROR("Can't return a tree fragment!");
delete exprResult;
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);
delete exprResult;
NS_ENSURE_SUCCESS(rv, rv);
return CallQueryInterface(xpathResult, aResult);
}

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

@ -0,0 +1,66 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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
* 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@netscape.com> (original author)
*
*
* 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 NPL, 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 NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsXPathExpression_h__
#define nsXPathExpression_h__
#include "nsIDOMXPathExpression.h"
class Expr;
/**
* A class for evaluating an XPath expression string
*/
class nsXPathExpression : public nsIDOMXPathExpression
{
public:
nsXPathExpression(Expr* aExpression);
virtual ~nsXPathExpression();
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIDOMXPathExpression interface
NS_DECL_NSIDOMXPATHEXPRESSION
private:
Expr* mExpression;
};
#endif

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

@ -0,0 +1,70 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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
* 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@netscape.com> (original author)
*
*
* 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 NPL, 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 NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsXPathNSResolver.h"
#include "nsIDOMClassInfo.h"
NS_IMPL_ADDREF(nsXPathNSResolver)
NS_IMPL_RELEASE(nsXPathNSResolver)
NS_INTERFACE_MAP_BEGIN(nsXPathNSResolver)
NS_INTERFACE_MAP_ENTRY(nsIDOMXPathNSResolver)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMXPathNSResolver)
NS_INTERFACE_MAP_ENTRY_EXTERNAL_DOM_CLASSINFO(XPathNSResolver)
NS_INTERFACE_MAP_END
nsXPathNSResolver::nsXPathNSResolver(nsIDOMNode* aNode)
{
NS_INIT_ISUPPORTS();
mNode = do_QueryInterface(aNode);
NS_ASSERTION(mNode, "Need a node to resolve namespaces.");
}
nsXPathNSResolver::~nsXPathNSResolver()
{
}
NS_IMETHODIMP
nsXPathNSResolver::LookupNamespaceURI(const nsAString & aPrefix,
nsAString & aResult)
{
if (mNode)
return mNode->LookupNamespaceURI(aPrefix, aResult);
SetDOMStringToNull(aResult);
return NS_OK;
}

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

@ -0,0 +1,66 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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
* 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@netscape.com> (original author)
*
*
* 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 NPL, 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 NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsXPathNSResolver_h__
#define nsXPathNSResolver_h__
#include "nsIDOMXPathNSResolver.h"
#include "nsIDOMNode.h"
#include "nsCOMPtr.h"
/**
* A class for evaluating an XPath expression string
*/
class nsXPathNSResolver : public nsIDOMXPathNSResolver
{
public:
nsXPathNSResolver(nsIDOMNode* aNode);
virtual ~nsXPathNSResolver();
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIDOMXPathNSResolver interface
NS_DECL_NSIDOMXPATHNSRESOLVER
private:
nsCOMPtr<nsIDOM3Node> mNode;
};
#endif

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

@ -0,0 +1,212 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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
* 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@netscape.com> (original author)
*
*
* 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 NPL, 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 NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsXPathNamespace.h"
#include "nsIDOMClassInfo.h"
NS_IMPL_ADDREF(nsXPathNamespace)
NS_IMPL_RELEASE(nsXPathNamespace)
NS_INTERFACE_MAP_BEGIN(nsXPathNamespace)
NS_INTERFACE_MAP_ENTRY(nsIDOMXPathNamespace)
NS_INTERFACE_MAP_ENTRY(nsIDOMNode)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMXPathNamespace)
NS_INTERFACE_MAP_ENTRY_EXTERNAL_DOM_CLASSINFO(XPathNamespace)
NS_INTERFACE_MAP_END
nsXPathNamespace::nsXPathNamespace()
{
NS_INIT_ISUPPORTS();
}
nsXPathNamespace::~nsXPathNamespace()
{
}
/* readonly attribute DOMString nodeName; */
NS_IMETHODIMP nsXPathNamespace::GetNodeName(nsAString & aNodeName)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* attribute DOMString nodeValue; */
NS_IMETHODIMP nsXPathNamespace::GetNodeValue(nsAString & aNodeValue)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsXPathNamespace::SetNodeValue(const nsAString & aNodeValue)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* readonly attribute unsigned short nodeType; */
NS_IMETHODIMP nsXPathNamespace::GetNodeType(PRUint16 *aNodeType)
{
*aNodeType = XPATH_NAMESPACE_NODE;
return NS_OK;
}
/* readonly attribute nsIDOMNode parentNode; */
NS_IMETHODIMP nsXPathNamespace::GetParentNode(nsIDOMNode * *aParentNode)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* readonly attribute nsIDOMNodeList childNodes; */
NS_IMETHODIMP nsXPathNamespace::GetChildNodes(nsIDOMNodeList * *aChildNodes)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* readonly attribute nsIDOMNode firstChild; */
NS_IMETHODIMP nsXPathNamespace::GetFirstChild(nsIDOMNode * *aFirstChild)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* readonly attribute nsIDOMNode lastChild; */
NS_IMETHODIMP nsXPathNamespace::GetLastChild(nsIDOMNode * *aLastChild)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* readonly attribute nsIDOMNode previousSibling; */
NS_IMETHODIMP nsXPathNamespace::GetPreviousSibling(nsIDOMNode * *aPreviousSibling)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* readonly attribute nsIDOMNode nextSibling; */
NS_IMETHODIMP nsXPathNamespace::GetNextSibling(nsIDOMNode * *aNextSibling)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* readonly attribute nsIDOMNamedNodeMap attributes; */
NS_IMETHODIMP nsXPathNamespace::GetAttributes(nsIDOMNamedNodeMap * *aAttributes)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* readonly attribute nsIDOMDocument ownerDocument; */
NS_IMETHODIMP nsXPathNamespace::GetOwnerDocument(nsIDOMDocument * *aOwnerDocument)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* nsIDOMNode insertBefore (in nsIDOMNode newChild, in nsIDOMNode refChild) raises (DOMException); */
NS_IMETHODIMP nsXPathNamespace::InsertBefore(nsIDOMNode *newChild, nsIDOMNode *refChild, nsIDOMNode **aResult)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* nsIDOMNode replaceChild (in nsIDOMNode newChild, in nsIDOMNode oldChild) raises (DOMException); */
NS_IMETHODIMP nsXPathNamespace::ReplaceChild(nsIDOMNode *newChild, nsIDOMNode *oldChild, nsIDOMNode **aResult)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* nsIDOMNode removeChild (in nsIDOMNode oldChild) raises (DOMException); */
NS_IMETHODIMP nsXPathNamespace::RemoveChild(nsIDOMNode *oldChild, nsIDOMNode **aResult)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* nsIDOMNode appendChild (in nsIDOMNode newChild) raises (DOMException); */
NS_IMETHODIMP nsXPathNamespace::AppendChild(nsIDOMNode *newChild, nsIDOMNode **aResult)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* boolean hasChildNodes (); */
NS_IMETHODIMP nsXPathNamespace::HasChildNodes(PRBool *aResult)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* nsIDOMNode cloneNode (in boolean deep); */
NS_IMETHODIMP nsXPathNamespace::CloneNode(PRBool deep, nsIDOMNode **aResult)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void normalize (); */
NS_IMETHODIMP nsXPathNamespace::Normalize()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* boolean isSupported (in DOMString feature, in DOMString version); */
NS_IMETHODIMP nsXPathNamespace::IsSupported(const nsAString & feature, const nsAString & version, PRBool *aResult)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* readonly attribute DOMString namespaceURI; */
NS_IMETHODIMP nsXPathNamespace::GetNamespaceURI(nsAString & aNamespaceURI)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* attribute DOMString prefix; */
NS_IMETHODIMP nsXPathNamespace::GetPrefix(nsAString & aPrefix)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsXPathNamespace::SetPrefix(const nsAString & aPrefix)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* readonly attribute DOMString localName; */
NS_IMETHODIMP nsXPathNamespace::GetLocalName(nsAString & aLocalName)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* boolean hasAttributes (); */
NS_IMETHODIMP nsXPathNamespace::HasAttributes(PRBool *aResult)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* readonly attribute nsIDOMElement ownerElement; */
NS_IMETHODIMP nsXPathNamespace::GetOwnerElement(nsIDOMElement * *aOwnerElement)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

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

@ -0,0 +1,71 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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
* 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@netscape.com> (original author)
*
*
* 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 NPL, 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 NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsXPathNamespace_h__
#define nsXPathNamespace_h__
#include "nsIDOMXPathNamespace.h"
/* d0a75e07-b5e7-11d5-a7f2-df109fb8a1fc */
#define TRANSFORMIIX_XPATH_NAMESPACE_CID \
{ 0xd0a75e07, 0xb5e7, 0x11d5, { 0xa7, 0xf2, 0xdf, 0x10, 0x9f, 0xb8, 0xa1, 0xfc } }
#define TRANSFORMIIX_XPATH_NAMESPACE_CONTRACTID \
"@mozilla.org/transformiix/xpath-namespace;1"
/**
* A class for representing XPath namespace nodes in the DOM.
*/
class nsXPathNamespace : public nsIDOMXPathNamespace
{
public:
nsXPathNamespace();
virtual ~nsXPathNamespace();
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIDOMNode interface
NS_DECL_NSIDOMNODE
// nsIDOMXPathNamespace interface
NS_DECL_NSIDOMXPATHNAMESPACE
};
#endif

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

@ -0,0 +1,472 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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
* 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@netscape.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 NPL, 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 NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsXPathResult.h"
#include "ExprResult.h"
#include "NodeSet.h"
#include "nsDOMError.h"
#include "nsIContent.h"
#include "nsIDOMClassInfo.h"
#include "nsSupportsArray.h"
#include "nsXPathException.h"
NS_IMPL_ADDREF(nsXPathResult)
NS_IMPL_RELEASE(nsXPathResult)
NS_INTERFACE_MAP_BEGIN(nsXPathResult)
NS_INTERFACE_MAP_ENTRY(nsIDOMXPathResult)
NS_INTERFACE_MAP_ENTRY(nsIDocumentObserver)
NS_INTERFACE_MAP_ENTRY(nsIXPathResult)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMXPathResult)
NS_INTERFACE_MAP_ENTRY_EXTERNAL_DOM_CLASSINFO(XPathResult)
NS_INTERFACE_MAP_END
nsXPathResult::nsXPathResult() : mNumberValue(0),
mDocument(0),
mCurrentPos(0),
mResultType(ANY_TYPE),
mInvalidIteratorState(PR_TRUE)
{
NS_INIT_ISUPPORTS();
}
nsXPathResult::~nsXPathResult()
{
Reset();
}
NS_IMETHODIMP
nsXPathResult::GetResultType(PRUint16 *aResultType)
{
NS_ENSURE_ARG(aResultType);
*aResultType = mResultType;
return NS_OK;
}
NS_IMETHODIMP
nsXPathResult::GetNumberValue(double *aNumberValue)
{
if (mResultType != NUMBER_TYPE)
return NS_ERROR_DOM_TYPE_ERR;
NS_ENSURE_ARG(aNumberValue);
*aNumberValue = mNumberValue;
return NS_OK;
}
NS_IMETHODIMP
nsXPathResult::GetStringValue(nsAString &aStringValue)
{
if (mResultType != STRING_TYPE)
return NS_ERROR_DOM_TYPE_ERR;
if (mStringValue)
aStringValue.Assign(mStringValue->getConstNSString());
else
SetDOMStringToNull(aStringValue);
return NS_OK;
}
NS_IMETHODIMP
nsXPathResult::GetBooleanValue(PRBool *aBooleanValue)
{
if (mResultType != BOOLEAN_TYPE)
return NS_ERROR_DOM_TYPE_ERR;
NS_ENSURE_ARG(aBooleanValue);
*aBooleanValue = mBooleanValue;
return NS_OK;
}
NS_IMETHODIMP
nsXPathResult::GetSingleNodeValue(nsIDOMNode **aSingleNodeValue)
{
if (mResultType != FIRST_ORDERED_NODE_TYPE &&
mResultType != ANY_UNORDERED_NODE_TYPE)
return NS_ERROR_DOM_TYPE_ERR;
NS_ENSURE_ARG(aSingleNodeValue);
*aSingleNodeValue = mNode;
NS_IF_ADDREF(*aSingleNodeValue);
return NS_OK;
}
NS_IMETHODIMP
nsXPathResult::GetInvalidIteratorState(PRBool *aInvalidIteratorState)
{
NS_ENSURE_ARG(aInvalidIteratorState);
if (mResultType != UNORDERED_NODE_ITERATOR_TYPE &&
mResultType != ORDERED_NODE_ITERATOR_TYPE) {
*aInvalidIteratorState = PR_FALSE;
return NS_OK;
}
*aInvalidIteratorState = mInvalidIteratorState;
return NS_OK;
}
NS_IMETHODIMP
nsXPathResult::GetSnapshotLength(PRUint32 *aSnapshotLength)
{
if (mResultType != UNORDERED_NODE_SNAPSHOT_TYPE &&
mResultType != ORDERED_NODE_SNAPSHOT_TYPE)
return NS_ERROR_DOM_TYPE_ERR;
NS_ENSURE_ARG(aSnapshotLength);
if (mElements)
return mElements->Count(aSnapshotLength);
*aSnapshotLength = 0;
return NS_OK;
}
NS_IMETHODIMP
nsXPathResult::IterateNext(nsIDOMNode **aResult)
{
if (mResultType != UNORDERED_NODE_ITERATOR_TYPE &&
mResultType != ORDERED_NODE_ITERATOR_TYPE)
return NS_ERROR_DOM_TYPE_ERR;
if (mDocument)
mDocument->FlushPendingNotifications(PR_FALSE);
if (mInvalidIteratorState)
return NS_ERROR_DOM_INVALID_STATE_ERR;
NS_ENSURE_ARG(aResult);
if (mElements) {
PRUint32 count;
mElements->Count(&count);
if (mCurrentPos < count) {
return mElements->QueryElementAt(mCurrentPos++,
NS_GET_IID(nsIDOMNode),
(void**)aResult);
}
}
*aResult = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsXPathResult::SnapshotItem(PRUint32 aIndex, nsIDOMNode **aResult)
{
if (mResultType != UNORDERED_NODE_SNAPSHOT_TYPE &&
mResultType != ORDERED_NODE_SNAPSHOT_TYPE)
return NS_ERROR_DOM_TYPE_ERR;
NS_ENSURE_ARG(aResult);
if (mElements) {
PRUint32 count;
mElements->Count(&count);
if (aIndex < count) {
return mElements->QueryElementAt(aIndex,
NS_GET_IID(nsIDOMNode),
(void**)aResult);
}
}
*aResult = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsXPathResult::BeginUpdate(nsIDocument* aDocument)
{
return NS_OK;
}
NS_IMETHODIMP
nsXPathResult::EndUpdate(nsIDocument* aDocument)
{
return NS_OK;
}
NS_IMETHODIMP
nsXPathResult::BeginLoad(nsIDocument* aDocument)
{
return NS_OK;
}
NS_IMETHODIMP
nsXPathResult::EndLoad(nsIDocument* aDocument)
{
return NS_OK;
}
NS_IMETHODIMP
nsXPathResult::BeginReflow(nsIDocument* aDocument,
nsIPresShell* aShell)
{
return NS_OK;
}
NS_IMETHODIMP
nsXPathResult::EndReflow(nsIDocument* aDocument,
nsIPresShell* aShell)
{
return NS_OK;
}
NS_IMETHODIMP
nsXPathResult::ContentChanged(nsIDocument* aDocument,
nsIContent *aContent,
nsISupports *aSubContent)
{
return NS_OK;
}
NS_IMETHODIMP
nsXPathResult::ContentStatesChanged(nsIDocument* aDocument,
nsIContent* aContent1,
nsIContent* aContent2,
nsIAtom* aChangedPseudoClass)
{
return NS_OK;
}
NS_IMETHODIMP
nsXPathResult::AttributeChanged(nsIDocument* aDocument,
nsIContent* aContent,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aModType,
PRInt32 aHint)
{
Invalidate();
return NS_OK;
}
NS_IMETHODIMP
nsXPathResult::ContentAppended(nsIDocument* aDocument,
nsIContent* aContainer,
PRInt32 aNewIndexInContainer)
{
Invalidate();
return NS_OK;
}
NS_IMETHODIMP
nsXPathResult::ContentInserted(nsIDocument* aDocument,
nsIContent* aContainer,
nsIContent* aChild,
PRInt32 aIndexInContainer)
{
Invalidate();
return NS_OK;
}
NS_IMETHODIMP
nsXPathResult::ContentReplaced(nsIDocument* aDocument,
nsIContent* aContainer,
nsIContent* aOldChild,
nsIContent* aNewChild,
PRInt32 aIndexInContainer)
{
Invalidate();
return NS_OK;
}
NS_IMETHODIMP
nsXPathResult::ContentRemoved(nsIDocument* aDocument,
nsIContent* aContainer,
nsIContent* aChild,
PRInt32 aIndexInContainer)
{
Invalidate();
return NS_OK;
}
NS_IMETHODIMP
nsXPathResult::StyleSheetAdded(nsIDocument* aDocument,
nsIStyleSheet* aStyleSheet)
{
return NS_OK;
}
NS_IMETHODIMP
nsXPathResult::StyleSheetRemoved(nsIDocument* aDocument,
nsIStyleSheet* aStyleSheet)
{
return NS_OK;
}
NS_IMETHODIMP
nsXPathResult::StyleSheetDisabledStateChanged(nsIDocument* aDocument,
nsIStyleSheet* aStyleSheet,
PRBool aDisabled)
{
return NS_OK;
}
NS_IMETHODIMP
nsXPathResult::StyleRuleChanged(nsIDocument* aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule,
PRInt32 aHint)
{
return NS_OK;
}
NS_IMETHODIMP
nsXPathResult::StyleRuleAdded(nsIDocument* aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule)
{
return NS_OK;
}
NS_IMETHODIMP
nsXPathResult::StyleRuleRemoved(nsIDocument* aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule)
{
return NS_OK;
}
NS_IMETHODIMP
nsXPathResult::DocumentWillBeDestroyed(nsIDocument* aDocument)
{
Invalidate();
return NS_OK;
}
NS_IMETHODIMP
nsXPathResult::SetExprResult(ExprResult* aExprResult, PRUint16 aResultType)
{
Reset();
mResultType = aResultType;
if (mResultType == NUMBER_TYPE) {
mNumberValue = aExprResult->numberValue();
return NS_OK;
}
if (mResultType == STRING_TYPE) {
mStringValue = new String;
NS_ENSURE_TRUE(mStringValue, NS_ERROR_OUT_OF_MEMORY);
aExprResult->stringValue(*mStringValue);
return NS_OK;
}
if (mResultType == BOOLEAN_TYPE) {
mBooleanValue = aExprResult->booleanValue();
return NS_OK;
}
if (aExprResult->getResultType() == ExprResult::NODESET) {
nsresult rv = NS_OK;
NodeSet* nodeSet = (NodeSet*)aExprResult;
if (mResultType == FIRST_ORDERED_NODE_TYPE ||
mResultType == ANY_UNORDERED_NODE_TYPE) {
Node* node = nodeSet->get(0);
if (node)
rv = CallQueryInterface(node->getNSObj(), &mNode);
}
else {
if (mResultType == UNORDERED_NODE_ITERATOR_TYPE ||
mResultType == ORDERED_NODE_ITERATOR_TYPE) {
mInvalidIteratorState = PR_FALSE;
}
int count = nodeSet->size();
if (count == 0)
return NS_OK;
NS_NewISupportsArray(&mElements);
NS_ENSURE_TRUE(mElements, NS_ERROR_OUT_OF_MEMORY);
nsISupports* mozNode = nsnull;
int i;
for (i = 0; i < count; ++i) {
mozNode = nodeSet->get(i)->getNSObj();
mElements->AppendElement(mozNode);
NS_ADDREF(mozNode);
}
if (mResultType == UNORDERED_NODE_ITERATOR_TYPE ||
mResultType == ORDERED_NODE_ITERATOR_TYPE) {
nsCOMPtr<nsIContent> content = do_QueryInterface(mozNode);
if (content)
content->GetDocument(*getter_AddRefs(mDocument));
else
mDocument = do_QueryInterface(mozNode);
NS_ASSERTION(mDocument, "We need a document!");
if (mDocument)
mDocument->AddObserver(this);
}
}
return rv;
}
return NS_ERROR_DOM_TYPE_ERR;
}
void
nsXPathResult::Invalidate()
{
if (mDocument) {
mDocument->RemoveObserver(this);
mDocument = 0;
}
mInvalidIteratorState = PR_TRUE;
}
void
nsXPathResult::Reset()
{
Invalidate();
if (mResultType == STRING_TYPE) {
delete mStringValue;
mStringValue = 0;
}
else if (mResultType == UNORDERED_NODE_ITERATOR_TYPE ||
mResultType == ORDERED_NODE_ITERATOR_TYPE ||
mResultType == UNORDERED_NODE_SNAPSHOT_TYPE ||
mResultType == ORDERED_NODE_SNAPSHOT_TYPE) {
NS_IF_RELEASE(mElements);
mCurrentPos = 0;
}
else if (mResultType == FIRST_ORDERED_NODE_TYPE ||
mResultType == ANY_UNORDERED_NODE_TYPE) {
NS_IF_RELEASE(mNode);
}
mResultType = ANY_TYPE;
return;
}

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

@ -0,0 +1,158 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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
* 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@netscape.com> (original author)
*
*
* 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 NPL, 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 NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsXPathResult_h__
#define nsXPathResult_h__
#include "nsIDOMXPathResult.h"
#include "nsIDocument.h"
#include "nsIDocumentObserver.h"
#include "nsCOMPtr.h"
class ExprResult;
class String;
class nsISupportsArray;
// {15b9b301-2012-11d6-a7f2-e6d0a678995c}
#define NS_IXPATHRESULT_IID \
{ 0x15b9b301, 0x2012, 0x11d6, {0xa7, 0xf2, 0xe6, 0xd0, 0xa6, 0x78, 0x99, 0x5c }};
class nsIXPathResult : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IXPATHRESULT_IID)
NS_IMETHOD SetExprResult(ExprResult* aExprResult,
PRUint16 aResultType) = 0;
};
/**
* A class for evaluating an XPath expression string
*/
class nsXPathResult : public nsIDOMXPathResult,
public nsIDocumentObserver,
public nsIXPathResult
{
public:
nsXPathResult();
virtual ~nsXPathResult();
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIDOMXPathResult interface
NS_DECL_NSIDOMXPATHRESULT
// nsIDocumentObserver interface
NS_IMETHOD BeginUpdate(nsIDocument* aDocument);
NS_IMETHOD EndUpdate(nsIDocument* aDocument);
NS_IMETHOD BeginLoad(nsIDocument* aDocument);
NS_IMETHOD EndLoad(nsIDocument* aDocument);
NS_IMETHOD BeginReflow(nsIDocument* aDocument,
nsIPresShell* aShell);
NS_IMETHOD EndReflow(nsIDocument* aDocument,
nsIPresShell* aShell);
NS_IMETHOD ContentChanged(nsIDocument* aDocument,
nsIContent* aContent,
nsISupports* aSubContent);
NS_IMETHOD ContentStatesChanged(nsIDocument* aDocument,
nsIContent* aContent1,
nsIContent* aContent2,
nsIAtom* aChangedPseudoClass);
NS_IMETHOD AttributeChanged(nsIDocument* aDocument,
nsIContent* aContent,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aModType,
PRInt32 aHint);
NS_IMETHOD ContentAppended(nsIDocument* aDocument,
nsIContent* aContainer,
PRInt32 aNewIndexInContainer);
NS_IMETHOD ContentInserted(nsIDocument* aDocument,
nsIContent* aContainer,
nsIContent* aChild,
PRInt32 aIndexInContainer);
NS_IMETHOD ContentReplaced(nsIDocument* aDocument,
nsIContent* aContainer,
nsIContent* aOldChild,
nsIContent* aNewChild,
PRInt32 aIndexInContainer);
NS_IMETHOD ContentRemoved(nsIDocument* aDocument,
nsIContent* aContainer,
nsIContent* aChild,
PRInt32 aIndexInContainer);
NS_IMETHOD StyleSheetAdded(nsIDocument* aDocument,
nsIStyleSheet* aStyleSheet);
NS_IMETHOD StyleSheetRemoved(nsIDocument* aDocument,
nsIStyleSheet* aStyleSheet);
NS_IMETHOD StyleSheetDisabledStateChanged(nsIDocument* aDocument,
nsIStyleSheet* aStyleSheet,
PRBool aDisabled);
NS_IMETHOD StyleRuleChanged(nsIDocument* aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule,
PRInt32 aHint);
NS_IMETHOD StyleRuleAdded(nsIDocument* aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule);
NS_IMETHOD StyleRuleRemoved(nsIDocument* aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule);
NS_IMETHOD DocumentWillBeDestroyed(nsIDocument* aDocument);
// nsIXPathResult interface
NS_IMETHOD SetExprResult(ExprResult* aExprResult,
PRUint16 aResultType);
private:
void Invalidate();
void Reset();
union {
double mNumberValue;
String* mStringValue;
PRBool mBooleanValue;
nsIDOMNode* mNode;
nsISupportsArray* mElements;
};
nsCOMPtr<nsIDocument> mDocument;
PRUint32 mCurrentPos;
PRUint16 mResultType;
PRPackedBool mInvalidIteratorState;
};
#endif