ncdengine/provider/protocol/src/ncd_parser_cp_queryelement.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:   CNcdConfigurationProtocolQueryParser implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "ncd_parser_cp_queryelement.h"
       
    20 #include "ncd_parser_cp_detail.h"
       
    21 #include "ncdunknownparser.h"
       
    22 #include "ncdprotocolwords.h"
       
    23 #include "ncdprotocolutils.h"
       
    24 #include "catalogsdebug.h"
       
    25 #include "ncd_cp_queryelementimpl.h"
       
    26 #include "ncd_cp_queryoptionimpl.h"
       
    27 #include "ncd_cp_detailimpl.h"
       
    28 #include "ncdstring.h"
       
    29 
       
    30 CNcdConfigurationProtocolQueryElementParser* 
       
    31 CNcdConfigurationProtocolQueryElementParser::NewL( 
       
    32     MNcdParserObserverBundle& aObservers,
       
    33     MNcdSubParserObserver& aSubParserObserver,
       
    34     TInt aDepth,
       
    35     const Xml::RTagInfo& aElement,
       
    36     const Xml::RAttributeArray& aAttributes )
       
    37     {
       
    38     CNcdConfigurationProtocolQueryElementParser* self 
       
    39         = new(ELeave) CNcdConfigurationProtocolQueryElementParser( 
       
    40             aObservers, aSubParserObserver, aDepth );
       
    41     CleanupStack::PushL( self );
       
    42     self->ConstructL( aElement, aAttributes );
       
    43     CleanupStack::Pop( self );
       
    44     return self;
       
    45     }
       
    46 
       
    47 CNcdConfigurationProtocolQueryElementParser::CNcdConfigurationProtocolQueryElementParser( 
       
    48     MNcdParserObserverBundle& aObservers,
       
    49     MNcdSubParserObserver& aSubParserObserver,
       
    50     TInt aDepth )
       
    51     
       
    52     : CNcdSubParser( aObservers, aSubParserObserver, aDepth )
       
    53     {
       
    54     }
       
    55 
       
    56 CNcdConfigurationProtocolQueryElementParser::~CNcdConfigurationProtocolQueryElementParser()
       
    57     {
       
    58     delete iQueryElement;
       
    59     iQueryElement = 0;
       
    60     }
       
    61 
       
    62 void CNcdConfigurationProtocolQueryElementParser::ConstructL( const Xml::RTagInfo& aElement,
       
    63                                                          const Xml::RAttributeArray& aAttributes )
       
    64     {
       
    65     CNcdSubParser::ConstructL( aElement );
       
    66     
       
    67     iQueryElement = new(ELeave) CNcdConfigurationProtocolQueryElementImpl();
       
    68     iQueryElement->ConstructL();
       
    69 
       
    70     // id
       
    71     NcdProtocolUtils::AssignDesL( iQueryElement->iId, AttributeValue( KAttrId, aAttributes ) );
       
    72     
       
    73     // semantics
       
    74     TPtrC8 semantics = AttributeValue( KAttrSemantics, aAttributes );
       
    75 
       
    76     if( semantics == KNcdQueryElementSemanticsMsisdn ) 
       
    77         iQueryElement->iSemantics = MNcdQueryItem::ESemanticsMsisdn;
       
    78     
       
    79     else if( semantics == KNcdQueryElementSemanticsEmailAddress )
       
    80         iQueryElement->iSemantics = MNcdQueryItem::ESemanticsEmailAddress;
       
    81         
       
    82     else if( semantics == KNcdQueryElementSemanticsCreditCardNumber )
       
    83         iQueryElement->iSemantics = MNcdQueryItem::ESemanticsCreditCardNumber;    
       
    84     
       
    85     else if( semantics == KNcdQueryElementSemanticsCreditCardExpirationYear )
       
    86         iQueryElement->iSemantics = MNcdQueryItem::ESemanticsCreditCardExpirationYear;    
       
    87     
       
    88     else if( semantics == KNcdQueryElementSemanticsCreditCardExpirationMonth )
       
    89             iQueryElement->iSemantics = MNcdQueryItem::ESemanticsCreditCardExpirationMonth;    
       
    90 
       
    91     else if( semantics == KNcdQueryElementSemanticsCreditCardOwner )
       
    92             iQueryElement->iSemantics = MNcdQueryItem::ESemanticsCreditCardOwner;
       
    93    
       
    94     else if( semantics == KNcdQueryElementSemanticsCreditCardVerificationCode )
       
    95             iQueryElement->iSemantics = MNcdQueryItem::ESemanticsCreditCardVerificationCode;
       
    96 
       
    97     else if( semantics == KNcdQueryElementSemanticsCreditCardType )
       
    98             iQueryElement->iSemantics = MNcdQueryItem::ESemanticsCreditCardType;
       
    99 
       
   100     else if( semantics == KNcdQueryElementSemanticsAddressStreet )
       
   101             iQueryElement->iSemantics = MNcdQueryItem::ESemanticsAddressStreet;
       
   102 
       
   103     else if( semantics == KNcdQueryElementSemanticsAddressZipCode )
       
   104         iQueryElement->iSemantics = MNcdQueryItem::ESemanticsAddressZipCode;
       
   105 
       
   106     else if( semantics == KNcdQueryElementSemanticsAddressCity )
       
   107         iQueryElement->iSemantics = MNcdQueryItem::ESemanticsAddressCity;
       
   108 
       
   109     else if( semantics == KNcdQueryElementSemanticsAddressCountry )
       
   110         iQueryElement->iSemantics = MNcdQueryItem::ESemanticsAddressCountry;
       
   111 
       
   112     else if( semantics == KNcdQueryElementSemanticsUserName )
       
   113         iQueryElement->iSemantics = MNcdQueryItem::ESemanticsUserName;
       
   114 
       
   115     else if( semantics == KNcdQueryElementSemanticsPassword )
       
   116         iQueryElement->iSemantics = MNcdQueryItem::ESemanticsPassword;
       
   117 
       
   118     else if( semantics == KNcdQueryElementSemanticsPinCode )
       
   119         iQueryElement->iSemantics = MNcdQueryItem::ESemanticsPinCode;
       
   120 
       
   121     else if( semantics == KNcdQueryElementSemanticsImei )
       
   122         iQueryElement->iSemantics = MNcdQueryItem::ESemanticsImei;
       
   123 
       
   124     else
       
   125         iQueryElement->iSemantics = MNcdQueryItem::ESemanticsUnknown;
       
   126     
       
   127     // type
       
   128     TPtrC8 type = AttributeValue( KAttrType, aAttributes );
       
   129     if( type == KNcdQueryElementTypeString )
       
   130         iQueryElement->iType = MNcdConfigurationProtocolQueryElement::EFreeText;
       
   131 
       
   132     else if( type == KNcdQueryElementTypeNumeric )
       
   133         iQueryElement->iType = MNcdConfigurationProtocolQueryElement::ENumeric;
       
   134 
       
   135     else if( type == KNcdQueryElementTypeSingleSelect )
       
   136         iQueryElement->iType = MNcdConfigurationProtocolQueryElement::ESingleSelect;
       
   137 
       
   138     else if( type == KNcdQueryElementTypeMultiSelect )
       
   139         iQueryElement->iType = MNcdConfigurationProtocolQueryElement::EMultiSelect;
       
   140 
       
   141     else if( type == KNcdQueryElementTypeGpsLocation )
       
   142         iQueryElement->iType = MNcdConfigurationProtocolQueryElement::EGpsLocation;
       
   143 
       
   144     else if( type == KNcdQueryElementTypeConfiguration )
       
   145         iQueryElement->iType = MNcdConfigurationProtocolQueryElement::EConfiguration;
       
   146 
       
   147     else if( type == KNcdQueryElementTypeFile )
       
   148         iQueryElement->iType = MNcdConfigurationProtocolQueryElement::EFile;
       
   149 
       
   150     else if( type == KNcdQueryElementTypeSms )
       
   151         iQueryElement->iType = MNcdConfigurationProtocolQueryElement::ESms;
       
   152 
       
   153     else if( type == KNcdQueryElementTypePurchaseHistory )
       
   154         iQueryElement->iType = MNcdConfigurationProtocolQueryElement::EPurchaseHistory;
       
   155 
       
   156     else
       
   157         iQueryElement->iType = MNcdConfigurationProtocolQueryElement::EUnknown;
       
   158     
       
   159     // optional
       
   160     TPtrC8 optional = AttributeValue( KAttrOptional, aAttributes );
       
   161     NcdProtocolUtils::DesToBool( iQueryElement->iOptional, optional );
       
   162 
       
   163     }
       
   164 
       
   165 void CNcdConfigurationProtocolQueryElementParser::OnStartElementL( const Xml::RTagInfo& aElement, 
       
   166                                                        const Xml::RAttributeArray& aAttributes, 
       
   167                                                        TInt aErrorCode ) 
       
   168     {
       
   169     CNcdSubParser::OnStartElementL( aElement, aAttributes, aErrorCode );
       
   170     TPtrC8 tag( aElement.LocalName().DesC() );
       
   171 
       
   172     if ( iSubParser == 0 ) 
       
   173         {
       
   174 
       
   175 
       
   176         DLTRACE(("query element start tag=%S error=%d depth=%d",&aElement.LocalName().DesC(),aErrorCode,iDepth));
       
   177         if( tag == KTagOption )
       
   178             {
       
   179             CNcdConfigurationProtocolQueryOptionImpl* queryOption = 
       
   180                 new(ELeave) CNcdConfigurationProtocolQueryOptionImpl();
       
   181             CleanupStack::PushL( queryOption );
       
   182             queryOption->ConstructL();
       
   183             
       
   184             // Queryoption value
       
   185             NcdProtocolUtils::AssignDesL( queryOption->iValue, AttributeValue( KAttrValue, aAttributes ) );
       
   186             // Queryoption name
       
   187             queryOption->iName->SetDataL( AttributeValue( KAttrName, aAttributes ) );
       
   188             // queryoption key
       
   189             queryOption->iName->SetKeyL( AttributeValue( KAttrKey, aAttributes ) );
       
   190             
       
   191             iQueryElement->iOptions.AppendL( queryOption );
       
   192             CleanupStack::Pop( queryOption );
       
   193             // subquery missing
       
   194             }
       
   195         else if( tag == KTagLabel )
       
   196             {
       
   197             iQueryElement->iLabel->SetKeyL( AttributeValue( KAttrKey, aAttributes ) );
       
   198             }
       
   199         else if( tag == KTagMessage )
       
   200             {
       
   201             iQueryElement->iMessage->SetKeyL( AttributeValue( KAttrKey, aAttributes ) );
       
   202             }
       
   203         else if( tag == KTagDescription )
       
   204             {
       
   205             iQueryElement->iDescription->SetKeyL( AttributeValue( KAttrKey, aAttributes ) );
       
   206             }
       
   207         else if( tag == KTagDetails )
       
   208             {
       
   209             iSubParser = CNcdConfigurationProtocolDetailParser::NewL( 
       
   210                 *iObservers, *this, iDepth+1, aElement, aAttributes );
       
   211             }
       
   212         else 
       
   213             {
       
   214             iSubParser = CNcdUnknownParser::NewL( 
       
   215                 *iObservers, *this, iDepth+1, aElement, aAttributes );
       
   216             }
       
   217         // sub-queryElements not yet implemented
       
   218         }
       
   219     else 
       
   220         {
       
   221         // Use existing subparser.
       
   222         iSubParser->OnStartElementL( aElement, aAttributes, aErrorCode );
       
   223         }
       
   224     }
       
   225 
       
   226 void CNcdConfigurationProtocolQueryElementParser::OnEndElementL(const Xml::RTagInfo& aElement, TInt aErrorCode) 
       
   227     {
       
   228     DLTRACEIN((""));
       
   229     
       
   230     TPtrC8 tag( aElement.LocalName().DesC() );
       
   231     DLTRACE(("end tag=%S",&aElement.LocalName().DesC()));
       
   232 
       
   233     if( iBuffer )
       
   234         {
       
   235         if( tag == KTagLabel )
       
   236             {
       
   237             iQueryElement->iLabel->SetDataL( *iBuffer );
       
   238             }
       
   239         else if( tag == KTagMessage )
       
   240             {
       
   241             iQueryElement->iMessage->SetDataL( *iBuffer );
       
   242             }
       
   243         else if( tag == KTagDescription )
       
   244             {
       
   245             iQueryElement->iDescription->SetDataL( *iBuffer );
       
   246             }
       
   247         delete iBuffer;
       
   248         iBuffer = 0;
       
   249         }
       
   250 
       
   251     if( iSubParser == 0 && iTag && *iTag == aElement.LocalName().DesC() )
       
   252         {
       
   253         DLTRACE(("end tag=%S",&aElement.LocalName().DesC()));
       
   254         iSubParserObserver->SubParserFinishedL( aElement.LocalName().DesC(), aErrorCode );
       
   255         }    
       
   256     else if( iSubParser )
       
   257         {
       
   258         iSubParser->OnEndElementL( aElement, aErrorCode );
       
   259         }
       
   260     else
       
   261         {
       
   262         DLWARNING(("end tag ignored, tag=%S",&aElement.LocalName().DesC()));
       
   263         }
       
   264     }
       
   265 
       
   266 void CNcdConfigurationProtocolQueryElementParser::SubParserFinishedL( 
       
   267     const TDesC8& aTag, TInt /*aErrorCode*/ )
       
   268     {
       
   269     DLTRACE(("tag=%S subparser=%X",&aTag,iSubParser));
       
   270     (void) aTag; // suppresses compiler warning
       
   271 
       
   272     if ( iSubParser->Tag() == KTagDetails ) 
       
   273         {
       
   274         MNcdConfigurationProtocolDetail* detail =
       
   275             static_cast<CNcdConfigurationProtocolDetailParser*>( iSubParser )->Detail();
       
   276         if ( detail && iQueryElement )
       
   277             {
       
   278             iQueryElement->iDetails = detail;
       
   279             }
       
   280         }
       
   281         
       
   282     delete iSubParser;
       
   283     iSubParser = 0;
       
   284     }
       
   285 
       
   286 CNcdConfigurationProtocolQueryElementImpl* CNcdConfigurationProtocolQueryElementParser::QueryElement()
       
   287 {
       
   288     CNcdConfigurationProtocolQueryElementImpl* tmpQueryElementPtr = iQueryElement;
       
   289     iQueryElement = 0;
       
   290     return tmpQueryElementPtr;
       
   291 }
       
   292