omads/omadsextensions/adapters/mediads/src/omadsfolderobject.cpp
branchRCL_3
changeset 24 8e7494275d3a
equal deleted inserted replaced
23:2bb96f4ecad8 24:8e7494275d3a
       
     1 /*
       
     2 * Copyright (c) 2009 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:  COMADSFolderObject class implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <utf.h>
       
    20 #include "omadsfolderobject.h"
       
    21 #include "logger.h"
       
    22 
       
    23 _LIT(KFolderBeginTag, "<Folder>");
       
    24 _LIT(KFolderEndTag, "</Folder>");
       
    25 _LIT(KNameBeginTag, "<name>");
       
    26 _LIT(KNameEndTag, "</name>");
       
    27 _LIT(KCreatedBeginTag, "<created>");
       
    28 _LIT(KCreatedEndTag, "</created>");
       
    29 _LIT(KModifiedBeginTag, "<modified>");
       
    30 _LIT(KModifiedEndTag, "</modified>");
       
    31 _LIT(KDateFormat, "%04d%02d%02dT%02d%02d%02d");
       
    32 const TInt KDateFormatLength( 15 );
       
    33 
       
    34 
       
    35 COMADSFolderObject* COMADSFolderObject::NewLC()
       
    36     {
       
    37     COMADSFolderObject* self = new (ELeave) COMADSFolderObject;
       
    38     CleanupStack::PushL( self );
       
    39     return self;
       
    40     }
       
    41 
       
    42 COMADSFolderObject::~COMADSFolderObject()
       
    43     {
       
    44     }
       
    45 
       
    46 void COMADSFolderObject::ExportFolderXmlL( CBufBase& aBuffer )
       
    47     {
       
    48     iBuffer = &aBuffer;
       
    49     iWriteBufPosition = 0;
       
    50     iWriteBufSize = aBuffer.Size();     
       
    51 
       
    52     ExportL();
       
    53     }
       
    54     
       
    55 void COMADSFolderObject::ExportL()
       
    56     {
       
    57     // Folder
       
    58     WriteL( KFolderBeginTag );
       
    59     
       
    60     // Name
       
    61     WriteL( KNameBeginTag );
       
    62     WriteL( iName );
       
    63     WriteL( KNameEndTag );
       
    64     
       
    65     // Created Date
       
    66     TBuf<KDateFormatLength> tempdate;
       
    67     tempdate.Format( KDateFormat, iCreatedDate.Year(), iCreatedDate.Month() + 1,
       
    68         iCreatedDate.Day(), iCreatedDate.Hour(), iCreatedDate.Minute(), iCreatedDate.Second() );
       
    69     
       
    70     WriteL( KCreatedBeginTag );
       
    71     WriteL( tempdate );
       
    72     WriteL( KCreatedEndTag );
       
    73     
       
    74     // Modified Date
       
    75     tempdate.Format( KDateFormat, iModifiedDate.Year(), iModifiedDate.Month() + 1,
       
    76         iModifiedDate.Day(), iModifiedDate.Hour(), iModifiedDate.Minute(), iModifiedDate.Second() );
       
    77     
       
    78     WriteL( KModifiedBeginTag );
       
    79     WriteL( tempdate );
       
    80     WriteL( KModifiedEndTag );
       
    81     
       
    82     // Folder end
       
    83     WriteL(KFolderEndTag);
       
    84     }
       
    85     
       
    86 void COMADSFolderObject::WriteL( const TDesC& aData )
       
    87     {   
       
    88     User::LeaveIfError( CnvUtfConverter::ConvertFromUnicodeToUtf8( iTemp, aData ) );
       
    89     
       
    90     TInt newPosition = iWriteBufPosition + iTemp.Length();
       
    91 
       
    92     if ( newPosition > iWriteBufSize )
       
    93         {
       
    94         TInt expand = newPosition - iWriteBufSize;
       
    95         iBuffer->ExpandL( iWriteBufSize, expand );
       
    96         iWriteBufSize += expand;
       
    97         }
       
    98 
       
    99     iBuffer->Write( iWriteBufPosition, iTemp );
       
   100     iWriteBufPosition = newPosition;
       
   101     }