ncdengine/provider/protocol/src/ncd_parser_cp_detail.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:   CNcdConfigurationProtocolDetailParser implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "ncdunknownparser.h"
       
    20 #include "ncdprotocolwords.h"
       
    21 #include "ncdprotocolutils.h"
       
    22 #include "ncd_cp_detailimpl.h"
       
    23 #include "ncd_parser_cp_detail.h"
       
    24 #include "ncd_parser_pp_response.h" 
       
    25 
       
    26 #include "catalogsdebug.h"
       
    27 
       
    28 CNcdConfigurationProtocolDetailParser* 
       
    29 CNcdConfigurationProtocolDetailParser::NewL( MNcdParserObserverBundle& aObservers,
       
    30                                              MNcdSubParserObserver& aSubParserObserver,
       
    31                                              TInt aDepth,
       
    32                                              const Xml::RTagInfo& aElement,
       
    33                                              const Xml::RAttributeArray& aAttributes )
       
    34     {
       
    35     CNcdConfigurationProtocolDetailParser* self 
       
    36         = new(ELeave) CNcdConfigurationProtocolDetailParser( aObservers,
       
    37                                                              aSubParserObserver,
       
    38                                                              aDepth );
       
    39     CleanupStack::PushL( self );
       
    40     self->ConstructL( aElement, aAttributes );
       
    41     CleanupStack::Pop( self );
       
    42     return self;
       
    43     }
       
    44 
       
    45 CNcdConfigurationProtocolDetailParser::CNcdConfigurationProtocolDetailParser( MNcdParserObserverBundle& aObservers,
       
    46                                                                               MNcdSubParserObserver& aSubParserObserver,
       
    47                                                                               TInt aDepth )
       
    48     : CNcdSubParser( aObservers, aSubParserObserver, aDepth )
       
    49     {
       
    50     }
       
    51 
       
    52 CNcdConfigurationProtocolDetailParser::~CNcdConfigurationProtocolDetailParser()
       
    53     {
       
    54     delete iDetail;
       
    55     iDetail = 0;
       
    56     delete iContent;
       
    57     iContent = 0;
       
    58     }
       
    59 
       
    60 void CNcdConfigurationProtocolDetailParser::ConstructL( const Xml::RTagInfo& aElement,
       
    61                                                         const Xml::RAttributeArray& aAttributes )
       
    62     {
       
    63     CNcdSubParser::ConstructL( aElement );
       
    64     
       
    65     iDetail = CNcdConfigurationProtocolDetailImpl::NewL();
       
    66     
       
    67     const TDesC8* id = &AttributeValue( KAttrId, aAttributes );
       
    68     if( *id == KNullDesC8 )
       
    69         {
       
    70         id = &AttributeValue( KAttrIdentifier, aAttributes );
       
    71         }
       
    72     NcdProtocolUtils::AssignDesL( iDetail->iId, *id );
       
    73     NcdProtocolUtils::AssignDesL( iDetail->iValue, AttributeValue( KAttrValue, aAttributes ) );
       
    74     NcdProtocolUtils::AssignDesL( iDetail->iGroupId, AttributeValue( KAttrGroupId, aAttributes ) );
       
    75     NcdProtocolUtils::AssignDesL( iDetail->iLabel, AttributeValue( KAttrLabel, aAttributes ) );
       
    76     }
       
    77 
       
    78 void CNcdConfigurationProtocolDetailParser::OnStartElementL( const Xml::RTagInfo& aElement, 
       
    79                                                              const Xml::RAttributeArray& aAttributes, 
       
    80                                                              TInt aErrorCode ) 
       
    81     {
       
    82     DLTRACEIN(("detail start tag=%S error=%d depth=%d",
       
    83         &aElement.LocalName().DesC(),aErrorCode,iDepth));
       
    84     
       
    85     CNcdSubParser::OnStartElementL( aElement, aAttributes, aErrorCode );
       
    86     
       
    87     TPtrC8 tag( aElement.LocalName().DesC() );
       
    88 
       
    89     if( iSubParser )
       
    90         {
       
    91         // Use existing subparser.
       
    92         iSubParser->OnStartElementL( aElement, aAttributes, aErrorCode );
       
    93         }
       
    94     else if( tag == KTagXmlFragment )
       
    95         {
       
    96 // Old Download! support case, no longer usable.
       
    97 //         if( AttributeValue( KAttrId, aAttributes ) == KIdPreminetProtocol &&
       
    98 //             AttributeValue( KAttrVersion, aAttributes ) == KIdPreminetProtocolVersion )     
       
    99 //             {
       
   100 //             DLINFO(("xmlFragment accepted, preminetResponse"));
       
   101 //             // The following tag will be "preminetResponse", handled below.
       
   102 //             }
       
   103 //         else
       
   104 //            {
       
   105             DLERROR(("Unknown xml fragment %S,%S",
       
   106                      &AttributeValue( KAttrId, aAttributes ),
       
   107                      &AttributeValue( KAttrVersion, aAttributes ) ));
       
   108             iSubParser = CNcdUnknownParser::NewL( *iObservers, *this, iDepth+1, aElement, aAttributes );
       
   109 //            }
       
   110         }
       
   111 // Old Download! support case, no longer usable.
       
   112 //     else if( tag == KTagPreminetResponse )
       
   113 //         {
       
   114 //         iSubParser = CNcdPreminetProtocolResponseParser::NewL( *iObservers, *this, iDepth+1, 
       
   115 //                                                                aElement, aAttributes );
       
   116 //         }
       
   117     else if( tag == KTagDetail )
       
   118         {
       
   119         iSubParser = CNcdConfigurationProtocolDetailParser::NewL( 
       
   120             *iObservers, *this, iDepth+1, aElement, aAttributes );
       
   121         }
       
   122     else if( tag == KTagContent )
       
   123         {
       
   124         iContent = CNcdConfigurationProtocolContentImpl::NewL();
       
   125         NcdProtocolUtils::AssignDesL( iContent->iKey, AttributeValue( KAttrKey, aAttributes ) );
       
   126         NcdProtocolUtils::AssignDesL( iContent->iValue, AttributeValue( KAttrValue, aAttributes ) );
       
   127         // content is saved in OnEndElementL
       
   128         }
       
   129     else
       
   130         {
       
   131         iSubParser = CNcdUnknownParser::NewL( *iObservers, *this, iDepth+1, aElement, aAttributes );
       
   132         }
       
   133     }
       
   134 
       
   135 
       
   136 void CNcdConfigurationProtocolDetailParser::OnEndElementL(const Xml::RTagInfo& aElement, TInt aErrorCode) 
       
   137     {
       
   138     DLTRACEIN((""));
       
   139     TPtrC8 tag( aElement.LocalName().DesC() );
       
   140     DLTRACE(("end tag=%S",&aElement.LocalName().DesC()));
       
   141     if (iBuffer) 
       
   142         {
       
   143         if (tag == KTagContent && iContent)
       
   144             {
       
   145             NcdProtocolUtils::AssignDesL(iContent->iContent, *iBuffer);
       
   146             }
       
   147         delete iBuffer;
       
   148         iBuffer = 0;
       
   149         }
       
   150     
       
   151     if ( tag == KTagContent && iContent ) 
       
   152         {
       
   153         User::LeaveIfError( iDetail->iContents.Append( iContent ) );
       
   154         iContent = 0;
       
   155         }
       
   156         
       
   157     if( iSubParser == 0 && iTag && *iTag == aElement.LocalName().DesC() )
       
   158         {
       
   159         DLTRACE(("end tag=%S",&aElement.LocalName().DesC()));
       
   160         iSubParserObserver->SubParserFinishedL( aElement.LocalName().DesC(), aErrorCode );
       
   161         }
       
   162     else if( iSubParser )
       
   163         {
       
   164         iSubParser->OnEndElementL( aElement, aErrorCode );
       
   165         }
       
   166     else
       
   167         {
       
   168         DLWARNING(("end tag ignored, tag=%S",&aElement.LocalName().DesC()));
       
   169         }
       
   170     }
       
   171 
       
   172 MNcdConfigurationProtocolDetail* CNcdConfigurationProtocolDetailParser::Detail()
       
   173 {
       
   174     MNcdConfigurationProtocolDetail* returnPtr = iDetail;
       
   175     iDetail = 0;
       
   176     return returnPtr;
       
   177 }
       
   178 
       
   179 void CNcdConfigurationProtocolDetailParser::SubParserFinishedL( const TDesC8& aTag, 
       
   180                                                                 TInt /*aErrorCode*/ )
       
   181     {
       
   182     DLTRACE(("tag=%S subparser=%X",&aTag,iSubParser));
       
   183 
       
   184     if( aTag == KTagDetail )
       
   185         {
       
   186         CNcdConfigurationProtocolDetailParser* detailParser = 
       
   187             static_cast<CNcdConfigurationProtocolDetailParser*>( iSubParser );
       
   188         MNcdConfigurationProtocolDetail* detail = detailParser->Detail();
       
   189         User::LeaveIfError( iDetail->iDetails.Append( detail ));
       
   190         }
       
   191     
       
   192     delete iSubParser;
       
   193     iSubParser = 0;
       
   194     }
       
   195 
       
   196