~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/extensions/webservices/soap/src/nsSOAPFault.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
2
/* ***** BEGIN LICENSE BLOCK *****
 
3
 * Version: NPL 1.1/GPL 2.0/LGPL 2.1
 
4
 *
 
5
 * The contents of this file are subject to the Netscape Public License
 
6
 * Version 1.1 (the "License"); you may not use this file except in
 
7
 * compliance with the License. You may obtain a copy of the License at
 
8
 * http://www.mozilla.org/NPL/
 
9
 *
 
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
 
13
 * License.
 
14
 *
 
15
 * The Original Code is mozilla.org code.
 
16
 *
 
17
 * The Initial Developer of the Original Code is 
 
18
 * Netscape Communications Corporation.
 
19
 * Portions created by the Initial Developer are Copyright (C) 2001
 
20
 * the Initial Developer. All Rights Reserved.
 
21
 *
 
22
 * Contributor(s):
 
23
 *
 
24
 *
 
25
 * Alternatively, the contents of this file may be used under the terms of
 
26
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 
27
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
28
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
29
 * of those above. If you wish to allow use of your version of this file only
 
30
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
31
 * use your version of this file under the terms of the NPL, indicate your
 
32
 * decision by deleting the provisions above and replace them with the notice
 
33
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
34
 * the provisions above, a recipient may use your version of this file under
 
35
 * the terms of any one of the NPL, the GPL or the LGPL.
 
36
 *
 
37
 * ***** END LICENSE BLOCK ***** */
 
38
 
 
39
#include "nsSOAPFault.h"
 
40
#include "nsSOAPUtils.h"
 
41
#include "nsIDOMNodeList.h"
 
42
#include "nsISOAPMessage.h"
 
43
#include "nsSOAPException.h"
 
44
 
 
45
nsSOAPFault::nsSOAPFault()
 
46
{
 
47
}
 
48
 
 
49
nsSOAPFault::~nsSOAPFault()
 
50
{
 
51
}
 
52
 
 
53
NS_IMPL_ISUPPORTS1_CI(nsSOAPFault, nsISOAPFault)
 
54
/* attribute nsIDOMElement element; */
 
55
NS_IMETHODIMP nsSOAPFault::SetElement(nsIDOMElement * aElement)
 
56
{
 
57
  if (aElement) {
 
58
    nsAutoString namespaceURI;
 
59
    nsAutoString name;
 
60
    nsresult rc = aElement->GetNamespaceURI(namespaceURI);
 
61
    if (NS_FAILED(rc))
 
62
      return rc;
 
63
    rc = aElement->GetLocalName(name);
 
64
    if (NS_FAILED(rc))
 
65
      return rc;
 
66
    if (name.Equals(gSOAPStrings->kFaultTagName)) {
 
67
      if (namespaceURI.
 
68
          Equals(*gSOAPStrings->kSOAPEnvURI[nsISOAPMessage::VERSION_1_2])) {
 
69
        mVersion = nsISOAPMessage::VERSION_1_2;
 
70
      } else if (namespaceURI.
 
71
                 Equals(*gSOAPStrings->kSOAPEnvURI[nsISOAPMessage::VERSION_1_1])) {
 
72
        mVersion = nsISOAPMessage::VERSION_1_1;
 
73
      } else {
 
74
        return SOAP_EXCEPTION(NS_ERROR_ILLEGAL_VALUE,"SOAP_BADFAULT", "Cannot recognize SOAP version from namespace URI of fault");
 
75
      }
 
76
    } else {
 
77
      return SOAP_EXCEPTION(NS_ERROR_ILLEGAL_VALUE,"SOAP_BADFAULT", "Cannot recognize element tag of fault.");
 
78
    }
 
79
  }
 
80
  mFaultElement = aElement;
 
81
  return NS_OK;
 
82
}
 
83
 
 
84
NS_IMETHODIMP nsSOAPFault::GetElement(nsIDOMElement * *aElement)
 
85
{
 
86
  NS_ENSURE_ARG_POINTER(aElement);
 
87
  *aElement = mFaultElement;
 
88
  NS_IF_ADDREF(*aElement);
 
89
  return NS_OK;
 
90
}
 
91
 
 
92
/* readonly attribute wstring faultCode; */
 
93
NS_IMETHODIMP nsSOAPFault::GetFaultCode(nsAString & aFaultCode)
 
