IMPSengine/messageencoder/wbxml/src/impsxmlutils.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     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: rovides the methods for pureData handling.
       
    15 *
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    <e32base.h>
       
    22 #include    <miutconv.h>
       
    23 #include    "impsxmlutils.h"
       
    24 #include    "impsdataaccessorapi.h"
       
    25 #include    "impsliterals.h"
       
    26 #include    "impscommonenums.h"
       
    27 #include    "impserrors.h"
       
    28 #include    "impspresence.h"
       
    29 #include    "impsfundamental.h"
       
    30 #include    "impsutils.h"
       
    31 
       
    32 // CONSTANTS
       
    33 const TInt KImpsMaxStringSize100 = 100;
       
    34 const TInt KImpsBaseIndex = 0;
       
    35 const TInt KImpsExtraSpace = 30;
       
    36 const TInt KIntegerBufSize = 10;
       
    37 
       
    38 const TInt KInitBufSize = 1000;
       
    39 const TInt KExpandBufSize = 500;
       
    40 
       
    41 const TInt KTrConStartLen = 19;
       
    42 const TInt KTagLen = 1;
       
    43 const TInt KEndTagLen = 2;
       
    44 
       
    45 _LIT8( KTrConStart,  "<TransactionContent");
       
    46 _LIT8( KTrConEnd,    "</TransactionContent>");
       
    47 
       
    48 
       
    49 // ================= MEMBER FUNCTIONS =======================
       
    50 // ---------------------------------------------------------
       
    51 // CImpsXmlUtils::CImpsXmlUtils()
       
    52 // C++ default constructor can NOT contain any code, that
       
    53 // might leave.
       
    54 // ---------------------------------------------------------
       
    55 CImpsXmlUtils::CImpsXmlUtils(): 
       
    56 iPosition( 0 ),
       
    57 iBufSize( KImpsMaxStringSize100 ),
       
    58 iEncodeBufferSize( KInitBufSize )
       
    59     {
       
    60     }
       
    61 // ---------------------------------------------------------
       
    62 // CImpsXmlUtils::ConstructL()
       
    63 // EPOC default constructor can leave.
       
    64 // ---------------------------------------------------------
       
    65 void CImpsXmlUtils::ConstructL()
       
    66     {
       
    67     iElementValue = HBufC8::NewL( iBufSize );
       
    68     iElementData  = HBufC::NewL( iBufSize );
       
    69     iIntegerValue = HBufC8::NewL( KIntegerBufSize );
       
    70     iEncodeBuffer = CBufFlat::NewL( 50 );
       
    71     iEncodeBuffer->ResizeL( iEncodeBufferSize );
       
    72     }
       
    73 // ---------------------------------------------------------
       
    74 // CImpsXmlUtils::ResetL()
       
    75 // ---------------------------------------------------------
       
    76 void CImpsXmlUtils::ResetL()
       
    77     {
       
    78     iPosition = 0;
       
    79     if ( iElementValue == NULL )
       
    80         {
       
    81         iBufSize = KImpsMaxStringSize100;
       
    82         iElementValue = HBufC8::NewL( iBufSize );
       
    83         }
       
    84     if ( iElementData == NULL )
       
    85         {
       
    86         iBufSize = KImpsMaxStringSize100;
       
    87         iElementData  = HBufC::NewL( iBufSize );
       
    88         }
       
    89     if ( iIntegerValue == NULL )
       
    90         {
       
    91         iIntegerValue = HBufC8::NewL( KIntegerBufSize );
       
    92         }
       
    93     if ( iEncodeBuffer == NULL )
       
    94         {
       
    95         iEncodeBuffer = CBufFlat::NewL( 50 );
       
    96         iEncodeBufferSize = KInitBufSize;
       
    97         iEncodeBuffer->ResizeL( iEncodeBufferSize );
       
    98         }
       
    99     }
       
   100 // ---------------------------------------------------------
       
   101 // CImpsXmlUtils::NewL()
       
   102 // Two-phased constructor.
       
   103 // ---------------------------------------------------------
       
   104 CImpsXmlUtils* CImpsXmlUtils::NewL()
       
   105     {
       
   106     CImpsXmlUtils* self = new ( ELeave ) CImpsXmlUtils;   
       
   107     CleanupStack::PushL( self );
       
   108     self->ConstructL();
       
   109     CleanupStack::Pop();
       
   110     return self;
       
   111     }
       
   112 // ---------------------------------------------------------
       
   113 // CImpsXmlUtils::~CImpsXmlUtils()
       
   114 // Destructor
       
   115 // ---------------------------------------------------------
       
   116 CImpsXmlUtils::~CImpsXmlUtils()
       
   117     {
       
   118     delete iElementValue;
       
   119     delete iIntegerValue;
       
   120     delete iElementData;
       
   121     delete iEncodeBuffer;
       
   122     }
       
   123 // ---------------------------------------------------------
       
   124 // CImpsXmlUtils::TransactionContentToXmlL
       
   125 // ---------------------------------------------------------
       
   126 void CImpsXmlUtils::TransactionContentToXmlL( MImpsDataAccessor& /*aImpsData*/ )
       
   127     {
       
   128     }
       
   129 // ---------------------------------------------------------
       
   130 // CImpsXmlUtils::StorePureDataL
       
   131 // ---------------------------------------------------------
       
   132 void CImpsXmlUtils::StorePureDataL( MImpsDataAccessor& aImpsData, TInt aIndex, TInt aMessageType )
       
   133     {
       
   134 //    if ( iAccessKey ) 
       
   135 //        {
       
   136 //        iAccessKey->Destroy();
       
   137 //        }
       
   138 
       
   139     iEncodeBufferSize = iPosition;
       
   140     iEncodeBuffer->ResizeL( iPosition );
       
   141 
       
   142     iAccessKey = aImpsData.NewKeyL();
       
   143     iAccessKey->AddL( CREATEKEY( EImpsKeySession, KImpsBaseIndex ) );
       
   144     iAccessKey->AddL( CREATEKEY( EImpsKeyTransaction, aIndex ) );
       
   145     iAccessKey->AddL( CREATEKEY( EImpsKeyTransactionContent, KImpsBaseIndex ) );
       
   146     iAccessKey->AddL( CREATEKEY( EImpsKeyPureData, KImpsBaseIndex ) );
       
   147     aImpsData.StoreDesc8L( iAccessKey, iEncodeBuffer->Ptr(0 ) );
       
   148     // store the actual message type
       
   149     iAccessKey->AddL( CREATEKEY( aMessageType, KImpsBaseIndex ) );
       
   150     aImpsData.StoreEmptyL( iAccessKey );
       
   151     
       
   152     if ( iEncodeBufferSize > KInitBufSize )
       
   153         {
       
   154         iEncodeBufferSize = KInitBufSize;
       
   155         iEncodeBuffer->ResizeL( iEncodeBufferSize );
       
   156         iEncodeBuffer->Compress();
       
   157         }
       
   158     iAccessKey->Destroy();
       
   159     }
       
   160 // ---------------------------------------------------------
       
   161 // CImpsXmlUtils::Convert16To8L
       
   162 // ---------------------------------------------------------
       
   163 //TPtrC8 CImpsXmlUtils::Convert16To8L( TDesC* aDes )
       
   164 //    {   
       
   165 //    TPtr8 ptr8 = iElementValue->Des();
       
   166 //    ptr8.Zero();
       
   167 //    if ( aDes != NULL )
       
   168 //        {
       
   169 //        TInt size = aDes->Length();
       
   170 //        if ( size <= 0 )
       
   171 //            return ptr8;
       
   172 //        if ( size > iBufSize )
       
   173 //            {
       
   174 //            delete iElementValue;
       
   175 //            iElementValue = NULL;
       
   176 //            iElementValue = HBufC8::NewL( size + KImpsExtraSpace );
       
   177 //            iBufSize = size + KImpsExtraSpace;
       
   178 //            TPtr8 ptr = iElementValue->Des();
       
   179 //            TInt rcode = CnvUtfConverter::ConvertFromUnicodeToUtf8( ptr, *aDes );
       
   180 //            iBufSize = size;
       
   181 //            if ( rcode != KErrNone )
       
   182 //                {
       
   183 //                User::Leave( KImpsErrorDecode );
       
   184 //                }
       
   185 //            return EscapeXmlL( );
       
   186 //            }
       
   187 //        TInt rcode = CnvUtfConverter::ConvertFromUnicodeToUtf8( ptr8, *aDes );
       
   188 //        if ( rcode != KErrNone )
       
   189 //            {
       
   190 //            User::Leave( KImpsErrorDecode );
       
   191 //            }
       
   192 //        }
       
   193 //    return EscapeXmlL( );
       
   194 //    }
       
   195 // ---------------------------------------------------------
       
   196 // CImpsXmlUtils::ConvertBooleanToChar
       
   197 // ---------------------------------------------------------
       
   198 //TPtrC8 CImpsXmlUtils::ConvertBooleanToChar( TBool aBool )
       
   199 //    {
       
   200 //    if ( aBool )
       
   201 //        return TPtrC8( KTrue );
       
   202 //    else
       
   203 //        return TPtrC8( KFalse );
       
   204 //    }
       
   205 // ---------------------------------------------------------
       
   206 // CImpsXmlUtils::ConvertIntToPtr
       
   207 // ---------------------------------------------------------
       
   208 //TPtrC8 CImpsXmlUtils::ConvertIntToPtr( TInt aInteger )
       
   209 //    {
       
   210 //    TPtr8 ptr = iIntegerValue->Des();
       
   211 //    ptr.Zero();
       
   212 //    ptr.AppendNum( aInteger );
       
   213 //    return ptr;
       
   214 //    }
       
   215 // ---------------------------------------------------------
       
   216 // CImpsXmlUtils::WriteToBufferL
       
   217 // ---------------------------------------------------------
       
   218 void CImpsXmlUtils::WriteToBufferL( const TDesC8& aData )
       
   219     {
       
   220 
       
   221 	if ( (iPosition + aData.Length() ) > iEncodeBufferSize )
       
   222         {
       
   223         iEncodeBufferSize += ( KExpandBufSize + aData.Length() );
       
   224         iEncodeBuffer->ResizeL( iEncodeBufferSize );
       
   225         }
       
   226 
       
   227     iEncodeBuffer->Write( iPosition, aData );
       
   228     iPosition += aData.Length();
       
   229     }
       
   230 // ---------------------------------------------------------
       
   231 // CImpsXmlUtils::StartElementL
       
   232 // ---------------------------------------------------------
       
   233 void CImpsXmlUtils::StartElementL( const TDesC8& aTag, const TDesC8& aAttribute )
       
   234     {
       
   235     WriteToBufferL( TPtrC8( KStartOfTag ) );
       
   236     WriteToBufferL( aTag );
       
   237     WriteToBufferL( aAttribute );
       
   238     WriteToBufferL( TPtrC8( KEndOfTag ) );
       
   239     }
       
   240 // ---------------------------------------------------------
       
   241 // CImpsXmlUtils::EndElementL
       
   242 // ---------------------------------------------------------
       
   243 void CImpsXmlUtils::EndElementL( const TDesC8& aTag )
       
   244     {
       
   245     WriteToBufferL( TPtrC8( KElementTerminator ) );
       
   246     WriteToBufferL( aTag );
       
   247     WriteToBufferL( TPtrC8( KEndOfTag ) );
       
   248     }
       
   249 // ---------------------------------------------------------
       
   250 // CImpsXmlUtils::WriteEmptyElementL
       
   251 // ---------------------------------------------------------
       
   252 void CImpsXmlUtils::WriteEmptyElementL( const TDesC8& aTag )
       
   253     {
       
   254     WriteToBufferL( TPtrC8( KStartOfTag ) );
       
   255     WriteToBufferL( aTag ); 
       
   256     WriteToBufferL( TPtrC8( KEndTag ) );
       
   257     }
       
   258 // ---------------------------------------------------------
       
   259 // CImpsXmlUtils::EncodeIntegerL
       
   260 // ---------------------------------------------------------
       
   261 //void CImpsXmlUtils::EncodeIntegerL( TInt aKey, 
       
   262 //                                    TPtrC8 aElementName, 
       
   263 //                                    TImpsKeyType aKeyType )
       
   264 //    {
       
   265 //    iAccessKey->AddL( CREATEKEY(aKey, KImpsBaseIndex ), aKeyType );
       
   266 //    TInt value;
       
   267 //    if ( iImpsData->RestoreIntegerL( iAccessKey, value ) )
       
   268 //        {
       
   269 //        StartElementL( aElementName, KNullDesC8 );
       
   270 //        TPtrC8 data = ConvertIntToPtr ( value );
       
   271 //        WriteToBufferL( data );
       
   272 //        EndElementL( aElementName );
       
   273 //        }
       
   274 //    iAccessKey->PopL();
       
   275 //    }
       
   276 // ---------------------------------------------------------
       
   277 // CImpsXmlUtils::NameToKeyPresenceElements
       
   278 // ---------------------------------------------------------
       
   279 TImpsPresenceContent CImpsXmlUtils::NameToKeyPresenceElements ( TDesC8* aName )
       
   280     {
       
   281     if ( aName->CompareF( KQualifier ) == 0 )              { return EImpsKeyPRQualifier; }
       
   282     else if ( aName->CompareF( KPresenceValue ) == 0 )     { return EImpsKeyPRPresenceValue; }
       
   283     else if ( aName->CompareF( KOnlineStatus ) == 0 )      { return EImpsKeyPROnlineStatus; }
       
   284     else if ( aName->CompareF( KRegistration ) == 0 )      { return EImpsKeyPRRegistration; }
       
   285     else if ( aName->CompareF( KFreeTextLocation ) == 0 )  { return EImpsKeyPRFreeTextLocation; }
       
   286     else if ( aName->CompareF( KPLMN ) == 0 )              { return EImpsKeyPRPLMN; }
       
   287     else if ( aName->CompareF( KUserAvailability ) == 0 )  { return EImpsKeyPRUserAvailability; }
       
   288     else if ( aName->CompareF( KPreferredLanguage ) == 0 ) { return EImpsKeyPRPreferredLanguage; }
       
   289     else if ( aName->CompareF( KStatusText ) == 0 )        { return EImpsKeyPRStatusText; }
       
   290     else if ( aName->CompareF( KStatusMood ) == 0 )        { return EImpsKeyPRStatusMood; }
       
   291     else if ( aName->CompareF( KAlias ) == 0 )             { return EImpsKeyPRAlias; }
       
   292     else if ( aName->CompareF( KClientInfo ) == 0 )        { return EImpsKeyPRClientInfo; }
       
   293     else if ( aName->CompareF( KClientType ) == 0 )        { return EImpsKeyPRClientType; }
       
   294     else if ( aName->CompareF( KDevManufacturer ) == 0 )   { return EImpsKeyPRDevManufacturer; }
       
   295     else if ( aName->CompareF( KClientProducer ) == 0 )    { return EImpsKeyPRClientProducer; }
       
   296     else if ( aName->CompareF( KModel ) == 0 )             { return EImpsKeyPRModel; }
       
   297     else if ( aName->CompareF( KClientVersion ) == 0 )     { return EImpsKeyPRClientVersion; }
       
   298     else if ( aName->CompareF( KLanguage ) == 0 )          { return EImpsKeyPRLanguage; }
       
   299     else if ( aName->CompareF( KTimeZone ) == 0 )          { return EImpsKeyPRTimeZone; }
       
   300     else if ( aName->CompareF( KZone ) == 0 )              { return EImpsKeyPRZone; }
       
   301     else if ( aName->CompareF( KGeoLocation ) == 0 )       { return EImpsKeyPRGeoLocation; }
       
   302     else if ( aName->CompareF( KLongitude ) == 0 )         { return EImpsKeyPRLongitude; }
       
   303     else if ( aName->CompareF( KLatitude ) == 0 )          { return EImpsKeyPRLatitude; }
       
   304     else if ( aName->CompareF( KAltitude ) == 0 )          { return EImpsKeyPRAltitude; }
       
   305     else if ( aName->CompareF( KAccuracy ) == 0 )          { return EImpsKeyPRAccuracy; }
       
   306     else if ( aName->CompareF( KAddress ) == 0 )           { return EImpsKeyPRAddress; }
       
   307     else if ( aName->CompareF( KCountry ) == 0 )           { return EImpsKeyPRCountry; }
       
   308     else if ( aName->CompareF( KCity ) == 0 )              { return EImpsKeyPRCity; }
       
   309     else if ( aName->CompareF( KStreet ) == 0 )            { return EImpsKeyPRStreet; }
       
   310     else if ( aName->CompareF( KCrossing1 ) == 0 )         { return EImpsKeyPRCrossing1; }
       
   311     else if ( aName->CompareF( KCrossing2 ) == 0 )         { return EImpsKeyPRCrossing2; }
       
   312     else if ( aName->CompareF( KBuilding ) == 0 )          { return EImpsKeyPRBuilding; }
       
   313     else if ( aName->CompareF( KNamedArea ) == 0 )         { return EImpsKeyPRNamedArea; }
       
   314     else if ( aName->CompareF( KCommCap ) == 0 )           { return EImpsKeyPRCommCap; }
       
   315     else if ( aName->CompareF( KCommC ) == 0 )             { return EImpsKeyPRCommC; }
       
   316     else if ( aName->CompareF( KCap ) == 0 )               { return EImpsKeyPRCap; }
       
   317     else if ( aName->CompareF( KStatus ) == 0 )            { return EImpsKeyPRStatus; }
       
   318     else if ( aName->CompareF( KContact ) == 0 )           { return EImpsKeyPRContact; }
       
   319     else if ( aName->CompareF( KNote ) == 0 )              { return EImpsKeyPRNote; }
       
   320     else if ( aName->CompareF( KPreferredContacts ) == 0 ) { return EImpsKeyPRPreferredContacts; }
       
   321     else if ( aName->CompareF( KAddrPref ) == 0 )          { return EImpsKeyPRAddrPref; }
       
   322     else if ( aName->CompareF( KPrefC ) == 0 )             { return EImpsKeyPRPrefC; }
       
   323     else if ( aName->CompareF( KCaddr ) == 0 )             { return EImpsKeyPRCaddr; }
       
   324     else if ( aName->CompareF( KCstatus ) == 0 )           { return EImpsKeyPRCstatus; }
       
   325     else if ( aName->CompareF( KCname ) == 0 )             { return EImpsKeyPRCname; }
       
   326     else if ( aName->CompareF( KCpriority ) == 0 )         { return EImpsKeyPRCpriority; }
       
   327     else if ( aName->CompareF( KStatusContent ) == 0 )     { return EImpsKeyPRStatusContent; }
       
   328     else if ( aName->CompareF( KDirectContent ) == 0 )     { return EImpsKeyPRDirectContent; }
       
   329     else if ( aName->CompareF( KReferredContent ) == 0 )   { return EImpsKeyPRReferredContent; }
       
   330     else if ( aName->CompareF( KContactInfo ) == 0 )       { return EImpsKeyPRContactInfo; }
       
   331     else if ( aName->CompareF( KContainedvCard ) == 0 )    { return EImpsKeyPRContainedvCard; }
       
   332     else if ( aName->CompareF( KReferredvCard ) == 0 )     { return EImpsKeyPRReferredvCard; }
       
   333     else if ( aName->CompareF( KInf_link ) == 0 )          { return EImpsKeyPRInf_link; }
       
   334     else if ( aName->CompareF( KInfoLink ) == 0 )          { return EImpsKeyPRInfoLink; }
       
   335     else if ( aName->CompareF( KLink ) == 0 )              { return EImpsKeyPRLink; }
       
   336     else if ( aName->CompareF( KStatusText ) == 0 )        { return EImpsKeyPRText; }
       
   337     else
       
   338         return EImpsKeyPREND;               
       
   339     }
       
   340 // ---------------------------------------------------------
       
   341 // CImpsXmlUtils::NameToKeyPresencePrimitives
       
   342 // ---------------------------------------------------------
       
   343 TImpsContent CImpsXmlUtils::NameToKeyPresencePrimitives ( TDesC8* aName )
       
   344     {   
       
   345     if ( aName->CompareF( KSubscribePresenceRequest ) == 0 )        
       
   346         { 
       
   347         iPrimitive = EImpsKeySubscribePresence_Request; 
       
   348         return EImpsKeySubscribePresence_Request;
       
   349         }
       
   350     else if ( aName->CompareF( KUnsubscribePresenceRequest ) == 0 ) 
       
   351         { 
       
   352         iPrimitive = EImpsKeyUnsubscribePresence_Request;
       
   353         return EImpsKeyUnsubscribePresence_Request;
       
   354         }
       
   355     else if ( aName->CompareF( KGetPresenceRequest ) == 0 )         
       
   356         { 
       
   357         iPrimitive = EImpsKeyGetPresence_Request; 
       
   358         return EImpsKeyGetPresence_Request;
       
   359         }
       
   360     else if ( aName->CompareF( KUpdatePresenceRequest ) == 0 )      
       
   361         { 
       
   362         iPrimitive = EImpsKeyUpdatePresence_Request;
       
   363         return EImpsKeyUpdatePresence_Request;
       
   364         }
       
   365     else if ( aName->CompareF( KGetAttributeListRequest ) == 0 )    
       
   366         { 
       
   367         iPrimitive = EImpsKeyGetAttributeList_Request;
       
   368         return EImpsKeyGetAttributeList_Request;
       
   369         }
       
   370     else if ( aName->CompareF( KDeleteAttributeListRequest ) == 0 ) 
       
   371         { 
       
   372         iPrimitive = EImpsKeyDeleteAttributeList_Request;
       
   373         return EImpsKeyDeleteAttributeList_Request;
       
   374         }
       
   375     else if ( aName->CompareF( KCreateAttributeListRequest ) == 0 ) 
       
   376         { 
       
   377         iPrimitive = EImpsKeyCreateAttributeList_Request;
       
   378         return EImpsKeyCreateAttributeList_Request;
       
   379         }
       
   380     else if ( aName->CompareF( KCancelAuthRequest ) == 0 )          
       
   381         { 
       
   382         iPrimitive = EImpsKeyCancelAuth_Request;
       
   383         return EImpsKeyCancelAuth_Request;
       
   384         }
       
   385     else if ( aName->CompareF( KPresenceAuthUser) == 0 )           
       
   386         { 
       
   387         iPrimitive = EImpsKeyPresenceAuth_User;
       
   388         return EImpsKeyPresenceAuth_User;
       
   389         }
       
   390     else if ( aName->CompareF( KGetWatcherListRequest ) == 0 )      
       
   391         { 
       
   392         iPrimitive = EImpsKeyGetWatcherList_Request;
       
   393         return EImpsKeyGetWatcherList_Request;
       
   394         } 
       
   395     else if ( aName->CompareF( KGetListRequest ) == 0 )         
       
   396         { 
       
   397         iPrimitive = EImpsKeyGetList_Request;
       
   398         return EImpsKeyGetList_Request;
       
   399         }
       
   400     else if ( aName->CompareF( KCreateListRequest ) == 0 )          
       
   401         { 
       
   402         iPrimitive = EImpsKeyCreateList_Request;
       
   403         return EImpsKeyCreateList_Request;
       
   404         }
       
   405     else if ( aName->CompareF( KDeleteListRequest ) == 0 )          
       
   406         { 
       
   407         iPrimitive = EImpsKeyDeleteList_Request;
       
   408         return EImpsKeyDeleteList_Request;
       
   409         }
       
   410     else if ( aName->CompareF( KListManageRequest ) == 0 )          
       
   411         { 
       
   412         iPrimitive = EImpsKeyListManage_Request;
       
   413         return EImpsKeyListManage_Request;
       
   414         }
       
   415 
       
   416     else if ( aName->CompareF( KGetReactiveAuthStatusRequest ) == 0 ) 
       
   417         {
       
   418         iPrimitive = EImpsKeyGetReactiveAuthStatus_Request;
       
   419         return EImpsKeyGetReactiveAuthStatus_Request;
       
   420         }
       
   421     
       
   422     else if ( aName->CompareF( KStatus ) == 0 )
       
   423         { 
       
   424         if ( iPrimitive == KErrNotFound )
       
   425             {
       
   426             iPrimitive = EImpsKeyStatus; 
       
   427             return EImpsKeyStatus;
       
   428             }
       
   429         return EImpsKeyEND;
       
   430     }    
       
   431     else if ( aName->CompareF( KTransactionContent ) == 0 )   { return EImpsKeyTransactionContent; }
       
   432     else if ( aName->FindF( KPresenceSubList ) != KErrNotFound)            
       
   433         { 
       
   434         return EImpsKeyPresenceSubList;
       
   435         }
       
   436     // These are here because they are not in PA namespace
       
   437     else if ( aName->CompareF( KUser ) == 0 )                 { return EImpsKeyUser; }
       
   438     else if ( aName->CompareF( KUserID ) == 0 )               { return EImpsKeyUserID; }
       
   439     else if ( aName->CompareF( KAcceptance ) == 0 )           { return EImpsKeyAcceptance; }
       
   440     else if ( aName->CompareF( KCode ) == 0 )                 { return EImpsKeyCode; }
       
   441     else if ( aName->CompareF( KContactList ) == 0 )          { return EImpsKeyContactList; }
       
   442     else if ( aName->CompareF( KDetailedResult ) == 0 )       { return EImpsKeyDetailedResult; }
       
   443     else if ( aName->CompareF( KPresence ) == 0 )             { return EImpsKeyPresence; } 
       
   444     else if ( aName->CompareF( KUser ) == 0 )                 { return EImpsKeyUser; }
       
   445     else if ( aName->CompareF( KURL ) == 0 )                  { return EImpsKeyURL; }
       
   446     else if ( aName->CompareF( KScreenName ) == 0 )           { return EImpsKeyScreenName; }
       
   447     else if ( aName->CompareF( KDefaultContactList ) == 0 )   { return EImpsKeyDefaultContactList; }
       
   448     else if ( aName->CompareF( KDefaultList ) == 0 )          { return EImpsKeyDefaultList; }
       
   449     else if ( aName->CompareF( KClientID ) == 0 )             { return EImpsKeyClientID; }
       
   450     else if ( aName->CompareF( KGroupID ) == 0 )              { return EImpsKeyGroupID; }
       
   451     else if ( aName->CompareF( KMessageID ) == 0 )            { return EImpsKeyMessageID; }
       
   452     else if ( aName->CompareF( KNickList ) == 0 )             { return EImpsKeyNickList; }
       
   453     else if ( aName->CompareF( KName ) == 0 )                 { return EImpsKeyName; }
       
   454     else if ( aName->CompareF( KNickName ) == 0 )             { return EImpsKeyNickName; }
       
   455     else if ( aName->CompareF( KDefaultAttributeList ) == 0 ) { return EImpsKeyDefaultAttributeList; }
       
   456     else if ( aName->CompareF( KResult ) == 0 )               { return EImpsKeyResult; }
       
   457     else if ( aName->CompareF( KProperty ) == 0 )             { return EImpsKeyProperty; }
       
   458     else if ( aName->CompareF( KValue ) == 0 )                { return EImpsKeyValue; }
       
   459     else if ( aName->CompareF( KContactListProperties ) == 0 ){ return EImpsKeyContactListProperties; }
       
   460     else if ( aName->CompareF( KAddNickList ) == 0 )          { return EImpsKeyAddNickList; }
       
   461     else if ( aName->CompareF( KRemoveNickList ) == 0 )       { return EImpsKeyRemoveNickList; }
       
   462     else if ( aName->CompareF( KResult ) == 0 )               { return EImpsKeyResult; }
       
   463     else if ( aName->CompareF( KDescription ) == 0 )          { return EImpsKeyDescription; }
       
   464     else if ( aName->CompareF( KContentType ) == 0 )          { return EImpsKeyContentType; }
       
   465     else if ( aName->CompareF( KReceiveList ) == 0 )		  {	return EImpsKeyReceiveList; }
       
   466     else if ( aName->CompareF( KAutoSubscribe ) == 0 )        { return EImpsKeyAuto_Subscribe; }
       
   467     else 
       
   468         return EImpsKeyEND;
       
   469     }
       
   470 // ---------------------------------------------------------
       
   471 // CImpsXmlUtils::DoParseL
       
   472 // ---------------------------------------------------------
       
   473 void CImpsXmlUtils::DoParseL( )
       
   474     {
       
   475     iAccessKey->AddL( CREATEKEY( EImpsKeySession, KImpsBaseIndex ) );
       
   476     iAccessKey->AddL( CREATEKEY( EImpsKeyTransaction, KImpsBaseIndex ) );
       
   477     iAccessKey->AddL( CREATEKEY( EImpsKeyTransactionContent, KImpsBaseIndex ) );
       
   478     iAccessKey->AddL( CREATEKEY( EImpsKeyPureData, KImpsBaseIndex ) );
       
   479 
       
   480     iPosition = 0;
       
   481     TDesC8* pureData;
       
   482     if ( iImpsData->RestoreDesc8L( iAccessKey, pureData ) )
       
   483         {
       
   484         // remove pureData from key      
       
   485         iAccessKey->PopL(); 
       
   486 
       
   487         TInt end = pureData->Find( KTrConEnd );
       
   488         if ( end == KErrNotFound )
       
   489             {
       
   490             User::Leave( KImpsErrorValidate );
       
   491             }
       
   492         // handle trCon start
       
   493         iData.Set( pureData->Mid( iPosition ) );
       
   494         if ( iData.Find( KTrConStart ) == KErrNotFound )
       
   495             {
       
   496             User::Leave( KImpsErrorValidate );
       
   497             }
       
   498         TInt trcon = iData.Find( KEndOfTag);      
       
   499         TPtrC8 data = iData.Mid( KTrConStartLen, ( trcon - KTrConStartLen ) );
       
   500       
       
   501         SaveDataL( &data, EImpsKeyTransactionContent );
       
   502         UpdatePosition( trcon + KTagLen );
       
   503         UpdatePosition( iData.Mid( iPosition ).Find( KStartOfTag ) );
       
   504 
       
   505         ParseElementsL();
       
   506         }
       
   507     }
       
   508 // ---------------------------------------------------------
       
   509 // CImpsXmlUtils::XmlToTransactionContentL
       
   510 // ---------------------------------------------------------
       
   511 TInt CImpsXmlUtils::XmlToTransactionContentL( MImpsDataAccessor& aImpsData )
       
   512     {
       
   513     TInt error( KErrNone );
       
   514     iPrimitive = KErrNotFound;
       
   515     iImpsData = &aImpsData;
       
   516     iAccessKey = aImpsData.NewKeyL();
       
   517 
       
   518     TRAP ( error, DoParseL() )
       
   519 
       
   520     iAccessKey->Destroy();
       
   521 
       
   522     if ( error != KErrNone )
       
   523         {
       
   524         User::Leave( error );
       
   525         }
       
   526     return iPrimitive;
       
   527     }
       
   528 // ---------------------------------------------------------
       
   529 // CImpsXmlUtils::UpdatePosition
       
   530 // ---------------------------------------------------------
       
   531 void CImpsXmlUtils::UpdatePosition ( TInt aLength )
       
   532     {
       
   533     iPosition += aLength;
       
   534     if ( iPosition >= iData.Size() )
       
   535         {
       
   536         iContinue = EFalse;
       
   537         }
       
   538     }
       
   539 // ---------------------------------------------------------
       
   540 // CImpsXmlUtils::FindNextTag
       
   541 // ---------------------------------------------------------
       
   542 TInt CImpsXmlUtils::FindNextTag ( )
       
   543     {
       
   544     TPtrC8 next = iData.Mid( iPosition );
       
   545     return next.Find ( KStartOfTag );
       
   546     }
       
   547 // ---------------------------------------------------------
       
   548 // CImpsXmlUtils::CreateKeyL
       
   549 // ---------------------------------------------------------
       
   550 TInt CImpsXmlUtils::CreateKeyL( TInt aLength )
       
   551     {
       
   552     TPtrC8 elementName = iData.Mid( iPosition, aLength ); 
       
   553     
       
   554     TImpsKeyType keyType ( EImpsKeyTypeIM );
       
   555     TInt key = NameToKeyPresencePrimitives ( &elementName );
       
   556     if ( key == EImpsKeyEND )
       
   557         {
       
   558         key = NameToKeyPresenceElements( &elementName );
       
   559         if ( key != EImpsKeyPREND )
       
   560             {
       
   561             keyType = EImpsKeyTypePre;
       
   562             }
       
   563         }
       
   564         if ( key != EImpsKeyEND && key != EImpsKeyPREND )
       
   565             {
       
   566             TBool found ( ETrue );  
       
   567             TInt index ( 0 );
       
   568             while( found )
       
   569                 {
       
   570                 iAccessKey->AddL( CREATEKEY( key, index ), keyType );
       
   571                 if ( iImpsData->CheckBranchExistenceL( iAccessKey ) )
       
   572                     {
       
   573                     iAccessKey->PopL();
       
   574                     index++;
       
   575                     }
       
   576                 else
       
   577                     found = EFalse;
       
   578                 }
       
   579             }      
       
   580     return key;
       
   581     }
       
   582 // ---------------------------------------------------------
       
   583 // CImpsXmlUtils::ParseElementsL
       
   584 // ---------------------------------------------------------
       
   585 void CImpsXmlUtils::ParseElementsL( )
       
   586     {
       
   587     iContinue = ETrue;
       
   588     while ( iContinue )
       
   589         {
       
   590         TPtrC8 ptr = iData.Mid( iPosition );              //  < 
       
   591         
       
   592         TInt tagEnd = ptr.Find( KEndOfTag );              //  >
       
   593         TInt emptyTag = ptr.Find( KEndTag );              //  />
       
   594         TInt elementEnd = ptr.Find( KElementTerminator ); //  </
       
   595 
       
   596         TImpsParseState state ( EImpsUndefined );
       
   597 
       
   598         if ( elementEnd == 0 )
       
   599             {
       
   600             state = EImpsEndElement;
       
   601             }
       
   602         else if ( tagEnd != KErrNotFound && emptyTag != KErrNotFound )
       
   603             {
       
   604             if ( tagEnd < emptyTag )
       
   605                 state = EImpsStartElement;
       
   606             else
       
   607                 state = EImpsEmptyElement;
       
   608             }
       
   609         else if ( tagEnd != KErrNotFound )
       
   610             {
       
   611             state = EImpsStartElement;      
       
   612             }
       
   613         else if ( emptyTag != KErrNotFound )
       
   614             { 
       
   615             state = EImpsEmptyElement;
       
   616             }
       
   617         else
       
   618             {
       
   619             iContinue = EFalse;
       
   620             }
       
   621 
       
   622         switch ( state )
       
   623             {
       
   624             case EImpsStartElement:
       
   625                 {
       
   626                 TInt length =  tagEnd - KTagLen;  
       
   627                 UpdatePosition( KTagLen);       
       
   628                 TInt key = CreateKeyL( length );
       
   629                 UpdatePosition( length + KTagLen );          
       
   630                 
       
   631                 TInt next = FindNextTag();
       
   632                 TPtrC8 data = iData.Mid( iPosition, next );
       
   633 
       
   634                 UpdatePosition( data.Size( ) );
       
   635                 SaveDataL( &data, key ); 
       
   636                 }
       
   637             break;
       
   638             case EImpsEmptyElement:
       
   639                 {
       
   640                 TInt length = emptyTag - KTagLen; 
       
   641                 UpdatePosition( KTagLen );
       
   642                 TInt key = CreateKeyL( length );
       
   643                 UpdatePosition( length + KEndTagLen );
       
   644 
       
   645                 TInt next = FindNextTag();
       
   646                 TPtrC8 data;
       
   647                 if (next != KErrNotFound )
       
   648                     {
       
   649                     data.Set( iData.Mid( iPosition, 0 ) );
       
   650                     UpdatePosition( next );
       
   651                     SaveDataL( &data, key );
       
   652                     }
       
   653                 iAccessKey->PopL();
       
   654                 }
       
   655             break;
       
   656             case EImpsEndElement:
       
   657                 {
       
   658                 iAccessKey->PopL();           
       
   659                 UpdatePosition( elementEnd + KTagLen );
       
   660                 
       
   661                 TInt next = FindNextTag();
       
   662                 if ( next != KErrNotFound )
       
   663                     {
       
   664                     UpdatePosition( next );
       
   665                     }
       
   666                 else
       
   667                     {
       
   668                     // the end
       
   669                     TInt end = iData.Mid( iPosition ).Find ( KEndOfTag );
       
   670                     if ( end != KErrNotFound )
       
   671                         {
       
   672                         UpdatePosition( end + KEndTagLen );
       
   673                         }
       
   674                     }
       
   675                 }
       
   676             break;
       
   677             default:
       
   678             break;
       
   679             } 
       
   680         }
       
   681     }
       
   682 // ---------------------------------------------------------
       
   683 // CImpsXmlUtils::SaveDataL
       
   684 // ---------------------------------------------------------
       
   685 void CImpsXmlUtils::SaveDataL( TDesC8* aData, TInt aKey )  
       
   686     {
       
   687     TImpsDataType dataType = iImpsData->KeyTypeL( iAccessKey );
       
   688     
       
   689     switch ( dataType )
       
   690         {
       
   691         case EImpsDataTypeInt:
       
   692             if ( aData->Length() > 0 )
       
   693                 {
       
   694                 iImpsData->StoreIntegerL( iAccessKey, ConvertToIntL( aData, aKey ) );
       
   695                 }
       
   696         break;
       
   697         case EImpsDataTypeDesc:
       
   698             {
       
   699             iElementValue->Des().Zero();
       
   700             TInt size = aData->Length();
       
   701             if ( size > iBufSize )
       
   702                 {
       
   703                 delete iElementValue;
       
   704                 iElementValue = NULL;
       
   705                 iElementValue = HBufC8::NewL( size + KImpsExtraSpace );
       
   706                 iBufSize = size + KImpsExtraSpace;
       
   707                 }
       
   708             TPtr8 ptr = iElementValue->Des();
       
   709             ptr.Copy(*aData);
       
   710             UnescapeL();
       
   711 
       
   712             TPtr dataPtr = iElementData->Des();
       
   713             dataPtr.Zero();
       
   714             TInt rcode = CnvUtfConverter::ConvertToUnicodeFromUtf8( dataPtr, *iElementValue );
       
   715             if ( rcode != KErrNone )
       
   716                 {
       
   717                 // should we leave here or not?
       
   718                 }
       
   719             iImpsData->StoreDescL( iAccessKey, *iElementData );
       
   720             }
       
   721         break;
       
   722         case EImpsDataTypeDesc8: 
       
   723             {
       
   724             iElementValue->Des().Zero();
       
   725             TInt size = aData->Length();
       
   726             if ( size > iBufSize )
       
   727                 {
       
   728                 delete iElementValue;
       
   729                 iElementValue = NULL;
       
   730                 iElementValue = HBufC8::NewL( size + KImpsExtraSpace );
       
   731                 iBufSize = size + KImpsExtraSpace;
       
   732                 }
       
   733             TPtr8 ptr = iElementValue->Des();
       
   734             ptr.Copy(*aData);
       
   735             UnescapeL();
       
   736             iImpsData->StoreDesc8L( iAccessKey, *iElementValue );
       
   737             }
       
   738         break;
       
   739         case EImpsDataTypeBoolean: 
       
   740             if ( aData->Length() > 0 )
       
   741                 {
       
   742                 iImpsData->StoreBooleanL( iAccessKey, ConvertToBoolean ( aData ) );
       
   743                 }
       
   744         break;
       
   745         case EImpsDataTypeNone: 
       
   746             iImpsData->StoreEmptyL( iAccessKey );
       
   747         break;
       
   748         case EImpsDataTypeNotSupported: 
       
   749             break;
       
   750         default:
       
   751             break;
       
   752         } 
       
   753     }
       
   754 // ---------------------------------------------------------
       
   755 // CImpsXmlUtils::ConvertToIntL
       
   756 // ---------------------------------------------------------
       
   757 TInt CImpsXmlUtils::ConvertToIntL( TDesC8* aData, TInt aKey )
       
   758     {
       
   759     if ( aData->CompareF( KInband ) == 0 )
       
   760         return EImpsInband;         
       
   761     else if ( aData->CompareF( KOutband ) == 0 )
       
   762         return EImpsOutband;        
       
   763     else if ( aData->CompareF( KRequest ) == 0 )
       
   764         return EImpsRequest;    
       
   765     else if ( aData->CompareF( KResponse ) == 0 )
       
   766         return EImpsResponse;       
       
   767     else if ( aData->CompareF( KURL ) == 0 )
       
   768         return EImpsCliURL;             
       
   769     else if ( aData->CompareF( KMSISDN ) == 0 )
       
   770         return EImpsCliMSISDN;      
       
   771     else if ( aData->CompareF( KPWD ) == 0 ) 
       
   772         return EImpsPWD;
       
   773     else if ( aData->CompareF( KSHA ) == 0 ) 
       
   774         return EImpsSHA;
       
   775     else if ( aData->CompareF( KMD4 ) == 0 ) 
       
   776         return EImpsMD4;
       
   777     else if ( aData->CompareF( KMD5 ) == 0 ) 
       
   778         return EImpsMD5;
       
   779     else if ( aData->CompareF( KMD6 ) == 0 )     
       
   780         return EImpsMD6;
       
   781     else if ( aData->CompareF( KMOBILE_PHONE ) == 0 )    
       
   782         return EImpsMOBILE_PHONE; 
       
   783     else if ( aData->CompareF( KCOMPUTER ) == 0 )    
       
   784         return EImpsCOMPUTER;
       
   785     else if ( aData->CompareF( KPDA ) == 0 ) 
       
   786         return EImpsPDA;
       
   787     else if ( aData->CompareF( KCLI ) == 0 ) 
       
   788         return EImpsCLI;
       
   789     else if ( aData->CompareF( KOTHER ) == 0 ) 
       
   790         return EImpsOTHER;
       
   791     else if ( aData->CompareF( KNotify ) == 0 ) 
       
   792         return EImpsN;
       
   793     else if ( aData->CompareF( KPush ) == 0 )    
       
   794         return  EImpsP;
       
   795     else if ( aData->CompareF( KSMS ) == 0 ) 
       
   796         {
       
   797         if ( aKey == EImpsKeySupportedBearer )
       
   798             return EImpsSMS;
       
   799         else
       
   800             return EImpsCapSMS;
       
   801         }
       
   802     else if ( aData->CompareF( KWSP ) == 0 ) 
       
   803         return EImpsWSP;
       
   804     else if ( aData->CompareF( KHTTP ) == 0 )    
       
   805         return EImpsHTTP;
       
   806     else if ( aData->CompareF( KHTTPS ) == 0 ) 
       
   807         return EImpsHTTPS;
       
   808     else if ( aData->CompareF( KWAPSMS ) == 0 ) 
       
   809         return EImpsWAPSMS; 
       
   810     else if ( aData->CompareF( KWAPUDP ) == 0 )  
       
   811         return EImpsWAPUDP;
       
   812     else if ( aData->CompareF( KSUDP ) == 0 )    
       
   813         return EImpsSUDP;
       
   814     else if ( aData->CompareF( KSTCP ) == 0 )    
       
   815         return EImpsSTCP;
       
   816     else if ( aData->CompareF( KUSER_ID ) == 0 ) 
       
   817         return EImpsUserID;
       
   818     else if ( aData->CompareF( KUSER_FIRST_NAME ) == 0 ) 
       
   819         return EImpsUserFirstName;
       
   820     else if ( aData->CompareF( KUSER_LAST_NAME ) == 0 )  
       
   821         return EImpsUserLastName;
       
   822     else if ( aData->CompareF( KUSER_EMAIL_ADDRESS ) == 0 )
       
   823         return EImpsUserEmailAddress;
       
   824     else if ( aData->CompareF( KUSER_ALIAS ) == 0 )
       
   825         return EImpsUserAlias;
       
   826     else if ( aData->CompareF( KUSER_ONLINE_STATUS ) == 0 )
       
   827         return EImpsUserOnlineStatus;
       
   828     else if ( aData->CompareF( KUSER_MOBILE_NUMBER ) == 0 ) 
       
   829         return EImpsUserMobileNumber;
       
   830     else if ( aData->CompareF( KGROUP_ID ) == 0 )
       
   831         return EImpsGroupID;
       
   832     else if ( aData->CompareF( KGROUP_NAME ) == 0 )
       
   833         return EImpsGroupName;
       
   834     else if ( aData->CompareF( KGROUP_TOPIC ) == 0 )
       
   835         return EImpsGroupTopic;
       
   836     else if ( aData->CompareF( KGROUP_USER_ID_JOINED ) == 0 )
       
   837         return EImpsGroupUserIDJoined;
       
   838     else if ( aData->CompareF( KGROUP_USER_ID_OWNER ) == 0 )
       
   839         return EImpsGroupUserIDOwner;
       
   840     else if ( aData->CompareF( KGR ) == 0 )
       
   841         return EImpsGR;
       
   842     else if ( aData->CompareF( KIM ) == 0 )
       
   843         return EImpsIM;
       
   844     else if ( aData->CompareF( KPR ) == 0 )
       
   845         return EImpsPR;
       
   846     else if ( aData->CompareF( KSC ) == 0 ) 
       
   847         return EImpsSC;  
       
   848     else if ( aData->CompareF( KGet ) == 0 ) 
       
   849         return EImpsG;
       
   850     else if ( aData->CompareF( KSet ) == 0 )
       
   851         return EImpsS;
       
   852     else if ( aData->CompareF( KUnset ) == 0 )
       
   853         return EImpsU;
       
   854     else if ( aData->CompareF( KNone ) == 0 )
       
   855         return EImpsNone;
       
   856     else if ( aData->CompareF( KBASE64 ) == 0 ) 
       
   857         return EImpsBASE64; 
       
   858     else if ( aData->CompareF( KIM ) == 0 )
       
   859         return EImpsCapIM;
       
   860     else if ( aData->CompareF( KCALL ) == 0 )
       
   861         return EImpsCapCALL;
       
   862     else if ( aData->CompareF( KSMS ) == 0 )
       
   863         return EImpsCapSMS;
       
   864     else if ( aData->CompareF( KMMS ) == 0 )
       
   865         return EImpsCapMMS;
       
   866     else if ( aData->CompareF( KEMAIL ) == 0 )
       
   867         return EImpsCapEMAIL;
       
   868     else if ( aData->CompareF( KAVAILABLE ) == 0 )
       
   869         return EImpsAvailable;
       
   870     else if ( aData->CompareF( KNOT_AVAILABLE ) == 0 )
       
   871         return EImpsNotAvailable;
       
   872     else if ( aData->CompareF( KDISCREET ) == 0 )
       
   873         return EImpsDiscreet;
       
   874     else if ( aData->CompareF( KOPEN ) == 0 )
       
   875         return 1;
       
   876     else if ( aData->CompareF( KCLOSED ) == 0 )
       
   877         return 2;
       
   878     else
       
   879         {       
       
   880         TLex8 lex( *aData );
       
   881         TInt converted;
       
   882         if ( KErrNone == lex.Val( converted ) )
       
   883             {
       
   884             return converted;
       
   885             }
       
   886         else
       
   887             {   
       
   888             User::Leave( KImpsErrorDecode );
       
   889             }
       
   890         // this is just for the compiler
       
   891         return KImpsErrorDecode;
       
   892         }
       
   893     }
       
   894 // ---------------------------------------------------------
       
   895 // CImpsXmlUtils::ConvertToBoolean
       
   896 // ---------------------------------------------------------
       
   897 TBool CImpsXmlUtils::ConvertToBoolean ( TDesC8* aData ) 
       
   898     {
       
   899     if ( aData->CompareF( KTrue ) == 0 )
       
   900         {
       
   901         return ETrue;
       
   902         }
       
   903     else   
       
   904         {
       
   905         return EFalse;
       
   906         }
       
   907     }
       
   908 // ---------------------------------------------------------
       
   909 // CImpsXmlUtils::EscapeXmlL 
       
   910 // ---------------------------------------------------------
       
   911 TPtrC8 CImpsXmlUtils::EscapeXmlL ( const TDesC8& aDes )
       
   912     {
       
   913 
       
   914     if ( iElementValue ) 
       
   915         {
       
   916         delete iElementValue;
       
   917         iElementValue = NULL;
       
   918         }
       
   919 
       
   920     iElementValue = aDes.AllocL();
       
   921     iBufSize = aDes.Length();
       
   922 
       
   923     TPtr8 ptr8a = iElementValue->Des();
       
   924     TBool rep ( EFalse );
       
   925     TInt found ( 0 );
       
   926     // count escaped characters
       
   927     for ( TInt i = 0; i < iElementValue->Length(); ++i )
       
   928         {
       
   929         TUint ch = ptr8a[ i ];
       
   930         TPtrC8 p ( iElementValue->Mid( i, 1) );
       
   931         if ( ch == '&'
       
   932             || ch == '<'
       
   933             || ch == '>'
       
   934             || ch == '"'
       
   935             || !p.Compare( KApos8 ) ) // '
       
   936             {
       
   937             ++found;
       
   938             }
       
   939         }
       
   940     // check the buffer size
       
   941     TInt len = iElementValue->Length() + found * 5;
       
   942     if ( len > iBufSize )
       
   943         {
       
   944             iElementValue = iElementValue->ReAllocL( len );
       
   945             iBufSize = len;
       
   946         }
       
   947     TPtr8 ptr8 = iElementValue->Des();
       
   948 
       
   949     // escape &
       
   950     // this is special case because the
       
   951     // escaping literal contains '&'
       
   952     found = 0;
       
   953     while ( found != KErrNotFound )
       
   954         {
       
   955         found = ptr8.Locate('&');
       
   956         if ( found != KErrNotFound )
       
   957             {
       
   958             ptr8.Replace( found, 1, KReplace );
       
   959             rep = ETrue;
       
   960             }
       
   961         }
       
   962     found = 0;
       
   963     if ( rep )
       
   964         {
       
   965         while ( found != KErrNotFound )
       
   966             {
       
   967             found = ptr8.Find( KReplace );
       
   968             if ( found != KErrNotFound )
       
   969                 {
       
   970                 ptr8.Replace( found, 5, KAndRep8 );
       
   971                 }
       
   972             }
       
   973         }
       
   974     // escape <
       
   975     found = 0;
       
   976     while ( found != KErrNotFound )
       
   977         {
       
   978         found = ptr8.Locate('<');
       
   979         if ( found != KErrNotFound )
       
   980             {
       
   981             ptr8.Replace( found, 1, KltRep8 );
       
   982             }
       
   983         }
       
   984     // escape >
       
   985     found = 0;
       
   986     while ( found != KErrNotFound )
       
   987         {
       
   988         found = ptr8.Locate('>');
       
   989         if ( found != KErrNotFound )
       
   990             {
       
   991             ptr8.Replace( found, 1, KgtRep8 );
       
   992             }
       
   993         }
       
   994     // escape "
       
   995     found = 0;
       
   996     while ( found != KErrNotFound )
       
   997         {
       
   998         found = ptr8.Locate('"');
       
   999         if ( found != KErrNotFound )
       
  1000             {
       
  1001             ptr8.Replace( found, 1, KQuotRep8 );
       
  1002             }
       
  1003         }
       
  1004     // escape '
       
  1005     found = 0;
       
  1006     while ( found != KErrNotFound )
       
  1007         {
       
  1008         found = ptr8.Find( KApos8);
       
  1009         if ( found != KErrNotFound )
       
  1010             {
       
  1011             ptr8.Replace( found, 1, KAposRep8 );
       
  1012             }
       
  1013         }    
       
  1014     return ptr8;
       
  1015     }
       
  1016 // ---------------------------------------------------------
       
  1017 // CImpsXmlUtils::ReplaceXmlSpecialCharacters ()
       
  1018 // ---------------------------------------------------------
       
  1019 void CImpsXmlUtils::UnescapeL()
       
  1020     {
       
  1021     TPtr8 ptr = iElementValue->Des();
       
  1022     // &amp;
       
  1023     TInt found ( 0 );
       
  1024     while ( found != KErrNotFound )
       
  1025         {
       
  1026         found = ptr.Find( KAndRep8 );
       
  1027         if ( found != KErrNotFound )
       
  1028             ptr.Replace( found, 5, KAnd8 );
       
  1029         }
       
  1030     // &lt;
       
  1031     found = 0;
       
  1032     while ( found != KErrNotFound )
       
  1033         {
       
  1034         found = ptr.Find( KltRep8 );
       
  1035         if ( found != KErrNotFound )
       
  1036             ptr.Replace( found, 4, Klt8 );
       
  1037         }
       
  1038     // &gt;
       
  1039     found = 0;
       
  1040     while ( found != KErrNotFound )
       
  1041         {
       
  1042         found = ptr.Find( KgtRep8 );
       
  1043         if ( found != KErrNotFound )
       
  1044             ptr.Replace( found, 4, Kgt8 );
       
  1045         }
       
  1046     // &quot;
       
  1047     found = 0;
       
  1048     while ( found != KErrNotFound )
       
  1049         {
       
  1050         found = ptr.Find( KQuotRep8 );
       
  1051         if ( found != KErrNotFound )
       
  1052             ptr.Replace( found, 6, KQuot8 );
       
  1053         }
       
  1054     // &apos;
       
  1055     found = 0;
       
  1056     while ( found != KErrNotFound)
       
  1057         {
       
  1058         found = ptr.Find(KAposRep8);
       
  1059         if ( found != KErrNotFound )
       
  1060             ptr.Replace( found, 4, KApos8 );
       
  1061         }
       
  1062     }
       
  1063