omads/omadsextensions/adapters/mediads/src/omadsfolderobject.cpp
branchRCL_3
changeset 24 8e7494275d3a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/omads/omadsextensions/adapters/mediads/src/omadsfolderobject.cpp	Tue Aug 31 15:05:37 2010 +0300
@@ -0,0 +1,101 @@
+/*
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:  COMADSFolderObject class implementation.
+*
+*/
+
+
+#include <utf.h>
+#include "omadsfolderobject.h"
+#include "logger.h"
+
+_LIT(KFolderBeginTag, "<Folder>");
+_LIT(KFolderEndTag, "</Folder>");
+_LIT(KNameBeginTag, "<name>");
+_LIT(KNameEndTag, "</name>");
+_LIT(KCreatedBeginTag, "<created>");
+_LIT(KCreatedEndTag, "</created>");
+_LIT(KModifiedBeginTag, "<modified>");
+_LIT(KModifiedEndTag, "</modified>");
+_LIT(KDateFormat, "%04d%02d%02dT%02d%02d%02d");
+const TInt KDateFormatLength( 15 );
+
+
+COMADSFolderObject* COMADSFolderObject::NewLC()
+    {
+    COMADSFolderObject* self = new (ELeave) COMADSFolderObject;
+    CleanupStack::PushL( self );
+    return self;
+    }
+
+COMADSFolderObject::~COMADSFolderObject()
+    {
+    }
+
+void COMADSFolderObject::ExportFolderXmlL( CBufBase& aBuffer )
+    {
+    iBuffer = &aBuffer;
+    iWriteBufPosition = 0;
+    iWriteBufSize = aBuffer.Size();     
+
+    ExportL();
+    }
+    
+void COMADSFolderObject::ExportL()
+    {
+    // Folder
+    WriteL( KFolderBeginTag );
+    
+    // Name
+    WriteL( KNameBeginTag );
+    WriteL( iName );
+    WriteL( KNameEndTag );
+    
+    // Created Date
+    TBuf<KDateFormatLength> tempdate;
+    tempdate.Format( KDateFormat, iCreatedDate.Year(), iCreatedDate.Month() + 1,
+        iCreatedDate.Day(), iCreatedDate.Hour(), iCreatedDate.Minute(), iCreatedDate.Second() );
+    
+    WriteL( KCreatedBeginTag );
+    WriteL( tempdate );
+    WriteL( KCreatedEndTag );
+    
+    // Modified Date
+    tempdate.Format( KDateFormat, iModifiedDate.Year(), iModifiedDate.Month() + 1,
+        iModifiedDate.Day(), iModifiedDate.Hour(), iModifiedDate.Minute(), iModifiedDate.Second() );
+    
+    WriteL( KModifiedBeginTag );
+    WriteL( tempdate );
+    WriteL( KModifiedEndTag );
+    
+    // Folder end
+    WriteL(KFolderEndTag);
+    }
+    
+void COMADSFolderObject::WriteL( const TDesC& aData )
+    {   
+    User::LeaveIfError( CnvUtfConverter::ConvertFromUnicodeToUtf8( iTemp, aData ) );
+    
+    TInt newPosition = iWriteBufPosition + iTemp.Length();
+
+    if ( newPosition > iWriteBufSize )
+        {
+        TInt expand = newPosition - iWriteBufSize;
+        iBuffer->ExpandL( iWriteBufSize, expand );
+        iWriteBufSize += expand;
+        }
+
+    iBuffer->Write( iWriteBufPosition, iTemp );
+    iWriteBufPosition = newPosition;
+    }