os/security/contentmgmt/referencedrmagent/contentiterator/embeddedcontentiteratorbase.cpp
First public contribution.
2 * Copyright (c) 2004-2010 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
22 #include "contentIterator.h"
23 #include "virtualpath.h"
25 #include "EmbeddedcontentIteratorBase.h"
26 #include "EmbeddedObject.h"
28 using namespace ContentAccess;
31 CEmbeddedContentIteratorBase* CEmbeddedContentIteratorBase ::NewL(CContent& aContent, TBool aRecursive, const TDesC8& aMimeType)
33 CEmbeddedContentIteratorBase* self = new (ELeave) CEmbeddedContentIteratorBase(aContent, aRecursive, aMimeType);
34 CleanupStack::PushL(self);
36 CleanupStack::Pop(self);
40 void CEmbeddedContentIteratorBase::ConstructL()
42 // populate the array with the items at this level of the content file
43 iContent.GetEmbeddedObjectsL(iEmbeddedContentObjects, EContentObject);
44 iContent.GetEmbeddedObjectsL(iEmbeddedContainerObjects, EContainerObject);
46 // Find the Next, (ie. first content object)
47 // This will leave if there is no object
48 User::LeaveIfError(Next());
51 CEmbeddedContentIteratorBase::CEmbeddedContentIteratorBase(CContent& aContent, TBool aRecursive, const TDesC8& aMimeType)
52 : iContent(aContent), iRecursive(aRecursive), iMimeType(aMimeType)
58 CEmbeddedContentIteratorBase::~CEmbeddedContentIteratorBase()
63 iEmbeddedContainerObjects.Close();
64 iEmbeddedContentObjects.Close();
67 CEmbeddedObject& CEmbeddedContentIteratorBase::EmbeddedObject()
69 // The next pointer is currently on an object inside the subiterator
72 return iSubIterator->EmbeddedObject();
76 return *iEmbeddedContentObjects[iContentIndex - 1];
80 TInt CEmbeddedContentIteratorBase::Next()
82 // Must figure out if there's a constant for this
83 TBuf8 <KMaxDataTypeLength> mimeType;
84 TInt ret = KErrNotFound;
86 // If we are already looking into a container, try finding the next in there
89 ret = iSubIterator->Next();
96 // come back to our level
97 iContent.CloseContainer();
99 // Delete sub-iterator
106 // Find content objects inside this container
107 for( ; iContentIndex < iEmbeddedContentObjects.Count(); iContentIndex++)
109 // if we don't care about mime type, this content object will do
110 if(iMimeType.Length() == 0)
112 // make sure next time we look at the next item in our array
117 // See if the content object has the right mime type that we are looking for
118 mimeType.Copy(iEmbeddedContentObjects[iContentIndex]->MimeType());
119 if(iMimeType == mimeType)
121 // make sure next time we look at the next item in our array
125 // otherwise continue to next iteration, for loop incrementes iContentIndex
128 // Free memory allocated for content objects
131 iEmbeddedContentObjects.ResetAndDestroy();
135 // Find content objects within nested containers
136 for( ; iContainerIndex < iEmbeddedContainerObjects.Count(); iContainerIndex++)
138 // If it's a container look inside
139 iContent.OpenContainer(iEmbeddedContainerObjects[iContainerIndex]->UniqueId());
140 TRAPD(err, iSubIterator = CEmbeddedContentIteratorBase::NewL(iContent, iRecursive, iMimeType));
143 // must have found something inside
144 // make sure next time we search at the next item in our array
148 // otherwise continue to next iteration
151 // must be at the end of the array, ie. can't find any more content objects