os/security/contentmgmt/contentaccessfwfordrm/source/cafutils/Metadataarray.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
#include <s32strm.h>
sl@0
    20
#include <caf/metadataarray.h>
sl@0
    21
#include <caf/metadata.h>
sl@0
    22
sl@0
    23
using namespace ContentAccess;
sl@0
    24
sl@0
    25
EXPORT_C CMetaDataArray* CMetaDataArray::NewL()
sl@0
    26
	{
sl@0
    27
	CMetaDataArray* self = NewLC();
sl@0
    28
	CleanupStack::Pop(self);
sl@0
    29
	return self;
sl@0
    30
	}
sl@0
    31
sl@0
    32
EXPORT_C CMetaDataArray* CMetaDataArray::NewLC()
sl@0
    33
	{
sl@0
    34
	CMetaDataArray* self = new (ELeave) CMetaDataArray;
sl@0
    35
	CleanupStack::PushL(self);
sl@0
    36
	return self;
sl@0
    37
	}
sl@0
    38
sl@0
    39
EXPORT_C CMetaDataArray* CMetaDataArray::NewL(RReadStream& aStream)
sl@0
    40
	{
sl@0
    41
	CMetaDataArray* self = new (ELeave) CMetaDataArray;
sl@0
    42
	CleanupStack::PushL(self);
sl@0
    43
	self->InternalizeL(aStream);
sl@0
    44
	CleanupStack::Pop(self);
sl@0
    45
	return self;
sl@0
    46
	}
sl@0
    47
sl@0
    48
CMetaDataArray::CMetaDataArray()
sl@0
    49
	{
sl@0
    50
	iMaxFieldLength = 0;
sl@0
    51
	}	
sl@0
    52
sl@0
    53
		
sl@0
    54
CMetaDataArray::~CMetaDataArray()
sl@0
    55
	{	
sl@0
    56
	iArray.ResetAndDestroy();
sl@0
    57
	}
sl@0
    58
sl@0
    59
EXPORT_C void CMetaDataArray::AddL(const TDesC8& aField, const TDesC8& aData)
sl@0
    60
	{
sl@0
    61
	// Construct a new CMetaData object with 8 bit data
sl@0
    62
	CMetaData* ptr = CMetaData::NewL(aField, aData);
sl@0
    63
	CleanupStack::PushL(ptr);
sl@0
    64
	
sl@0
    65
	// Add it to the array
sl@0
    66
	User::LeaveIfError(iArray.Append(ptr));
sl@0
    67
sl@0
    68
	// Array owns the pointer so we don't need it in the cleanup stack any longer
sl@0
    69
	CleanupStack::Pop(ptr);
sl@0
    70
sl@0
    71
	// See if this field is longer than any previous field
sl@0
    72
	if(aField.Length() > iMaxFieldLength)
sl@0
    73
		{
sl@0
    74
		iMaxFieldLength = aField.Length();
sl@0
    75
		}
sl@0
    76
	}
sl@0
    77
sl@0
    78
EXPORT_C void CMetaDataArray::AddL(const TDesC& aField, const TDesC& aData)
sl@0
    79
	{
sl@0
    80
	// Construct a new CMetaData object with unicode data
sl@0
    81
	CMetaData* ptr = CMetaData::NewL(aField, aData);
sl@0
    82
	CleanupStack::PushL(ptr);
sl@0
    83
sl@0
    84
	// Add it to the array
sl@0
    85
	User::LeaveIfError(iArray.Append(ptr));
sl@0
    86
	
sl@0
    87
	// Array owns the pointer so we don't need it in the cleanup stack any longer
sl@0
    88
	CleanupStack::Pop(ptr);
sl@0
    89
sl@0
    90
	// See if this field is longer than any previous field
sl@0
    91
	if(aField.Length() > iMaxFieldLength)
sl@0
    92
		{
sl@0
    93
		iMaxFieldLength = aField.Length();
sl@0
    94
		}
sl@0
    95
	}
sl@0
    96
sl@0
    97
EXPORT_C const CMetaData& CMetaDataArray::operator [] (TInt aIndex) const
sl@0
    98
	{
sl@0
    99
	return *iArray[aIndex];
sl@0
   100
	}
sl@0
   101
sl@0
   102
EXPORT_C TInt CMetaDataArray::Count() const
sl@0
   103
	{
sl@0
   104
	return iArray.Count();
sl@0
   105
	}
sl@0
   106
sl@0
   107
