nsXULTemplateResultStorage.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. #include "nsIServiceManager.h"
  6. #include "nsRDFCID.h"
  7. #include "nsIRDFService.h"
  8. #include "nsString.h"
  9. #include "nsXULTemplateResultStorage.h"
  10. NS_IMPL_ISUPPORTS(nsXULTemplateResultStorage, nsIXULTemplateResult)
  11. nsXULTemplateResultStorage::nsXULTemplateResultStorage(nsXULTemplateResultSetStorage* aResultSet)
  12. {
  13. static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
  14. nsCOMPtr<nsIRDFService> rdfService = do_GetService(kRDFServiceCID);
  15. rdfService->GetAnonymousResource(getter_AddRefs(mNode));
  16. mResultSet = aResultSet;
  17. if (aResultSet) {
  18. mResultSet->FillColumnValues(mValues);
  19. }
  20. }
  21. nsXULTemplateResultStorage::~nsXULTemplateResultStorage()
  22. {
  23. }
  24. NS_IMETHODIMP
  25. nsXULTemplateResultStorage::GetIsContainer(bool* aIsContainer)
  26. {
  27. *aIsContainer = false;
  28. return NS_OK;
  29. }
  30. NS_IMETHODIMP
  31. nsXULTemplateResultStorage::GetIsEmpty(bool* aIsEmpty)
  32. {
  33. *aIsEmpty = true;
  34. return NS_OK;
  35. }
  36. NS_IMETHODIMP
  37. nsXULTemplateResultStorage::GetMayProcessChildren(bool* aMayProcessChildren)
  38. {
  39. *aMayProcessChildren = false;
  40. return NS_OK;
  41. }
  42. NS_IMETHODIMP
  43. nsXULTemplateResultStorage::GetId(nsAString& aId)
  44. {
  45. const char* uri = nullptr;
  46. mNode->GetValueConst(&uri);
  47. aId.Assign(NS_ConvertUTF8toUTF16(uri));
  48. return NS_OK;
  49. }
  50. NS_IMETHODIMP
  51. nsXULTemplateResultStorage::GetResource(nsIRDFResource** aResource)
  52. {
  53. *aResource = mNode;
  54. NS_IF_ADDREF(*aResource);
  55. return NS_OK;
  56. }
  57. NS_IMETHODIMP
  58. nsXULTemplateResultStorage::GetType(nsAString& aType)
  59. {
  60. aType.Truncate();
  61. return NS_OK;
  62. }
  63. NS_IMETHODIMP
  64. nsXULTemplateResultStorage::GetBindingFor(nsIAtom* aVar, nsAString& aValue)
  65. {
  66. NS_ENSURE_ARG_POINTER(aVar);
  67. aValue.Truncate();
  68. if (!mResultSet) {
  69. return NS_OK;
  70. }
  71. int32_t idx = mResultSet->GetColumnIndex(aVar);
  72. if (idx < 0) {
  73. return NS_OK;
  74. }
  75. nsIVariant * value = mValues[idx];
  76. if (value) {
  77. value->GetAsAString(aValue);
  78. }
  79. return NS_OK;
  80. }
  81. NS_IMETHODIMP
  82. nsXULTemplateResultStorage::GetBindingObjectFor(nsIAtom* aVar, nsISupports** aValue)
  83. {
  84. NS_ENSURE_ARG_POINTER(aVar);
  85. if (mResultSet) {
  86. int32_t idx = mResultSet->GetColumnIndex(aVar);
  87. if (idx >= 0) {
  88. *aValue = mValues[idx];
  89. NS_IF_ADDREF(*aValue);
  90. return NS_OK;
  91. }
  92. }
  93. *aValue = nullptr;
  94. return NS_OK;
  95. }
  96. NS_IMETHODIMP
  97. nsXULTemplateResultStorage::RuleMatched(nsISupports* aQuery, nsIDOMNode* aRuleNode)
  98. {
  99. return NS_OK;
  100. }
  101. NS_IMETHODIMP
  102. nsXULTemplateResultStorage::HasBeenRemoved()
  103. {
  104. return NS_OK;
  105. }