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
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/
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
15
* The Original Code is mozilla.org code.
17
* The Initial Developer of the Original Code is Robert Sayre.
19
* Portions created by the Initial Developer are Copyright (C) 2005
20
* the Initial Developer. All Rights Reserved.
24
* Alternatively, the contents of this file may be used under the terms of
25
* either the GNU General Public License Version 2 or later (the "GPL"), or
26
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
* in which case the provisions of the GPL or the LGPL are applicable instead
28
* of those above. If you wish to allow use of your version of this file only
29
* under the terms of either the GPL or the LGPL, and not to allow others to
30
* use your version of this file under the terms of the MPL, indicate your
31
* decision by deleting the provisions above and replace them with the notice
32
* and other provisions required by the GPL or the LGPL. If you do not delete
33
* the provisions above, a recipient may use your version of this file under
34
* the terms of any one of the MPL, the GPL or the LGPL.
36
* ***** END LICENSE BLOCK ***** */
38
#include "nsSAXAttributes.h"
40
NS_IMPL_ISUPPORTS2(nsSAXAttributes, nsISAXAttributes, nsISAXMutableAttributes)
43
nsSAXAttributes::GetIndexFromName(const nsAString &aURI,
44
const nsAString &aLocalName,
47
PRInt32 len = mAttrs.Length();
49
for (i = 0; i < len; ++i) {
50
const SAXAttr &att = mAttrs[i];
51
if (att.localName.Equals(aLocalName) && att.uri.Equals(aURI)) {
62
nsSAXAttributes::GetIndexFromQName(const nsAString &aQName, PRInt32 *aResult)
64
PRInt32 len = mAttrs.Length();
66
for (i = 0; i < len; ++i) {
67
const SAXAttr &att = mAttrs[i];
68
if (att.qName.Equals(aQName)) {
79
nsSAXAttributes::GetLength(PRInt32 *aResult)
81
*aResult = mAttrs.Length();
86
nsSAXAttributes::GetLocalName(PRUint32 aIndex, nsAString &aResult)
88
PRUint32 len = mAttrs.Length();
90
aResult.SetIsVoid(PR_TRUE);
92
const SAXAttr &att = mAttrs[aIndex];
93
aResult = att.localName;
100
nsSAXAttributes::GetQName(PRUint32 aIndex, nsAString &aResult)
102
PRUint32 len = mAttrs.Length();
104
aResult.SetIsVoid(PR_TRUE);
106
const SAXAttr &att = mAttrs[aIndex];
114
nsSAXAttributes::GetType(PRUint32 aIndex, nsAString &aResult)
116
PRUint32 len = mAttrs.Length();
118
aResult.SetIsVoid(PR_TRUE);
120
const SAXAttr &att = mAttrs[aIndex];
128
nsSAXAttributes::GetTypeFromName(const nsAString &aURI,
129
const nsAString &aLocalName,
133
GetIndexFromName(aURI, aLocalName, &index);
135
aResult = mAttrs[index].type;
137
aResult.SetIsVoid(PR_TRUE);
144
nsSAXAttributes::GetTypeFromQName(const nsAString &aQName, nsAString &aResult)
147
GetIndexFromQName(aQName, &index);
149
aResult = mAttrs[index].type;
151
aResult.SetIsVoid(PR_TRUE);
158
nsSAXAttributes::GetURI(PRUint32 aIndex, nsAString &aResult)
160
PRUint32 len = mAttrs.Length();
162
aResult.SetIsVoid(PR_TRUE);
164
const SAXAttr &att = mAttrs[aIndex];
172
nsSAXAttributes::GetValue(PRUint32 aIndex, nsAString &aResult)
174
PRUint32 len = mAttrs.Length();
176
aResult.SetIsVoid(PR_TRUE);
178
const SAXAttr &att = mAttrs[aIndex];
186
nsSAXAttributes::GetValueFromName(const nsAString &aURI,
187
const nsAString &aLocalName,
191
GetIndexFromName(aURI, aLocalName, &index);
193
aResult = mAttrs[index].value;
195
aResult.SetIsVoid(PR_TRUE);
202
nsSAXAttributes::GetValueFromQName(const nsAString &aQName,
206
GetIndexFromQName(aQName, &index);
208
aResult = mAttrs[index].value;
210
aResult.SetIsVoid(PR_TRUE);
217
nsSAXAttributes::AddAttribute(const nsAString &aURI,
218
const nsAString &aLocalName,
219
const nsAString &aQName,
220
const nsAString &aType,
221
const nsAString &aValue)
223
SAXAttr *att = mAttrs.AppendElement();
225
return NS_ERROR_OUT_OF_MEMORY;
229
att->localName = aLocalName;
238
nsSAXAttributes::Clear()
246
nsSAXAttributes::RemoveAttribute(PRUint32 aIndex)
248
if (aIndex >= mAttrs.Length()) {
249
return NS_ERROR_FAILURE;
251
mAttrs.RemoveElementAt(aIndex);
257
nsSAXAttributes::SetAttributes(nsISAXAttributes *aAttributes)
259
NS_ENSURE_ARG(aAttributes);
263
rv = aAttributes->GetLength(&len);
264
NS_ENSURE_SUCCESS(rv, rv);
269
for (i = 0; i < len; ++i) {
270
att = mAttrs.AppendElement();
272
return NS_ERROR_OUT_OF_MEMORY;
274
rv = aAttributes->GetURI(i, att->uri);
275
NS_ENSURE_SUCCESS(rv, rv);
276
rv = aAttributes->GetLocalName(i, att->localName);
277
NS_ENSURE_SUCCESS(rv, rv);
278
rv = aAttributes->GetQName(i, att->qName);
279
NS_ENSURE_SUCCESS(rv, rv);
280
rv = aAttributes->GetType(i, att->type);
281
NS_ENSURE_SUCCESS(rv, rv);
282
rv = aAttributes->GetValue(i, att->value);
283
NS_ENSURE_SUCCESS(rv, rv);
290
nsSAXAttributes::SetAttribute(PRUint32 aIndex,
291
const nsAString &aURI,
292
const nsAString &aLocalName,
293
const nsAString &aQName,
294
const nsAString &aType,
295
const nsAString &aValue)
297
if (aIndex >= mAttrs.Length()) {
298
return NS_ERROR_FAILURE;
301
SAXAttr &att = mAttrs[aIndex];
303
att.localName = aLocalName;
312
nsSAXAttributes::SetLocalName(PRUint32 aIndex, const nsAString &aLocalName)
314
if (aIndex >= mAttrs.Length()) {
315
return NS_ERROR_FAILURE;
317
mAttrs[aIndex].localName = aLocalName;
323
nsSAXAttributes::SetQName(PRUint32 aIndex, const nsAString &aQName)
325
if (aIndex >= mAttrs.Length()) {
326
return NS_ERROR_FAILURE;
328
mAttrs[aIndex].qName = aQName;
334
nsSAXAttributes::SetType(PRUint32 aIndex, const nsAString &aType)
336
if (aIndex >= mAttrs.Length()) {
337
return NS_ERROR_FAILURE;
339
mAttrs[aIndex].type = aType;
345
nsSAXAttributes::SetURI(PRUint32 aIndex, const nsAString &aURI)
347
if (aIndex >= mAttrs.Length()) {
348
return NS_ERROR_FAILURE;
350
mAttrs[aIndex].uri = aURI;
356
nsSAXAttributes::SetValue(PRUint32 aIndex, const nsAString &aValue)
358
if (aIndex >= mAttrs.Length()) {
359
return NS_ERROR_FAILURE;
361
mAttrs[aIndex].value = aValue;