os/security/contentmgmt/referencedrmagent/contentiterator/embeddedcontentiteratorbase.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2004-2010 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 <f32file.h>
sl@0
    20
#include <apmstd.h>
sl@0
    21
sl@0
    22
#include "contentIterator.h"
sl@0
    23
#include "virtualpath.h"
sl@0
    24
#include "content.h"
sl@0
    25
#include "EmbeddedcontentIteratorBase.h"
sl@0
    26
#include "EmbeddedObject.h"
sl@0
    27
sl@0
    28
using namespace ContentAccess;
sl@0
    29
sl@0
    30
sl@0
    31
CEmbeddedContentIteratorBase* CEmbeddedContentIteratorBase ::NewL(CContent& aContent, TBool aRecursive, const TDesC8& aMimeType)
sl@0
    32
	{
sl@0
    33
	CEmbeddedContentIteratorBase* self = new (ELeave) CEmbeddedContentIteratorBase(aContent, aRecursive, aMimeType);
sl@0
    34
	CleanupStack::PushL(self);
sl@0
    35
	self->ConstructL();
sl@0
    36
	CleanupStack::Pop(self);
sl@0
    37
	return self;
sl@0
    38
	}
sl@0
    39
sl@0
    40
void CEmbeddedContentIteratorBase::ConstructL()
sl@0
    41
	{
sl@0
    42
	// populate the array with the items at this level of the content file
sl@0
    43
	iContent.GetEmbeddedObjectsL(iEmbeddedContentObjects, EContentObject);
sl@0
    44
	iContent.GetEmbeddedObjectsL(iEmbeddedContainerObjects, EContainerObject);
sl@0
    45
sl@0
    46
	// Find the Next,  (ie. first content object)
sl@0
    47
	// This will leave if there is no object
sl@0
    48
	User::LeaveIfError(Next());
sl@0
    49
	}
sl@0
    50
sl@0
    51
CEmbeddedContentIteratorBase::CEmbeddedContentIteratorBase(CContent& aContent, TBool aRecursive, const TDesC8& aMimeType) 
sl@0
    52
	: iContent(aContent), iRecursive(aRecursive), iMimeType(aMimeType)
sl@0
    53
	{
sl@0
    54
	iContentIndex = 0;
sl@0
    55
	iContainerIndex = 0;
sl@0
    56
	}
sl@0
    57
sl@0
    58
CEmbeddedContentIteratorBase::~CEmbeddedContentIteratorBase()
sl@0
    59
	{
sl@0
    60
	delete iSubIterator;
sl@0
    61
sl@0
    62
	// Clear array 
sl@0
    63
	iEmbeddedContainerObjects.Close();
sl@0
    64
	iEmbeddedContentObjects.Close();
sl@0
    65
	}	
sl@0
    66
sl@0
    67
CEmbeddedObject& CEmbeddedContentIteratorBase::EmbeddedObject()
sl@0
    68
	{
sl@0
    69
	// The next pointer is currently on an object inside the subiterator
sl@0
    70
	if(iSubIterator)
sl@0
    71
		{
sl@0
    72
		return iSubIterator->EmbeddedObject();
sl@0
    73
		}
sl@0
    74
	else
sl@0
    75
		{	
sl@0
    76
		return *iEmbeddedContentObjects[iContentIndex - 1];
sl@0
    77
		}
sl@0
    78
	}
sl@0
    79
		
sl@0
    80
TInt CEmbeddedContentIteratorBase::Next()
sl@0
    81
	{
sl@0
    82
	// Must figure out if there's a constant for this
sl@0
    83
	TBuf8 <KMaxDataTypeLength> mimeType;
sl@0
    84
	TInt ret = KErrNotFound;
sl@0
    85
sl@0
    86
	// If we are already looking into a container, try finding the next in there
sl@0
    87
	if(iSubIterator)
sl@0
    88
		{
sl@0
    89
		ret = iSubIterator->Next();
sl@0
    90
		if(ret == KErrNone)
sl@0
    91
			{
sl@0
    92
			return ret;
sl@0
    93
			}
sl@0
    94
		else 
sl@0
    95
			{
sl@0
    96
			// come back to our level
sl@0
    97
			iContent.CloseContainer();
sl@0
    98
sl@0
    99
			// Delete sub-iterator
sl@0
   100
			delete iSubIterator;
sl@0
   101
			iSubIterator = NULL;
sl@0
   102
			}
sl@0
   103
		}
sl@0
   104
	
sl@0
   105
sl@0
   106
	// Find content objects inside this container
sl@0
   107
	for( ; iContentIndex < iEmbeddedContentObjects.Count(); iContentIndex++)
sl@0
   108
		{
sl@0
   109
		// if we don't care about mime type, this content object will do
sl@0
   110
		if(iMimeType.Length() == 0)
sl@0
   111
			{
sl@0
   112
			// make sure next time we look at the next item in our array
sl@0
   113
			iContentIndex++;
sl@0
   114
			return KErrNone;
sl@0
   115
			}
sl@0
   116
sl@0
   117
		// See if the content object has the right mime type that we are looking for
sl@0
   118
		mimeType.Copy(iEmbeddedContentObjects[iContentIndex]->MimeType());
sl@0
   119
		if(iMimeType == mimeType)
sl@0
   120
			{
sl@0
   121
			// make sure next time we look at the next item in our array
sl@0
   122
			iContentIndex++;
sl@0
   123
			return KErrNone;
sl@0
   124
			}
sl@0
   125
		// otherwise continue to next iteration, for loop incrementes iContentIndex		
sl@0
   126
		}		
sl@0
   127
	
sl@0
   128
	// Free memory allocated for content objects
sl@0
   129
	if(iContentIndex)
sl@0
   130
		{
sl@0
   131
		iEmbeddedContentObjects.ResetAndDestroy();
sl@0
   132
		iContentIndex = 0;
sl@0
   133
		}
sl@0
   134
sl@0
   135
	// Find content objects within nested containers
sl@0
   136
	for( ; iContainerIndex < iEmbeddedContainerObjects.Count(); iContainerIndex++)
sl@0
   137
		{
sl@0
   138
		// If it's a container look inside 
sl@0
   139
		iContent.OpenContainer(iEmbeddedContainerObjects[iContainerIndex]->UniqueId());
sl@0
   140
		TRAPD(err, iSubIterator = CEmbeddedContentIteratorBase::NewL(iContent, iRecursive, iMimeType));
sl@0
   141
		if(err == KErrNone)
sl@0
   142
			{
sl@0
   143
			// must have found something inside
sl@0
   144
			// make sure next time we search at the next item in our array
sl@0
   145
			iContainerIndex++;
sl@0
   146
			return KErrNone;
sl@0
   147
			}
sl@0
   148
		// otherwise continue to next iteration
sl@0
   149
		}
sl@0
   150
sl@0
   151
	// must be at the end of the array, ie. can't find any more content objects
sl@0
   152
	return KErrNotFound;
sl@0
   153
	}
sl@0
   154
sl@0
   155