LCOV - code coverage report
Current view: directory - content/xul/templates/src - nsXMLBinding.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 71 2 2.8 %
Date: 2012-06-02 Functions: 14 2 14.3 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       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                 :  *
      23                 :  * Alternatively, the contents of this file may be used under the terms of
      24                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      25                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      26                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      27                 :  * of those above. If you wish to allow use of your version of this file only
      28                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      29                 :  * use your version of this file under the terms of the MPL, indicate your
      30                 :  * decision by deleting the provisions above and replace them with the notice
      31                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      32                 :  * the provisions above, a recipient may use your version of this file under
      33                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      34                 :  *
      35                 :  * ***** END LICENSE BLOCK ***** */
      36                 : 
      37                 : #include "nsXULTemplateQueryProcessorXML.h"
      38                 : #include "nsXULTemplateResultXML.h"
      39                 : #include "nsXMLBinding.h"
      40                 : 
      41               0 : NS_IMPL_ADDREF(nsXMLBindingSet)
      42               0 : NS_IMPL_RELEASE(nsXMLBindingSet)
      43                 : 
      44            1464 : NS_IMPL_CYCLE_COLLECTION_CLASS(nsXMLBindingSet)
      45                 : 
      46               0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_NATIVE(nsXMLBindingSet)
      47               0 :   nsXMLBinding* binding = tmp->mFirst;
      48               0 :   while (binding) {
      49               0 :     binding->mExpr = nsnull;
      50               0 :     binding = binding->mNext;
      51                 :   }
      52               0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_END
      53                 : 
      54               0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_BEGIN(nsXMLBindingSet)
      55               0 :   nsXMLBinding* binding = tmp->mFirst;
      56               0 :   while (binding) {
      57               0 :     NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "nsXMLBinding::mExpr"); 
      58               0 :     cb.NoteXPCOMChild(binding->mExpr);
      59               0 :     binding = binding->mNext;
      60                 :   }
      61               0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
      62                 : 
      63               0 : NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsXMLBindingSet, AddRef)
      64               0 : NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsXMLBindingSet, Release)
      65                 : 
      66                 : nsresult
      67               0 : nsXMLBindingSet::AddBinding(nsIAtom* aVar, nsIDOMXPathExpression* aExpr)
      68                 : {
      69               0 :   nsAutoPtr<nsXMLBinding> newbinding(new nsXMLBinding(aVar, aExpr));
      70               0 :   NS_ENSURE_TRUE(newbinding, NS_ERROR_OUT_OF_MEMORY);
      71                 : 
      72               0 :   if (mFirst) {
      73               0 :     nsXMLBinding* binding = mFirst;
      74                 : 
      75               0 :     while (binding) {
      76                 :       // if the target variable is already used in a binding, ignore it
      77                 :       // since it won't be useful for anything
      78               0 :       if (binding->mVar == aVar)
      79               0 :         return NS_OK;
      80                 : 
      81                 :       // add the binding at the end of the list
      82               0 :       if (!binding->mNext) {
      83               0 :         binding->mNext = newbinding;
      84               0 :         break;
      85                 :       }
      86                 : 
      87               0 :       binding = binding->mNext;
      88                 :     }
      89                 :   }
      90                 :   else {
      91               0 :     mFirst = newbinding;
      92                 :   }
      93                 : 
      94               0 :   return NS_OK;
      95                 : }
      96                 : 
      97                 : PRInt32
      98               0 : nsXMLBindingSet::LookupTargetIndex(nsIAtom* aTargetVariable,
      99                 :                                    nsXMLBinding** aBinding)
     100                 : {
     101               0 :   PRInt32 idx = 0;
     102               0 :   nsXMLBinding* binding = mFirst;
     103                 : 
     104               0 :   while (binding) {
     105               0 :     if (binding->mVar == aTargetVariable) {
     106               0 :       *aBinding = binding;
     107               0 :       return idx;
     108                 :     }
     109               0 :     idx++;
     110               0 :     binding = binding->mNext;
     111                 :   }
     112                 : 
     113               0 :   *aBinding = nsnull;
     114               0 :   return -1;
     115                 : }
     116                 : 
     117                 : void
     118               0 : nsXMLBindingValues::GetAssignmentFor(nsXULTemplateResultXML* aResult,
     119                 :                                      nsXMLBinding* aBinding,
     120                 :                                      PRInt32 aIndex,
     121                 :                                      PRUint16 aType,
     122                 :                                      nsIDOMXPathResult** aValue)
     123                 : {
     124               0 :   *aValue = mValues.SafeObjectAt(aIndex);
     125                 : 
     126               0 :   if (!*aValue) {
     127               0 :     nsCOMPtr<nsIDOMNode> contextNode;
     128               0 :     aResult->GetNode(getter_AddRefs(contextNode));
     129               0 :     if (contextNode) {
     130               0 :       nsCOMPtr<nsISupports> resultsupports;
     131               0 :       aBinding->mExpr->Evaluate(contextNode, aType,
     132               0 :                                 nsnull, getter_AddRefs(resultsupports));
     133                 : 
     134               0 :       nsCOMPtr<nsIDOMXPathResult> result = do_QueryInterface(resultsupports);
     135               0 :       if (result && mValues.ReplaceObjectAt(result, aIndex))
     136               0 :         *aValue = result;
     137                 :     }
     138                 :   }
     139                 : 
     140               0 :   NS_IF_ADDREF(*aValue);
     141               0 : }
     142                 : 
     143                 : void
     144               0 : nsXMLBindingValues::GetNodeAssignmentFor(nsXULTemplateResultXML* aResult,
     145                 :                                          nsXMLBinding* aBinding,
     146                 :                                          PRInt32 aIndex,
     147                 :                                          nsIDOMNode** aNode)
     148                 : {
     149               0 :   nsCOMPtr<nsIDOMXPathResult> result;
     150                 :   GetAssignmentFor(aResult, aBinding, aIndex,
     151                 :                    nsIDOMXPathResult::FIRST_ORDERED_NODE_TYPE,
     152               0 :                    getter_AddRefs(result));
     153                 : 
     154               0 :   if (result)
     155               0 :     result->GetSingleNodeValue(aNode);
     156                 :   else
     157               0 :     *aNode = nsnull;
     158               0 : }
     159                 : 
     160                 : void
     161               0 : nsXMLBindingValues::GetStringAssignmentFor(nsXULTemplateResultXML* aResult,
     162                 :                                            nsXMLBinding* aBinding,
     163                 :                                            PRInt32 aIndex,
     164                 :                                            nsAString& aValue)
     165                 : {
     166               0 :   nsCOMPtr<nsIDOMXPathResult> result;
     167                 :   GetAssignmentFor(aResult, aBinding, aIndex,
     168               0 :                    nsIDOMXPathResult::STRING_TYPE, getter_AddRefs(result));
     169                 : 
     170               0 :   if (result)
     171               0 :     result->GetStringValue(aValue);
     172                 :   else
     173               0 :     aValue.Truncate();
     174            4392 : }

Generated by: LCOV version 1.7