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