Back to index

lightning-sunbird  0.9+nobinonly
nsSOAPUtils.h
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 #ifndef nsSOAPUtils_h__
00039 #define nsSOAPUtils_h__
00040 
00041 #include "nsString.h"
00042 #include "nsIDOMElement.h"
00043 #include "nsISOAPEncoding.h"
00044 
00045 class nsSOAPUtils {
00046 private:
00047   nsSOAPUtils() {}  //  Never create a member of this class
00048   ~nsSOAPUtils() {}
00049 public:
00050   static void GetSpecificChildElement(nsISOAPEncoding * aEncoding,
00051                                       nsIDOMElement * aParent,
00052                                       const nsAString & aNamespace,
00053                                       const nsAString & aType,
00054                                       nsIDOMElement * *aElement);
00055   static void GetSpecificSiblingElement(nsISOAPEncoding * aEncoding,
00056                                         nsIDOMElement * aSibling,
00057                                         const nsAString & aNamespace,
00058                                         const nsAString & aType,
00059                                         nsIDOMElement * *aElement);
00060   static void GetFirstChildElement(nsIDOMElement * aParent,
00061                                    nsIDOMElement ** aElement);
00062   static void GetNextSiblingElement(nsIDOMElement * aStart,
00063                                     nsIDOMElement ** aElement);
00064   static nsresult GetElementTextContent(nsIDOMElement * aElement,
00065                                         nsAString & aText);
00066   static PRBool HasChildElements(nsIDOMElement * aElement);
00067 
00068   static void GetNextSibling(nsIDOMNode * aSibling, nsIDOMNode ** aNext);
00069   static nsresult MakeNamespacePrefix(nsISOAPEncoding *aEncoding,
00070                                       nsIDOMElement * aElement,
00071                                       const nsAString & aURI,
00072                                       nsAString & aPrefix);
00073   static nsresult GetNamespaceURI(nsISOAPEncoding *aEncoding,
00074                                   nsIDOMElement * aElement,
00075                                   const nsAString & aQName,
00076                                   nsAString & aURI);
00077   static nsresult GetLocalName(const nsAString & aQName,
00078                                nsAString & aLocalName);
00079 
00080   static PRBool GetAttribute(nsISOAPEncoding *aEncoding,
00081                                   nsIDOMElement * aElement,
00082                                   const nsAString & aNamespaceURI,
00083                                   const nsAString & aLocalName,
00084                                   nsAString & aValue);
00085 };
00086 
00087 struct nsSOAPStrings
00088 {
00089   const nsLiteralString  kSOAPEnvURI1;
00090   const nsLiteralString  kSOAPEnvURI2;
00091   const nsLiteralString *kSOAPEnvURI[2];
00092 
00093   const nsLiteralString  kSOAPEncURI;
00094   const nsLiteralString  kSOAPEncURI11;
00095   const nsLiteralString  kXSIURI;
00096   const nsLiteralString  kXSURI;
00097   const nsLiteralString  kXSIURI1999;
00098   const nsLiteralString  kXSURI1999;
00099   const nsLiteralString  kSOAPEnvPrefix;
00100   const nsLiteralString  kSOAPEncPrefix;
00101   const nsLiteralString  kXSIPrefix;
00102   const nsLiteralString  kXSITypeAttribute;
00103   const nsLiteralString  kXSPrefix;
00104   const nsLiteralString  kEncodingStyleAttribute;
00105   const nsLiteralString  kActorAttribute;
00106   const nsLiteralString  kMustUnderstandAttribute;
00107   const nsLiteralString  kEnvelopeTagName;
00108   const nsLiteralString  kHeaderTagName;
00109   const nsLiteralString  kBodyTagName;
00110   const nsLiteralString  kFaultTagName;
00111   const nsLiteralString  kFaultCodeTagName;
00112   const nsLiteralString  kFaultStringTagName;
00113   const nsLiteralString  kFaultActorTagName;
00114   const nsLiteralString  kFaultDetailTagName;
00115   const nsLiteralString  kEncodingSeparator;
00116   const nsLiteralString  kQualifiedSeparator;
00117   const nsLiteralString  kXMLNamespaceNamespaceURI;
00118   const nsLiteralString  kXMLNamespaceURI;
00119   const nsLiteralString  kXMLNamespacePrefix;
00120   const nsLiteralString  kXMLPrefix;
00121   const nsLiteralString  kTrue;
00122   const nsLiteralString  kTrueA;
00123   const nsLiteralString  kFalse;
00124   const nsLiteralString  kFalseA;
00125   const nsLiteralString  kVerifySourceHeader;
00126   const nsLiteralString  kVerifySourceURI;
00127   const nsLiteralString  kVerifySourceNamespaceURI;
00128 
00129   // used by nsDefaultSOAPEncoder.cpp
00130   const nsLiteralString  kEmpty;
00131   const nsLiteralString  kNull;
00132   const nsLiteralString  kNil;
00133   const nsLiteralString  kSOAPArrayTypeAttribute;
00134   const nsLiteralString  kSOAPArrayOffsetAttribute;
00135   const nsLiteralString  kSOAPArrayPositionAttribute;
00136   const nsLiteralString  kAnyTypeSchemaType;
00137   const nsLiteralString  kAnySimpleTypeSchemaType;
00138   const nsLiteralString  kArraySOAPType;
00139   const nsLiteralString  kStructSOAPType;
00140   const nsLiteralString  kStringSchemaType;
00141   const nsLiteralString  kBooleanSchemaType;
00142   const nsLiteralString  kFloatSchemaType;
00143   const nsLiteralString  kDoubleSchemaType;
00144   const nsLiteralString  kLongSchemaType;
00145   const nsLiteralString  kIntSchemaType;
00146   const nsLiteralString  kShortSchemaType;
00147   const nsLiteralString  kByteSchemaType;
00148   const nsLiteralString  kUnsignedLongSchemaType;
00149   const nsLiteralString  kUnsignedIntSchemaType;
00150   const nsLiteralString  kUnsignedShortSchemaType;
00151   const nsLiteralString  kUnsignedByteSchemaType;
00152   const nsLiteralString  kNormalizedStringSchemaType;
00153   const nsLiteralString  kTokenSchemaType;
00154   const nsLiteralString  kNameSchemaType;
00155   const nsLiteralString  kNCNameSchemaType;
00156   const nsLiteralString  kDecimalSchemaType;
00157   const nsLiteralString  kIntegerSchemaType;
00158   const nsLiteralString  kNonPositiveIntegerSchemaType;
00159   const nsLiteralString  kNonNegativeIntegerSchemaType;
00160   const nsLiteralString  kBase64BinarySchemaType;
00161 
00162   nsSOAPStrings();
00163 };
00164 
00165 extern nsSOAPStrings *gSOAPStrings;
00166 
00167 //  Used to support null strings.
00168 
00169 inline PRBool AStringIsNull(const nsAString & aString)
00170 {
00171   return aString.IsVoid() || aString.IsEmpty();        // Get rid of empty hack when string implementations support.
00172 }
00173 
00174 inline void SetAStringToNull(nsAString & aString)
00175 {
00176   aString.SetIsVoid(PR_TRUE);
00177 }
00178 
00179 #define NS_SOAP_ENSURE_ARG_STRING(arg) \
00180 NS_ENSURE_FALSE(AStringIsNull(arg), NS_ERROR_INVALID_ARG)
00181 
00182 inline void
00183 SOAPEncodingKey(const nsAString & aURI, const nsAString & aType,
00184                 nsAString & result)
00185 {
00186   result = aURI + gSOAPStrings->kEncodingSeparator + aType;
00187 }
00188 
00189 #endif