Back to index

lightning-sunbird  0.9+nobinonly
nsDOMLists.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 2003
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Peter Van der Beken <peterv@netscape.com>
00024  *
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #include "nsDOMLists.h"
00041 #include "nsDOMError.h"
00042 #include "nsIDOMClassInfo.h"
00043 #include "nsContentUtils.h"
00044 
00045 nsDOMStringList::nsDOMStringList()
00046 {
00047 }
00048 
00049 nsDOMStringList::~nsDOMStringList()
00050 {
00051 }
00052 
00053 NS_IMPL_ADDREF(nsDOMStringList)
00054 NS_IMPL_RELEASE(nsDOMStringList)
00055 NS_INTERFACE_MAP_BEGIN(nsDOMStringList)
00056   NS_INTERFACE_MAP_ENTRY(nsIDOMDOMStringList)
00057   NS_INTERFACE_MAP_ENTRY(nsISupports)
00058   NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(DOMStringList)
00059 NS_INTERFACE_MAP_END
00060 
00061 NS_IMETHODIMP
00062 nsDOMStringList::Item(PRUint32 aIndex, nsAString& aResult)
00063 {
00064   if (aIndex >= (PRUint32)mNames.Count()) {
00065     return NS_ERROR_DOM_INDEX_SIZE_ERR;
00066   }
00067 
00068   mNames.StringAt(aIndex, aResult);
00069 
00070   return NS_OK;
00071 }
00072 
00073 NS_IMETHODIMP
00074 nsDOMStringList::GetLength(PRUint32 *aLength)
00075 {
00076   *aLength = (PRUint32)mNames.Count();
00077 
00078   return NS_OK;
00079 }
00080 
00081 NS_IMETHODIMP
00082 nsDOMStringList::Contains(const nsAString& aString, PRBool *aResult)
00083 {
00084   *aResult = mNames.IndexOf(aString) > -1;
00085 
00086   return NS_OK;
00087 }
00088 
00089 
00090 nsNameList::nsNameList()
00091 {
00092 }
00093 
00094 nsNameList::~nsNameList()
00095 {
00096 }
00097 
00098 NS_IMPL_ADDREF(nsNameList)
00099   NS_IMPL_RELEASE(nsNameList)
00100   NS_INTERFACE_MAP_BEGIN(nsNameList)
00101   NS_INTERFACE_MAP_ENTRY(nsIDOMNameList)
00102   NS_INTERFACE_MAP_ENTRY(nsISupports)
00103   NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(NameList)
00104   NS_INTERFACE_MAP_END
00105 
00106 NS_IMETHODIMP
00107 nsNameList::GetName(PRUint32 aIndex, nsAString& aResult)
00108 {
00109   if (aIndex >= (PRUint32)mNames.Count()) {
00110     return NS_ERROR_DOM_INDEX_SIZE_ERR;
00111   }
00112 
00113   mNames.StringAt(aIndex, aResult);
00114 
00115   return NS_OK;
00116 }
00117 
00118 NS_IMETHODIMP
00119 nsNameList::GetNamespaceURI(PRUint32 aIndex, nsAString& aResult)
00120 {
00121   if (aIndex >= (PRUint32)mNames.Count()) {
00122     return NS_ERROR_DOM_INDEX_SIZE_ERR;
00123   }
00124 
00125   mNamespaceURIs.StringAt(aIndex, aResult);
00126 
00127   return NS_OK;
00128 }
00129 
00130 NS_IMETHODIMP
00131 nsNameList::GetLength(PRUint32 *aLength)
00132 {
00133   *aLength = (PRUint32)mNames.Count();
00134 
00135   return NS_OK;
00136 }
00137 
00138 PRBool
00139 nsNameList::Add(const nsAString& aNamespaceURI, const nsAString& aName)
00140 {
00141   PRInt32 count = mNamespaceURIs.Count();
00142   if (mNamespaceURIs.InsertStringAt(aNamespaceURI, count)) {
00143     if (mNames.InsertStringAt(aName, count)) {
00144       return PR_TRUE;
00145     }
00146     mNamespaceURIs.RemoveStringAt(count);
00147   }
00148 
00149   return PR_FALSE;
00150 }
00151 
00152 NS_IMETHODIMP
00153 nsNameList::Contains(const nsAString& aName, PRBool *aResult)
00154 {
00155   *aResult = mNames.IndexOf(aName) > -1;
00156 
00157   return NS_OK;
00158 }
00159 
00160 NS_IMETHODIMP
00161 nsNameList::ContainsNS(const nsAString& aNamespaceURI, const nsAString& aName,
00162                        PRBool *aResult)
00163 {
00164   PRInt32 index = mNames.IndexOf(aName);
00165   if (index > -1) {
00166     nsAutoString ns;
00167     mNamespaceURIs.StringAt(index, ns);
00168 
00169     *aResult = ns.Equals(aNamespaceURI);
00170   }
00171   else {
00172     *aResult = PR_FALSE;
00173   }
00174 
00175   return NS_OK;
00176 }