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