ncdengine/provider/protocol/src/ncd_parser_pp_purchaseentity.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2006 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:   CNcdPreminetProtocolPurchaseEntityParser implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "ncd_parser_pp_purchaseentity.h"
       
    20 #include "ncd_parser_pp_payment.h"
       
    21 #include "ncd_parser_pp_download.h"
       
    22 #include "ncd_pp_purchaseentityimpl.h"
       
    23 #include "ncd_pp_download.h"
       
    24 #include "ncd_pp_purchase.h"
       
    25 #include "ncdparserobserverbundleimpl.h"
       
    26 #include "ncdunknownparser.h"
       
    27 #include "ncdprotocolwords.h"
       
    28 #include "ncdprotocolutils.h"
       
    29 #include "ncdprotocoltypes.h"
       
    30 
       
    31 #include "catalogsdebug.h"
       
    32 
       
    33 
       
    34 CNcdPreminetProtocolPurchaseEntityParser* 
       
    35 CNcdPreminetProtocolPurchaseEntityParser::NewL( 
       
    36     MNcdParserObserverBundle& aObservers,
       
    37     MNcdSubParserObserver& aSubParserObserver,
       
    38     TInt aDepth,
       
    39     const Xml::RTagInfo& aElement,
       
    40     const Xml::RAttributeArray& aAttributes,
       
    41     const TDesC& aParentId )
       
    42     {
       
    43     CNcdPreminetProtocolPurchaseEntityParser* self 
       
    44         = new(ELeave) CNcdPreminetProtocolPurchaseEntityParser( 
       
    45             aObservers, aSubParserObserver, aDepth );
       
    46     CleanupStack::PushL( self );
       
    47     self->ConstructL( aElement, aAttributes, aParentId );
       
    48     CleanupStack::Pop( self );
       
    49     return self;
       
    50     }
       
    51 
       
    52 CNcdPreminetProtocolPurchaseEntityParser::CNcdPreminetProtocolPurchaseEntityParser( 
       
    53     MNcdParserObserverBundle& aObservers,
       
    54     MNcdSubParserObserver& aSubParserObserver,
       
    55     TInt aDepth )
       
    56     : CNcdSubParser( aObservers, aSubParserObserver, aDepth )
       
    57     {
       
    58 
       
    59     }
       
    60 
       
    61 CNcdPreminetProtocolPurchaseEntityParser::~CNcdPreminetProtocolPurchaseEntityParser()
       
    62     {
       
    63     delete iEntity;
       
    64     }
       
    65 
       
    66 void CNcdPreminetProtocolPurchaseEntityParser::ConstructL( 
       
    67     const Xml::RTagInfo& aElement,
       
    68     const Xml::RAttributeArray& aAttributes,
       
    69     const TDesC& /*aParentId*/ )
       
    70     {
       
    71     CNcdSubParser::ConstructL( aElement );
       
    72 
       
    73     DLTRACEIN(("depth=%d tag=%S",iDepth,iTag));
       
    74     //DLINFO((_L("parent=%S"),&aParentId));
       
    75 
       
    76     if (!iEntity)
       
    77         {
       
    78         iEntity = CNcdPreminetProtocolPurchaseEntityImpl::NewL();
       
    79         }
       
    80 
       
    81     // read attributes here
       
    82     TPtrC8 ticket = AttributeValue( KAttrTicket, aAttributes );
       
    83     NcdProtocolUtils::AssignDesL(iEntity->iTicket, ticket);
       
    84 
       
    85     TPtrC8 id = AttributeValue( KAttrId, aAttributes );
       
    86     NcdProtocolUtils::AssignDesL(iEntity->iId, id);
       
    87     }
       
    88 
       
    89 
       
    90 void CNcdPreminetProtocolPurchaseEntityParser::OnStartElementL( 
       
    91     const Xml::RTagInfo& aElement, 
       
    92     const Xml::RAttributeArray& aAttributes, 
       
    93     TInt aErrorCode) 
       
    94     {
       
    95     CNcdSubParser::OnStartElementL( aElement, aAttributes, aErrorCode );
       
    96     
       
    97     TPtrC8 tag( aElement.LocalName().DesC() );
       
    98     
       
    99     if( iSubParser == 0 )
       
   100         {
       
   101         DLTRACEIN(("purchaseEntity start tag=%S error=%d depth=%d",
       
   102             &aElement.LocalName().DesC(),aErrorCode,iDepth));
       
   103         if( tag == KTagDelivery )
       
   104             {
       
   105             TPtrC8 method = AttributeValue( KAttrMethod, aAttributes );
       
   106             if (method == KValueDirect)
       
   107                 iEntity->iDeliveryMethods.Append(EDeliveryDirect);
       
   108             if (method == KValueSms)
       
   109                 iEntity->iDeliveryMethods.Append(EDeliverySms);
       
   110             if (method == KValueWapPush)
       
   111                 iEntity->iDeliveryMethods.Append(EDeliveryWapPush);
       
   112             if (method == KValueNone)
       
   113                 iEntity->iDeliveryMethods.Append(EDeliveryNone);
       
   114             }
       
   115         else if( tag == KTagPrice )
       
   116             {
       
   117             TPtrC8 currency = AttributeValue( KAttrCurrency, aAttributes );
       
   118             NcdProtocolUtils::AssignDesL(iEntity->iPriceCurrency, currency);
       
   119             // price value saved in OnEndElementL
       
   120             }
       
   121         else if( tag == KTagPriceText )
       
   122             {
       
   123             // price text saved in OnEndElementL
       
   124             }
       
   125         else if( tag == KTagDownloadDetails )
       
   126             {
       
   127             iSubParser = CNcdPreminetProtocolDownloadParser::NewL( 
       
   128                 *iObservers, *this, iDepth+1, aElement, aAttributes,
       
   129                 KNullDesC /*no parent id*/ );
       
   130             }
       
   131         else
       
   132             {
       
   133             iSubParser = CNcdUnknownParser::NewL( 
       
   134                 *iObservers, *this, iDepth+1, aElement, aAttributes );
       
   135             }
       
   136         }
       
   137     else
       
   138         {
       
   139         iSubParser->OnStartElementL( aElement, aAttributes, aErrorCode );
       
   140         }
       
   141     }
       
   142 
       
   143 
       
   144 
       
   145 void CNcdPreminetProtocolPurchaseEntityParser::OnEndElementL(
       
   146     const Xml::RTagInfo& aElement, TInt aErrorCode) 
       
   147     {
       
   148     DLTRACEIN((""));
       
   149 
       
   150     TPtrC8 tag( aElement.LocalName().DesC() );
       
   151     if (iBuffer) 
       
   152         {
       
   153         if (tag == KTagPrice)
       
   154             {
       
   155             NcdProtocolUtils::AssignDesL(iEntity->iPrice, *iBuffer);
       
   156             }
       
   157         else if (tag == KTagPriceText)
       
   158             {
       
   159             NcdProtocolUtils::AssignDesL(iEntity->iPriceText, *iBuffer);
       
   160             }
       
   161         delete iBuffer;
       
   162         iBuffer = 0;
       
   163         }
       
   164 
       
   165     if( iSubParser == 0 && iTag && *iTag == aElement.LocalName().DesC() )
       
   166         {
       
   167         DLTRACE(("end tag=%S",&aElement.LocalName().DesC()));
       
   168         // Should store finished entity, or let the parent do it with some function?
       
   169         iSubParserObserver->SubParserFinishedL( aElement.LocalName().DesC(), aErrorCode );
       
   170         }
       
   171     else if( iSubParser )
       
   172         {
       
   173         iSubParser->OnEndElementL( aElement, aErrorCode );
       
   174         }
       
   175     else
       
   176         {
       
   177         DLWARNING(("end tag ignored, tag=%S",&aElement.LocalName().DesC()));
       
   178         }
       
   179     }
       
   180 
       
   181 
       
   182 void CNcdPreminetProtocolPurchaseEntityParser::SubParserFinishedL( 
       
   183     const TDesC8& aTag, TInt aErrorCode )
       
   184     {
       
   185     DLTRACEIN(("tag=%S subparser=%X error=%d",&aTag,iSubParser,aErrorCode));
       
   186     (void) aTag; // suppresses compiler warning
       
   187     (void) aErrorCode; // suppresses compiler warning
       
   188 
       
   189     // : child entity has been finished. store it as a 
       
   190     // a childen to the node this parser is parsing.
       
   191 
       
   192     // Needs nodemanager.
       
   193     if( iSubParser->Tag() == KTagDownloadDetails )
       
   194         {
       
   195         // A subentity is now ready. Report it
       
   196         MNcdPreminetProtocolDownload* download = 
       
   197             static_cast<CNcdPreminetProtocolDownloadParser*>
       
   198             (iSubParser)->Download();
       
   199         DLINFO(("subparser download=%X",download));
       
   200         if( download && iEntity )
       
   201             {
       
   202             iEntity->iDownloadDetails.AppendL( download );
       
   203             }
       
   204         }
       
   205 
       
   206     delete iSubParser;
       
   207     iSubParser = 0;
       
   208     }
       
   209 
       
   210 MNcdPreminetProtocolPurchaseEntity*
       
   211 CNcdPreminetProtocolPurchaseEntityParser::Entity()
       
   212     {
       
   213     MNcdPreminetProtocolPurchaseEntity* entity = iEntity;
       
   214     iEntity = 0;
       
   215     return entity;
       
   216     }
       
   217