omads/omadsextensions/dsutils/nsmlfolderutils/src/NSmlExtData.cpp
changeset 1 95fdac6ccb5c
equal deleted inserted replaced
0:dab8a81a92de 1:95fdac6ccb5c
       
     1 /*
       
     2 * Copyright (c) 2004 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:  Sources
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <s32buf.h>
       
    22 #include <s32file.h>
       
    23 
       
    24 #include <nsmlfolderparser.h>
       
    25 #include "nsmlparserconstants.h"
       
    26 
       
    27 
       
    28 // ============================ MEMBER FUNCTIONS ===============================
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // CNSmlExtData::NewL
       
    32 // Two-phased constructor.
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 EXPORT_C CNSmlExtData* CNSmlExtData::NewL()
       
    36 	{
       
    37 	CNSmlExtData* self = CNSmlExtData::NewLC();
       
    38 	CleanupStack::Pop();
       
    39 
       
    40 	return self;
       
    41 	}
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CNSmlExtData::NewLC
       
    45 // Two-phased constructor.
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 EXPORT_C CNSmlExtData* CNSmlExtData::NewLC()
       
    49 	{
       
    50 	CNSmlExtData* self = new (ELeave) CNSmlExtData();
       
    51 	CleanupStack::PushL(self);
       
    52 	self->ConstructL();
       
    53 
       
    54 	return self;
       
    55 	}
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CNSmlExtData::~CNSmlExtData
       
    59 // Destructor.
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 EXPORT_C CNSmlExtData::~CNSmlExtData()
       
    63 	{
       
    64 	if (iXVals) 
       
    65 		{
       
    66 		iXVals->ResetAndDestroy();
       
    67 		delete iXVals;
       
    68 		}
       
    69 
       
    70 	if (iXNam) delete iXNam;
       
    71 	}
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CNSmlExtData::AddXValL
       
    75 // Adds given buffer to iXVals.
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 EXPORT_C void CNSmlExtData::AddXValL( HBufC8* aXVal )
       
    79 	{
       
    80 	iXVals->AppendL(aXVal);
       
    81 	}
       
    82 
       
    83 // -----------------------------------------------------------------------------
       
    84 // CNSmlExtData::GenerateXmlL
       
    85 // Generates ext data xml using aParser and appends the xml to aXml.
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 EXPORT_C void CNSmlExtData::GenerateXmlL( TPtr8& aXml, const CNSmlXmlParser* aParser) const
       
    89 	{
       
    90 	if ( aParser == NULL )
       
    91 		return;
       
    92 
       
    93 	aParser->AppendElement(aXml, KExtElement());
       
    94 
       
    95 	if( iXNam )
       
    96 		{
       
    97 		aParser->AppendElement(aXml, KExtXNamElement(), *iXNam);
       
    98 		}
       
    99 	else
       
   100 		User::Leave(EMandatoryFieldNotFound);
       
   101 
       
   102 	if ( iXVals )
       
   103 		{
       
   104 		for (TInt i=0; i < iXVals->Count(); ++i)
       
   105 			{
       
   106 			aParser->AppendElement(aXml, KExtXValElement(), *iXVals->At(i));
       
   107 			}
       
   108 		}
       
   109 
       
   110 	aParser->AppendEndElement(aXml, KExtElement());
       
   111 
       
   112 	}
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // CNSmlExtData::CountXmlSize
       
   116 // Counts the size of the ext data xml if it was generated with current 
       
   117 // values in member variables.
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 EXPORT_C TInt CNSmlExtData::CountXmlSize( const CNSmlXmlParser* aParser ) const
       
   121 	{
       
   122 	TInt size = 0;
       
   123 	size += aParser->SizeOfElements( KExtElement() );
       
   124 
       
   125 	if( iXNam )
       
   126 		{
       
   127 		size += aParser->SizeOfString( iXNam, KExtXNamElement() );
       
   128 		}
       
   129 
       
   130 	if ( iXVals )
       
   131 		{
       
   132 		for (TInt i=0; i < iXVals->Count(); ++i)
       
   133 			{
       
   134 			size += aParser->SizeOfString( iXVals->At(i), KExtXValElement() );
       
   135 			}
       
   136 		}
       
   137 
       
   138 	return size;
       
   139 	}
       
   140 
       
   141 // -----------------------------------------------------------------------------
       
   142 // CNSmlExtData::ConvertIntoEntitiesL
       
   143 // Converts special characters in member variables into entities.
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 EXPORT_C void CNSmlExtData::ConvertIntoEntitiesL( const CNSmlXmlParser* aParser )
       
   147 	{
       
   148 	if( iXNam )
       
   149 		aParser->CharactersToEntitiesL(iXNam, 0, iXNam->Length());
       
   150 
       
   151 	if( iXVals )
       
   152 		{
       
   153 		for (TInt i=0; i < iXVals->Count(); ++i)
       
   154 			{
       
   155 			aParser->CharactersToEntitiesL(iXVals->At(i), 0, iXVals->At(i)->Length());
       
   156 			}
       
   157 		}
       
   158 	}
       
   159 
       
   160 // -----------------------------------------------------------------------------
       
   161 // CNSmlExtData::CNSmlExtData
       
   162 // Constructor.
       
   163 // -----------------------------------------------------------------------------
       
   164 //
       
   165 CNSmlExtData::CNSmlExtData()
       
   166 	{
       
   167 	}
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // CNSmlExtData::ConstructL
       
   171 // Second phase construction.
       
   172 // -----------------------------------------------------------------------------
       
   173 //
       
   174 void CNSmlExtData::ConstructL()
       
   175 	{
       
   176 	iXVals = new (ELeave) CNSmlXValArray(3);
       
   177 	}
       
   178 
       
   179 //  End of File