LCOV - code coverage report
Current view: directory - content/xul/templates/src - nsXULTemplateQueryProcessorXML.h (source / functions) Found Hit Coverage
Test: app.info Lines: 23 1 4.3 %
Date: 2012-06-02 Functions: 16 1 6.2 %

       1                 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is mozilla.org code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is Neil Deakin
      18                 :  * Portions created by the Initial Developer are Copyright (C) 2006
      19                 :  * the Initial Developer. All Rights Reserved.
      20                 :  *
      21                 :  * Contributor(s):
      22                 :  *    Laurent Jouanneau <laurent.jouanneau@disruptive-innovations.com>
      23                 :  *
      24                 :  * Alternatively, the contents of this file may be used under the terms of
      25                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      26                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      27                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      28                 :  * of those above. If you wish to allow use of your version of this file only
      29                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      30                 :  * use your version of this file under the terms of the MPL, indicate your
      31                 :  * decision by deleting the provisions above and replace them with the notice
      32                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      33                 :  * the provisions above, a recipient may use your version of this file under
      34                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      35                 :  *
      36                 :  * ***** END LICENSE BLOCK ***** */
      37                 : 
      38                 : #ifndef nsXULTemplateQueryProcessorXML_h__
      39                 : #define nsXULTemplateQueryProcessorXML_h__
      40                 : 
      41                 : #include "nsIXULTemplateBuilder.h"
      42                 : #include "nsIXULTemplateQueryProcessor.h"
      43                 : 
      44                 : #include "nsISimpleEnumerator.h"
      45                 : #include "nsString.h"
      46                 : #include "nsCOMArray.h"
      47                 : #include "nsRefPtrHashtable.h"
      48                 : #include "nsIDOMElement.h"
      49                 : #include "nsIDOMEventListener.h"
      50                 : #include "nsIDOMXPathExpression.h"
      51                 : #include "nsIDOMXPathEvaluator.h"
      52                 : #include "nsIDOMXPathResult.h"
      53                 : #include "nsXMLBinding.h"
      54                 : #include "nsCycleCollectionParticipant.h"
      55                 : #include "nsIXMLHttpRequest.h"
      56                 : 
      57                 : class nsXULTemplateQueryProcessorXML;
      58                 : 
      59                 : #define NS_IXMLQUERY_IID \
      60                 :   {0x0358d692, 0xccce, 0x4a97, \
      61                 :     { 0xb2, 0x51, 0xba, 0x8f, 0x17, 0x0f, 0x3b, 0x6f }}
      62                 :  
      63                 : class nsXMLQuery : public nsISupports
      64               0 : {
      65                 :   public:
      66                 :     NS_DECLARE_STATIC_IID_ACCESSOR(NS_IXMLQUERY_IID)
      67                 : 
      68                 :     NS_DECL_ISUPPORTS
      69                 : 
      70                 :     // return a weak reference to the processor the query was created from
      71               0 :     nsXULTemplateQueryProcessorXML* Processor() { return mProcessor; }
      72                 : 
      73                 :     // return a weak reference t the member variable for the query
      74               0 :     nsIAtom* GetMemberVariable() { return mMemberVariable; }
      75                 : 
      76                 :     // return a weak reference to the expression used to generate results
      77               0 :     nsIDOMXPathExpression* GetResultsExpression() { return mResultsExpr; }
      78                 : 
      79                 :     // return a weak reference to the additional required bindings
      80               0 :     nsXMLBindingSet* GetBindingSet() { return mRequiredBindings; }
      81                 : 
      82                 :     // add a required binding for the query
      83                 :     nsresult
      84               0 :     AddBinding(nsIAtom* aVar, nsIDOMXPathExpression* aExpr)
      85                 :     {
      86               0 :         if (!mRequiredBindings) {
      87               0 :             mRequiredBindings = new nsXMLBindingSet();
      88               0 :             NS_ENSURE_TRUE(mRequiredBindings, NS_ERROR_OUT_OF_MEMORY);
      89                 :         }
      90                 : 
      91               0 :         return mRequiredBindings->AddBinding(aVar, aExpr);
      92                 :     }
      93                 : 
      94               0 :     nsXMLQuery(nsXULTemplateQueryProcessorXML* aProcessor,
      95                 :                         nsIAtom* aMemberVariable,
      96                 :                         nsIDOMXPathExpression* aResultsExpr)
      97                 :         : mProcessor(aProcessor),
      98                 :           mMemberVariable(aMemberVariable),
      99               0 :           mResultsExpr(aResultsExpr)
     100               0 :     { }
     101                 : 
     102                 :   protected:
     103                 :     nsXULTemplateQueryProcessorXML* mProcessor;
     104                 : 
     105                 :     nsCOMPtr<nsIAtom> mMemberVariable;
     106                 : 
     107                 :     nsCOMPtr<nsIDOMXPathExpression> mResultsExpr;
     108                 : 
     109                 :     nsRefPtr<nsXMLBindingSet> mRequiredBindings;
     110                 : };
     111                 : 
     112                 : NS_DEFINE_STATIC_IID_ACCESSOR(nsXMLQuery, NS_IXMLQUERY_IID)
     113                 : 
     114                 : class nsXULTemplateResultSetXML : public nsISimpleEnumerator
     115               0 : {
     116                 : private:
     117                 : 
     118                 :     // reference back to the query
     119                 :     nsCOMPtr<nsXMLQuery> mQuery;
     120                 : 
     121                 :     // the binding set created from <assign> nodes
     122                 :     nsRefPtr<nsXMLBindingSet> mBindingSet;
     123                 : 
     124                 :     // set of results contained in this enumerator
     125                 :     nsCOMPtr<nsIDOMXPathResult> mResults;
     126                 : 
     127                 :     // current position within the list of results
     128                 :     PRUint32 mPosition;
     129                 : 
     130                 : public:
     131                 : 
     132                 :     // nsISupports interface
     133                 :     NS_DECL_ISUPPORTS
     134                 : 
     135                 :     // nsISimpleEnumerator interface
     136                 :     NS_DECL_NSISIMPLEENUMERATOR
     137                 : 
     138               0 :     nsXULTemplateResultSetXML(nsXMLQuery* aQuery,
     139                 :                               nsIDOMXPathResult* aResults,
     140                 :                               nsXMLBindingSet* aBindingSet)
     141                 :         : mQuery(aQuery),
     142                 :           mBindingSet(aBindingSet),
     143                 :           mResults(aResults),
     144               0 :           mPosition(0)
     145               0 :     {}
     146                 : };
     147                 : 
     148                 : class nsXULTemplateQueryProcessorXML : public nsIXULTemplateQueryProcessor,
     149                 :                                        public nsIDOMEventListener
     150               0 : {
     151                 : public:
     152                 : 
     153               0 :     nsXULTemplateQueryProcessorXML()
     154               0 :         : mGenerationStarted(false)
     155               0 :     {}
     156                 : 
     157                 :     // nsISupports interface
     158               0 :     NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     159            1464 :     NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsXULTemplateQueryProcessorXML,
     160                 :                                              nsIXULTemplateQueryProcessor)
     161                 : 
     162                 :     // nsIXULTemplateQueryProcessor interface
     163                 :     NS_DECL_NSIXULTEMPLATEQUERYPROCESSOR
     164                 : 
     165                 :     // nsIDOMEventListener interface
     166                 :     NS_DECL_NSIDOMEVENTLISTENER
     167                 : 
     168                 :     nsXMLBindingSet*
     169                 :     GetOptionalBindingsForRule(nsIDOMNode* aRuleNode);
     170                 : 
     171                 :     // create an XPath expression from aExpr, using aNode for
     172                 :     // resolving namespaces
     173                 :     nsresult
     174                 :     CreateExpression(const nsAString& aExpr,
     175                 :                      nsIDOMNode* aNode,
     176                 :                      nsIDOMXPathExpression** aCompiledExpr);
     177                 : 
     178                 : private:
     179                 : 
     180                 :     bool mGenerationStarted;
     181                 : 
     182                 :     nsRefPtrHashtable<nsISupportsHashKey, nsXMLBindingSet> mRuleToBindingsMap;
     183                 : 
     184                 :     nsCOMPtr<nsIDOMElement> mRoot;
     185                 : 
     186                 :     nsCOMPtr<nsIDOMXPathEvaluator> mEvaluator;
     187                 : 
     188                 :     nsCOMPtr<nsIXULTemplateBuilder> mTemplateBuilder;
     189                 : 
     190                 :     nsCOMPtr<nsIXMLHttpRequest> mRequest;
     191                 : };
     192                 : 
     193                 : 
     194                 : #endif // nsXULTemplateQueryProcessorXML_h__

Generated by: LCOV version 1.7