2007-06-15 19:03:44 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-06-15 19:03:44 +04:00
|
|
|
|
|
|
|
#ifndef nsXULTemplateQueryProcessorXML_h__
|
|
|
|
#define nsXULTemplateQueryProcessorXML_h__
|
|
|
|
|
2007-07-19 17:49:29 +04:00
|
|
|
#include "nsIXULTemplateBuilder.h"
|
2007-06-15 19:03:44 +04:00
|
|
|
#include "nsIXULTemplateQueryProcessor.h"
|
|
|
|
|
2016-06-07 23:10:18 +03:00
|
|
|
#include "nsAutoPtr.h"
|
2007-06-15 19:03:44 +04:00
|
|
|
#include "nsISimpleEnumerator.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsCOMArray.h"
|
|
|
|
#include "nsRefPtrHashtable.h"
|
2007-07-19 17:49:29 +04:00
|
|
|
#include "nsIDOMEventListener.h"
|
2007-06-15 19:03:44 +04:00
|
|
|
#include "nsIDOMXPathEvaluator.h"
|
|
|
|
#include "nsXMLBinding.h"
|
2007-07-19 17:49:29 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2008-02-20 22:02:31 +03:00
|
|
|
#include "nsIXMLHttpRequest.h"
|
2012-06-19 06:30:09 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-06-27 23:39:50 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
|
|
|
#include "mozilla/dom/XPathEvaluator.h"
|
2013-07-04 19:40:06 +04:00
|
|
|
#include "mozilla/dom/XPathResult.h"
|
2007-06-15 19:03:44 +04:00
|
|
|
|
|
|
|
class nsXULTemplateQueryProcessorXML;
|
|
|
|
|
|
|
|
#define NS_IXMLQUERY_IID \
|
|
|
|
{0x0358d692, 0xccce, 0x4a97, \
|
|
|
|
{ 0xb2, 0x51, 0xba, 0x8f, 0x17, 0x0f, 0x3b, 0x6f }}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsXMLQuery final : public nsISupports
|
2007-06-15 19:03:44 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IXMLQUERY_IID)
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// return a weak reference to the processor the query was created from
|
|
|
|
nsXULTemplateQueryProcessorXML* Processor() { return mProcessor; }
|
|
|
|
|
|
|
|
// return a weak reference t the member variable for the query
|
|
|
|
nsIAtom* GetMemberVariable() { return mMemberVariable; }
|
|
|
|
|
|
|
|
// return a weak reference to the expression used to generate results
|
2014-06-27 23:39:50 +04:00
|
|
|
mozilla::dom::XPathExpression* GetResultsExpression()
|
|
|
|
{ return mResultsExpr; }
|
2007-06-15 19:03:44 +04:00
|
|
|
|
|
|
|
// return a weak reference to the additional required bindings
|
|
|
|
nsXMLBindingSet* GetBindingSet() { return mRequiredBindings; }
|
|
|
|
|
|
|
|
// add a required binding for the query
|
2013-07-04 19:40:10 +04:00
|
|
|
void
|
2014-06-27 23:39:50 +04:00
|
|
|
AddBinding(nsIAtom* aVar, nsAutoPtr<mozilla::dom::XPathExpression>&& aExpr)
|
2007-06-15 19:03:44 +04:00
|
|
|
{
|
|
|
|
if (!mRequiredBindings) {
|
|
|
|
mRequiredBindings = new nsXMLBindingSet();
|
|
|
|
}
|
|
|
|
|
2014-06-27 23:39:50 +04:00
|
|
|
mRequiredBindings->AddBinding(aVar, mozilla::Move(aExpr));
|
2007-06-15 19:03:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsXMLQuery(nsXULTemplateQueryProcessorXML* aProcessor,
|
2014-06-27 23:39:50 +04:00
|
|
|
nsIAtom* aMemberVariable,
|
|
|
|
nsAutoPtr<mozilla::dom::XPathExpression>&& aResultsExpr)
|
2007-06-15 19:03:44 +04:00
|
|
|
: mProcessor(aProcessor),
|
|
|
|
mMemberVariable(aMemberVariable),
|
|
|
|
mResultsExpr(aResultsExpr)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
protected:
|
2014-06-25 06:09:15 +04:00
|
|
|
~nsXMLQuery() {}
|
|
|
|
|
2007-06-15 19:03:44 +04:00
|
|
|
nsXULTemplateQueryProcessorXML* mProcessor;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> mMemberVariable;
|
|
|
|
|
2014-06-27 23:39:50 +04:00
|
|
|
nsAutoPtr<mozilla::dom::XPathExpression> mResultsExpr;
|
2007-06-15 19:03:44 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsXMLBindingSet> mRequiredBindings;
|
2007-06-15 19:03:44 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(nsXMLQuery, NS_IXMLQUERY_IID)
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsXULTemplateResultSetXML final : public nsISimpleEnumerator
|
2007-06-15 19:03:44 +04:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
// reference back to the query
|
|
|
|
nsCOMPtr<nsXMLQuery> mQuery;
|
|
|
|
|
|
|
|
// the binding set created from <assign> nodes
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsXMLBindingSet> mBindingSet;
|
2007-06-15 19:03:44 +04:00
|
|
|
|
|
|
|
// set of results contained in this enumerator
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::XPathResult> mResults;
|
2007-06-15 19:03:44 +04:00
|
|
|
|
|
|
|
// current position within the list of results
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mPosition;
|
2007-06-15 19:03:44 +04:00
|
|
|
|
2014-06-25 06:09:15 +04:00
|
|
|
~nsXULTemplateResultSetXML() {}
|
|
|
|
|
2007-06-15 19:03:44 +04:00
|
|
|
public:
|
|
|
|
|
|
|
|
// nsISupports interface
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsISimpleEnumerator interface
|
|
|
|
NS_DECL_NSISIMPLEENUMERATOR
|
|
|
|
|
|
|
|
nsXULTemplateResultSetXML(nsXMLQuery* aQuery,
|
2014-06-27 23:39:50 +04:00
|
|
|
already_AddRefed<mozilla::dom::XPathResult> aResults,
|
2007-06-15 19:03:44 +04:00
|
|
|
nsXMLBindingSet* aBindingSet)
|
|
|
|
: mQuery(aQuery),
|
|
|
|
mBindingSet(aBindingSet),
|
|
|
|
mResults(aResults),
|
|
|
|
mPosition(0)
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsXULTemplateQueryProcessorXML final : public nsIXULTemplateQueryProcessor,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsIDOMEventListener
|
2007-06-15 19:03:44 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
nsXULTemplateQueryProcessorXML()
|
2011-10-17 18:59:28 +04:00
|
|
|
: mGenerationStarted(false)
|
2007-06-15 19:03:44 +04:00
|
|
|
{}
|
|
|
|
|
|
|
|
// nsISupports interface
|
2007-07-19 17:49:29 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsXULTemplateQueryProcessorXML,
|
|
|
|
nsIXULTemplateQueryProcessor)
|
2007-06-15 19:03:44 +04:00
|
|
|
|
|
|
|
// nsIXULTemplateQueryProcessor interface
|
|
|
|
NS_DECL_NSIXULTEMPLATEQUERYPROCESSOR
|
|
|
|
|
2007-07-19 17:49:29 +04:00
|
|
|
// nsIDOMEventListener interface
|
|
|
|
NS_DECL_NSIDOMEVENTLISTENER
|
|
|
|
|
2007-06-15 19:03:44 +04:00
|
|
|
nsXMLBindingSet*
|
|
|
|
GetOptionalBindingsForRule(nsIDOMNode* aRuleNode);
|
|
|
|
|
|
|
|
// create an XPath expression from aExpr, using aNode for
|
|
|
|
// resolving namespaces
|
2014-06-27 23:39:50 +04:00
|
|
|
mozilla::dom::XPathExpression*
|
2007-06-15 19:03:44 +04:00
|
|
|
CreateExpression(const nsAString& aExpr,
|
2013-07-04 19:40:10 +04:00
|
|
|
nsINode* aNode,
|
2014-06-27 23:39:50 +04:00
|
|
|
mozilla::ErrorResult& aRv);
|
2007-06-15 19:03:44 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2014-06-25 06:09:15 +04:00
|
|
|
~nsXULTemplateQueryProcessorXML() {}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mGenerationStarted;
|
2007-06-15 19:03:44 +04:00
|
|
|
|
|
|
|
nsRefPtrHashtable<nsISupportsHashKey, nsXMLBindingSet> mRuleToBindingsMap;
|
|
|
|
|
2014-06-27 23:39:50 +04:00
|
|
|
nsCOMPtr<mozilla::dom::Element> mRoot;
|
2007-06-15 19:03:44 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::XPathEvaluator> mEvaluator;
|
2007-07-19 17:49:29 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIXULTemplateBuilder> mTemplateBuilder;
|
2008-02-20 22:02:31 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIXMLHttpRequest> mRequest;
|
2007-06-15 19:03:44 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // nsXULTemplateQueryProcessorXML_h__
|