~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/embedding/browser/activex/src/xml/XMLElement.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// XMLElement.cpp : Implementation of CXMLElement
 
2
#include "stdafx.h"
 
3
//#include "Activexml.h"
 
4
#include "XMLElement.h"
 
5
 
 
6
 
 
7
CXMLElement::CXMLElement()
 
8
{
 
9
        m_nType = 0;
 
10
        m_pParent = NULL;
 
11
}
 
12
 
 
13
 
 
14
CXMLElement::~CXMLElement()
 
15
{
 
16
}
 
17
 
 
18
 
 
19
HRESULT CXMLElement::SetParent(IXMLElement *pParent)
 
20
{
 
21
        // Note: parent is not refcounted
 
22
        m_pParent = pParent;
 
23
        return S_OK;
 
24
}
 
25
 
 
26
 
 
27
HRESULT CXMLElement::PutType(long nType)
 
28
{
 
29
        m_nType = nType;
 
30
        return S_OK;
 
31
}
 
32
 
 
33
 
 
34
HRESULT CXMLElement::ReleaseAll()
 
35
{
 
36
        // Release all children
 
37
        m_cChildren.clear();
 
38
        return S_OK;
 
39
}
 
40
 
 
41
 
 
42
/////////////////////////////////////////////////////////////////////////////
 
43
// CXMLElement
 
44
 
 
45
 
 
46
// Return the element's tag name
 
47
HRESULT STDMETHODCALLTYPE CXMLElement::get_tagName(/* [out][retval] */ BSTR __RPC_FAR *p)
 
48
{
 
49
        if (p == NULL)
 
50
        {
 
51
                return E_INVALIDARG;
 
52
        }
 
53
        USES_CONVERSION;
 
54
        *p = SysAllocString(A2OLE(m_szTagName.c_str()));
 
55
        return S_OK;
 
56
}
 
57
 
 
58
 
 
59
// Store the tag name
 
60
HRESULT STDMETHODCALLTYPE CXMLElement::put_tagName(/* [in] */ BSTR p)
 
61
{
 
62
        if (p == NULL)
 
63
        {
 
64
                return E_INVALIDARG;
 
65
        }
 
66
        USES_CONVERSION;
 
67
        m_szTagName = OLE2A(p);
 
68
        return S_OK;
 
69
}
 
70
 
 
71
 
 
72
// Returns the parent element
 
73
HRESULT STDMETHODCALLTYPE CXMLElement::get_parent(/* [out][retval] */ IXMLElement __RPC_FAR *__RPC_FAR *ppParent)
 
74
{
 
75
        if (ppParent == NULL)
 
76
        {
 
77
                return E_INVALIDARG;
 
78
        }
 
79
 
 
80
        *ppParent = NULL;
 
81
        if (m_pParent)
 
82
        {
 
83
                return m_pParent->QueryInterface(IID_IXMLElement, (void **) ppParent);
 
84
        }
 
85
 
 
86
        return S_OK;
 
87
}
 
88
 
 
89
 
 
90
// Set the specified attribute value
 
91
HRESULT STDMETHODCALLTYPE CXMLElement::setAttribute(/* [in] */ BSTR strPropertyName, /* [in] */ VARIANT PropertyValue)
 
92
{
 
93
        if (strPropertyName == NULL || PropertyValue.vt != VT_BSTR)
 
94
        {
 
95
                return E_INVALIDARG;
 
96
        }
 
97
 
 
98
        USES_CONVERSION;
 
99
        std::string szPropertyName = OLE2A(strPropertyName);
 
100
        std::string szPropertyValue = OLE2A(PropertyValue.bstrVal);
 
101
        m_cAttributes[szPropertyName] = szPropertyValue;
 
102
 
 
103
        return S_OK;
 
104
}
 
105
 
 
106
 
 
107
// Return the requested attribute
 
108
HRESULT STDMETHODCALLTYPE CXMLElement::getAttribute(/* [in] */ BSTR strPropertyName, /* [out][retval] */ VARIANT __RPC_FAR *PropertyValue)
 
