languageinterworkingfw/servicehandler/src/liwservicedata.cpp
changeset 57 61b27eec6533
parent 45 7aa6007702af
equal deleted inserted replaced
45:7aa6007702af 57:61b27eec6533
     1 /*
       
     2 * Copyright (c) 2003-2005 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 the License "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:       Class modelling service provider data. The important
       
    15 *				 service provider data that are part of this class
       
    16 *				 is metadata information.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 #include "liwservicedata.h"
       
    27 #include <liwvariant.h>
       
    28 #include <liwgenericparam.h>
       
    29 
       
    30 #include <escapeutils.h>
       
    31 
       
    32 #include <badesca.h> 
       
    33 
       
    34 /**
       
    35 * Creates and returns an instance of \c CLiwServiceData
       
    36 *
       
    37 * @return an instance of \c CLiwServiceData
       
    38 */
       
    39 CLiwServiceData* CLiwServiceData::NewL()
       
    40 {
       
    41 	CLiwServiceData* srvData = CLiwServiceData::NewLC();
       
    42 	CleanupStack::Pop(srvData);
       
    43 	return srvData;
       
    44 }
       
    45 
       
    46 /**
       
    47 * Creates and returns an instance of \c CLiwServiceData.
       
    48 * Leaves the created instance in the cleanupstack. 
       
    49 *
       
    50 * @return an instance of \c CLiwServiceData
       
    51 */
       
    52 CLiwServiceData* CLiwServiceData::NewLC()
       
    53 {
       
    54 	CLiwServiceData* srvData = new (ELeave) CLiwServiceData();
       
    55 	CleanupStack::PushL( srvData );
       
    56 	srvData->ConstructL();
       
    57 	return srvData;
       
    58 }
       
    59 
       
    60 /**
       
    61 * Default constructor
       
    62 *
       
    63 */
       
    64 CLiwServiceData::CLiwServiceData():iDataList(NULL)
       
    65 {
       
    66 }
       
    67 
       
    68 /**
       
    69 * Instantiates metadata instance
       
    70 *
       
    71 */
       
    72 void CLiwServiceData::ConstructL()
       
    73 {
       
    74 	iDataList = CLiwGenericParamList::NewL();
       
    75 }
       
    76 
       
    77 /**
       
    78 * Destructor. Cleans up the metadata instance
       
    79 *
       
    80 */
       
    81 CLiwServiceData::~CLiwServiceData()
       
    82 {
       
    83 	if(iDataList)
       
    84 	{
       
    85 		iDataList->Reset();
       
    86 		delete iDataList;
       
    87 	}
       
    88 }
       
    89 
       
    90 CLiwGenericParamList* CLiwServiceData::GetMetaData() const
       
    91 {
       
    92 	if(iDataList)
       
    93 		return iDataList;
       
    94 	else
       
    95 		return NULL;
       
    96 }
       
    97 
       
    98 void CLiwServiceData::AddMetaDataL(const TDesC8& aKey, const TLiwVariant& aValue)
       
    99 {
       
   100 	TInt idx(0);
       
   101 	const TLiwGenericParam* constParam = iDataList->FindFirst(idx,aKey);
       
   102 	
       
   103 	if(constParam)
       
   104 	{
       
   105 			TLiwGenericParam* param = const_cast<TLiwGenericParam*>(constParam);
       
   106 			
       
   107 			//list exists already..fetch the value list and append aValue to it
       
   108 			CLiwList* pValues = const_cast<CLiwList*>(param->Value().AsList());
       
   109 			pValues->AppendL(aValue);
       
   110 	}
       
   111 	else
       
   112 	{
       
   113 	 		//key does not exist so far..
       
   114 			CLiwList* pValues = CLiwDefaultList::NewLC();
       
   115 			pValues->AppendL(aValue);
       
   116 			
       
   117 			iDataList->AppendL(TLiwGenericParam(aKey,TLiwVariant(pValues)));
       
   118 			CleanupStack::Pop(pValues);
       
   119 			pValues->DecRef();
       
   120 	}
       
   121 }
       
   122 
       
   123 /*
       
   124  * Adds a metadata name-value pair if not already added. If the key already
       
   125  * exists, then the new metadata value (if does not exist already) will be added
       
   126  * to the list of values associated with a metadata key.
       
   127  *
       
   128  * @param aKey		the metadata key to be inserted
       
   129  * @param aValue  the metadata value corresponding to the key to be added
       
   130  *
       
   131  */
       
   132 void CLiwServiceData::AddMetaDataL(const TDesC8& aKey, const TDesC8& aValue)
       
   133 {
       
   134 	HBufC *buff = EscapeUtils::ConvertToUnicodeFromUtf8L(aValue);
       
   135 	CleanupStack::PushL(buff);
       
   136 	TPtrC ptr = buff->Des();
       
   137     TLiwVariant tempVar(ptr);
       
   138     tempVar.PushL();
       
   139     
       
   140 	this->AddMetaDataL(aKey,tempVar);
       
   141 	
       
   142 	CleanupStack::Pop(&tempVar);
       
   143 	tempVar.Reset();
       
   144 	CleanupStack::PopAndDestroy(buff);	
       
   145 }
       
   146 
       
   147 /*
       
   148  * Removes all the metadata key-value pairs.
       
   149  * This is called from service handler implementation if and only
       
   150  * if there is an error in parsing. Since, the FW uses SAX parser
       
   151  * and if the XML error happens after the metadata entries are 
       
   152  * created, the entries should be cleaned up.
       
   153  *
       
   154  */
       
   155 void CLiwServiceData::CleanUpMetaData()
       
   156 {
       
   157 	iDataList->Reset();
       
   158 }
       
   159