williamr@2: /* williamr@2: * Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies). williamr@2: * All rights reserved. williamr@2: * This component and the accompanying materials are made available williamr@2: * under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members williamr@2: * which accompanies this distribution, and is available williamr@2: * at the URL "http://www.symbianfoundation.org/legal/licencesv10.html". williamr@2: * williamr@2: * Initial Contributors: williamr@2: * Nokia Corporation - initial contribution. williamr@2: * williamr@2: * Contributors: williamr@2: * williamr@2: * Description: CSenSoapEnvelope is an utility class offering capability to williamr@2: * parse XML SOAP envelope and manipulation methods to alter its williamr@2: * contents. williamr@2: * williamr@2: */ williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: #ifndef SEN_SOAP_ENVELOPE_H williamr@2: #define SEN_SOAP_ENVELOPE_H williamr@2: williamr@2: // INCLUDES williamr@2: #include williamr@2: #include williamr@2: williamr@2: // CONSTANTS williamr@2: _LIT8(KSoapActionHeaderValueEmpty, "\"\""); // default, if not set williamr@2: williamr@2: /* williamr@2: // Now declared in williamr@2: _LIT8(KSenSoap12ContentTypeHeaderValue, "application/soap+xml; charset=\"UTF-8\""); williamr@2: _LIT8(KSenSoap12AcceptHeaderValue, "application/soap+xml"); williamr@2: _LIT8(KSenSoapEnvelopeName, "Envelope"); williamr@2: _LIT8(KSenSoapEnvelopeQName, "S:Envelope"); williamr@2: williamr@2: _LIT8(KSenSoapEnvelopeXmlns, "http://schemas.xmlsoap.org/soap/envelope/"); williamr@2: _LIT8(KSenSoap12EnvelopeXmlns, "http://www.w3.org/2003/05/soap-envelope"); williamr@2: _LIT8(KSenSoapEnvelopeHeaderName, "Header"); williamr@2: _LIT8(KSenSoapEnvelopeHeaderQName, "S:Header"); williamr@2: _LIT8(KSenSoapEnvelopeBodyName, "Body"); williamr@2: _LIT8(KSenSoapEnvelopeBodyQName, "S:Body"); williamr@2: _LIT8(KSenSoapFaultName, "Fault"); williamr@2: williamr@2: _LIT8(KSenSoapActionHeaderName, "SOAPAction"); williamr@2: _LIT8(KSenSoapActionHeaderValueEmpty, "\"\""); williamr@2: williamr@2: williamr@2: const TInt KStateParsingSoapHeader = 20; // ignore state (even number) williamr@2: const TInt KStateParsingSoapBody = 40; // ignore state (even number) williamr@2: const TInt KStateParsingSoapFault = 5; // save state (odd number) williamr@2: williamr@2: enum TSOAPVersion williamr@2: { williamr@2: ESOAP11 = 1, williamr@2: ESOAP12 williamr@2: }; williamr@2: */ williamr@2: williamr@2: // FORWARD DECLARATIONS williamr@2: class CSenSoapFault; williamr@2: williamr@2: // CLASS DECLARATION williamr@2: williamr@2: /** williamr@2: * CSenSoapEnvelope is an utility class offering capability to parse williamr@2: * XML SOAP envelope and manipulation methods to alter its contents. williamr@2: * Typically WSC uses this class to parse messages received through williamr@2: * WSF HandleMessageL() and HandleErrorL() callbacks. williamr@2: * Class has convenience methods for checking if a SOAP envelope body williamr@2: * contains a fault and functionality to detach SOAP Fault object out williamr@2: * from it. Also possibility to set SOAPAction HTTP header is supported. williamr@2: * @lib SenUtils.lib williamr@2: * @since Series60 3.0 williamr@2: */ williamr@2: class CSenSoapEnvelope : public CSenBaseFragment williamr@2: { williamr@2: public: // Constructors and destructor williamr@2: williamr@2: /** williamr@2: * Two-phased constructor. williamr@2: */ williamr@2: IMPORT_C static CSenSoapEnvelope* NewL(); williamr@2: williamr@2: /** williamr@2: * Destructor. williamr@2: */ williamr@2: IMPORT_C virtual ~CSenSoapEnvelope(); williamr@2: williamr@2: // New functions williamr@2: williamr@2: /** williamr@2: * Sets body of the envelope. williamr@2: * @since Series60 3.0 williamr@2: * @param aBody Body (content) to be set. williamr@2: * @return SOAP body (content) which was just set williamr@2: */ williamr@2: IMPORT_C virtual TPtrC8 SetBodyL(const TDesC8& aBody); williamr@2: williamr@2: /** williamr@2: * Getter for envelopes body williamr@2: * @since Series60 3.0 williamr@2: * @return body as CSenElement williamr@2: */ williamr@2: IMPORT_C virtual CSenElement& BodyL(); williamr@2: williamr@2: /** williamr@2: * Getter for envelopes header williamr@2: * @since Series60 3.0 williamr@2: * @return header as CSenElement williamr@2: */ williamr@2: IMPORT_C virtual CSenElement& HeaderL(); williamr@2: williamr@2: /** williamr@2: * Adds an element to the header. williamr@2: * @since Series60 3.0 williamr@2: * @param aHeaderElement new child element to be williamr@2: * added inside Header element. Ownership williamr@2: * is always transferred to CSenSoapEnvelope. williamr@2: * @return added CSenElement williamr@2: */ williamr@2: IMPORT_C virtual CSenElement& AddHeaderL(CSenElement& aHeaderElement); williamr@2: williamr@2: /** williamr@2: * Getter for the envelope body as a UTF-8 form XML string. williamr@2: * @since Series60 3.0 williamr@2: * @return body as a HBufC8 pointer. Ownership is transferred to caller. williamr@2: */ williamr@2: IMPORT_C virtual HBufC8* BodyAsStringL(); williamr@2: williamr@2: /** williamr@2: * Checks if this SOAP envelope body contains SOAP fault or not. williamr@2: * @since Series60 3.0 williamr@2: * @return TBool ETrue if there is a fault, EFalse if not. williamr@2: */ williamr@2: IMPORT_C virtual TBool IsFault(); williamr@2: williamr@2: /** williamr@2: * Detaches the element from the envelope, removing the element williamr@2: * from the envelope. williamr@2: * @since Series60 3.0 williamr@2: * @return pointer to the soap fault. Caller takes the ownership. williamr@2: * NULL if element is non-existent. williamr@2: */ williamr@2: IMPORT_C virtual CSenSoapFault* DetachFaultL(); williamr@2: williamr@2: /** williamr@2: * Gets the element. Ownership is not transferred. williamr@2: * NULL if not a fault. williamr@2: * @since Series60 3.0 williamr@2: * @return reference to SOAP fault object owned by this SOAP envelope williamr@2: */ williamr@2: IMPORT_C virtual CSenSoapFault* FaultL(); williamr@2: williamr@2: /** williamr@2: * Sets the SOAP action HTTP header. WSF will use this value williamr@2: * while submitting this SOAP envelope request over HTTP/S transport. williamr@2: * @since Series60 3.0 williamr@2: * @param aSoapAction the SOAP Action HTTP header to be set. williamr@2: * The default value is KSenSoapActionHeaderValueEmpty, which is williamr@2: * two double quotation marks - "" - without any character in between. williamr@2: * SOAP specification requires double quotation marks, even if action williamr@2: * is empty. williamr@2: * If a string without double quotation marks is passed, it will be williamr@2: * wrapped inside double quotation marks, added in the beginning and williamr@2: * at the end of the actual SOAP Action string. williamr@2: * williamr@2: * @return newly set SOAP action header. String might have been williamr@2: * extended to include double quotation marks, if those were missing williamr@2: * from the argument. williamr@2: */ williamr@2: IMPORT_C virtual TPtrC8 SetSoapActionL(const TDesC8& aSoapAction); williamr@2: williamr@2: /** williamr@2: * Gets the soap action header. williamr@2: * @since Series60 3.0 williamr@2: * @return current SOAP action header, which is always wrapped williamr@2: * inside double quotation marks. If SOAPAction has not been set williamr@2: * for this SOAP envelope, function will return zero-length williamr@2: * descriptor (KNullDesC8) williamr@2: */ williamr@2: IMPORT_C virtual TPtrC8 SoapAction(); williamr@2: williamr@2: /** williamr@2: * Gets the soap action header. williamr@2: * @since Series60 5.0 williamr@2: * @return current SOAP action header, which is always wrapped williamr@2: * inside double quotation marks. If SOAPAction has not been set williamr@2: * for this SOAP envelope, function will return zero-length williamr@2: * descriptor (KNullDesC8) williamr@2: */ williamr@2: IMPORT_C TPtrC8 SoapAction2() ; williamr@2: williamr@2: /** williamr@2: * Method parses given piece of XML into this SOAP envelope williamr@2: */ williamr@2: IMPORT_C void ParseL(const TDesC8& aXml); williamr@2: williamr@2: /* williamr@2: * Getter for checking whether this message has at least one williamr@2: * valid
element williamr@2: * @return ETrue, if
element exists, EFalse otherwise. williamr@2: */ williamr@2: IMPORT_C TBool HasHeader(); williamr@2: williamr@2: /* williamr@2: * Getter for checking whether this message has valid element williamr@2: * @return ETrue, if element exists, EFalse otherwise. williamr@2: */ williamr@2: IMPORT_C TBool HasBody(); williamr@2: williamr@2: /** williamr@2: * Getter for currently effecitve SOAP version. williamr@2: * @return enumeration which dictates SOAP version. williamr@2: */ williamr@2: IMPORT_C TSOAPVersion SoapVersion(); williamr@2: williamr@2: williamr@2: protected: williamr@2: williamr@2: /** williamr@2: * Constructor. williamr@2: */ williamr@2: CSenSoapEnvelope(); williamr@2: williamr@2: /** williamr@2: * This method should be called from the deriving williamr@2: * classes ConstructL() methods. williamr@2: * @since Series60 3.0 williamr@2: */ williamr@2: IMPORT_C void BaseConstructL(TSOAPVersion aVersion); williamr@2: williamr@2: /** williamr@2: * This method should be called from the deriving williamr@2: * classes ConstructL() methods. williamr@2: * @since Series60 3.0 williamr@2: */ williamr@2: IMPORT_C void BaseConstructL(); williamr@2: williamr@2: // New functions williamr@2: williamr@2: /** williamr@2: * This method should be overridden by subclasses. williamr@2: * Implements functionality to parse SOAP header if one is found williamr@2: * during parsing the envelope. williamr@2: * Parses all elements found under top
element by williamr@2: * using DOM fragment. williamr@2: * @since Series60 3.0 williamr@2: * @param aNsUri The namespace URI of the new element williamr@2: * @param aLocalName The local name of the new element williamr@2: * @param aQName The qualified name of the new element williamr@2: * @param aAttributes The attributes of the new element williamr@2: */ williamr@2: IMPORT_C virtual void ParseHeaderL( const TDesC8& aNsUri, williamr@2: const TDesC8& aLocalName, williamr@2: const TDesC8& aQName, williamr@2: const RAttributeArray& aAttributes); williamr@2: williamr@2: // Functions from base classes williamr@2: williamr@2: // From CSenBaseFragment williamr@2: williamr@2: /** williamr@2: * Callback function which implement the XML content handler interface. williamr@2: * This callback will occur on each start element tag found in the XML williamr@2: * document. williamr@2: * The SOAP envelope recognizes and parses the following elements and williamr@2: * their corresponding attributes inside namespace defined in williamr@2: * KSenSoapEnvelopeXmlns: williamr@2: * KSenSoapEnvelopeName, "Envelope" williamr@2: * KSenSoapHeaderName, "Header" williamr@2: * KSenSoapBodyName, "Body" williamr@2: * KSenSoapFault, "Fault" (only if found inside Body element) williamr@2: * williamr@2: * @since Series60 3.0 williamr@2: * @param aNsUri The namespace URI of the new element williamr@2: * @param aLocalName The local name of the new element williamr@2: * @param aQName The qualified name of the new element williamr@2: * @param aAttributes The attributes of the new element williamr@2: */ williamr@2: IMPORT_C virtual void StartElementL(const TDesC8& aNsUri, williamr@2: const TDesC8& aLocalName, williamr@2: const TDesC8& aQName, williamr@2: const RAttributeArray& aAttributes); williamr@2: williamr@2: /** williamr@2: * Callback function which implement the XML content handler interface. williamr@2: * This callback will occur on each end element tag found in the XML williamr@2: * document. williamr@2: * @since Series60 3.0 williamr@2: * @param aNsUri The namespace URI of the new element williamr@2: * @param aLocalName The local name of the new element williamr@2: * @param aQName The qualified name of the new element williamr@2: */ williamr@2: IMPORT_C virtual void EndElementL(const TDesC8& aNsUri, williamr@2: const TDesC8& aLocalName, williamr@2: const TDesC8& aQName); williamr@2: williamr@2: protected: // Data williamr@2: // Internal members, protected so that deriving classes have access to them. williamr@2: CSenBaseFragment* ipBodyFragment; williamr@2: CSenBaseFragment* ipHeaderFragment; williamr@2: HBufC8* ipSoapAction; williamr@2: williamr@2: private: // Data williamr@2: TBool iFault; williamr@2: }; williamr@2: williamr@2: #endif // SEN_SOAP_ENVELOPE_H williamr@2: williamr@2: // End of File williamr@2: williamr@2: williamr@2: