epoc32/include/mw/sensoapenvelope.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
parent 2 2fe1408b6811
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
     1 /*
     2 * Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies). 
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description:        CSenSoapEnvelope is an utility class offering capability to 
    15 *                 parse XML SOAP envelope and manipulation methods to alter its
    16 *                 contents.
    17 *
    18 */
    19 
    20 
    21 
    22 
    23 
    24 
    25 
    26 
    27 #ifndef SEN_SOAP_ENVELOPE_H
    28 #define SEN_SOAP_ENVELOPE_H
    29 
    30 //  INCLUDES
    31 #include <SenBaseFragment.h>
    32 #include <SenSoapConstants.h>
    33 
    34 // CONSTANTS
    35 _LIT8(KSoapActionHeaderValueEmpty,	"\"\""); // default, if not set
    36 
    37 /*
    38 // Now declared in <SenSoapConstants.h>
    39 _LIT8(KSenSoap12ContentTypeHeaderValue, "application/soap+xml; charset=\"UTF-8\"");
    40 _LIT8(KSenSoap12AcceptHeaderValue,      "application/soap+xml");
    41 _LIT8(KSenSoapEnvelopeName,             "Envelope");
    42 _LIT8(KSenSoapEnvelopeQName,            "S:Envelope");
    43 
    44 _LIT8(KSenSoapEnvelopeXmlns,            "http://schemas.xmlsoap.org/soap/envelope/");
    45 _LIT8(KSenSoap12EnvelopeXmlns,          "http://www.w3.org/2003/05/soap-envelope");
    46 _LIT8(KSenSoapEnvelopeHeaderName,       "Header");
    47 _LIT8(KSenSoapEnvelopeHeaderQName,      "S:Header");
    48 _LIT8(KSenSoapEnvelopeBodyName,         "Body");
    49 _LIT8(KSenSoapEnvelopeBodyQName,        "S:Body");
    50 _LIT8(KSenSoapFaultName,                "Fault");
    51 
    52 _LIT8(KSenSoapActionHeaderName,         "SOAPAction");
    53 _LIT8(KSenSoapActionHeaderValueEmpty,   "\"\"");
    54 
    55 
    56 const TInt KStateParsingSoapHeader  = 20; // ignore state   (even number)
    57 const TInt KStateParsingSoapBody    = 40; // ignore state   (even number)
    58 const TInt KStateParsingSoapFault   = 5;  // save state     (odd number)
    59 
    60 enum TSOAPVersion
    61         {
    62         ESOAP11 = 1,
    63         ESOAP12
    64         };
    65 */
    66 
    67 // FORWARD DECLARATIONS
    68 class CSenSoapFault;
    69 
    70 // CLASS DECLARATION
    71 
    72 /**
    73 * CSenSoapEnvelope is an utility class offering capability to parse
    74 * XML SOAP envelope and manipulation methods to alter its contents.
    75 * Typically WSC uses this class to parse messages received through
    76 * WSF HandleMessageL() and HandleErrorL() callbacks.
    77 * Class has convenience methods for checking if a SOAP envelope body
    78 * contains a fault and functionality to detach SOAP Fault object out
    79 * from it. Also possibility to set SOAPAction HTTP header is supported.
    80 *  @lib SenUtils.lib
    81 *  @since Series60 3.0
    82 */
    83 class CSenSoapEnvelope : public CSenBaseFragment
    84     {
    85     public:  // Constructors and destructor
    86         
    87         /**
    88         * Two-phased constructor.
    89         */
    90         IMPORT_C static CSenSoapEnvelope* NewL();
    91         
    92         /**
    93         * Destructor.
    94         */
    95         IMPORT_C virtual ~CSenSoapEnvelope();
    96 
    97         // New functions
    98         
    99         /**
   100         * Sets body of the envelope.
   101         * @since Series60 3.0 
   102         * @param aBody      Body (content) to be set.
   103         * @return SOAP body (content) which was just set
   104         */
   105         IMPORT_C virtual TPtrC8 SetBodyL(const TDesC8& aBody);
   106 
   107         /**
   108         * Getter for envelopes body
   109         * @since Series60 3.0 
   110         * @return body as CSenElement
   111         */
   112         IMPORT_C virtual CSenElement& BodyL();
   113 
   114         /**
   115         * Getter for envelopes header
   116         * @since Series60 3.0 
   117         * @return header as CSenElement
   118         */
   119         IMPORT_C virtual CSenElement& HeaderL();
   120 
   121         /**
   122         * Adds an element to the header.
   123         * @since Series60 3.0 
   124         * @param aHeaderElement new child element to be
   125         *        added inside Header  element. Ownership
   126         *        is always transferred to CSenSoapEnvelope.
   127         * @return added CSenElement
   128         */
   129         IMPORT_C virtual CSenElement& AddHeaderL(CSenElement& aHeaderElement);
   130 
   131         /**
   132         * Getter for the envelope body as a UTF-8 form XML string.
   133         * @since Series60 3.0 
   134         * @return body as a HBufC8 pointer. Ownership is transferred to caller.
   135         */
   136         IMPORT_C virtual HBufC8* BodyAsStringL();
   137 
   138         /**
   139         * Checks if this SOAP envelope body contains SOAP fault or not.
   140         * @since Series60 3.0 
   141         * @return TBool ETrue if there is a fault, EFalse if not.
   142         */
   143         IMPORT_C virtual TBool IsFault();
   144 
   145         /**
   146         * Detaches the <Fault> element from the envelope, removing the element
   147         * from the envelope.
   148         * @since Series60 3.0 
   149         * @return pointer to the soap fault. Caller takes the ownership. 
   150         *         NULL if <Fault> element is non-existent.
   151         */
   152         IMPORT_C virtual CSenSoapFault* DetachFaultL();
   153         
   154         /**
   155         * Gets the <Fault> element. Ownership is not transferred. 
   156         * NULL if not a fault.
   157         * @since Series60 3.0 
   158         * @return reference to SOAP fault object owned by this SOAP envelope
   159         */
   160         IMPORT_C virtual CSenSoapFault* FaultL();
   161 
   162         /**
   163         * Sets the SOAP action HTTP header. WSF will use this value
   164         * while submitting this SOAP envelope request over HTTP/S transport.
   165         * @since Series60 3.0 
   166         * @param aSoapAction    the SOAP Action HTTP header to be set.
   167         * The default value is KSenSoapActionHeaderValueEmpty, which is
   168         * two double quotation marks - "" - without any character in between.
   169         * SOAP specification requires double quotation marks, even if action
   170         * is empty.
   171         * If a string without double quotation marks is passed, it will be 
   172         * wrapped inside double quotation marks, added in the beginning and 
   173         * at the end of the actual SOAP Action string.
   174         *
   175         * @return newly set SOAP action header. String might have been
   176         * extended to include double quotation marks, if those were missing 
   177         * from the argument. 
   178         */
   179         IMPORT_C virtual TPtrC8 SetSoapActionL(const TDesC8& aSoapAction);
   180 
   181         /**
   182         * Gets the soap action header.
   183         * @since Series60 3.0 
   184         * @return   current SOAP action header, which is always wrapped
   185         * inside double quotation marks. If SOAPAction has not been set
   186         * for this SOAP envelope, function will return zero-length 
   187         * descriptor (KNullDesC8)
   188         */
   189         IMPORT_C virtual TPtrC8 SoapAction();      
   190 
   191         /**
   192         * Gets the soap action header.
   193         * @since Series60 5.0 
   194         * @return   current SOAP action header, which is always wrapped
   195         * inside double quotation marks. If SOAPAction has not been set
   196         * for this SOAP envelope, function will return zero-length 
   197         * descriptor (KNullDesC8)
   198         */
   199 			IMPORT_C TPtrC8 SoapAction2() ;
   200         
   201         /**
   202         * Method parses given piece of XML into this SOAP envelope
   203         */
   204         IMPORT_C void ParseL(const TDesC8& aXml); 
   205 
   206         /*
   207         * Getter for checking whether this message has at least one
   208         * valid <Header> element
   209         * @return ETrue, if <Header> element exists, EFalse otherwise.
   210         */
   211         IMPORT_C TBool HasHeader();
   212 
   213         /*
   214         * Getter for checking whether this message has valid <Body> element
   215         * @return ETrue, if <Body> element exists, EFalse otherwise.
   216         */
   217         IMPORT_C TBool HasBody();
   218 
   219         /**
   220         * Getter for currently effecitve SOAP version.
   221         * @return enumeration which dictates SOAP version.
   222         */
   223         IMPORT_C TSOAPVersion SoapVersion();
   224 
   225 
   226     protected:  
   227             
   228         /**
   229          *    Constructor.
   230          */
   231         CSenSoapEnvelope();
   232         
   233         /**
   234         * This method should be called from the deriving
   235         * classes ConstructL() methods. 
   236         * @since Series60 3.0
   237         */
   238         IMPORT_C void BaseConstructL(TSOAPVersion aVersion);
   239 
   240         /**
   241         * This method should be called from the deriving
   242         * classes ConstructL() methods. 
   243         * @since Series60 3.0
   244         */
   245         IMPORT_C void BaseConstructL();
   246         
   247         // New functions
   248         
   249         /**
   250         * This method should be overridden by subclasses. 
   251         * Implements functionality to parse SOAP header if one is found
   252         * during parsing the envelope.
   253         * Parses all elements found under top <Header> element by
   254         * using DOM fragment.
   255         * @since Series60 3.0 
   256         * @param aNsUri            The namespace URI of the new element
   257         * @param aLocalName        The local name of the new element
   258         * @param aQName            The qualified name of the new element
   259         * @param aAttributes    The attributes of the new element
   260         */
   261         IMPORT_C virtual void ParseHeaderL( const TDesC8& aNsUri,
   262                                             const TDesC8& aLocalName,
   263                                             const TDesC8& aQName,
   264                                             const RAttributeArray& aAttributes);
   265                                             
   266         // Functions from base classes
   267         
   268         // From CSenBaseFragment 
   269         
   270         /**
   271         * Callback function which implement the XML content handler interface.
   272         * This callback will occur on each start element tag found in the XML
   273         * document.
   274         * The SOAP envelope recognizes and parses the following elements and
   275         * their corresponding attributes inside namespace defined in 
   276         * KSenSoapEnvelopeXmlns:
   277         *  KSenSoapEnvelopeName,    "Envelope"
   278         *  KSenSoapHeaderName,      "Header"
   279         *  KSenSoapBodyName,        "Body"
   280         *  KSenSoapFault,           "Fault" (only if found inside Body element)
   281         *
   282         * @since Series60 3.0 
   283         * @param aNsUri            The namespace URI of the new element
   284         * @param aLocalName        The local name of the new element
   285         * @param aQName            The qualified name of the new element
   286         * @param aAttributes    The attributes of the new element
   287         */
   288         IMPORT_C virtual void StartElementL(const TDesC8& aNsUri,
   289                                             const TDesC8& aLocalName,
   290                                             const TDesC8& aQName,
   291                                             const RAttributeArray& aAttributes);
   292 
   293         /**
   294         * Callback function which implement the XML content handler interface.
   295         * This callback will occur on each end element tag found in the XML
   296         * document.
   297         * @since Series60 3.0 
   298         * @param aNsUri        The namespace URI of the new element
   299         * @param aLocalName    The local name of the new element
   300         * @param aQName        The qualified name of the new element
   301         */
   302         IMPORT_C virtual void EndElementL(const TDesC8& aNsUri,
   303                                           const TDesC8& aLocalName,
   304                                           const TDesC8& aQName);
   305 
   306     protected: // Data
   307         // Internal members, protected so that deriving classes have access to them.
   308         CSenBaseFragment* ipBodyFragment;
   309         CSenBaseFragment* ipHeaderFragment;
   310         HBufC8* ipSoapAction;
   311 
   312     private: // Data
   313         TBool iFault;
   314        };
   315 
   316 #endif // SEN_SOAP_ENVELOPE_H
   317 
   318 // End of File
   319 
   320 
   321