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