messagingappbase/smartmessaging/wmlbc/src/WmlFieldParser.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2002 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:  
       
    15 *     This class is used to parse fields to wml control from array, 
       
    16 *     which is created by Wap Parser (wapp.dll).
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 
       
    24 #include "WmlFieldParser.h"             // CWmlFieldParser
       
    25 #include "WmlBMSubItem30.h"             // for CWmlBMSubItem
       
    26 #include "WmlBioControl.pan"
       
    27 
       
    28 #include <wappdef.h>                    // Labels for use in array of ParsedFields
       
    29 #include <bsp.h>                        // for CParsedField
       
    30 #include <featmgr.h>
       
    31 #include <bldvariant.hrh>
       
    32 
       
    33 // ================= MEMBER FUNCTIONS =======================
       
    34 
       
    35 // ---------------------------------------------------------
       
    36 // Constructor
       
    37 // ---------------------------------------------------------
       
    38 //
       
    39 CWmlFieldParser::CWmlFieldParser() : iCurrentCharacteristicType(ENotSpecifyed)
       
    40     {
       
    41     }
       
    42 
       
    43 // ---------------------------------------------------------
       
    44 // Destructor
       
    45 // ---------------------------------------------------------
       
    46 //
       
    47 CWmlFieldParser::~CWmlFieldParser()
       
    48     {
       
    49     delete iBm;
       
    50     }
       
    51 
       
    52 // ---------------------------------------------------------
       
    53 // CWmlFieldParser::ParseFieldsL()
       
    54 // Function goes through parsedfieldarray and creates subitems, 
       
    55 // important thing is that field array has name value pairs and 
       
    56 // meaning of these depends on which is the current character tag.
       
    57 // ---------------------------------------------------------
       
    58 //
       
    59 void CWmlFieldParser::ParseFieldsL(
       
    60     const CArrayPtrSeg<CParsedField>& aParsedFieldArray,   
       
    61     CArrayPtrSeg<CWmlSubItemBase>& aBMArray )
       
    62     {
       
    63     iBMArray = &aBMArray;
       
    64 
       
    65     const TInt fieldCount = aParsedFieldArray.Count();
       
    66     
       
    67     TPtrC fieldName;
       
    68     TPtrC fieldValue;
       
    69     TInt fieldEnum;
       
    70 
       
    71     for ( TInt i = 0; i < fieldCount; i++ )
       
    72         {
       
    73         fieldName.Set( aParsedFieldArray.At(i)->FieldName() );  
       
    74         fieldValue.Set( aParsedFieldArray.At(i)->FieldValue() );
       
    75 		RDebug::Print(_L("FieldParser Name: %S Value: %S"), &fieldName, &fieldValue);
       
    76 
       
    77         // Checks if the field indicates a new characteristic type.
       
    78         // Sets the iCurrentCharacteristicType attribute!
       
    79         if( !IsCharacteristicTypeL( fieldName, fieldValue, fieldEnum ) )
       
    80             {
       
    81             
       
    82             // Have to check what is the current characteric type, 
       
    83             // because fields in same name need to be added 
       
    84             // differently in different types.  
       
    85             switch ( iCurrentCharacteristicType )
       
    86                 {				
       
    87                 case EWappCharacteristicBookmark:
       
    88                     {
       
    89                     // iBm is always created when arrived here
       
    90                     iBm->AddFieldL( fieldValue, fieldEnum);
       
    91                     break;
       
    92                     }
       
    93                 default:
       
    94                     {
       
    95                     break;
       
    96                     }
       
    97                 }
       
    98             }
       
    99         }
       
   100 
       
   101     AddCurrentBMToArrayL();
       
   102 
       
   103 	// If bookmarks are not supported clear the array
       
   104 	if ( !FeatureManager::FeatureSupported( KFeatureIdSmartmsgSMSBookmarkReceiving ) )
       
   105 		{
       
   106 		iBMArray->ResetAndDestroy();
       
   107 		}
       
   108     }
       
   109 
       
   110 // ---------------------------------------------------------
       
   111 // CWmlFieldParser :: CompareField
       
   112 // This is used to map a fieldname to program enumerations.
       
   113 // Done only because it is much faster to compare enums later
       
   114 // ---------------------------------------------------------
       
   115 //
       
   116 TWappParserFields CWmlFieldParser::CompareField( TPtrC aFieldName ) 
       
   117     {
       
   118     if ( !aFieldName.Compare( KWappCharAddress ) )  
       
   119         return EWappCharacteristicAddress;
       
   120     if ( !aFieldName.Compare( KWappCharBookmark ) ) 
       
   121         return EWappCharacteristicBookmark;
       
   122     if ( !aFieldName.Compare( KWappCharName ) )     
       
   123         return EWappCharacteristicName;
       
   124     if ( !aFieldName.Compare( KWappCharURL ) )      
       
   125         return EWappCharacteristicURL;
       
   126     if ( !aFieldName.Compare( KWappCharMMSURL ) )      
       
   127         return EWappCharacteristicMMSURL;
       
   128     if ( !aFieldName.Compare( KWappCharID ) )     
       
   129         return EWappCharacteristicID; 
       
   130     if ( !aFieldName.Compare( KWappISP ) )         
       
   131         return EWappISP;
       
   132     if ( !aFieldName.Compare( KWappName ) )        
       
   133         return EWappName;
       
   134     if ( !aFieldName.Compare( KWappBearer ) )      
       
   135         return EWappBearer;
       
   136     if ( !aFieldName.Compare( KWappSMSCAddress ) ) 
       
   137         return EWappSMSCAddress;
       
   138     if ( !aFieldName.Compare( KWappProxy ) )       
       
   139         return EWappProxy;
       
   140     if ( !aFieldName.Compare( KWappPort ) )        
       
   141         return EWappPort;
       
   142     if ( !aFieldName.Compare( KWappProxyType ) )       
       
   143         return EWappProxyType;
       
   144     if ( !aFieldName.Compare( KWappURL ) )         
       
   145         return EWappURL;
       
   146     if ( !aFieldName.Compare( KWappProxyAuthName ) )   
       
   147         return EWappProxyAuthName;
       
   148     if ( !aFieldName.Compare( KWappProxyAuthSecret ) ) 
       
   149         return EWappProxyAuthSecret;
       
   150     if ( !aFieldName.Compare( KWappProxyLoginType ) ) 
       
   151         return EWappProxyLoginType;
       
   152     if ( !aFieldName.Compare( KWappUSSDCode ) )        
       
   153         return EWappUSSDCode;
       
   154     if ( !aFieldName.Compare( KWappAccessPointName ) ) 
       
   155         return EWappGPRSAccessPointName;
       
   156     if ( !aFieldName.Compare( KWappCsdDial ) )       
       
   157         return EWappCsdDial;
       
   158     if ( !aFieldName.Compare( KWappCsdCallType ) )   
       
   159         return EWappCsdCallType;
       
   160     if ( !aFieldName.Compare( KWappCsdCallSpeed ) )  
       
   161         return EWappCsdCallSpeed;
       
   162     if ( !aFieldName.Compare( KWappPPPAuthType ) )   
       
   163         return EWappPPPAuthType;
       
   164     if ( !aFieldName.Compare( KWappPPPAuthName ) )   
       
   165         return EWappPPPAuthName;
       
   166     if ( !aFieldName.Compare( KWappPPPLoginType ) )  
       
   167         return EWappPPPLoginType;
       
   168     if ( !aFieldName.Compare( KWappPPPAuthSecret ) ) 
       
   169         return EWappPPPAuthSecret;
       
   170 
       
   171     return ENotSpecifyed;
       
   172     }
       
   173 
       
   174 // ---------------------------------------------------------
       
   175 // CWmlFieldParser :: IsCharacteristicTypeL
       
   176 // ---------------------------------------------------------
       
   177 //
       
   178 TBool CWmlFieldParser::IsCharacteristicTypeL(
       
   179     TPtrC aFieldName, 
       
   180     TPtrC /*aFieldValue*/, 
       
   181     TInt& aEnumField )
       
   182     {
       
   183     aEnumField = CompareField( aFieldName );
       
   184 	TBool retValue(EFalse);
       
   185 	
       
   186     switch( aEnumField )
       
   187         {
       
   188         case EWappCharacteristicBookmark:
       
   189             {            
       
   190             AddCurrentBMToArrayL();            
       
   191             iBm = CWmlBMSubItem::NewL();
       
   192             iCurrentCharacteristicType = EWappCharacteristicBookmark;
       
   193             retValue = ETrue;
       
   194             break;
       
   195             }
       
   196         default:
       
   197             {
       
   198             retValue = EFalse;
       
   199             break;
       
   200             }
       
   201         }   
       
   202 	return retValue;        
       
   203     }
       
   204 
       
   205 // ---------------------------------------------------------
       
   206 // CWmlFieldParser :: AddCurrentBMToArrayL
       
   207 // ---------------------------------------------------------
       
   208 //
       
   209 void CWmlFieldParser::AddCurrentBMToArrayL()
       
   210     {
       
   211     if( iBm && iBm->IsValidL() )
       
   212         { 
       
   213         iBMArray->AppendL( iBm ); 
       
   214         iBm = NULL;
       
   215         }
       
   216     else // item is not valid and it must be deleted.
       
   217         {
       
   218         delete iBm;
       
   219         iBm = NULL;
       
   220         }
       
   221     }
       
   222 
       
   223 //  End of File