109
{
 
110
        if (strPropertyName == NULL || PropertyValue == NULL)
 
111
        {
 
112
                return E_INVALIDARG;
 
113
        }
 
114
 
 
115
        USES_CONVERSION;
 
116
        std::string szPropertyName = OLE2A(strPropertyName);
 
117
        StringMap::iterator i = m_cAttributes.find(szPropertyName);
 
118
        if (i == m_cAttributes.end())
 
119
        {
 
120
                return S_FALSE;
 
121
        }
 
122
 
 
123
        PropertyValue->vt = VT_BSTR;
 
124
        PropertyValue->bstrVal = SysAllocString(A2OLE((*i).second.c_str()));
 
125
        return S_OK;
 
126
}
 
127
 
 
128
 
 
129
// Find and remove the specified attribute
 
130
HRESULT STDMETHODCALLTYPE CXMLElement::removeAttribute(/* [in] */ BSTR strPropertyName)
 
131
{
 
132
        if (strPropertyName == NULL)
 
133
        {
 
134
                return E_INVALIDARG;
 
135
        }
 
136
 
 
137
        USES_CONVERSION;
 
138
        std::string szPropertyName = OLE2A(strPropertyName);
 
139
        StringMap::iterator i = m_cAttributes.find(szPropertyName);
 
140
        if (i == m_cAttributes.end())
 
141
        {
 
142
                return E_INVALIDARG;
 
143
        }
 
144
        
 
145
        m_cAttributes.erase(i);
 
146
        
 
147
        return S_OK;
 
148
}
 
149
 
 
150
 
 
151
// Return the child collection for this element
 
152
HRESULT STDMETHODCALLTYPE CXMLElement::get_children(/* [out][retval] */ IXMLElementCollection __RPC_FAR *__RPC_FAR *pp)
 
153
{
 
154
        CXMLElementCollectionInstance *pCollection = NULL;
 
155
        CXMLElementCollectionInstance::CreateInstance(&pCollection);
 
156
        if (pCollection == NULL)
 
157
        {
 
158
                return E_OUTOFMEMORY;
 
159
        }
 
160
 
 
161
        // Add children to the collection
 
162
        for (ElementList::iterator i = m_cChildren.begin(); i != m_cChildren.end(); i++)
 
163
        {
 
164
                pCollection->Add(*i);
 
165
        }
 
166
 
 
167
        pCollection->QueryInterface(IID_IXMLElementCollection, (void **) pp);
 
168
 
 
169
        return S_OK;
 
170
}
 
171
 
 
172
 
 
173
HRESULT STDMETHODCALLTYPE CXMLElement::get_type(/* [out][retval] */ long __RPC_FAR *plType)
 
174
{
 
175
        if (plType == NULL)
 
176
        {
 
177
                return E_INVALIDARG;
 
178
        }
 
179
        *plType = m_nType;
 
180
        return S_OK;
 
181
}
 
182
 
 
183
 
 
184
HRESULT STDMETHODCALLTYPE CXMLElement::get_text(/* [out][retval] */ BSTR __RPC_FAR *p)
 
185
{
 
186
        return E_NOTIMPL;
 
187
}
 
188
 
 
189
 
 
190
HRESULT STDMETHODCALLTYPE CXMLElement::put_text(/* [in] */ BSTR p)
 
191
{
 
192
        return E_NOTIMPL;
 
193
}
 
194
 
 
195
 
 
196
HRESULT STDMETHODCALLTYPE CXMLElement::addChild(/* [in] */ IXMLElement __RPC_FAR *pChildElem, long lIndex, long lReserved)
 
197
{
 
198
        if (pChildElem == NULL)
 
199
        {
 
200
                return E_INVALIDARG;
 
201
        }
 
202
 
 
203
        // Set the child's parent to be this element
 
204
        ((CXMLElement *) pChildElem)->SetParent(this);
 
205
 
 
206
        if (lIndex < 0 || lIndex >= m_cChildren.size())
 
207
        {
 
208
                // Append to end
 
209
                m_cChildren.push_back(pChildElem);
 
210
        }
 
211
        else
 
212
        {
 
213
// TODO         m_cChildren.insert(&m_cChildren[lIndex]);
 
214
                m_cChildren.push_back(pChildElem);
 
215
        }
 
216
 
 
217
        return S_OK;
 
218
}
 
219
 
 
220
 
 
221
HRESULT STDMETHODCALLTYPE CXMLElement::removeChild(/* [in] */ IXMLElement __RPC_FAR *pChildElem)
 
222
{
 
223
        // TODO
 
224
        return E_NOTIMPL;
 
225
}
 
226