Back to index

lightning-sunbird  0.9+nobinonly
nsSOAPFault.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) 2001
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "nsSOAPFault.h"
00039 #include "nsSOAPUtils.h"
00040 #include "nsIDOMNodeList.h"
00041 #include "nsISOAPMessage.h"
00042 #include "nsSOAPException.h"
00043 
00044 nsSOAPFault::nsSOAPFault()
00045 {
00046 }
00047 
00048 nsSOAPFault::~nsSOAPFault()
00049 {
00050 }
00051 
00052 NS_IMPL_ISUPPORTS1_CI(nsSOAPFault, nsISOAPFault)
00053 /* attribute nsIDOMElement element; */
00054 NS_IMETHODIMP nsSOAPFault::SetElement(nsIDOMElement * aElement)
00055 {
00056   if (aElement) {
00057     nsAutoString namespaceURI;
00058     nsAutoString name;
00059     nsresult rc = aElement->GetNamespaceURI(namespaceURI);
00060     if (NS_FAILED(rc))
00061       return rc;
00062     rc = aElement->GetLocalName(name);
00063     if (NS_FAILED(rc))
00064       return rc;
00065     if (name.Equals(gSOAPStrings->kFaultTagName)) {
00066       if (namespaceURI.
00067           Equals(*gSOAPStrings->kSOAPEnvURI[nsISOAPMessage::VERSION_1_2])) {
00068         mVersion = nsISOAPMessage::VERSION_1_2;
00069       } else if (namespaceURI.
00070                  Equals(*gSOAPStrings->kSOAPEnvURI[nsISOAPMessage::VERSION_1_1])) {
00071         mVersion = nsISOAPMessage::VERSION_1_1;
00072       } else {
00073         return SOAP_EXCEPTION(NS_ERROR_ILLEGAL_VALUE,"SOAP_BADFAULT", "Cannot recognize SOAP version from namespace URI of fault");
00074       }
00075     } else {
00076       return SOAP_EXCEPTION(NS_ERROR_ILLEGAL_VALUE,"SOAP_BADFAULT", "Cannot recognize element tag of fault.");
00077     }
00078   }
00079   mFaultElement = aElement;
00080   return NS_OK;
00081 }
00082 
00083 NS_IMETHODIMP nsSOAPFault::GetElement(nsIDOMElement * *aElement)
00084 {
00085   NS_ENSURE_ARG_POINTER(aElement);
00086   *aElement = mFaultElement;
00087   NS_IF_ADDREF(*aElement);
00088   return NS_OK;
00089 }
00090 
00091 /* readonly attribute wstring faultCode; */
00092 NS_IMETHODIMP nsSOAPFault::GetFaultCode(nsAString & aFaultCode)
00093 {
00094   if (!mFaultElement)
00095     return NS_ERROR_ILLEGAL_VALUE;
00096   aFaultCode.Truncate();
00097   nsCOMPtr<nsIDOMElement> faultcode;
00098   nsSOAPUtils::GetSpecificChildElement(nsnull, mFaultElement,
00099                                        gSOAPStrings->kEmpty,
00100                                        gSOAPStrings->kFaultCodeTagName,
00101                                        getter_AddRefs(faultcode));
00102   if (faultcode) {
00103     nsAutoString combined;
00104     nsresult rc = nsSOAPUtils::GetElementTextContent(faultcode, combined);
00105     if (NS_FAILED(rc))
00106       return rc;
00107     return nsSOAPUtils::GetLocalName(combined, aFaultCode);
00108   }
00109   return NS_OK;
00110 }
00111 
00112 /* readonly attribute wstring faultNamespaceURI; */
00113 NS_IMETHODIMP nsSOAPFault::GetFaultNamespaceURI(nsAString & aNamespaceURI)
00114 {
00115   if (!mFaultElement)
00116     return NS_ERROR_ILLEGAL_VALUE;
00117   aNamespaceURI.Truncate();
00118   nsCOMPtr<nsIDOMElement> faultcode;
00119   nsSOAPUtils::GetSpecificChildElement(nsnull, mFaultElement,
00120                                        gSOAPStrings->kEmpty,
00121                                        gSOAPStrings->kFaultCodeTagName,
00122                                        getter_AddRefs(faultcode));
00123   if (faultcode) {
00124     nsAutoString combined;
00125     nsresult rc = nsSOAPUtils::GetElementTextContent(faultcode, combined);
00126     if (NS_FAILED(rc))
00127       return rc;
00128     return nsSOAPUtils::GetNamespaceURI(nsnull, faultcode, combined, aNamespaceURI);
00129   }
00130   return NS_OK;
00131 }
00132 
00133 /* readonly attribute wstring faultString; */
00134 NS_IMETHODIMP nsSOAPFault::GetFaultString(nsAString & aFaultString)
00135 {
00136   if (!mFaultElement)
00137     return NS_ERROR_ILLEGAL_VALUE;
00138 
00139   aFaultString.Truncate();
00140   nsCOMPtr<nsIDOMElement> element;
00141   nsSOAPUtils::GetSpecificChildElement(nsnull, mFaultElement,
00142                                        gSOAPStrings->kEmpty,
00143                                        gSOAPStrings->kFaultStringTagName,
00144                                        getter_AddRefs(element));
00145   if (element) {
00146     nsresult rc = nsSOAPUtils::GetElementTextContent(element, aFaultString);
00147     if (NS_FAILED(rc))
00148       return rc;
00149   }
00150   return NS_OK;
00151 }
00152 
00153 /* readonly attribute wstring faultActor; */
00154 NS_IMETHODIMP nsSOAPFault::GetFaultActor(nsAString & aFaultActor)
00155 {
00156   if (!mFaultElement)
00157     return NS_ERROR_ILLEGAL_VALUE;
00158 
00159   aFaultActor.Truncate();
00160   nsCOMPtr<nsIDOMElement> element;
00161   nsSOAPUtils::GetSpecificChildElement(nsnull, mFaultElement,
00162                                        gSOAPStrings->kEmpty,
00163                                        gSOAPStrings->kFaultActorTagName,
00164                                        getter_AddRefs(element));
00165   if (element) {
00166     nsresult rc = nsSOAPUtils::GetElementTextContent(element, aFaultActor);
00167     if (NS_FAILED(rc))
00168       return rc;
00169   }
00170   return NS_OK;
00171 }
00172 
00173 /* readonly attribute nsIDOMElement detail; */
00174 NS_IMETHODIMP nsSOAPFault::GetDetail(nsIDOMElement * *aDetail)
00175 {
00176   NS_ENSURE_ARG_POINTER(aDetail);
00177   if (!mFaultElement)
00178     return NS_ERROR_ILLEGAL_VALUE;
00179 
00180   nsSOAPUtils::GetSpecificChildElement(nsnull, mFaultElement,
00181                                        gSOAPStrings->kEmpty,
00182                                        gSOAPStrings->kFaultDetailTagName,
00183                                        aDetail);
00184   return NS_OK;
00185 }