ncdengine/provider/protocol/src/ncd_parser_pp_download.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:   CNcdEntityRefParser implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "ncd_parser_pp_download.h"
       
    20 #include "ncd_parser_pp_rights.h"
       
    21 #include "ncd_parser_cp_query.h"
       
    22 #include "ncd_pp_download.h"
       
    23 #include "ncd_pp_downloadimpl.h"
       
    24 #include "ncd_pp_descriptor.h"
       
    25 #include "ncd_pp_descriptorimpl.h"
       
    26 #include "ncd_cp_query.h"
       
    27 #include "ncd_cp_queryimpl.h"
       
    28 #include "ncdparserobserverbundleimpl.h"
       
    29 #include "ncdunknownparser.h"
       
    30 #include "ncdprotocolwords.h"
       
    31 #include "ncdprotocolutils.h"
       
    32 #include "ncdprotocoltypes.h"
       
    33 
       
    34 #include "catalogsdebug.h"
       
    35 
       
    36 
       
    37 CNcdPreminetProtocolDownloadParser* CNcdPreminetProtocolDownloadParser::NewL( 
       
    38     MNcdParserObserverBundle& aObservers,
       
    39     MNcdSubParserObserver& aSubParserObserver,
       
    40     TInt aDepth,
       
    41     const Xml::RTagInfo& aElement,
       
    42     const Xml::RAttributeArray& aAttributes,
       
    43     const TDesC& aParentId )
       
    44     {
       
    45     CNcdPreminetProtocolDownloadParser* self 
       
    46         = new(ELeave) CNcdPreminetProtocolDownloadParser( 
       
    47             aObservers, aSubParserObserver, aDepth );
       
    48     CleanupStack::PushL( self );
       
    49     self->ConstructL( aElement, aAttributes, aParentId );
       
    50     CleanupStack::Pop( self );
       
    51     return self;
       
    52     }
       
    53 
       
    54 CNcdPreminetProtocolDownloadParser::CNcdPreminetProtocolDownloadParser( 
       
    55     MNcdParserObserverBundle& aObservers,
       
    56     MNcdSubParserObserver& aSubParserObserver,
       
    57     TInt aDepth )
       
    58     : CNcdSubParser( aObservers, aSubParserObserver, aDepth )
       
    59     {
       
    60 
       
    61     }
       
    62 
       
    63 CNcdPreminetProtocolDownloadParser::~CNcdPreminetProtocolDownloadParser()
       
    64     {
       
    65     delete iDownload;
       
    66     }
       
    67 
       
    68 void CNcdPreminetProtocolDownloadParser::ConstructL( 
       
    69     const Xml::RTagInfo& aElement,
       
    70     const Xml::RAttributeArray& aAttributes,
       
    71     const TDesC& /*aParentId*/ )
       
    72     {
       
    73     CNcdSubParser::ConstructL( aElement );
       
    74 
       
    75     DLTRACEIN(("depth=%d tag=%S",iDepth,iTag));
       
    76     //DLINFO((_L("parent=%S"),&aParentId));
       
    77 
       
    78     if (!iDownload)
       
    79         {
       
    80         iDownload = CNcdPreminetProtocolDownloadImpl::NewL();
       
    81         }
       
    82 
       
    83     DLTRACE(("Download created"));
       
    84     // read attributes here
       
    85     TPtrC8 uri = AttributeValue( KAttrUri, aAttributes );
       
    86     NcdProtocolUtils::AssignDesL(iDownload->iUri, uri);
       
    87 
       
    88     DLTRACE((""));
       
    89     TPtrC8 autoDownload = AttributeValue( KAttrAutoDownload, aAttributes );
       
    90     if ( autoDownload != KNullDesC8 )
       
    91         NcdProtocolUtils::DesToBool(iDownload->iAutoDownload, autoDownload);
       
    92     
       
    93     DLTRACE((""));
       
    94 
       
    95     TPtrC8 delayDelta = AttributeValue( KAttrDelayDelta, aAttributes );
       
    96     if ( delayDelta != KNullDesC8 )
       
    97         iDownload->iDelayDelta = NcdProtocolUtils::DesDecToIntL(delayDelta);
       
    98     DLTRACE((""));
       
    99 
       
   100     TPtrC8 validityDelta = AttributeValue( KAttrValidityDelta, aAttributes );
       
   101     if ( validityDelta != KNullDesC8 )
       
   102         iDownload->iValidityDelta = NcdProtocolUtils::DesDecToIntL(validityDelta);
       
   103     DLTRACE((""));
       
   104 
       
   105     TPtrC8 chunkSize = AttributeValue( KAttrChunkSize, aAttributes );
       
   106     if ( chunkSize != KNullDesC8 )
       
   107         iDownload->iChunkSize = NcdProtocolUtils::DesDecToIntL(chunkSize);
       
   108     DLTRACE((""));
       
   109 
       
   110     TPtrC8 launchable = AttributeValue( KAttrLaunchable, aAttributes );
       
   111     if ( launchable != KNullDesC8 )
       
   112         NcdProtocolUtils::DesToBool(iDownload->iLaunchable, launchable);
       
   113     DLTRACE((""));
       
   114 
       
   115     TPtrC8 installNotificationUri = AttributeValue( KAttrInstallNotificationUri, aAttributes );
       
   116     NcdProtocolUtils::AssignDesL(iDownload->iInstallNotificationUri, installNotificationUri);
       
   117 
       
   118     DLTRACE((""));
       
   119     TPtrC8 size = AttributeValue( KAttrSize, aAttributes );
       
   120     if ( size != KNullDesC8 )
       
   121         iDownload->iSize = NcdProtocolUtils::DesDecToIntL(size);
       
   122     DLTRACE((""));
       
   123 
       
   124     TPtrC8 mime = AttributeValue( KAttrMime, aAttributes );
       
   125     NcdProtocolUtils::AssignDesL(iDownload->iMime, mime);
       
   126     DLTRACE((""));
       
   127     TPtrC8 reDownloadable = AttributeValue( KAttrReDownloadable, aAttributes );
       
   128     NcdProtocolUtils::DesToBool(iDownload->iReDownloadable, reDownloadable);
       
   129     DLTRACE((""));
       
   130     TPtrC8 previewType = AttributeValue( KAttrType, aAttributes );
       
   131     NcdProtocolUtils::AssignDesL(iDownload->iPreviewType, previewType);
       
   132 
       
   133     DLTRACE((""));
       
   134     TPtrC8 target = AttributeValue( KAttrTarget, aAttributes );
       
   135     if ( target == KValueConsumable ) 
       
   136         {
       
   137         iDownload->iTarget = EDownloadTargetConsumable;
       
   138         }
       
   139     else if ( target == KValueDownloadable ) 
       
   140         {
       
   141         iDownload->iTarget = EDownloadTargetDownloadable;
       
   142         }
       
   143     DLTRACE((""));
       
   144     TPtrC8 deliveryMethod = AttributeValue( KAttrDeliveryMethod, aAttributes );
       
   145     if ( deliveryMethod == KValueWlan ) 
       
   146         {
       
   147         iDownload->iDeliveryMethod = EUriDeliveryWlan;
       
   148         }
       
   149     else if ( deliveryMethod == KValueGprs ) 
       
   150         {
       
   151         iDownload->iDeliveryMethod = EUriDeliveryGprs;
       
   152         }
       
   153     else if ( deliveryMethod == KValueBroadband ) 
       
   154         {
       
   155         iDownload->iDeliveryMethod = EUriDeliveryBroadband;
       
   156         }
       
   157     DLTRACEOUT((""));
       
   158     }
       
   159 
       
   160 
       
   161 void CNcdPreminetProtocolDownloadParser::OnStartElementL( 
       
   162     const Xml::RTagInfo& aElement, 
       
   163     const Xml::RAttributeArray& aAttributes, 
       
   164     TInt aErrorCode) 
       
   165     {
       
   166     CNcdSubParser::OnStartElementL( aElement, aAttributes, aErrorCode );
       
   167 
       
   168     DLTRACEIN(("download start tag=%S error=%d depth=%d",
       
   169         &aElement.LocalName().DesC(),aErrorCode,iDepth));
       
   170     
       
   171     TPtrC8 tag( aElement.LocalName().DesC() );
       
   172     
       
   173     if( iSubParser == 0 )
       
   174         {
       
   175         if ( tag == KTagMessage )
       
   176             {
       
   177             iSubParser = CNcdConfigurationProtocolQueryParser::NewL( 
       
   178                 *iObservers, *this, iDepth+1, aElement, aAttributes );
       
   179             }
       
   180         else if ( tag == KTagRightsDetails )
       
   181             {
       
   182             iSubParser = CNcdPreminetProtocolRightsParser::NewL( 
       
   183                 *iObservers, *this, iDepth+1, aElement, aAttributes, KNullDesC );
       
   184             }
       
   185         else if ( tag == KTagDescriptor )
       
   186             {
       
   187             CNcdPreminetProtocolDescriptorImpl* descriptor = 
       
   188                 CNcdPreminetProtocolDescriptorImpl::NewL();
       
   189             TPtrC8 type = AttributeValue( KAttrType, aAttributes );
       
   190             NcdProtocolUtils::AssignDesL(descriptor->iType, type);
       
   191             TPtrC8 name = AttributeValue( KAttrName, aAttributes );
       
   192             NcdProtocolUtils::AssignDesL(descriptor->iName, name);
       
   193             TPtrC8 uri = AttributeValue( KAttrUri, aAttributes );
       
   194             NcdProtocolUtils::AssignDesL(descriptor->iUri, uri);
       
   195             iDownload->iDescriptor = descriptor;
       
   196             // data saved in OnEndElementL
       
   197             }
       
   198         else
       
   199             {
       
   200             iSubParser = CNcdUnknownParser::NewL( 
       
   201                 *iObservers, *this, iDepth+1, aElement, aAttributes );
       
   202             }
       
   203         }
       
   204     else
       
   205         {
       
   206         iSubParser->OnStartElementL( aElement, aAttributes, aErrorCode );
       
   207         }
       
   208     }
       
   209 
       
   210 
       
   211 
       
   212 void CNcdPreminetProtocolDownloadParser::OnEndElementL(
       
   213     const Xml::RTagInfo& aElement, TInt aErrorCode) 
       
   214     {
       
   215     DLTRACEIN((""));
       
   216     TPtrC8 tag( aElement.LocalName().DesC() );
       
   217 
       
   218     if ( iBuffer )
       
   219         {
       
   220         if ( tag == KTagDescriptor && iDownload && iDownload->iDescriptor ) 
       
   221             {
       
   222             NcdProtocolUtils::AssignDesL(iDownload->iDescriptor->iData, 
       
   223                 *NcdProtocolUtils::DecodeBase64L(*iBuffer));
       
   224             }
       
   225         delete iBuffer;
       
   226         iBuffer = 0;
       
   227         }
       
   228 
       
   229     if( iSubParser == 0 && iTag && *iTag == aElement.LocalName().DesC() )
       
   230         {
       
   231         DLTRACE(("end tag=%S",&aElement.LocalName().DesC()));
       
   232         // Should store finished entity, or let the parent do it with some function?
       
   233         iSubParserObserver->SubParserFinishedL( aElement.LocalName().DesC(), aErrorCode );
       
   234         }
       
   235     else if( iSubParser )
       
   236         {
       
   237         iSubParser->OnEndElementL( aElement, aErrorCode );
       
   238         }
       
   239     else
       
   240         {
       
   241         DLWARNING(("end tag ignored, tag=%S",&aElement.LocalName().DesC()));
       
   242         }
       
   243     }
       
   244 
       
   245 
       
   246 void CNcdPreminetProtocolDownloadParser::SubParserFinishedL( const TDesC8& aTag, 
       
   247                                                               TInt /*aErrorCode*/ )
       
   248     {
       
   249     DLTRACEIN(("tag=%S subparser=%X",&aTag,iSubParser));
       
   250     (void) aTag; // suppresses compiler warning
       
   251 
       
   252     // : child entity has been finished. store it as a 
       
   253     // a childen to the node this parser is parsing.
       
   254     // Needs nodemanager.
       
   255     if( iSubParser->Tag() == KTagMessage )
       
   256         {
       
   257         // A subentity is now ready. Report it.
       
   258         MNcdConfigurationProtocolQuery* message =
       
   259             static_cast<CNcdConfigurationProtocolQueryParser*>( iSubParser )->Query();
       
   260         DLINFO(("subparser message=%X",message));
       
   261         if( message && iDownload )
       
   262             {
       
   263             iDownload->iMessage = message;
       
   264             }
       
   265         }
       
   266     else if( iSubParser->Tag() == KTagRightsDetails )
       
   267         {
       
   268         // A subentity is now ready. Report it.
       
   269         MNcdPreminetProtocolRights* rights =
       
   270             static_cast<CNcdPreminetProtocolRightsParser*>( iSubParser )->Rights();
       
   271         DLINFO(("subparser rights=%X",rights));
       
   272         if( rights && iDownload )
       
   273             {
       
   274             iDownload->iRights = rights;
       
   275             }
       
   276         }
       
   277 
       
   278     delete iSubParser;
       
   279     iSubParser = 0;
       
   280     }
       
   281 
       
   282 MNcdPreminetProtocolDownload*
       
   283 CNcdPreminetProtocolDownloadParser::Download()
       
   284     {
       
   285     DLTRACEIN((""));
       
   286     MNcdPreminetProtocolDownload* download = iDownload;
       
   287     iDownload = 0;
       
   288     return download;
       
   289     }
       
   290