94
{
 
95
  NS_ENSURE_ARG_POINTER(&aFaultCode);
 
96
  if (!mFaultElement)
 
97
    return NS_ERROR_ILLEGAL_VALUE;
 
98
  aFaultCode.Truncate();
 
99
  nsCOMPtr < nsIDOMElement > faultcode;
 
100
  nsSOAPUtils::GetSpecificChildElement(nsnull, mFaultElement,
 
101
                                       gSOAPStrings->kEmpty,
 
102
                                       gSOAPStrings->kFaultCodeTagName,
 
103
                                       getter_AddRefs(faultcode));
 
104
  if (faultcode) {
 
105
    nsAutoString combined;
 
106
    nsresult rc = nsSOAPUtils::GetElementTextContent(faultcode, combined);
 
107
    if (NS_FAILED(rc))
 
108
      return rc;
 
109
    return nsSOAPUtils::GetLocalName(combined, aFaultCode);
 
110
  }
 
111
  return NS_OK;
 
112
}
 
113
 
 
114
/* readonly attribute wstring faultNamespaceURI; */
 
115
NS_IMETHODIMP nsSOAPFault::GetFaultNamespaceURI(nsAString & aNamespaceURI)
 
116
{
 
117
  NS_ENSURE_ARG_POINTER(&aNamespaceURI);
 
118
  if (!mFaultElement)
 
119
    return NS_ERROR_ILLEGAL_VALUE;
 
120
  aNamespaceURI.Truncate();
 
121
  nsCOMPtr < nsIDOMElement > faultcode;
 
122
  nsSOAPUtils::GetSpecificChildElement(nsnull, mFaultElement,
 
123
                                       gSOAPStrings->kEmpty,
 
124
                                       gSOAPStrings->kFaultCodeTagName,
 
125
                                       getter_AddRefs(faultcode));
 
126
  if (faultcode) {
 
127
    nsAutoString combined;
 
128
    nsresult rc = nsSOAPUtils::GetElementTextContent(faultcode, combined);
 
129
    if (NS_FAILED(rc))
 
130
      return rc;
 
131
    return nsSOAPUtils::GetNamespaceURI(nsnull, faultcode, combined, aNamespaceURI);
 
132
  }
 
133
  return NS_OK;
 
134
}
 
135
 
 
136
/* readonly attribute wstring faultString; */
 
137
NS_IMETHODIMP nsSOAPFault::GetFaultString(nsAString & aFaultString)
 
138
{
 
139
  NS_ENSURE_ARG_POINTER(&aFaultString);
 
140
  if (!mFaultElement)
 
141
    return NS_ERROR_ILLEGAL_VALUE;
 
142
 
 
143
  aFaultString.Truncate();
 
144
  nsCOMPtr < nsIDOMElement > element;
 
145
  nsSOAPUtils::GetSpecificChildElement(nsnull, mFaultElement,
 
146
                                       gSOAPStrings->kEmpty,
 
147
                                       gSOAPStrings->kFaultStringTagName,
 
148
                                       getter_AddRefs(element));
 
149
  if (element) {
 
150
    nsresult rc = nsSOAPUtils::GetElementTextContent(element, aFaultString);
 
151
    if (NS_FAILED(rc))
 
152
      return rc;
 
153
  }
 
154
  return NS_OK;
 
155
}
 
156
 
 
157
/* readonly attribute wstring faultActor; */
 
158
NS_IMETHODIMP nsSOAPFault::GetFaultActor(nsAString & aFaultActor)
 
159
{
 
160
  NS_ENSURE_ARG_POINTER(&aFaultActor);
 
161
  if (!mFaultElement)
 
162
    return NS_ERROR_ILLEGAL_VALUE;
 
163
 
 
164
  aFaultActor.Truncate();
 
165
  nsCOMPtr < nsIDOMElement > element;
 
166
  nsSOAPUtils::GetSpecificChildElement(nsnull, mFaultElement,
 
167
                                       gSOAPStrings->kEmpty,
 
168
                                       gSOAPStrings->kFaultActorTagName,
 
169
                                       getter_AddRefs(element));
 
170
  if (element) {
 
171
    nsresult rc = nsSOAPUtils::GetElementTextContent(element, aFaultActor);
 
172
    if (NS_FAILED(rc))
 
173
      return rc;
 
174
  }
 
175
  return NS_OK;
 
176
}
 
177
 
 
178
/* readonly attribute nsIDOMElement detail; */
 
179
NS_IMETHODIMP nsSOAPFault::GetDetail(nsIDOMElement * *aDetail)
 
180
{
 
181
  NS_ENSURE_ARG_POINTER(aDetail);
 
182
  if (!mFaultElement)
 
183
    return NS_ERROR_ILLEGAL_VALUE;
 
184
 
 
185
  nsSOAPUtils::GetSpecificChildElement(nsnull, mFaultElement,
 
186
                                       gSOAPStrings->kEmpty,
 
187
                                       gSOAPStrings->kFaultDetailTagName,
 
188
                                       aDetail);
 
189
  return NS_OK;
 
190
}