meetingrequest/mrversit2/src/cesmricalpropertyparam.cpp
changeset 0 8466d47a6819
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2002-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: This file implements classes CESMRICalPropertyParam, CESMRICalPropertyParam. 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // Class include.
       
    20 #include "emailtrace.h"
       
    21 #include "cesmricalpropertyparam.h"	// CESMRICalPropertyParam
       
    22 
       
    23 //debug
       
    24 
       
    25 // User includes.
       
    26 #include "cesmricalcontentlinewriter.h"	// CESMRICalContentLineWriter
       
    27 #include "esmricalerrors.h"				// Error values
       
    28 #include "esmricalkeywords.h"			// Literals
       
    29 #include "cesmricalvalue.h"				// CESMRICalValue
       
    30 
       
    31 /**
       
    32 Static factory constructor. Takes ownership of the passed value pointer and
       
    33 deletes it if this function leaves. Note that other values may be added later.
       
    34 @param aType The type of parameter.
       
    35 @param aValue A value of the parameter - this class takes ownership.
       
    36 @return A new property parameter
       
    37 @leave Leaves with KErrParameterHasNoValue if aValue is NULL.
       
    38 @publishedPartner
       
    39 */
       
    40 EXPORT_C CESMRICalPropertyParam* CESMRICalPropertyParam::NewL(const TDesC& aType, CESMRICalValue* aValue)
       
    41 	{
       
    42     FUNC_LOG;
       
    43 	
       
    44 	CESMRICalPropertyParam* self = CESMRICalPropertyParam::NewLC(aType, aValue);
       
    45 	CleanupStack::Pop(self);
       
    46 	
       
    47 	return self;
       
    48 	}
       
    49 
       
    50 /**
       
    51 Static factory constructor. Takes ownership of the passed value pointer and
       
    52 deletes it if this function leaves. Note that other values may be added later.
       
    53 The constructed object is pushed onto the Cleanup Stack.
       
    54 @param aType The type of parameter.
       
    55 @param aValue A value of the parameter - this class takes ownership.
       
    56 @return A new property parameter
       
    57 @leave Leaves with KErrParameterHasNoValue if aValue is NULL.
       
    58 @publishedPartner
       
    59 */
       
    60 EXPORT_C CESMRICalPropertyParam* CESMRICalPropertyParam::NewLC(const TDesC& aType, CESMRICalValue* aValue)
       
    61 	{
       
    62     FUNC_LOG;
       
    63 	
       
    64 	// Test that the value is valid before construction.
       
    65 	if (!aValue)
       
    66 		{
       
    67 		User::Leave(KErrParameterHasNoValue);
       
    68 		}
       
    69 	
       
    70 	// Push aValue on the Cleanup Stack.
       
    71 	CleanupStack::PushL(aValue);
       
    72 		
       
    73 	// Create a new object.
       
    74 	CESMRICalPropertyParam* self = new (ELeave) CESMRICalPropertyParam(aValue);
       
    75 	
       
    76 	// Pop aValue from the Cleanup Stack as it is temporarily owned by self.
       
    77 	CleanupStack::Pop(aValue);
       
    78 	
       
    79 	// Construct the new object.
       
    80 	CleanupStack::PushL(self);
       
    81 	self->ConstructL(aType, aValue);
       
    82 	
       
    83 	return self;
       
    84 	}
       
    85 	
       
    86 /**
       
    87 Static factory constructor. Note that other values may be added later. The
       
    88 constructed object is pushed onto the Cleanup Stack.
       
    89 @param aType The type of parameter.
       
    90 @param aValue A value of the parameter passed as a descriptor.
       
    91 @return A new property parameter
       
    92 @publishedPartner
       
    93 */
       
    94 EXPORT_C CESMRICalPropertyParam* CESMRICalPropertyParam::NewL(const TDesC& aType, const TDesC& aValue)
       
    95 	{
       
    96     FUNC_LOG;
       
    97 	
       
    98 	CESMRICalPropertyParam* self = NewLC(aType, aValue);
       
    99 	CleanupStack::Pop(self);
       
   100 	
       
   101 	return self;
       
   102 	}
       
   103 	
       
   104 /**
       
   105 Static factory constructor. Note that other values may be added later. The
       
   106 constructed object is pushed onto the Cleanup Stack.
       
   107 @param aType The type of parameter.
       
   108 @param aValue A value of the parameter passed as a descriptor.
       
   109 @return A new property parameter
       
   110 @publishedPartner
       
   111 */
       
   112 EXPORT_C CESMRICalPropertyParam* CESMRICalPropertyParam::NewLC(const TDesC& aType, const TDesC& aValue)
       
   113 	{
       
   114     FUNC_LOG;
       
   115 	
       
   116 	CESMRICalPropertyParam* self = new (ELeave) CESMRICalPropertyParam;
       
   117 	CleanupStack::PushL(self);
       
   118 	self->ConstructL(aType, aValue);
       
   119 	
       
   120 	return self;
       
   121 	}
       
   122 	
       
   123 /**
       
   124 Destructor
       
   125 @internalTechnology
       
   126 */
       
   127 CESMRICalPropertyParam::~CESMRICalPropertyParam()
       
   128 	{
       
   129     FUNC_LOG;
       
   130 	
       
   131 	delete iValue;
       
   132 	delete iType;
       
   133 	iValues.ResetAndDestroy();
       
   134 	
       
   135 	}
       
   136 
       
   137 /**
       
   138 Static factory construction. The constructed object is pushed onto the Cleanup
       
   139 Stack. Note that this constructor is not exported.
       
   140 @return A new blank property parameter.
       
   141 @internalTechnology
       
   142 */
       
   143 CESMRICalPropertyParam* CESMRICalPropertyParam::NewLC()
       
   144 	{
       
   145     FUNC_LOG;
       
   146 	
       
   147 	CESMRICalPropertyParam* self = new (ELeave) CESMRICalPropertyParam;
       
   148 	CleanupStack::PushL(self);
       
   149 	self->ConstructL(KNullDesC);	// No type set - SetTypeL() must be called on this object.
       
   150 	
       
   151 	return self;
       
   152 	}
       
   153 	
       
   154 /**
       
   155 Adds a string to the parameter's list of values. Any quotes are removed from
       
   156 the value as they are only used to escape other characters and are not a valid
       
   157 parameter value character in themselves.
       
   158 @param aValue The value to add.
       
   159 @leave Leaves if there is an error adding a value.
       
   160 @publishedPartner
       
   161 */
       
   162 EXPORT_C void CESMRICalPropertyParam::AddValueL(const TDesC& aValue)
       
   163 	{
       
   164     FUNC_LOG;
       
   165 	
       
   166 	// First remove any double quotes. These are used to escape colons, etc.
       
   167 	// in property parameter values and do not need to be stored.
       
   168 	// Note that double quote is not a valid character here and this assumes
       
   169 	// that they should all be removed. There is no check for matching quotes.
       
   170 	HBufC* parameterValue = aValue.AllocLC();
       
   171 	
       
   172 	TInt location(parameterValue->Locate(KICalQuoteChar));
       
   173 
       
   174 	while (location >= 0)
       
   175 		{
       
   176 		parameterValue->Des().Delete(location, 1);
       
   177 		location = parameterValue->Locate(KICalQuoteChar);
       
   178 		}
       
   179 
       
   180 	if (parameterValue->Length() > 0)
       
   181 		{
       
   182 		// Create a new value and append to the list of values.
       
   183 		CESMRICalValue* value = CESMRICalValue::NewLC();
       
   184 		value->SetTextL(*parameterValue);
       
   185 		User::LeaveIfError(iValues.Append(value));
       
   186 		CleanupStack::Pop(value);
       
   187 		}
       
   188 		
       
   189 	CleanupStack::PopAndDestroy(parameterValue);
       
   190 	
       
   191 	}
       
   192 	
       
   193 /**
       
   194 Adds a value to the parameter's list of values, taking ownership. Note that the
       
   195 value is deleted if this function leaves.
       
   196 @param aValue The value to add.
       
   197 @leave Leaves with KErrParameterHasNoValue if aValue is NULL.
       
   198 @publishedPartner
       
   199 */
       
   200 EXPORT_C void CESMRICalPropertyParam::AddValueL(CESMRICalValue* aValue)
       
   201 	{
       
   202     FUNC_LOG;
       
   203 	
       
   204 	if (!aValue)
       
   205 		{
       
   206 		User::Leave(KErrParameterHasNoValue);
       
   207 		}
       
   208 		
       
   209 	// Append the value to the list of values.
       
   210 	TInt err(iValues.Append(aValue));
       
   211 	
       
   212 	if (err)
       
   213 		{
       
   214 		delete aValue;
       
   215 		User::Leave(err);
       
   216 		}
       
   217 	}
       
   218 	
       
   219 /**
       
   220 Gets the type of the parameter
       
   221 @return The type of the property parameter or an empty descriptor if no type is
       
   222 set.
       
   223 @publishedPartner
       
   224 */
       
   225 EXPORT_C const TDesC& CESMRICalPropertyParam::Type() const
       
   226 	{
       
   227     FUNC_LOG;
       
   228 	
       
   229 	if (iType)
       
   230 		{
       
   231 		return *iType;
       
   232 		}
       
   233 		
       
   234 	// Else type is not set due to SetTypeL() leaving.
       
   235 	return KNullDesC;
       
   236 	}
       
   237 
       
   238 /**
       
   239 Access method for the value array.
       
   240 @return The array of values.
       
   241 @publishedPartner
       
   242 */
       
   243 EXPORT_C const RPointerArray<CESMRICalValue>& CESMRICalPropertyParam::Values() const
       
   244 	{
       
   245 	return iValues;
       
   246 	}
       
   247 
       
   248 /**
       
   249 Sets the type of the parameter to a string value
       
   250 @param aType the type of the property parameter
       
   251 @internalTechnology
       
   252 */
       
   253 void CESMRICalPropertyParam::SetTypeL(const TDesC& aType)
       
   254 	{
       
   255     FUNC_LOG;
       
   256 	
       
   257 	delete iType;
       
   258 	iType = NULL;
       
   259 	iType = aType.AllocL();
       
   260 	
       
   261 	}
       
   262 	
       
   263 /**
       
   264 Export this property parameter using the given line writer. Values are quoted
       
   265 if they contain characters that need to be escaped. Assumes it contains at
       
   266 least one value from the check in CESMRICalProperty::ExternalizeL().
       
   267 @param aWriter The content line writer to export to.
       
   268 @internalTechnology
       
   269 */
       
   270 void CESMRICalPropertyParam::ExternalizeL(CESMRICalContentLineWriter& aWriter)
       
   271 	{
       
   272     FUNC_LOG;
       
   273 
       
   274 	// Export the property parameter name.
       
   275 	aWriter.AppendL(Type());
       
   276 	aWriter.AppendL(KICalEquals());
       
   277 
       
   278 	// Export each property parameter value.
       
   279 	
       
   280 	const TInt lastValue = iValues.Count() - 1;	
       
   281 
       
   282 	for (TInt x = 0; x <= lastValue; ++x)
       
   283 		{
       
   284 		// Decide if this value needs to be escaped - in other words
       
   285 		// if it contains a colon, a semi-colon or a comma.
       
   286 		const TDesC& value = iValues[x]->TextL();
       
   287 		
       
   288 		if ((value.Locate(KICalCommaChar) >= 0) ||
       
   289 			(value.Locate(KICalColonChar) >= 0) ||
       
   290 			(value.Locate(KICalSemiColonChar) >= 0))
       
   291 			{
       
   292 			// Escape by quoting entire string.
       
   293 			aWriter.AppendL(KICalQuote());
       
   294 			aWriter.AppendL(value);
       
   295 			aWriter.AppendL(KICalQuote());
       
   296 			}
       
   297 		else
       
   298 			{
       
   299 			// No need to escape value.
       
   300 			aWriter.AppendL(value);
       
   301 			}
       
   302 
       
   303 		// Write out a comma separator between values.			
       
   304 		if (x < lastValue)
       
   305 			{
       
   306 			aWriter.AppendL(KICalComma());
       
   307 			}
       
   308 		}
       
   309 	}
       
   310 	
       
   311 /**
       
   312 Determines if two property parameters are equal. Comparison is case-sensitive.
       
   313 @param aParam1 The first property parameter.
       
   314 @param aParam2 The second property parameter.
       
   315 @return ETrue if they are equal.
       
   316 @internalTechnology
       
   317 */
       
   318 TBool CESMRICalPropertyParam::EqualsL(const CESMRICalPropertyParam& aParam1, const CESMRICalPropertyParam& aParam2)
       
   319 	{
       
   320     FUNC_LOG;
       
   321 	
       
   322 	if (aParam1.Type() != aParam2.Type())
       
   323 		{
       
   324 		return EFalse;
       
   325 		}
       
   326 	
       
   327 	const TInt values1 = aParam1.iValues.Count();
       
   328 	const TInt values2 = aParam2.iValues.Count();
       
   329 	
       
   330 	if (values1 != values2)
       
   331 		{
       
   332 		return EFalse;
       
   333 		}
       
   334 		
       
   335 	for (TInt i = 0; i < values1; i++)
       
   336 		{
       
   337 		if (aParam1.iValues[i]->TextL() != aParam2.iValues[i]->TextL())
       
   338 			{
       
   339 			return EFalse;
       
   340 			}
       
   341 		}
       
   342 	
       
   343 	return ETrue;
       
   344 	}
       
   345 	
       
   346 /**
       
   347 Constructor
       
   348 @internalTechnology
       
   349 */
       
   350 CESMRICalPropertyParam::CESMRICalPropertyParam()
       
   351 	{
       
   352     FUNC_LOG;
       
   353 	}
       
   354 	
       
   355 /**
       
   356 Constructor
       
   357 @param aValue The initial value.
       
   358 @internalTechnology
       
   359 */
       
   360 CESMRICalPropertyParam::CESMRICalPropertyParam(CESMRICalValue* aValue)
       
   361  :	iValue(aValue)
       
   362 	{
       
   363     FUNC_LOG;
       
   364 	}
       
   365 	
       
   366 /**
       
   367 Internal construction.
       
   368 @param aType The type of parameter.
       
   369 @internalTechnology
       
   370 */
       
   371 void CESMRICalPropertyParam::ConstructL(const TDesC& aType)
       
   372 	{
       
   373     FUNC_LOG;
       
   374 	
       
   375 	iType = aType.AllocL();
       
   376 	
       
   377 	}
       
   378 
       
   379 /**
       
   380 Internal construction.
       
   381 @param aType The type of parameter.
       
   382 @param aValue A value of the parameter.
       
   383 @internalTechnology
       
   384 */
       
   385 void CESMRICalPropertyParam::ConstructL(const TDesC& aType, const TDesC& aValue)
       
   386 	{
       
   387     FUNC_LOG;
       
   388 	
       
   389 	ConstructL(aType);
       
   390 	
       
   391 	// Add the value.
       
   392 	AddValueL(aValue);
       
   393 	
       
   394 	}
       
   395 	
       
   396 /**
       
   397 Internal construction. Takes ownership of the passed value pointer and
       
   398 deletes it if this function leaves.
       
   399 @param aType The type of parameter.
       
   400 @param aValue A value of the parameter - this class takes ownership.
       
   401 @internalTechnology
       
   402 */
       
   403 void CESMRICalPropertyParam::ConstructL(const TDesC& aType, CESMRICalValue* aValue)
       
   404 	{
       
   405     FUNC_LOG;
       
   406 	
       
   407 	ConstructL(aType);
       
   408 	
       
   409 	// Add the value.
       
   410 	iValue = NULL;	// If we got this far then we can release direct ownership of the value.
       
   411 	AddValueL(aValue);	// Value is deleted if this leaves.
       
   412 	
       
   413 	}
       
   414 
       
   415 // End of File
       
   416