os/security/contentmgmt/referencedrmagent/contentiterator/FileContentIteratorbase.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.
23 #include "contentIterator.h"
24 #include "virtualpath.h"
27 #include "EmbeddedObject.h"
28 #include "FileContentIteratorBase.h"
29 #include "EmbeddedcontentIterator.h"
31 using namespace ContentAccess;
33 _LIT(KCAFBackSlashCharacter, "\\");
36 CFileContentIteratorBase* CFileContentIteratorBase::NewL(CManager &aManager, const TDesC& aPath, TBool aRecursive, const TDesC8& aMimeType)
38 CFileContentIteratorBase* self = new (ELeave) CFileContentIteratorBase(aManager, aPath, aRecursive, aMimeType);
39 CleanupStack::PushL(self);
41 CleanupStack::Pop(self);
45 CFileContentIteratorBase::CFileContentIteratorBase(CManager& aManager, const TDesC& aPath, TBool aRecursive, const TDesC8& aMimeType) :
46 iManager(aManager), iPath(aPath), iRecursive(aRecursive), iMimeType(aMimeType)
52 void CFileContentIteratorBase::ConstructL()
54 // Get our list of files and directories
55 User::LeaveIfError(iManager.GetDir(iPath, ESortByName, KEntryAttNormal, iCurrentFileList, iCurrentDirectoryList));
59 // Won't be needing the list of directories
60 delete iCurrentDirectoryList;
61 iCurrentDirectoryList = NULL;
64 // Find the Next, (ie. first content object) inside this directory
65 // This will leave if nothing was found
66 User::LeaveIfError(Next());
69 CFileContentIteratorBase::~CFileContentIteratorBase()
72 delete iCurrentDirectoryList;
73 delete iCurrentFileList;
77 const TDesC& CFileContentIteratorBase::FileName() const
79 return iSubIterator->FileName();
82 const TDesC& CFileContentIteratorBase::UniqueId() const
84 return iSubIterator->UniqueId();
87 const TDesC& CFileContentIteratorBase::Name() const
89 return iSubIterator->Name();
92 const TDesC8& CFileContentIteratorBase::MimeType() const
94 return iSubIterator->MimeType();
97 TInt CFileContentIteratorBase::Next()
99 _LIT(KSysDirEntry, "sys");
101 TInt ret = KErrNotFound;
103 // If we are already looking into some sub container, try finding the next in there
106 ret = iSubIterator->Next();
113 // Delete sub-iterator
122 // Search files in our directory first
123 // this allows us to free memory used by iCurrentFileList
124 // before recursing into sub-directories
127 for ( ; iFileIndex < iCurrentFileList->Count(); iFileIndex++)
129 // Get a reference to the file we are interested in
130 const TEntry &entry = (*iCurrentFileList)[iFileIndex];
132 // create a new path string for the sub directory
133 TRAP(ret, iNewPath = HBufC::NewL(iPath.Length() + entry.iName.Length()));
138 iNewPath->Des().Append(iPath);
139 iNewPath->Des().Append(entry.iName);
141 // Look inside the file
142 TRAP(ret, iSubIterator = CEmbeddedContentIterator::NewL(TVirtualPathPtr(*iNewPath, KNullDesC()), iRecursive, iMimeType));
146 // must have found something in the file
147 // make sure next time we look at the next item in our list
155 delete iCurrentFileList;
156 iCurrentFileList = NULL;
162 // Search sub directories
163 for ( ; iDirIndex < iCurrentDirectoryList->Count(); iDirIndex++)
165 // Get a reference to the directory we are interested in
166 const TEntry &entry = (*iCurrentDirectoryList)[iDirIndex];
168 // make sure it's not the sys directory
169 if(KSysDirEntry().CompareF(entry.iName) == 0 && iPath.Length() == 3)
171 // go to the next iteration, skip the sys directory
175 // create a new path string for the sub directory
176 TRAP(ret, iNewPath = HBufC::NewL(iPath.Length() + 1 + entry.iName.Length()));
181 iNewPath->Des().Append(iPath);
182 iNewPath->Des().Append(entry.iName);
183 iNewPath->Des().Append(KCAFBackSlashCharacter);
186 // lets look inside the directory
187 TRAP(ret, iSubIterator = CFileContentIteratorBase::NewL(iManager, *iNewPath, iRecursive, iMimeType));
191 // must have found something in the sub-iterator
192 // make sure next time we look at the next item in our list
202 // reached the end of our list of directories and list of files