EXPORT_C const TDesC& CMetaDataArray::SearchL(const TDesC& aField, TBool aMatchCase) const
sl@0
   108
	{
sl@0
   109
	TInt i;
sl@0
   110
	if(!aMatchCase)
sl@0
   111
		{
sl@0
   112
		// Allocate space for upper case version of field to search for
sl@0
   113
		HBufC* searchField = aField.AllocLC();
sl@0
   114
		TPtr searchFieldPtr = searchField->Des();
sl@0
   115
		searchFieldPtr.UpperCase();
sl@0
   116
sl@0
   117
		// Allocate space for upper case version fields in the array
sl@0
   118
		HBufC* field = HBufC::NewLC(iMaxFieldLength);
sl@0
   119
		TPtr fieldPtr = field->Des();
sl@0
   120
sl@0
   121
		// search through the array to find the data matching the given field
sl@0
   122
		for(i = 0; i < iArray.Count(); i++)
sl@0
   123
			{
sl@0
   124
			fieldPtr.Copy(iArray[i]->Field());
sl@0
   125
			fieldPtr.UpperCase();
sl@0
   126
			if(fieldPtr == searchFieldPtr)
sl@0
   127
				{
sl@0
   128
				CleanupStack::PopAndDestroy(2, searchField); // searchField, field
sl@0
   129
				return iArray[i]->Data();
sl@0
   130
				}
sl@0
   131
			}
sl@0
   132
		CleanupStack::PopAndDestroy(2, searchField); // searchField, field
sl@0
   133
		}
sl@0
   134
	else	
sl@0
   135
		{
sl@0
   136
		// search through the array to find the data matching the given field
sl@0
   137
		for(i = 0; i < iArray.Count(); i++)
sl@0
   138
			{
sl@0
   139
			if(iArray[i]->Field() == aField)
sl@0
   140
				{
sl@0
   141
				return iArray[i]->Data();
sl@0
   142
				}
sl@0
   143
			}
sl@0
   144
		}
sl@0
   145
	// not found so return an empty string
sl@0
   146
	return KNullDesC16();
sl@0
   147
	}
sl@0
   148
		
sl@0
   149
EXPORT_C const TDesC8& CMetaDataArray::SearchL(const TDesC8& aField8, TBool aMatchCase) const
sl@0
   150
	{
sl@0
   151
	TInt i;
sl@0
   152
sl@0
   153
	if(!aMatchCase)
sl@0
   154
		{
sl@0
   155
		// Allocate space for upper case version of field to search for
sl@0
   156
		HBufC8* searchField = aField8.AllocLC();
sl@0
   157
		TPtr8 searchFieldPtr = searchField->Des();
sl@0
   158
		searchFieldPtr.UpperCase();
sl@0
   159
sl@0
   160
		// Allocate space for upper case version fields in the array
sl@0
   161
		HBufC8* field = HBufC8::NewLC(iMaxFieldLength);
sl@0
   162
		TPtr8 fieldPtr = field->Des();
sl@0
   163
sl@0
   164
		// search through the array to find the data matching the given field
sl@0
   165
		for(i = 0; i < iArray.Count(); i++)
sl@0
   166
			{
sl@0
   167
			fieldPtr.Copy(iArray[i]->Field8());
sl@0
   168
			fieldPtr.UpperCase();
sl@0
   169
			if(fieldPtr == searchFieldPtr)
sl@0
   170
				{
sl@0
   171
				CleanupStack::PopAndDestroy(2, searchField); // searchField, field
sl@0
   172
				return iArray[i]->Data8();
sl@0
   173
				}
sl@0
   174
			}
sl@0
   175
		CleanupStack::PopAndDestroy(2, searchField); // searchField, field
sl@0
   176
		}
sl@0
   177
	else	
sl@0
   178
		{
sl@0
   179
		// search through the array to find the data matching the given field
sl@0
   180
		for(i = 0; i < iArray.Count(); i++)
sl@0
   181
			{
sl@0
   182
			if(iArray[i]->Field8() == aField8)
sl@0
   183
				{
sl@0
   184
				return iArray[i]->Data8();
sl@0
   185
				}
sl@0
   186
			}
sl@0
   187
		}
sl@0
   188
	// not found so return an empty string
sl@0
   189
	return KNullDesC8();
sl@0
   190
	}
sl@0
   191
	
sl@0
   192
EXPORT_C void CMetaDataArray::ExternalizeL(RWriteStream& aStream) const
sl@0
   193
	{
sl@0
   194
	TInt i;
sl@0
   195
	aStream.WriteInt32L(iArray.Count());
sl@0
   196
	for(i = 0; i < iArray.Count();i++)
sl@0
   197
		{
sl@0
   198
		aStream << *(iArray[i]);
sl@0
   199
		}
sl@0
   200
	}
sl@0
   201
sl@0
   202
void CMetaDataArray::InternalizeL(RReadStream& aStream)
sl@0
   203
	{
sl@0
   204
	TInt i;
sl@0
   205
	TInt length = 0;
sl@0
   206
sl@0
   207
	// Read the number of CMetaData objects from the stream
sl@0
   208
	TInt count = aStream.ReadInt32L();
sl@0
   209
sl@0
   210
	// Read the CMetaData objects from the stream and add them to the array
sl@0
   211
	for(i = 0; i < count; i++)
sl@0
   212
		{
sl@0
   213
		CMetaData* metaData = CMetaData::NewL(aStream);
sl@0
   214
		CleanupStack::PushL(metaData);
sl@0
   215
		User::LeaveIfError(iArray.Append(metaData));
sl@0
   216
sl@0
   217
		// See if this field is longer than any previous field
sl@0
   218
		length = metaData->Field().Length();
sl@0
   219
		if(length > iMaxFieldLength)
sl@0
   220
			{
sl@0
   221
			iMaxFieldLength = length;
sl@0
   222
			}
sl@0
   223
		
sl@0
   224
		// Finished with cleanup stack, metaData now owned by the array so don't delete
sl@0
   225
		CleanupStack::Pop(metaData);
sl@0
   226
		}
sl@0
   227
	}
sl@0
   228
sl@0
   229