1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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/. */
6 #include "nsSAXAttributes.h"
8 NS_IMPL_ISUPPORTS(nsSAXAttributes
, nsISAXAttributes
, nsISAXMutableAttributes
)
11 nsSAXAttributes::GetIndexFromName(const nsAString
&aURI
,
12 const nsAString
&aLocalName
,
15 int32_t len
= mAttrs
.Length();
17 for (i
= 0; i
< len
; ++i
) {
18 const SAXAttr
&att
= mAttrs
[i
];
19 if (att
.localName
.Equals(aLocalName
) && att
.uri
.Equals(aURI
)) {
30 nsSAXAttributes::GetIndexFromQName(const nsAString
&aQName
, int32_t *aResult
)
32 int32_t len
= mAttrs
.Length();
34 for (i
= 0; i
< len
; ++i
) {
35 const SAXAttr
&att
= mAttrs
[i
];
36 if (att
.qName
.Equals(aQName
)) {
47 nsSAXAttributes::GetLength(int32_t *aResult
)
49 *aResult
= mAttrs
.Length();
54 nsSAXAttributes::GetLocalName(uint32_t aIndex
, nsAString
&aResult
)
56 uint32_t len
= mAttrs
.Length();
58 aResult
.SetIsVoid(true);
60 const SAXAttr
&att
= mAttrs
[aIndex
];
61 aResult
= att
.localName
;
68 nsSAXAttributes::GetQName(uint32_t aIndex
, nsAString
&aResult
)
70 uint32_t len
= mAttrs
.Length();
72 aResult
.SetIsVoid(true);
74 const SAXAttr
&att
= mAttrs
[aIndex
];
82 nsSAXAttributes::GetType(uint32_t aIndex
, nsAString
&aResult
)
84 uint32_t len
= mAttrs
.Length();
86 aResult
.SetIsVoid(true);
88 const SAXAttr
&att
= mAttrs
[aIndex
];
96 nsSAXAttributes::GetTypeFromName(const nsAString
&aURI
,
97 const nsAString
&aLocalName
,
101 GetIndexFromName(aURI
, aLocalName
, &index
);
103 aResult
= mAttrs
[index
].type
;
105 aResult
.SetIsVoid(true);
112 nsSAXAttributes::GetTypeFromQName(const nsAString
&aQName
, nsAString
&aResult
)
115 GetIndexFromQName(aQName
, &index
);
117 aResult
= mAttrs
[index
].type
;
119 aResult
.SetIsVoid(true);
126 nsSAXAttributes::GetURI(uint32_t aIndex
, nsAString
&aResult
)
128 uint32_t len
= mAttrs
.Length();
130 aResult
.SetIsVoid(true);
132 const SAXAttr
&att
= mAttrs
[aIndex
];
140 nsSAXAttributes::GetValue(uint32_t aIndex
, nsAString
&aResult
)
142 uint32_t len
= mAttrs
.Length();
144 aResult
.SetIsVoid(true);
146 const SAXAttr
&att
= mAttrs
[aIndex
];
154 nsSAXAttributes::GetValueFromName(const nsAString
&aURI
,
155 const nsAString
&aLocalName
,
159 GetIndexFromName(aURI
, aLocalName
, &index
);
161 aResult
= mAttrs
[index
].value
;
163 aResult
.SetIsVoid(true);
170 nsSAXAttributes::GetValueFromQName(const nsAString
&aQName
,
174 GetIndexFromQName(aQName
, &index
);
176 aResult
= mAttrs
[index
].value
;
178 aResult
.SetIsVoid(true);
185 nsSAXAttributes::AddAttribute(const nsAString
&aURI
,
186 const nsAString
&aLocalName
,
187 const nsAString
&aQName
,
188 const nsAString
&aType
,
189 const nsAString
&aValue
)
191 SAXAttr
*att
= mAttrs
.AppendElement();
193 return NS_ERROR_OUT_OF_MEMORY
;
197 att
->localName
= aLocalName
;
206 nsSAXAttributes::Clear()
214 nsSAXAttributes::RemoveAttribute(uint32_t aIndex
)
216 if (aIndex
>= mAttrs
.Length()) {
217 return NS_ERROR_FAILURE
;
219 mAttrs
.RemoveElementAt(aIndex
);
225 nsSAXAttributes::SetAttributes(nsISAXAttributes
*aAttributes
)
227 NS_ENSURE_ARG(aAttributes
);
231 rv
= aAttributes
->GetLength(&len
);
232 NS_ENSURE_SUCCESS(rv
, rv
);
237 for (i
= 0; i
< len
; ++i
) {
238 att
= mAttrs
.AppendElement();
240 return NS_ERROR_OUT_OF_MEMORY
;
242 rv
= aAttributes
->GetURI(i
, att
->uri
);
243 NS_ENSURE_SUCCESS(rv
, rv
);
244 rv
= aAttributes
->GetLocalName(i
, att
->localName
);
245 NS_ENSURE_SUCCESS(rv
, rv
);
246 rv
= aAttributes
->GetQName(i
, att
->qName
);
247 NS_ENSURE_SUCCESS(rv
, rv
);
248 rv
= aAttributes
->GetType(i
, att
->type
);
249 NS_ENSURE_SUCCESS(rv
, rv
);
250 rv
= aAttributes
->GetValue(i
, att
->value
);
251 NS_ENSURE_SUCCESS(rv
, rv
);
258 nsSAXAttributes::SetAttribute(uint32_t aIndex
,
259 const nsAString
&aURI
,
260 const nsAString
&aLocalName
,
261 const nsAString
&aQName
,
262 const nsAString
&aType
,
263 const nsAString
&aValue
)
265 if (aIndex
>= mAttrs
.Length()) {
266 return NS_ERROR_FAILURE
;
269 SAXAttr
&att
= mAttrs
[aIndex
];
271 att
.localName
= aLocalName
;
280 nsSAXAttributes::SetLocalName(uint32_t aIndex
, const nsAString
&aLocalName
)
282 if (aIndex
>= mAttrs
.Length()) {
283 return NS_ERROR_FAILURE
;
285 mAttrs
[aIndex
].localName
= aLocalName
;
291 nsSAXAttributes::SetQName(uint32_t aIndex
, const nsAString
&aQName
)
293 if (aIndex
>= mAttrs
.Length()) {
294 return NS_ERROR_FAILURE
;
296 mAttrs
[aIndex
].qName
= aQName
;
302 nsSAXAttributes::SetType(uint32_t aIndex
, const nsAString
&aType
)
304 if (aIndex
>= mAttrs
.Length()) {
305 return NS_ERROR_FAILURE
;
307 mAttrs
[aIndex
].type
= aType
;
313 nsSAXAttributes::SetURI(uint32_t aIndex
, const nsAString
&aURI
)
315 if (aIndex
>= mAttrs
.Length()) {
316 return NS_ERROR_FAILURE
;
318 mAttrs
[aIndex
].uri
= aURI
;
324 nsSAXAttributes::SetValue(uint32_t aIndex
, const nsAString
&aValue
)
326 if (aIndex
>= mAttrs
.Length()) {
327 return NS_ERROR_FAILURE
;
329 mAttrs
[aIndex
].value
= aValue
;