content/xul/templates/src/nsXULTemplateQueryProcessorXML.h

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:52f1e5342635
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #ifndef nsXULTemplateQueryProcessorXML_h__
7 #define nsXULTemplateQueryProcessorXML_h__
8
9 #include "nsIXULTemplateBuilder.h"
10 #include "nsIXULTemplateQueryProcessor.h"
11
12 #include "nsISimpleEnumerator.h"
13 #include "nsString.h"
14 #include "nsCOMArray.h"
15 #include "nsRefPtrHashtable.h"
16 #include "nsIDOMElement.h"
17 #include "nsIDOMEventListener.h"
18 #include "nsIDOMXPathExpression.h"
19 #include "nsIDOMXPathEvaluator.h"
20 #include "nsIDOMXPathResult.h"
21 #include "nsXMLBinding.h"
22 #include "nsCycleCollectionParticipant.h"
23 #include "nsIXMLHttpRequest.h"
24 #include "mozilla/Attributes.h"
25
26 class nsXULTemplateQueryProcessorXML;
27
28 #define NS_IXMLQUERY_IID \
29 {0x0358d692, 0xccce, 0x4a97, \
30 { 0xb2, 0x51, 0xba, 0x8f, 0x17, 0x0f, 0x3b, 0x6f }}
31
32 class nsXMLQuery MOZ_FINAL : public nsISupports
33 {
34 public:
35 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IXMLQUERY_IID)
36
37 NS_DECL_ISUPPORTS
38
39 // return a weak reference to the processor the query was created from
40 nsXULTemplateQueryProcessorXML* Processor() { return mProcessor; }
41
42 // return a weak reference t the member variable for the query
43 nsIAtom* GetMemberVariable() { return mMemberVariable; }
44
45 // return a weak reference to the expression used to generate results
46 nsIDOMXPathExpression* GetResultsExpression() { return mResultsExpr; }
47
48 // return a weak reference to the additional required bindings
49 nsXMLBindingSet* GetBindingSet() { return mRequiredBindings; }
50
51 // add a required binding for the query
52 nsresult
53 AddBinding(nsIAtom* aVar, nsIDOMXPathExpression* aExpr)
54 {
55 if (!mRequiredBindings) {
56 mRequiredBindings = new nsXMLBindingSet();
57 NS_ENSURE_TRUE(mRequiredBindings, NS_ERROR_OUT_OF_MEMORY);
58 }
59
60 return mRequiredBindings->AddBinding(aVar, aExpr);
61 }
62
63 nsXMLQuery(nsXULTemplateQueryProcessorXML* aProcessor,
64 nsIAtom* aMemberVariable,
65 nsIDOMXPathExpression* aResultsExpr)
66 : mProcessor(aProcessor),
67 mMemberVariable(aMemberVariable),
68 mResultsExpr(aResultsExpr)
69 { }
70
71 protected:
72 nsXULTemplateQueryProcessorXML* mProcessor;
73
74 nsCOMPtr<nsIAtom> mMemberVariable;
75
76 nsCOMPtr<nsIDOMXPathExpression> mResultsExpr;
77
78 nsRefPtr<nsXMLBindingSet> mRequiredBindings;
79 };
80
81 NS_DEFINE_STATIC_IID_ACCESSOR(nsXMLQuery, NS_IXMLQUERY_IID)
82
83 class nsXULTemplateResultSetXML MOZ_FINAL : public nsISimpleEnumerator
84 {
85 private:
86
87 // reference back to the query
88 nsCOMPtr<nsXMLQuery> mQuery;
89
90 // the binding set created from <assign> nodes
91 nsRefPtr<nsXMLBindingSet> mBindingSet;
92
93 // set of results contained in this enumerator
94 nsCOMPtr<nsIDOMXPathResult> mResults;
95
96 // current position within the list of results
97 uint32_t mPosition;
98
99 public:
100
101 // nsISupports interface
102 NS_DECL_ISUPPORTS
103
104 // nsISimpleEnumerator interface
105 NS_DECL_NSISIMPLEENUMERATOR
106
107 nsXULTemplateResultSetXML(nsXMLQuery* aQuery,
108 nsIDOMXPathResult* aResults,
109 nsXMLBindingSet* aBindingSet)
110 : mQuery(aQuery),
111 mBindingSet(aBindingSet),
112 mResults(aResults),
113 mPosition(0)
114 {}
115 };
116
117 class nsXULTemplateQueryProcessorXML MOZ_FINAL : public nsIXULTemplateQueryProcessor,
118 public nsIDOMEventListener
119 {
120 public:
121
122 nsXULTemplateQueryProcessorXML()
123 : mGenerationStarted(false)
124 {}
125
126 // nsISupports interface
127 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
128 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsXULTemplateQueryProcessorXML,
129 nsIXULTemplateQueryProcessor)
130
131 // nsIXULTemplateQueryProcessor interface
132 NS_DECL_NSIXULTEMPLATEQUERYPROCESSOR
133
134 // nsIDOMEventListener interface
135 NS_DECL_NSIDOMEVENTLISTENER
136
137 nsXMLBindingSet*
138 GetOptionalBindingsForRule(nsIDOMNode* aRuleNode);
139
140 // create an XPath expression from aExpr, using aNode for
141 // resolving namespaces
142 nsresult
143 CreateExpression(const nsAString& aExpr,
144 nsIDOMNode* aNode,
145 nsIDOMXPathExpression** aCompiledExpr);
146
147 private:
148
149 bool mGenerationStarted;
150
151 nsRefPtrHashtable<nsISupportsHashKey, nsXMLBindingSet> mRuleToBindingsMap;
152
153 nsCOMPtr<nsIDOMElement> mRoot;
154
155 nsCOMPtr<nsIDOMXPathEvaluator> mEvaluator;
156
157 nsCOMPtr<nsIXULTemplateBuilder> mTemplateBuilder;
158
159 nsCOMPtr<nsIXMLHttpRequest> mRequest;
160 };
161
162
163 #endif // nsXULTemplateQueryProcessorXML_h__

mercurial