sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2003-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 <caf/caftypes.h>
|
sl@0
|
20 |
#include <caf/metadataarray.h>
|
sl@0
|
21 |
#include <caf/supplier.h>
|
sl@0
|
22 |
#include "resolver.h"
|
sl@0
|
23 |
#include <caf/importfile.h>
|
sl@0
|
24 |
#include "agentinfo.h"
|
sl@0
|
25 |
#include <caf/agentinterface.h>
|
sl@0
|
26 |
|
sl@0
|
27 |
#ifndef REMOVE_CAF1
|
sl@0
|
28 |
#include <caf/cafmimeheader.h>
|
sl@0
|
29 |
#include <apmstd.h>
|
sl@0
|
30 |
#endif // REMOVE_CAF1
|
sl@0
|
31 |
|
sl@0
|
32 |
using namespace ContentAccess;
|
sl@0
|
33 |
|
sl@0
|
34 |
EXPORT_C CSupplier* CSupplier::NewLC()
|
sl@0
|
35 |
{
|
sl@0
|
36 |
CSupplier* self = new (ELeave) CSupplier();
|
sl@0
|
37 |
CleanupStack::PushL(self);
|
sl@0
|
38 |
self->ConstructL();
|
sl@0
|
39 |
return self;
|
sl@0
|
40 |
}
|
sl@0
|
41 |
|
sl@0
|
42 |
EXPORT_C CSupplier* CSupplier::NewL()
|
sl@0
|
43 |
{
|
sl@0
|
44 |
CSupplier* self = NewLC();
|
sl@0
|
45 |
CleanupStack::Pop(self);
|
sl@0
|
46 |
return self;
|
sl@0
|
47 |
}
|
sl@0
|
48 |
|
sl@0
|
49 |
CSupplier::CSupplier()
|
sl@0
|
50 |
{
|
sl@0
|
51 |
}
|
sl@0
|
52 |
|
sl@0
|
53 |
CSupplier::~CSupplier()
|
sl@0
|
54 |
{
|
sl@0
|
55 |
delete iAgentResolver;
|
sl@0
|
56 |
delete iOutputDirectory;
|
sl@0
|
57 |
}
|
sl@0
|
58 |
|
sl@0
|
59 |
void CSupplier::ConstructL()
|
sl@0
|
60 |
{
|
sl@0
|
61 |
iAgentResolver = CAgentResolver::NewL(EFalse);
|
sl@0
|
62 |
iOutputDirectory=HBufC::NewL(0);
|
sl@0
|
63 |
}
|
sl@0
|
64 |
|
sl@0
|
65 |
EXPORT_C TBool CSupplier::IsImportSupported(const TDesC8& aMimeType)
|
sl@0
|
66 |
{
|
sl@0
|
67 |
TBuf8 <KMaxDataTypeLength> mimeLowerCase;
|
sl@0
|
68 |
if(aMimeType.Length() > KMaxDataTypeLength)
|
sl@0
|
69 |
{
|
sl@0
|
70 |
return EFalse;
|
sl@0
|
71 |
}
|
sl@0
|
72 |
|
sl@0
|
73 |
// Convert supplied mime type to lower case
|
sl@0
|
74 |
mimeLowerCase.Copy(aMimeType);
|
sl@0
|
75 |
mimeLowerCase.LowerCase();
|
sl@0
|
76 |
|
sl@0
|
77 |
// Search for the mime type in the agents
|
sl@0
|
78 |
for(TInt i = 0; i < iAgentResolver->SupplierMimeTypes().Count(); i++)
|
sl@0
|
79 |
{
|
sl@0
|
80 |
if(mimeLowerCase.Compare(iAgentResolver->SupplierMimeTypes()[i]) == 0)
|
sl@0
|
81 |
{
|
sl@0
|
82 |
return ETrue;
|
sl@0
|
83 |
}
|
sl@0
|
84 |
}
|
sl@0
|
85 |
return EFalse;
|
sl@0
|
86 |
}
|
sl@0
|
87 |
|
sl@0
|
88 |
EXPORT_C void CSupplier::PrepareHTTPRequestHeaders(RStringPool& aStringPool, RHTTPHeaders& aRequestHeaders) const
|
sl@0
|
89 |
{
|
sl@0
|
90 |
// Ignore errors from any particular agent because we can't
|
sl@0
|
91 |
// let one agent ruin things for everyone else.
|
sl@0
|
92 |
TInt i = 0;
|
sl@0
|
93 |
TInt err = KErrNone;
|
sl@0
|
94 |
CAgentManager* manager = NULL;
|
sl@0
|
95 |
for(i = 0; i < iAgentResolver->AgentInfoCount(); i++)
|
sl@0
|
96 |
{
|
sl@0
|
97 |
TRAP(err, manager = &iAgentResolver->AgentInfo(i).AgentManagerL());
|
sl@0
|
98 |
if(err == KErrNone)
|
sl@0
|
99 |
{
|
sl@0
|
100 |
manager->PrepareHTTPRequestHeaders(aStringPool, aRequestHeaders);
|
sl@0
|
101 |
}
|
sl@0
|
102 |
}
|
sl@0
|
103 |
}
|
sl@0
|
104 |
|
sl@0
|
105 |
|
sl@0
|
106 |
EXPORT_C void CSupplier::SetOutputDirectoryL(const TDesC &aOutputDirectory)
|
sl@0
|
107 |
{
|
sl@0
|
108 |
HBufC *newOutputDirectory;
|
sl@0
|
109 |
|
sl@0
|
110 |
// Make sure the path has a backslash at the end
|
sl@0
|
111 |
TInt pos = aOutputDirectory.LocateReverse(TChar(KPathDelimiter));
|
sl@0
|
112 |
if(pos + 1 != aOutputDirectory.Length())
|
sl@0
|
113 |
{
|
sl@0
|
114 |
// Append a trailing backslash
|
sl@0
|
115 |
newOutputDirectory=HBufC::NewL(aOutputDirectory.Length()+1);
|
sl@0
|
116 |
newOutputDirectory->Des().Append(aOutputDirectory);
|
sl@0
|
117 |
newOutputDirectory->Des().Append(TChar(KPathDelimiter));
|
sl@0
|
118 |
}
|
sl@0
|
119 |
else
|
sl@0
|
120 |
{
|
sl@0
|
121 |
newOutputDirectory=aOutputDirectory.AllocL();
|
sl@0
|
122 |
}
|
sl@0
|
123 |
|
sl@0
|
124 |
// replace the existing output path
|
sl@0
|
125 |
delete iOutputDirectory;
|
sl@0
|
126 |
iOutputDirectory = newOutputDirectory;
|
sl@0
|
127 |
}
|
sl@0
|
128 |
|
sl@0
|
129 |
EXPORT_C CImportFile* CSupplier::ImportFileL(const TDesC8& aMimeType, const CMetaDataArray& aImportMetaData, const TDesC& aSuggestedFileName)
|
sl@0
|
130 |
{
|
sl@0
|
131 |
CAgentInfo& agentInfo = iAgentResolver->ResolveSupplierMimeL(aMimeType);
|
sl@0
|
132 |
|
sl@0
|
133 |
TUid agentUid = agentInfo.Agent().ImplementationUid();
|
sl@0
|
134 |
|
sl@0
|
135 |
// Create import object, agent creates output files
|
sl@0
|
136 |
CImportFile* import = CImportFile::NewL (agentUid, aMimeType, aImportMetaData, *iOutputDirectory, aSuggestedFileName);
|
sl@0
|
137 |
return import;
|
sl@0
|
138 |
}
|
sl@0
|
139 |
|
sl@0
|
140 |
EXPORT_C CImportFile* CSupplier::ImportFileL(const TDesC8& aMimeType, const CMetaDataArray& aImportMetaData)
|
sl@0
|
141 |
{
|
sl@0
|
142 |
// Create import object, client provides output files
|
sl@0
|
143 |
CAgentInfo& agentInfo = iAgentResolver->ResolveSupplierMimeL(aMimeType);
|
sl@0
|
144 |
|
sl@0
|
145 |
TUid agentUid = agentInfo.Agent().ImplementationUid();
|
sl@0
|
146 |
|
sl@0
|
147 |
// Create import object, agent creates output files
|
sl@0
|
148 |
CImportFile* import = CImportFile::NewL (agentUid, aMimeType, aImportMetaData);
|
sl@0
|
149 |
return import;
|
sl@0
|
150 |
}
|
sl@0
|
151 |
|
sl@0
|
152 |
#ifndef REMOVE_CAF1
|
sl@0
|
153 |
EXPORT_C CImportFile * CSupplier::ImportFileL (CCafMimeHeader &aMimeHeader, const TDesC &aSuggestedFileName)
|
sl@0
|
154 |
{
|
sl@0
|
155 |
TBuf8 <KMaxDataTypeLength> mimeType;
|
sl@0
|
156 |
|
sl@0
|
157 |
// string constants used to fill in CMetaDataArray
|
sl@0
|
158 |
_LIT8(KContentType, "Content-Type");
|
sl@0
|
159 |
_LIT8(KContentLength, "Content-Length");
|
sl@0
|
160 |
_LIT8(KContentId, "Content-Id");
|
sl@0
|
161 |
_LIT8(KContentTransferEncoding, "Content-Tranfer-Encoding");
|
sl@0
|
162 |
_LIT8(KBoundary, "Content-Boundary");
|
sl@0
|
163 |
|
sl@0
|
164 |
// create new CMetaDataArray to hold the information previously supplied in CCafMimeHeader
|
sl@0
|
165 |
CMetaDataArray *array = CMetaDataArray::NewLC();
|
sl@0
|
166 |
|
sl@0
|
167 |
// Copy "standard mime data" to the CMetaDataArray
|
sl@0
|
168 |
if(aMimeHeader.StandardMimeData(EContentType).Length() != 0)
|
sl@0
|
169 |
{
|
sl@0
|
170 |
array->AddL(KContentType(),aMimeHeader.StandardMimeData(EContentType));
|
sl@0
|
171 |
mimeType.Append(aMimeHeader.StandardMimeData(EContentType));
|
sl@0
|
172 |
}
|
sl@0
|
173 |
if(aMimeHeader.StandardMimeData(EContentLength).Length() != 0)
|
sl@0
|
174 |
{
|
sl@0
|
175 |
array->AddL(KContentLength(),aMimeHeader.StandardMimeData(EContentLength));
|
sl@0
|
176 |
}
|
sl@0
|
177 |
if(aMimeHeader.StandardMimeData(EContentLength).Length() != 0)
|
sl@0
|
178 |
{
|
sl@0
|
179 |
array->AddL(KContentLength(),aMimeHeader.StandardMimeData(EContentLength));
|
sl@0
|
180 |
}
|
sl@0
|
181 |
if(aMimeHeader.StandardMimeData(EContentId).Length() != 0)
|
sl@0
|
182 |
{
|
sl@0
|
183 |
array->AddL(KContentId(),aMimeHeader.StandardMimeData(EContentId));
|
sl@0
|
184 |
}
|
sl@0
|
185 |
if(aMimeHeader.StandardMimeData(EContentTransferEncoding).Length() != 0)
|
sl@0
|
186 |
{
|
sl@0
|
187 |
array->AddL(KContentTransferEncoding(),aMimeHeader.StandardMimeData(EContentTransferEncoding));
|
sl@0
|
188 |
}
|
sl@0
|
189 |
if(aMimeHeader.StandardMimeData(EBoundary).Length() != 0)
|
sl@0
|
190 |
{
|
sl@0
|
191 |
array->AddL(KBoundary(),aMimeHeader.StandardMimeData(EBoundary));
|
sl@0
|
192 |
}
|
sl@0
|
193 |
|
sl@0
|
194 |
// Add "non-standard" mime fields to CMetaDataArray
|
sl@0
|
195 |
TInt count = aMimeHeader.NonStandardMimeCount();
|
sl@0
|
196 |
for( TInt i = 0; i < count; i++)
|
sl@0
|
197 |
{
|
sl@0
|
198 |
array->AddL(aMimeHeader.NonStandardMimeField(i), aMimeHeader.NonStandardMimeData(i));
|
sl@0
|
199 |
}
|
sl@0
|
200 |
|
sl@0
|
201 |
// Create new CImportFile object
|
sl@0
|
202 |
CImportFile *importFile = ImportFileL(mimeType, *array, aSuggestedFileName);
|
sl@0
|
203 |
CleanupStack::PopAndDestroy(array);
|
sl@0
|
204 |
return importFile;
|
sl@0
|
205 |
}
|
sl@0
|
206 |
|
sl@0
|
207 |
#endif // REMOVE_CAF1
|
sl@0
|
208 |
|
sl@0
|
209 |
|