summaryrefslogtreecommitdiffstats
path: root/dom/xul/templates/nsXULTemplateResultStorage.cpp
blob: b840fc2c7545d05e3f87aa0c31bb692e56799248 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "nsIServiceManager.h"
#include "nsRDFCID.h"
#include "nsIRDFService.h"
#include "nsString.h"
#include "nsXULTemplateResultStorage.h"

NS_IMPL_ISUPPORTS(nsXULTemplateResultStorage, nsIXULTemplateResult)

nsXULTemplateResultStorage::nsXULTemplateResultStorage(nsXULTemplateResultSetStorage* aResultSet)
{
    static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
    nsCOMPtr<nsIRDFService> rdfService = do_GetService(kRDFServiceCID);
    rdfService->GetAnonymousResource(getter_AddRefs(mNode));
    mResultSet = aResultSet;
    if (aResultSet) {
        mResultSet->FillColumnValues(mValues);
    }
}

nsXULTemplateResultStorage::~nsXULTemplateResultStorage()
{
}

NS_IMETHODIMP
nsXULTemplateResultStorage::GetIsContainer(bool* aIsContainer)
{
    *aIsContainer = false;
    return NS_OK;
}

NS_IMETHODIMP
nsXULTemplateResultStorage::GetIsEmpty(bool* aIsEmpty)
{
    *aIsEmpty = true;
    return NS_OK;
}

NS_IMETHODIMP
nsXULTemplateResultStorage::GetMayProcessChildren(bool* aMayProcessChildren)
{
    *aMayProcessChildren = false;
    return NS_OK;
}

NS_IMETHODIMP
nsXULTemplateResultStorage::GetId(nsAString& aId)
{
    const char* uri = nullptr;
    mNode->GetValueConst(&uri);

    aId.Assign(NS_ConvertUTF8toUTF16(uri));

    return NS_OK;
}

NS_IMETHODIMP
nsXULTemplateResultStorage::GetResource(nsIRDFResource** aResource)
{
    *aResource = mNode;
    NS_IF_ADDREF(*aResource);
    return NS_OK;
}

NS_IMETHODIMP
nsXULTemplateResultStorage::GetType(nsAString& aType)
{
    aType.Truncate();
    return NS_OK;
}


NS_IMETHODIMP
nsXULTemplateResultStorage::GetBindingFor(nsIAtom* aVar, nsAString& aValue)
{
    NS_ENSURE_ARG_POINTER(aVar);

    aValue.Truncate();
    if (!mResultSet) {
        return NS_OK;
    }

    int32_t idx = mResultSet->GetColumnIndex(aVar);
    if (idx < 0) {
        return NS_OK;
    }

    nsIVariant * value = mValues[idx];
    if (value) {
        value->GetAsAString(aValue);
    }
    return NS_OK;
}

NS_IMETHODIMP
nsXULTemplateResultStorage::GetBindingObjectFor(nsIAtom* aVar, nsISupports** aValue)
{
    NS_ENSURE_ARG_POINTER(aVar);

    if (mResultSet) {
        int32_t idx = mResultSet->GetColumnIndex(aVar);
        if (idx >= 0) {
            *aValue = mValues[idx];
            NS_IF_ADDREF(*aValue);
            return NS_OK;
        }
    }
    *aValue = nullptr;
    return NS_OK;
}

NS_IMETHODIMP
nsXULTemplateResultStorage::RuleMatched(nsISupports* aQuery, nsIDOMNode* aRuleNode)
{
    return NS_OK;
}

NS_IMETHODIMP
nsXULTemplateResultStorage::HasBeenRemoved()
{
    return NS_OK;
}