michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsSAXAttributes.h" michael@0: michael@0: NS_IMPL_ISUPPORTS(nsSAXAttributes, nsISAXAttributes, nsISAXMutableAttributes) michael@0: michael@0: NS_IMETHODIMP michael@0: nsSAXAttributes::GetIndexFromName(const nsAString &aURI, michael@0: const nsAString &aLocalName, michael@0: int32_t *aResult) michael@0: { michael@0: int32_t len = mAttrs.Length(); michael@0: int32_t i; michael@0: for (i = 0; i < len; ++i) { michael@0: const SAXAttr &att = mAttrs[i]; michael@0: if (att.localName.Equals(aLocalName) && att.uri.Equals(aURI)) { michael@0: *aResult = i; michael@0: return NS_OK; michael@0: } michael@0: } michael@0: *aResult = -1; michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsSAXAttributes::GetIndexFromQName(const nsAString &aQName, int32_t *aResult) michael@0: { michael@0: int32_t len = mAttrs.Length(); michael@0: int32_t i; michael@0: for (i = 0; i < len; ++i) { michael@0: const SAXAttr &att = mAttrs[i]; michael@0: if (att.qName.Equals(aQName)) { michael@0: *aResult = i; michael@0: return NS_OK; michael@0: } michael@0: } michael@0: *aResult = -1; michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsSAXAttributes::GetLength(int32_t *aResult) michael@0: { michael@0: *aResult = mAttrs.Length(); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsSAXAttributes::GetLocalName(uint32_t aIndex, nsAString &aResult) michael@0: { michael@0: uint32_t len = mAttrs.Length(); michael@0: if (aIndex >= len) { michael@0: aResult.SetIsVoid(true); michael@0: } else { michael@0: const SAXAttr &att = mAttrs[aIndex]; michael@0: aResult = att.localName; michael@0: } michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsSAXAttributes::GetQName(uint32_t aIndex, nsAString &aResult) michael@0: { michael@0: uint32_t len = mAttrs.Length(); michael@0: if (aIndex >= len) { michael@0: aResult.SetIsVoid(true); michael@0: } else { michael@0: const SAXAttr &att = mAttrs[aIndex]; michael@0: aResult = att.qName; michael@0: } michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsSAXAttributes::GetType(uint32_t aIndex, nsAString &aResult) michael@0: { michael@0: uint32_t len = mAttrs.Length(); michael@0: if (aIndex >= len) { michael@0: aResult.SetIsVoid(true); michael@0: } else { michael@0: const SAXAttr &att = mAttrs[aIndex]; michael@0: aResult = att.type; michael@0: } michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsSAXAttributes::GetTypeFromName(const nsAString &aURI, michael@0: const nsAString &aLocalName, michael@0: nsAString &aResult) michael@0: { michael@0: int32_t index = -1; michael@0: GetIndexFromName(aURI, aLocalName, &index); michael@0: if (index >= 0) { michael@0: aResult = mAttrs[index].type; michael@0: } else { michael@0: aResult.SetIsVoid(true); michael@0: } michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsSAXAttributes::GetTypeFromQName(const nsAString &aQName, nsAString &aResult) michael@0: { michael@0: int32_t index = -1; michael@0: GetIndexFromQName(aQName, &index); michael@0: if (index >= 0) { michael@0: aResult = mAttrs[index].type; michael@0: } else { michael@0: aResult.SetIsVoid(true); michael@0: } michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsSAXAttributes::GetURI(uint32_t aIndex, nsAString &aResult) michael@0: { michael@0: uint32_t len = mAttrs.Length(); michael@0: if (aIndex >= len) { michael@0: aResult.SetIsVoid(true); michael@0: } else { michael@0: const SAXAttr &att = mAttrs[aIndex]; michael@0: aResult = att.uri; michael@0: } michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsSAXAttributes::GetValue(uint32_t aIndex, nsAString &aResult) michael@0: { michael@0: uint32_t len = mAttrs.Length(); michael@0: if (aIndex >= len) { michael@0: aResult.SetIsVoid(true); michael@0: } else { michael@0: const SAXAttr &att = mAttrs[aIndex]; michael@0: aResult = att.value; michael@0: } michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsSAXAttributes::GetValueFromName(const nsAString &aURI, michael@0: const nsAString &aLocalName, michael@0: nsAString &aResult) michael@0: { michael@0: int32_t index = -1; michael@0: GetIndexFromName(aURI, aLocalName, &index); michael@0: if (index >= 0) { michael@0: aResult = mAttrs[index].value; michael@0: } else { michael@0: aResult.SetIsVoid(true); michael@0: } michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsSAXAttributes::GetValueFromQName(const nsAString &aQName, michael@0: nsAString &aResult) michael@0: { michael@0: int32_t index = -1; michael@0: GetIndexFromQName(aQName, &index); michael@0: if (index >= 0) { michael@0: aResult = mAttrs[index].value; michael@0: } else { michael@0: aResult.SetIsVoid(true); michael@0: } michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsSAXAttributes::AddAttribute(const nsAString &aURI, michael@0: const nsAString &aLocalName, michael@0: const nsAString &aQName, michael@0: const nsAString &aType, michael@0: const nsAString &aValue) michael@0: { michael@0: SAXAttr *att = mAttrs.AppendElement(); michael@0: if (!att) { michael@0: return NS_ERROR_OUT_OF_MEMORY; michael@0: } michael@0: michael@0: att->uri = aURI; michael@0: att->localName = aLocalName; michael@0: att->qName = aQName; michael@0: att->type = aType; michael@0: att->value = aValue; michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsSAXAttributes::Clear() michael@0: { michael@0: mAttrs.Clear(); michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsSAXAttributes::RemoveAttribute(uint32_t aIndex) michael@0: { michael@0: if (aIndex >= mAttrs.Length()) { michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: mAttrs.RemoveElementAt(aIndex); michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsSAXAttributes::SetAttributes(nsISAXAttributes *aAttributes) michael@0: { michael@0: NS_ENSURE_ARG(aAttributes); michael@0: michael@0: nsresult rv; michael@0: int32_t len; michael@0: rv = aAttributes->GetLength(&len); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: mAttrs.Clear(); michael@0: SAXAttr *att; michael@0: int32_t i; michael@0: for (i = 0; i < len; ++i) { michael@0: att = mAttrs.AppendElement(); michael@0: if (!att) { michael@0: return NS_ERROR_OUT_OF_MEMORY; michael@0: } michael@0: rv = aAttributes->GetURI(i, att->uri); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: rv = aAttributes->GetLocalName(i, att->localName); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: rv = aAttributes->GetQName(i, att->qName); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: rv = aAttributes->GetType(i, att->type); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: rv = aAttributes->GetValue(i, att->value); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: } michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsSAXAttributes::SetAttribute(uint32_t aIndex, michael@0: const nsAString &aURI, michael@0: const nsAString &aLocalName, michael@0: const nsAString &aQName, michael@0: const nsAString &aType, michael@0: const nsAString &aValue) michael@0: { michael@0: if (aIndex >= mAttrs.Length()) { michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: michael@0: SAXAttr &att = mAttrs[aIndex]; michael@0: att.uri = aURI; michael@0: att.localName = aLocalName; michael@0: att.qName = aQName; michael@0: att.type = aType; michael@0: att.value = aValue; michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsSAXAttributes::SetLocalName(uint32_t aIndex, const nsAString &aLocalName) michael@0: { michael@0: if (aIndex >= mAttrs.Length()) { michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: mAttrs[aIndex].localName = aLocalName; michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsSAXAttributes::SetQName(uint32_t aIndex, const nsAString &aQName) michael@0: { michael@0: if (aIndex >= mAttrs.Length()) { michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: mAttrs[aIndex].qName = aQName; michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsSAXAttributes::SetType(uint32_t aIndex, const nsAString &aType) michael@0: { michael@0: if (aIndex >= mAttrs.Length()) { michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: mAttrs[aIndex].type = aType; michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsSAXAttributes::SetURI(uint32_t aIndex, const nsAString &aURI) michael@0: { michael@0: if (aIndex >= mAttrs.Length()) { michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: mAttrs[aIndex].uri = aURI; michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsSAXAttributes::SetValue(uint32_t aIndex, const nsAString &aValue) michael@0: { michael@0: if (aIndex >= mAttrs.Length()) { michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: mAttrs[aIndex].value = aValue; michael@0: michael@0: return NS_OK; michael@0: }