michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsXULTemplateQueryProcessorXML_h__ michael@0: #define nsXULTemplateQueryProcessorXML_h__ michael@0: michael@0: #include "nsIXULTemplateBuilder.h" michael@0: #include "nsIXULTemplateQueryProcessor.h" michael@0: michael@0: #include "nsISimpleEnumerator.h" michael@0: #include "nsString.h" michael@0: #include "nsCOMArray.h" michael@0: #include "nsRefPtrHashtable.h" michael@0: #include "nsIDOMElement.h" michael@0: #include "nsIDOMEventListener.h" michael@0: #include "nsIDOMXPathExpression.h" michael@0: #include "nsIDOMXPathEvaluator.h" michael@0: #include "nsIDOMXPathResult.h" michael@0: #include "nsXMLBinding.h" michael@0: #include "nsCycleCollectionParticipant.h" michael@0: #include "nsIXMLHttpRequest.h" michael@0: #include "mozilla/Attributes.h" michael@0: michael@0: class nsXULTemplateQueryProcessorXML; michael@0: michael@0: #define NS_IXMLQUERY_IID \ michael@0: {0x0358d692, 0xccce, 0x4a97, \ michael@0: { 0xb2, 0x51, 0xba, 0x8f, 0x17, 0x0f, 0x3b, 0x6f }} michael@0: michael@0: class nsXMLQuery MOZ_FINAL : public nsISupports michael@0: { michael@0: public: michael@0: NS_DECLARE_STATIC_IID_ACCESSOR(NS_IXMLQUERY_IID) michael@0: michael@0: NS_DECL_ISUPPORTS michael@0: michael@0: // return a weak reference to the processor the query was created from michael@0: nsXULTemplateQueryProcessorXML* Processor() { return mProcessor; } michael@0: michael@0: // return a weak reference t the member variable for the query michael@0: nsIAtom* GetMemberVariable() { return mMemberVariable; } michael@0: michael@0: // return a weak reference to the expression used to generate results michael@0: nsIDOMXPathExpression* GetResultsExpression() { return mResultsExpr; } michael@0: michael@0: // return a weak reference to the additional required bindings michael@0: nsXMLBindingSet* GetBindingSet() { return mRequiredBindings; } michael@0: michael@0: // add a required binding for the query michael@0: nsresult michael@0: AddBinding(nsIAtom* aVar, nsIDOMXPathExpression* aExpr) michael@0: { michael@0: if (!mRequiredBindings) { michael@0: mRequiredBindings = new nsXMLBindingSet(); michael@0: NS_ENSURE_TRUE(mRequiredBindings, NS_ERROR_OUT_OF_MEMORY); michael@0: } michael@0: michael@0: return mRequiredBindings->AddBinding(aVar, aExpr); michael@0: } michael@0: michael@0: nsXMLQuery(nsXULTemplateQueryProcessorXML* aProcessor, michael@0: nsIAtom* aMemberVariable, michael@0: nsIDOMXPathExpression* aResultsExpr) michael@0: : mProcessor(aProcessor), michael@0: mMemberVariable(aMemberVariable), michael@0: mResultsExpr(aResultsExpr) michael@0: { } michael@0: michael@0: protected: michael@0: nsXULTemplateQueryProcessorXML* mProcessor; michael@0: michael@0: nsCOMPtr mMemberVariable; michael@0: michael@0: nsCOMPtr mResultsExpr; michael@0: michael@0: nsRefPtr mRequiredBindings; michael@0: }; michael@0: michael@0: NS_DEFINE_STATIC_IID_ACCESSOR(nsXMLQuery, NS_IXMLQUERY_IID) michael@0: michael@0: class nsXULTemplateResultSetXML MOZ_FINAL : public nsISimpleEnumerator michael@0: { michael@0: private: michael@0: michael@0: // reference back to the query michael@0: nsCOMPtr mQuery; michael@0: michael@0: // the binding set created from nodes michael@0: nsRefPtr mBindingSet; michael@0: michael@0: // set of results contained in this enumerator michael@0: nsCOMPtr mResults; michael@0: michael@0: // current position within the list of results michael@0: uint32_t mPosition; michael@0: michael@0: public: michael@0: michael@0: // nsISupports interface michael@0: NS_DECL_ISUPPORTS michael@0: michael@0: // nsISimpleEnumerator interface michael@0: NS_DECL_NSISIMPLEENUMERATOR michael@0: michael@0: nsXULTemplateResultSetXML(nsXMLQuery* aQuery, michael@0: nsIDOMXPathResult* aResults, michael@0: nsXMLBindingSet* aBindingSet) michael@0: : mQuery(aQuery), michael@0: mBindingSet(aBindingSet), michael@0: mResults(aResults), michael@0: mPosition(0) michael@0: {} michael@0: }; michael@0: michael@0: class nsXULTemplateQueryProcessorXML MOZ_FINAL : public nsIXULTemplateQueryProcessor, michael@0: public nsIDOMEventListener michael@0: { michael@0: public: michael@0: michael@0: nsXULTemplateQueryProcessorXML() michael@0: : mGenerationStarted(false) michael@0: {} michael@0: michael@0: // nsISupports interface michael@0: NS_DECL_CYCLE_COLLECTING_ISUPPORTS michael@0: NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsXULTemplateQueryProcessorXML, michael@0: nsIXULTemplateQueryProcessor) michael@0: michael@0: // nsIXULTemplateQueryProcessor interface michael@0: NS_DECL_NSIXULTEMPLATEQUERYPROCESSOR michael@0: michael@0: // nsIDOMEventListener interface michael@0: NS_DECL_NSIDOMEVENTLISTENER michael@0: michael@0: nsXMLBindingSet* michael@0: GetOptionalBindingsForRule(nsIDOMNode* aRuleNode); michael@0: michael@0: // create an XPath expression from aExpr, using aNode for michael@0: // resolving namespaces michael@0: nsresult michael@0: CreateExpression(const nsAString& aExpr, michael@0: nsIDOMNode* aNode, michael@0: nsIDOMXPathExpression** aCompiledExpr); michael@0: michael@0: private: michael@0: michael@0: bool mGenerationStarted; michael@0: michael@0: nsRefPtrHashtable mRuleToBindingsMap; michael@0: michael@0: nsCOMPtr mRoot; michael@0: michael@0: nsCOMPtr mEvaluator; michael@0: michael@0: nsCOMPtr mTemplateBuilder; michael@0: michael@0: nsCOMPtr mRequest; michael@0: }; michael@0: michael@0: michael@0: #endif // nsXULTemplateQueryProcessorXML_h__