1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/xul/templates/src/nsXULTemplateResultStorage.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,122 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "nsIServiceManager.h" 1.10 +#include "nsRDFCID.h" 1.11 +#include "nsIRDFService.h" 1.12 +#include "nsString.h" 1.13 +#include "nsXULTemplateResultStorage.h" 1.14 + 1.15 +NS_IMPL_ISUPPORTS(nsXULTemplateResultStorage, nsIXULTemplateResult) 1.16 + 1.17 +nsXULTemplateResultStorage::nsXULTemplateResultStorage(nsXULTemplateResultSetStorage* aResultSet) 1.18 +{ 1.19 + static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); 1.20 + nsCOMPtr<nsIRDFService> rdfService = do_GetService(kRDFServiceCID); 1.21 + rdfService->GetAnonymousResource(getter_AddRefs(mNode)); 1.22 + mResultSet = aResultSet; 1.23 + if (aResultSet) { 1.24 + mResultSet->FillColumnValues(mValues); 1.25 + } 1.26 +} 1.27 + 1.28 +NS_IMETHODIMP 1.29 +nsXULTemplateResultStorage::GetIsContainer(bool* aIsContainer) 1.30 +{ 1.31 + *aIsContainer = false; 1.32 + return NS_OK; 1.33 +} 1.34 + 1.35 +NS_IMETHODIMP 1.36 +nsXULTemplateResultStorage::GetIsEmpty(bool* aIsEmpty) 1.37 +{ 1.38 + *aIsEmpty = true; 1.39 + return NS_OK; 1.40 +} 1.41 + 1.42 +NS_IMETHODIMP 1.43 +nsXULTemplateResultStorage::GetMayProcessChildren(bool* aMayProcessChildren) 1.44 +{ 1.45 + *aMayProcessChildren = false; 1.46 + return NS_OK; 1.47 +} 1.48 + 1.49 +NS_IMETHODIMP 1.50 +nsXULTemplateResultStorage::GetId(nsAString& aId) 1.51 +{ 1.52 + const char* uri = nullptr; 1.53 + mNode->GetValueConst(&uri); 1.54 + 1.55 + aId.Assign(NS_ConvertUTF8toUTF16(uri)); 1.56 + 1.57 + return NS_OK; 1.58 +} 1.59 + 1.60 +NS_IMETHODIMP 1.61 +nsXULTemplateResultStorage::GetResource(nsIRDFResource** aResource) 1.62 +{ 1.63 + *aResource = mNode; 1.64 + NS_IF_ADDREF(*aResource); 1.65 + return NS_OK; 1.66 +} 1.67 + 1.68 +NS_IMETHODIMP 1.69 +nsXULTemplateResultStorage::GetType(nsAString& aType) 1.70 +{ 1.71 + aType.Truncate(); 1.72 + return NS_OK; 1.73 +} 1.74 + 1.75 + 1.76 +NS_IMETHODIMP 1.77 +nsXULTemplateResultStorage::GetBindingFor(nsIAtom* aVar, nsAString& aValue) 1.78 +{ 1.79 + NS_ENSURE_ARG_POINTER(aVar); 1.80 + 1.81 + aValue.Truncate(); 1.82 + if (!mResultSet) { 1.83 + return NS_OK; 1.84 + } 1.85 + 1.86 + int32_t idx = mResultSet->GetColumnIndex(aVar); 1.87 + if (idx < 0) { 1.88 + return NS_OK; 1.89 + } 1.90 + 1.91 + nsIVariant * value = mValues[idx]; 1.92 + if (value) { 1.93 + value->GetAsAString(aValue); 1.94 + } 1.95 + return NS_OK; 1.96 +} 1.97 + 1.98 +NS_IMETHODIMP 1.99 +nsXULTemplateResultStorage::GetBindingObjectFor(nsIAtom* aVar, nsISupports** aValue) 1.100 +{ 1.101 + NS_ENSURE_ARG_POINTER(aVar); 1.102 + 1.103 + if (mResultSet) { 1.104 + int32_t idx = mResultSet->GetColumnIndex(aVar); 1.105 + if (idx >= 0) { 1.106 + *aValue = mValues[idx]; 1.107 + NS_IF_ADDREF(*aValue); 1.108 + return NS_OK; 1.109 + } 1.110 + } 1.111 + *aValue = nullptr; 1.112 + return NS_OK; 1.113 +} 1.114 + 1.115 +NS_IMETHODIMP 1.116 +nsXULTemplateResultStorage::RuleMatched(nsISupports* aQuery, nsIDOMNode* aRuleNode) 1.117 +{ 1.118 + return NS_OK; 1.119 +} 1.120 + 1.121 +NS_IMETHODIMP 1.122 +nsXULTemplateResultStorage::HasBeenRemoved() 1.123 +{ 1.124 + return NS_OK; 1.125 +}