content/xul/templates/public/nsIXULTemplateQueryProcessor.idl

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "domstubs.idl"
michael@0 7
michael@0 8 interface nsIAtom;
michael@0 9 interface nsIArray;
michael@0 10 interface nsISimpleEnumerator;
michael@0 11 interface nsIXULTemplateResult;
michael@0 12 interface nsIXULTemplateRuleFilter;
michael@0 13 interface nsIXULTemplateBuilder;
michael@0 14
michael@0 15 /**
michael@0 16 * A query processor takes a template query and generates results for it given
michael@0 17 * a datasource and a reference point. There is a one-to-one relationship
michael@0 18 * between a template builder and a query processor. The template builder
michael@0 19 * creates the query processor, and there is no other means to retrieve it.
michael@0 20 *
michael@0 21 * A template query is the contents inside a <query> element within the
michael@0 22 * template. The actual syntax is opaque to the template builder and defined
michael@0 23 * by a query processor. The query is expected to consist of either text or
michael@0 24 * DOM nodes that, when executed by a call to the generateResults method, will
michael@0 25 * allow the generation of a list of results.
michael@0 26 *
michael@0 27 * The template builder will supply two variables, the reference variable and
michael@0 28 * the member variable to further indicate what part of the datasource is to
michael@0 29 * be examined in addition to the query itself. The reference is always
michael@0 30 * a placeholder for the starting point and the member is always a placeholder
michael@0 31 * for the end points (the results).
michael@0 32 *
michael@0 33 * The reference point is important when generating output recursively, as
michael@0 34 * the query will be the same for each iteration, however, the reference point
michael@0 35 * will differ.
michael@0 36 *
michael@0 37 * For instance, when examining an XML source, an XML query processor might
michael@0 38 * begin at the node referred by the reference variable and end at a list of
michael@0 39 * that node's children.
michael@0 40 *
michael@0 41 * Some queries may not need the reference variable if the syntax or the form
michael@0 42 * of the data implies the value. For instance, a datasource that holds a
michael@0 43 * table that can only produce one set of results.
michael@0 44 *
michael@0 45 * The reference variable may be specified in a template by setting the
michael@0 46 * "container" attribute on the <template> element to the variable to use. The
michael@0 47 * member variable may be specified in a similar way using the "member"
michael@0 48 * attribute, or it may be specified in the first <action> body in the
michael@0 49 * template as the value of a uri attribute on an element. A breadth-first
michael@0 50 * search of the first action is performed to find this element.
michael@0 51 *
michael@0 52 * If unspecified, the default value of the reference variable is ?uri.
michael@0 53 *
michael@0 54 * For example, a query might have the following syntax:
michael@0 55 *
michael@0 56 * (?id, ?name, ?url) from Bookmarks where parentfolder = ?start
michael@0 57 *
michael@0 58 * This query might generate a result for each bookmark within a given folder.
michael@0 59 * The variable ?start would be the reference variable, while the variable ?id
michael@0 60 * would be the member variable, since it is the unique value that identifies
michael@0 61 * a result. Each result will have the four variables referred to defined for
michael@0 62 * it and the values may be retrieved using the result's getBindingFor and
michael@0 63 * getBindingObjectFor methods.
michael@0 64 *
michael@0 65 * The template builder must call initializeForBuilding before the other
michael@0 66 * methods, except for translateRef. The builder will then call compileQuery
michael@0 67 * for each query in the template to compile the queries. When results need
michael@0 68 * to be generated, the builder will call generateResults. The
michael@0 69 * initializeForBuilding, compileQuery and addBinding methods may not be
michael@0 70 * called after generateResults has been called until the builder indicates
michael@0 71 * that the generated output is being removed by calling the done method.
michael@0 72 *
michael@0 73 * Currently, the datasource supplied to the methods will always be an
michael@0 74 * nsIRDFDataSource or a DOM node, and will always be the same one in between
michael@0 75 * calls to initializeForBuilding and done.
michael@0 76 */
michael@0 77 [scriptable, uuid(C257573F-444F-468A-BA27-DE979DC55FE4)]
michael@0 78 interface nsIXULTemplateQueryProcessor : nsISupports
michael@0 79 {
michael@0 80 /**
michael@0 81 * Retrieve the datasource to use for the query processor. The list of
michael@0 82 * datasources in a template is specified using the datasources attribute as
michael@0 83 * a space separated list of URIs. This list is processed by the builder and
michael@0 84 * supplied to the query processor in the aDataSources array as a list of
michael@0 85 * nsIURI objects or nsIDOMNode objects. This method may return an object
michael@0 86 * corresponding to these URIs and the builder will supply this object to
michael@0 87 * other query processor methods. For example, for an XML source, the
michael@0 88 * datasource might be an nsIDOMNode.
michael@0 89 *
michael@0 90 * All of these URIs are checked by the builder so it is safe to use them,
michael@0 91 * however note that a URI that redirects may still needs to be checked to
michael@0 92 * ensure that the document containing aRootNode may access it. This is the
michael@0 93 * responsibility of the query processor if it needs to load the content of
michael@0 94 * the URI.
michael@0 95 *
michael@0 96 * If the query processor needs to load the datasource asynchronously, it
michael@0 97 * may set the aShouldDelayBuilding returned parameter to true to delay
michael@0 98 * building the template content, and call the builder's Rebuild method when
michael@0 99 * the data is available.
michael@0 100 *
michael@0 101 * @param aDataSources the list of nsIURI objects and/or nsIDOMNode objects
michael@0 102 * @param aRootNode the root node the builder is attached to
michael@0 103 * @param aIsTrusted true if the template is in a trusted document
michael@0 104 * @param aBuilder the template builder
michael@0 105 * @param aShouldDelayBuilding [out] whether the builder should wait to
michael@0 106 * build the content or not
michael@0 107 * @returns a datasource object
michael@0 108 */
michael@0 109 nsISupports getDatasource(in nsIArray aDataSources,
michael@0 110 in nsIDOMNode aRootNode,
michael@0 111 in boolean aIsTrusted,
michael@0 112 in nsIXULTemplateBuilder aBuilder,
michael@0 113 out boolean aShouldDelayBuilding);
michael@0 114
michael@0 115 /**
michael@0 116 * Initialize for query generation. This will be called before the rules are
michael@0 117 * processed and whenever the template is rebuilt. This method must be
michael@0 118 * called once before any of the other query processor methods except for
michael@0 119 * translateRef.
michael@0 120 *
michael@0 121 * @param aDatasource datasource for the data
michael@0 122 * @param aBuilder the template builder
michael@0 123 * @param aRootNode the root node the builder is attached to
michael@0 124 *
michael@0 125 * @throws NS_ERROR_INVALID_ARG if the datasource is not supported or
michael@0 126 * NS_ERROR_UNEXPECTED if generateResults has already been called.
michael@0 127 */
michael@0 128 void initializeForBuilding(in nsISupports aDatasource,
michael@0 129 in nsIXULTemplateBuilder aBuilder,
michael@0 130 in nsIDOMNode aRootNode);
michael@0 131
michael@0 132 /**
michael@0 133 * Called when the template builder is being destroyed so that the query
michael@0 134 * processor can clean up any state. The query processor should remove as
michael@0 135 * much state as possible, such as results or references to the builder.
michael@0 136 * This method will also be called when the template is going to be rebuilt.
michael@0 137 */
michael@0 138 void done();
michael@0 139
michael@0 140 /**
michael@0 141 * Compile a query from a node. The result of this function will later be
michael@0 142 * passed to generateResults for result generation. If null is returned,
michael@0 143 * the query will be ignored.
michael@0 144 *
michael@0 145 * The template builder will call this method once for each query within
michael@0 146 * the template, before any results can be generated using generateResults,
michael@0 147 * but after initializeForBuilding has been called. This method should not
michael@0 148 * be called again for the same query unless the template is rebuilt.
michael@0 149 *
michael@0 150 * The reference variable may be used by the query processor as a
michael@0 151 * placeholder for the reference point, or starting point in the query.
michael@0 152 *
michael@0 153 * The member variable is determined from the member attribute on the
michael@0 154 * template, or from the uri in the first action's rule if that attribute is
michael@0 155 * not present. A rule processor may use the member variable as a hint to
michael@0 156 * indicate what variable is expected to contain the results.
michael@0 157 *
michael@0 158 * @param aBuilder the template builder
michael@0 159 * @param aQuery <query> node to compile
michael@0 160 * @param aRefVariable the reference variable
michael@0 161 * @param aMemberVariable the member variable
michael@0 162 *
michael@0 163 * @returns a compiled query object
michael@0 164 */
michael@0 165 nsISupports compileQuery(in nsIXULTemplateBuilder aBuilder,
michael@0 166 in nsIDOMNode aQuery,
michael@0 167 in nsIAtom aRefVariable,
michael@0 168 in nsIAtom aMemberVariable);
michael@0 169
michael@0 170 /**
michael@0 171 * Generate the results of a query and return them in an enumerator. The
michael@0 172 * enumerator must contain nsIXULTemplateResult objects. If there are no
michael@0 173 * results, an empty enumerator must be returned.
michael@0 174 *
michael@0 175 * The datasource will be the same as the one passed to the earlier
michael@0 176 * initializeForBuilding method. The context reference (aRef) is a reference
michael@0 177 * point used when calculating results.
michael@0 178 *
michael@0 179 * The value of aQuery must be the result of a previous call to compileQuery
michael@0 180 * from this query processor. This method may be called multiple times,
michael@0 181 * typically with different values for aRef.
michael@0 182 *
michael@0 183 * @param aDatasource datasource for the data
michael@0 184 * @param aRef context reference value used as a starting point
michael@0 185 * @param aQuery the compiled query returned from query compilation
michael@0 186 *
michael@0 187 * @returns an enumerator of nsIXULTemplateResult objects as the results
michael@0 188 *
michael@0 189 * @throws NS_ERROR_INVALID_ARG if aQuery is invalid
michael@0 190 */
michael@0 191 nsISimpleEnumerator generateResults(in nsISupports aDatasource,
michael@0 192 in nsIXULTemplateResult aRef,
michael@0 193 in nsISupports aQuery);
michael@0 194
michael@0 195 /**
michael@0 196 * Add a variable binding for a particular rule. A binding allows an
michael@0 197 * additional variable to be set for a result, outside of those defined
michael@0 198 * within the query. These bindings are always optional, in that they will
michael@0 199 * never affect the results generated.
michael@0 200 *
michael@0 201 * This function will never be called after generateResults. Any bindings
michael@0 202 * that were added should be applied to each result when the result's
michael@0 203 * ruleMatched method is called, since the bindings are different for each
michael@0 204 * rule.
michael@0 205 *
michael@0 206 * The reference aRef may be used to determine the reference when
michael@0 207 * calculating the value for the binding, for example when a value should
michael@0 208 * depend on the value of another variable.
michael@0 209 *
michael@0 210 * The syntax of the expression aExpr is defined by the query processor. If
michael@0 211 * the syntax is invalid, the binding should be ignored. Only fatal errors
michael@0 212 * should be thrown, or NS_ERROR_UNEXPECTED if generateResults has already
michael@0 213 * been called.
michael@0 214 *
michael@0 215 * As an example, if the reference aRef is the variable '?count' which
michael@0 216 * holds the value 5, and the expression aExpr is the string '+2', the value
michael@0 217 * of the variable aVar would be 7, assuming the query processor considers
michael@0 218 * the syntax '+2' to mean add two to the reference.
michael@0 219 *
michael@0 220 * @param aRuleNode rule to add the binding to
michael@0 221 * @param aVar variable that will be bound
michael@0 222 * @param aRef variable that holds reference value
michael@0 223 * @param aExpr expression used to compute the value to assign
michael@0 224 */
michael@0 225 void addBinding(in nsIDOMNode aRuleNode,
michael@0 226 in nsIAtom aVar,
michael@0 227 in nsIAtom aRef,
michael@0 228 in AString aExpr);
michael@0 229
michael@0 230 /**
michael@0 231 * Translate a ref attribute string into a result. This is used as the
michael@0 232 * reference point by the template builder when generating the first level
michael@0 233 * of content. For recursive generation, the result from the parent
michael@0 234 * generation phase will be used directly as the reference so a translation
michael@0 235 * is not needed. This allows all levels to be generated using objects that
michael@0 236 * all implement the nsIXULTemplateResult interface.
michael@0 237 *
michael@0 238 * This method may be called before initializeForBuilding, so the
michael@0 239 * implementation may use the supplied datasource if it is needed to
michael@0 240 * translate the reference.
michael@0 241 *
michael@0 242 * @param aDatasource datasource for the data
michael@0 243 * @param aRefString the ref attribute string
michael@0 244 *
michael@0 245 * @return the translated ref
michael@0 246 */
michael@0 247 nsIXULTemplateResult translateRef(in nsISupports aDatasource,
michael@0 248 in AString aRefString);
michael@0 249
michael@0 250 /**
michael@0 251 * Compare two results to determine their order, used when sorting results.
michael@0 252 * This method should return -1 when the left result is less than the right,
michael@0 253 * 0 if both are equivalent, and 1 if the left is greater than the right.
michael@0 254 * The comparison should only consider the values for the specified
michael@0 255 * variable.
michael@0 256 *
michael@0 257 * If the comparison variable is null, the results may be
michael@0 258 * sorted in a natural order, for instance, based on the order the data in
michael@0 259 * stored in the datasource.
michael@0 260 *
michael@0 261 * The sort hints are the flags in nsIXULSortService.
michael@0 262 *
michael@0 263 * This method must only be called with results that were created by this
michael@0 264 * query processor.
michael@0 265 *
michael@0 266 * @param aLeft the left result to compare
michael@0 267 * @param aRight the right result to compare
michael@0 268 * @param aVar variable to compare
michael@0 269 *
michael@0 270 * @param returns -1 if less, 0 if equal, or 1 if greater
michael@0 271 */
michael@0 272 int32_t compareResults(in nsIXULTemplateResult aLeft,
michael@0 273 in nsIXULTemplateResult aRight,
michael@0 274 in nsIAtom aVar,
michael@0 275 in unsigned long aSortHints);
michael@0 276 };

mercurial