1 /* |
|
2 * Copyright (c) 2005-2006 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 "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: CJavaSuperDParser definition. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef C_JAVASUPERDPARSER_H |
|
20 #define C_JAVASUPERDPARSER_H |
|
21 |
|
22 #include <e32base.h> |
|
23 #include <f32file.h> |
|
24 #include <s32strm.h> |
|
25 #include <e32std.h> |
|
26 |
|
27 class CZipFile; |
|
28 class CZipFileMember; |
|
29 |
|
30 namespace Java |
|
31 { |
|
32 |
|
33 /** |
|
34 * CJavaSuperDParser includes methods for parsing SuperD packages. |
|
35 * |
|
36 * This class includes methods for creating a superdistributable JAR |
|
37 * package and also methods for parsing a superdistributable JAR |
|
38 * package when installing it. |
|
39 * |
|
40 * A superdistributable JAR package is in uncompressed ZIP format |
|
41 * containing: |
|
42 * -# a manifest file (META-INF/MANIFEST.MF), |
|
43 * -# a JAD file and |
|
44 * -# either a plaintext JAR file or a JAR file in DCF. |
|
45 * |
|
46 * The manifest file must have the following attributes: |
|
47 * -# Distribution-Package: <SuperD version number> |
|
48 * -# Distribution-Descriptor-Filename: <JAD file name> |
|
49 * -# Distribution-Content-Filename: <JAR file name> |
|
50 * |
|
51 * To create a superdistributable jar package use the static method |
|
52 * CreateSuperDPackageL: |
|
53 * @code |
|
54 * using namespace Java; |
|
55 * CJavaSuperDParser::CreateSuperDPackageL( RFs& aFileSession, |
|
56 * const TDesC& aDestinationFileName, |
|
57 * const TDesC& aJadFileName, |
|
58 * const TDesC& aJarFileName ); |
|
59 * @endcode |
|
60 * |
|
61 * To parse a superdistributable jar package: |
|
62 * @code |
|
63 * using namespace Java; |
|
64 * CJavaSuperDParser* parser( NULL ); |
|
65 * TRAPD( err, parser = CJavaSuperDParser::NewL( aFileSession, |
|
66 * KSuperDFile, |
|
67 * KDestinationDir ) ); |
|
68 * if ( !err ) |
|
69 * { |
|
70 * // Now you know that KSuperDFile is a superdistributable package. |
|
71 * // JAD and JAR file have been written in KDestinationDir. |
|
72 * } |
|
73 * delete parser; |
|
74 * @endcode |
|
75 * |
|
76 * CJavaSuperDParser was renamed from CJcfSuperDParser. |
|
77 * |
|
78 * @lib javadrmutils.lib |
|
79 * @since S60 v3.2 |
|
80 */ |
|
81 NONSHARABLE_CLASS(CJavaSuperDParser) : public CBase |
|
82 { |
|
83 |
|
84 public: |
|
85 |
|
86 /** |
|
87 * First phase constructor. Creates a CJavaSuperDParser object, parses |
|
88 * the SuperD package and extracts its contents to the specified |
|
89 * folder. |
|
90 * |
|
91 * @since S60 v3.2 |
|
92 * @param aFileSession File session handle to be used by this object |
|
93 * @param aJarFileName Filename of the file containing SuperD |
|
94 * package |
|
95 * @param aDestinationFolder Folder where descriptor and content |
|
96 * files will be saved |
|
97 * @return The newly created CJavaSuperDParser object handle |
|
98 * @leave KErrCorrupt If supplied file is not a SuperD package |
|
99 */ |
|
100 IMPORT_C static CJavaSuperDParser* NewL(RFs& aFileSession, |
|
101 const TDesC& aJarFileName, |
|
102 const TDesC& aDestinationFolder); |
|
103 |
|
104 /** |
|
105 * First phase constructor. Creates a CJavaSuperDParser object, parses |
|
106 * the SuperD package and extracts its contents to the specified |
|
107 * folder. |
|
108 * |
|
109 * @since S60 v3.2 |
|
110 * @param aFileSession File session handle to be used by this object |
|
111 * @param aJarFileHandle File handle of the file containing SuperD |
|
112 * package |
|
113 * @param aDestinationFolder Folder where descriptor and content |
|
114 * files will be saved |
|
115 * @return The newly created CJavaSuperDParser object handle |
|
116 * @leave KErrCorrupt If supplied file is not a SuperD package |
|
117 */ |
|
118 IMPORT_C static CJavaSuperDParser* NewL(RFs& aFileSession, |
|
119 RFile& aJarFileHandle, |
|
120 const TDesC& aDestinationFolder); |
|
121 |
|
122 /** |
|
123 * Destructor. Frees allocated resources. |
|
124 * |
|
125 * @since S60 v3.2 |
|
126 */ |
|
127 virtual ~CJavaSuperDParser(); |
|
128 |
|
129 /** |
|
130 * Creates a superdistribution package from the given JAD and JAR file. |
|
131 * |
|
132 * @since S60 v3.2 |
|
133 * @param aFileSession File session handle to be used by this object |
|
134 * @param aDestinationFileName Filename of the destination SuperD |
|
135 * package. |
|
136 * @param aDescriptorFileName JAD file name |
|
137 * @param aContentFileName JAR file name |
|
138 */ |
|
139 IMPORT_C static void CreateSuperDPackageL(RFs& aFileSession, |
|
140 const TDesC& aDestinationFileName, |
|
141 const TDesC& aDescriptorFileName, |
|
142 const TDesC& aContentFileName); |
|
143 |
|
144 /** |
|
145 * Returns the name of the JAD file in the SuperD package parsed by |
|
146 * this object. |
|
147 * |
|
148 * @since S60 v3.2 |
|
149 * @return Descriptor file name |
|
150 */ |
|
151 IMPORT_C TFileName DescriptorFileName() const; |
|
152 |
|
153 /** |
|
154 * Returns the name of the JAR file in the SuperD package parsed by |
|
155 * this object. |
|
156 * |
|
157 * @since S60 v3.2 |
|
158 * @return Content file name |
|
159 */ |
|
160 IMPORT_C TFileName ContentFileName() const; |
|
161 |
|
162 private: |
|
163 |
|
164 /** |
|
165 * Private C++ constructor. |
|
166 * |
|
167 * @since S60 v3.2 |
|
168 * @param aFileSession File session handle to be used by this object |
|
169 */ |
|
170 CJavaSuperDParser(RFs& aFileSession); |
|
171 |
|
172 /** |
|
173 * Second phase Symbian constructor. Extracts the contents of the |
|
174 * SuperD package into the destination folder. |
|
175 * |
|
176 * @since S60 v3.2 |
|
177 * @param aJarFileName File name of SuperD package in the files system |
|
178 * @param aDestinationFolder Files from the package will be extracted |
|
179 * here. |
|
180 * @leave KErrCorrupt If supplied file is not a SuperD package |
|
181 */ |
|
182 void ConstructL(const TDesC& aJarFileName, |
|
183 const TDesC& aDestinationFolder); |
|
184 |
|
185 /** |
|
186 * Second phase Symbian constructor. Checks and extracts the contents |
|
187 * of the SuperD package into the destination folder with |
|
188 * ParseZipFileL. |
|
189 * |
|
190 * @since S60 v3.2 |
|
191 * @param aJarFileHandle File handle to the SuperD package |
|
192 * @param aDestinationFolder Files from the package will be extracted |
|
193 * here. |
|
194 * @leave KErrCorrupt If supplied file is not a SuperD package |
|
195 */ |
|
196 void ConstructL(RFile& aJarFileHandle, |
|
197 const TDesC& aDestinationFolder); |
|
198 |
|
199 /** |
|
200 * Calculates the CRC of a given file according to zip specification. |
|
201 * |
|
202 * @since S60 v3.2 |
|
203 * @param aFile File to calculate the CRC for |
|
204 * @return CRC value |
|
205 */ |
|
206 static TUint32 CalculateCRC(RFile& aFile); |
|
207 |
|
208 /** |
|
209 * Creates and writes the MANIFEST.MF file for the SuperD package. |
|
210 * The manifest file contains the following three lines: |
|
211 * -# Distribution-Package: <SuperD version number> |
|
212 * -# Distribution-Descriptor-Filename: <JAD file name> |
|
213 * -# Distribution-Content-Filename: <JAR file name> |
|
214 * |
|
215 * This function creates a META-INF/MANIFEST.MF (in the META-INF |
|
216 * directory inside the SuperD JAR file with the structure above, |
|
217 * and writes it to a RWriteStream with WriteEntryAndUpdateIndexL. |
|
218 * |
|
219 * @since S60 v3.2 |
|
220 * @param aFileSession File session handle to be used by this object |
|
221 * @param aStream File write stream where the manifest file will be |
|
222 * written |
|
223 * @param aCurrentOffset Offset where to start to write in the write |
|
224 * stream |
|
225 * @param aZipIndex The zip file index |
|
226 * @param aRelativeJadFileName Name of the JAD file with relative path |
|
227 * @param aRelativeJarFileName Name of the JAR file with relative path |
|
228 */ |
|
229 static void CreateAndWriteManifestL(RFs& aFileSession, |
|
230 RWriteStream& aStream, |
|
231 TInt& aCurrentOffset, |
|
232 HBufC8*& aZipIndex, |
|
233 const TDesC8& aRelativeJadFileName, |
|
234 const TDesC8& aRelativeJarFileName); |
|
235 /** |
|
236 * Writes an entry (file or directory) to the zip file stream and |
|
237 * updates the zip file index. |
|
238 * |
|
239 * @since S60 v3.2 |
|
240 * @param aFileSession File session handle to be used by this object |
|
241 * @param aStream ZIP file write stream where the entry will be written |
|
242 * @param aCurrentOffset Offset where to start to write |
|
243 * @param aZipIndex The zip file index |
|
244 * @param aRelativeFileName Relative name of the entry inside the ZIP |
|
245 * file |
|
246 * @param aFileName Name of the file in the file system which will be |
|
247 * written in the ZIP file. Use NULL to create a directory. |
|
248 */ |
|
249 static void WriteEntryAndUpdateIndexL(RFs& aFileSession, |
|
250 RWriteStream& aStream, |
|
251 TInt& aCurrentOffset, |
|
252 HBufC8*& aZipIndex, |
|
253 const TDesC8& aRelativeFileName, |
|
254 const TDesC* aFileName); |
|
255 /** |
|
256 * Writes the ZIP index entry to the ZIP output stream. The ZIP index |
|
257 * should be the last entry in the ZIP file. |
|
258 * |
|
259 * @since S60 v3.2 |
|
260 * @param aStream ZIP file write stream where the entry will be written |
|
261 * @param aCurrentOffset Offset where to start to write |
|
262 * @param aZipIndex The zip file index which will be written in the stream |
|
263 */ |
|
264 static void WriteIndexL(RWriteStream& aStream, |
|
265 TInt aCurrentOffset, |
|
266 const HBufC8* aZipIndex); |
|
267 |
|
268 /** |
|
269 * Checks and parses the contents of the SuperD package. |
|
270 * |
|
271 * @since S60 v3.2 |
|
272 * @param aDestinationFolder Files from the package will be extracted |
|
273 * here. |
|
274 */ |
|
275 void ParseZipFileL(const TDesC& aDestinationFolder); |
|
276 |
|
277 /** |
|
278 * Checks from the manifest file that this is a SuperD package. |
|
279 * Extracts the JAD and JAR file name from the manifest file in the |
|
280 * SuperD package and checks wether the package version is compatible |
|
281 * with the parser. |
|
282 * |
|
283 * @since S60 v3.2 |
|
284 * @param aManifest The manifest file entry in the ZIP file. |
|
285 */ |
|
286 void ParseManifestL(CZipFileMember* aManifest); |
|
287 |
|
288 /** |
|
289 * Extracts the JAD and the JAR file from the SuperD package to the |
|
290 * destination folder. |
|
291 * |
|
292 * @since S60 v3.2 |
|
293 * @param aDestinationFolder Destination folder name. |
|
294 */ |
|
295 void WriteFileL(const TDesC& aDestinationFolder); |
|
296 |
|
297 private: // data |
|
298 |
|
299 /** |
|
300 * File session handle to be used by this object. |
|
301 * Not own. |
|
302 */ |
|
303 RFs& iFileSession; |
|
304 |
|
305 /** |
|
306 * Zip file object. |
|
307 * Own. |
|
308 */ |
|
309 CZipFile* iZipFile; |
|
310 |
|
311 /** |
|
312 * JAD file entry in the SuperD package. |
|
313 * Own. |
|
314 */ |
|
315 CZipFileMember* iJadMember; |
|
316 |
|
317 /** |
|
318 * JAR file entry in the SuperD package. |
|
319 * Own. |
|
320 */ |
|
321 CZipFileMember* iJarMember; |
|
322 |
|
323 /** |
|
324 * Shows wether there is a valid manifest file in the package. |
|
325 */ |
|
326 TBool iManifestFound; |
|
327 |
|
328 /** |
|
329 * Name of the JAD file in the SuperD package. |
|
330 */ |
|
331 TFileName iDescriptorFileName; |
|
332 |
|
333 /** |
|
334 * Name of the JAR file in the SuperD package. |
|
335 */ |
|
336 TFileName iContentFileName; |
|
337 |
|
338 }; |
|
339 |
|
340 } |
|
341 |
|
342 #endif // C_JAVASUPERDPARSER_H |
|
343 |
|
344 // End of File |
|