xref: /AOO41X/main/l10ntools/source/help/HelpIndexerTool.java (revision 7fb4469baf101f57be8a5178c651dd81bd1f6514)
1d127360fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3d127360fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4d127360fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5d127360fSAndrew Rist  * distributed with this work for additional information
6d127360fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7d127360fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8d127360fSAndrew Rist  * "License"); you may not use this file except in compliance
9d127360fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11d127360fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13d127360fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14d127360fSAndrew Rist  * software distributed under the License is distributed on an
15d127360fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16d127360fSAndrew Rist  * KIND, either express or implied.  See the License for the
17d127360fSAndrew Rist  * specific language governing permissions and limitations
18d127360fSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20d127360fSAndrew Rist  *************************************************************/
21d127360fSAndrew Rist 
22d127360fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package com.sun.star.help;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import java.io.FileInputStream;
27cdf0e10cSrcweir import java.io.FileOutputStream;
28cdf0e10cSrcweir import java.util.Arrays;
29cdf0e10cSrcweir import java.util.HashSet;
30cdf0e10cSrcweir import java.util.List;
31cdf0e10cSrcweir import java.util.zip.ZipEntry;
32cdf0e10cSrcweir import java.util.zip.ZipOutputStream;
33cdf0e10cSrcweir import java.util.zip.CRC32;
34cdf0e10cSrcweir import org.apache.lucene.analysis.standard.StandardAnalyzer;
35cdf0e10cSrcweir import org.apache.lucene.analysis.cjk.CJKAnalyzer;
36cdf0e10cSrcweir import org.apache.lucene.analysis.Analyzer;
37cdf0e10cSrcweir import org.apache.lucene.index.IndexWriter;
38*7fb4469bSPedro Giffuni import org.apache.lucene.util.Version;
39*7fb4469bSPedro Giffuni import org.apache.lucene.store.NIOFSDirectory;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir import java.io.File;
42cdf0e10cSrcweir import java.io.FileNotFoundException;
43cdf0e10cSrcweir import java.io.IOException;
44cdf0e10cSrcweir import java.util.Date;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir public class HelpIndexerTool
47cdf0e10cSrcweir {
48cdf0e10cSrcweir     public HelpIndexerTool()
49cdf0e10cSrcweir 	{
50cdf0e10cSrcweir     }
51cdf0e10cSrcweir 
52cdf0e10cSrcweir 
53cdf0e10cSrcweir     /**
54cdf0e10cSrcweir      * @param args the command line arguments
55cdf0e10cSrcweir      */
56cdf0e10cSrcweir     public static void main( String[] args )
57cdf0e10cSrcweir 	{
58cdf0e10cSrcweir 		boolean bExtensionMode = false;
59cdf0e10cSrcweir 		mainImpl( args, bExtensionMode );
60cdf0e10cSrcweir 	}
61cdf0e10cSrcweir 
62cdf0e10cSrcweir     public static void mainImpl( String[] args, boolean bExtensionMode )
63cdf0e10cSrcweir 	{
64cdf0e10cSrcweir         String aDirToZipStr = "";
65cdf0e10cSrcweir         String aSrcDirStr = "";
66cdf0e10cSrcweir         String aLanguageStr = "";
67cdf0e10cSrcweir         String aModule = "";
68cdf0e10cSrcweir         String aTargetZipFileStr = "";
69cdf0e10cSrcweir         String aCfsName = "";
70cdf0e10cSrcweir         String aSegmentName = "";
71cdf0e10cSrcweir 
72cdf0e10cSrcweir         // Scan arguments
73cdf0e10cSrcweir         //If this tool is invoked in the build process for extensions help,
74cdf0e10cSrcweir         //then -extension must be set.
75cdf0e10cSrcweir         boolean bExtension = false;
76cdf0e10cSrcweir         boolean bLang = false;
77cdf0e10cSrcweir         boolean bMod = false;
78cdf0e10cSrcweir         boolean bZipDir = false;
79cdf0e10cSrcweir         boolean bSrcDir = false;
80cdf0e10cSrcweir         boolean bOutput = false;
81cdf0e10cSrcweir         boolean bCfsName = false;
82cdf0e10cSrcweir         boolean bSegmentName = false;
83cdf0e10cSrcweir 
84cdf0e10cSrcweir         int nArgCount = args.length;
85cdf0e10cSrcweir         for( int i = 0 ; i < nArgCount ; i++ )
86cdf0e10cSrcweir 		{
87cdf0e10cSrcweir             if( "-extension".equals(args[i]) )
88cdf0e10cSrcweir 			{
89cdf0e10cSrcweir                 bExtension = true;
90cdf0e10cSrcweir             }
91cdf0e10cSrcweir             else if( "-lang".equals(args[i]) )
92cdf0e10cSrcweir 			{
93cdf0e10cSrcweir                 if( i + 1 < nArgCount )
94cdf0e10cSrcweir 				{
95cdf0e10cSrcweir                     aLanguageStr = args[i + 1];
96cdf0e10cSrcweir                     bLang = true;
97cdf0e10cSrcweir                 }
98cdf0e10cSrcweir                 i++;
99cdf0e10cSrcweir             }
100cdf0e10cSrcweir 			else if( "-mod".equals(args[i]) )
101cdf0e10cSrcweir 			{
102cdf0e10cSrcweir                 if( i + 1 < nArgCount )
103cdf0e10cSrcweir 				{
104cdf0e10cSrcweir                     aModule = args[i + 1];
105cdf0e10cSrcweir                     bMod = true;
106cdf0e10cSrcweir                 }
107cdf0e10cSrcweir                 i++;
108cdf0e10cSrcweir             }
109cdf0e10cSrcweir 			else if( "-zipdir".equals(args[i]) )
110cdf0e10cSrcweir 			{
111cdf0e10cSrcweir                 if( i + 1 < nArgCount )
112cdf0e10cSrcweir 				{
113cdf0e10cSrcweir                     aDirToZipStr = args[i + 1];
114cdf0e10cSrcweir                     bZipDir = true;
115cdf0e10cSrcweir                 }
116cdf0e10cSrcweir                 i++;
117cdf0e10cSrcweir             }
118cdf0e10cSrcweir 			else if( "-srcdir".equals(args[i]) )
119cdf0e10cSrcweir 			{
120cdf0e10cSrcweir                 if( i + 1 < nArgCount )
121cdf0e10cSrcweir 				{
122cdf0e10cSrcweir                     aSrcDirStr = args[i + 1];
123cdf0e10cSrcweir                     bSrcDir = true;
124cdf0e10cSrcweir                 }
125cdf0e10cSrcweir                 i++;
126cdf0e10cSrcweir             }
127cdf0e10cSrcweir 			else if( "-o".equals(args[i]) )
128cdf0e10cSrcweir 			{
129cdf0e10cSrcweir                 if( i + 1 < nArgCount )
130cdf0e10cSrcweir 				{
131cdf0e10cSrcweir                     aTargetZipFileStr = args[i + 1];
132cdf0e10cSrcweir                     bOutput = true;
133cdf0e10cSrcweir                 }
134cdf0e10cSrcweir                 i++;
135cdf0e10cSrcweir             }
136cdf0e10cSrcweir 			else if( "-checkcfsandsegname".equals(args[i]) )
137cdf0e10cSrcweir 			{
138cdf0e10cSrcweir                 if( i + 1 < nArgCount )
139cdf0e10cSrcweir 				{
140cdf0e10cSrcweir                     aCfsName = args[i + 1] + ".cfs";
141cdf0e10cSrcweir                     bCfsName = true;
142cdf0e10cSrcweir                 }
143cdf0e10cSrcweir                 i++;
144cdf0e10cSrcweir                 if( i + 1 < nArgCount )
145cdf0e10cSrcweir 				{
146cdf0e10cSrcweir                     aSegmentName = "segments" + args[i + 1];
147cdf0e10cSrcweir                     bSegmentName = true;
148cdf0e10cSrcweir                 }
149cdf0e10cSrcweir                 i++;
150cdf0e10cSrcweir                 if (!(bCfsName && bSegmentName))
151cdf0e10cSrcweir                 {
152cdf0e10cSrcweir                     System.out.println("Usage: HelpIndexer -checkcfsandsegname _0 _3 (2 arguments needed)");
153cdf0e10cSrcweir                     System.exit( -1 );
154cdf0e10cSrcweir                 }
155cdf0e10cSrcweir             }
156cdf0e10cSrcweir         }
157cdf0e10cSrcweir 
158cdf0e10cSrcweir         if( !bLang || !bMod || !bZipDir || (!bOutput && !bExtensionMode && !bExtension) )
159cdf0e10cSrcweir 		{
160cdf0e10cSrcweir 			if( bExtensionMode )
161cdf0e10cSrcweir 				return;
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 			System.out.println("Usage: HelpIndexer -lang ISOLangCode -mod HelpModule -zipdir TempZipDir -o OutputZipFile");
164cdf0e10cSrcweir             System.out.println("Usage: HelpIndexer -extension -lang ISOLangCode -mod HelpModule -zipdir PathToLangDir");
165cdf0e10cSrcweir 			System.exit( -1 );
166cdf0e10cSrcweir         }
167cdf0e10cSrcweir 
168cdf0e10cSrcweir         String aIndexDirName = aModule + ".idxl";
169cdf0e10cSrcweir         File aIndexDir = new File( aDirToZipStr + File.separator + aIndexDirName );
170cdf0e10cSrcweir 		if( !bSrcDir )
171cdf0e10cSrcweir 			aSrcDirStr = aDirToZipStr;
172cdf0e10cSrcweir         File aCaptionFilesDir = new File( aSrcDirStr + File.separator + "caption" );
173cdf0e10cSrcweir         File aContentFilesDir = new File( aSrcDirStr + File.separator + "content" );
174cdf0e10cSrcweir 
175cdf0e10cSrcweir         try
176cdf0e10cSrcweir 		{
177cdf0e10cSrcweir             Date start = new Date();
178*7fb4469bSPedro Giffuni 	    Analyzer analyzer = aLanguageStr.equals("ja") ? (Analyzer)new CJKAnalyzer(Version.LUCENE_29) : (Analyzer)new StandardAnalyzer(Version.LUCENE_29);
179*7fb4469bSPedro Giffuni 	    IndexWriter writer = new IndexWriter( NIOFSDirectory.open(aIndexDir), analyzer, true, IndexWriter.MaxFieldLength.LIMITED );
180cdf0e10cSrcweir 			if( !bExtensionMode )
181cdf0e10cSrcweir 	            System.out.println( "Lucene: Indexing to directory '" + aIndexDir + "'..." );
182cdf0e10cSrcweir             int nRet = indexDocs( writer, aModule, bExtensionMode, aCaptionFilesDir, aContentFilesDir );
183cdf0e10cSrcweir             if( nRet != -1 )
184cdf0e10cSrcweir 			{
185cdf0e10cSrcweir 				if( !bExtensionMode )
186cdf0e10cSrcweir 				{
187cdf0e10cSrcweir 					System.out.println();
188cdf0e10cSrcweir 					System.out.println( "Optimizing ..." );
189cdf0e10cSrcweir 				}
190cdf0e10cSrcweir                 writer.optimize();
191cdf0e10cSrcweir             }
192cdf0e10cSrcweir             writer.close();
193cdf0e10cSrcweir 
194cdf0e10cSrcweir 			boolean bCfsFileOk = true;
195cdf0e10cSrcweir 			boolean bSegmentFileOk = true;
196cdf0e10cSrcweir 			if( bCfsName && bSegmentName && !bExtensionMode && nRet != -1 )
197cdf0e10cSrcweir 			{
198cdf0e10cSrcweir 				String aCompleteCfsFileName = aDirToZipStr + File.separator + aIndexDirName + File.separator + aCfsName;
199cdf0e10cSrcweir 				String aCompleteSegmentFileName = aDirToZipStr + File.separator + aIndexDirName + File.separator + aSegmentName;
200cdf0e10cSrcweir 				File aCfsFile = new File( aCompleteCfsFileName );
201cdf0e10cSrcweir 				File aSegmentFile = new File( aCompleteSegmentFileName );
202cdf0e10cSrcweir 				bCfsFileOk = aCfsFile.exists();
203cdf0e10cSrcweir 				bSegmentFileOk = aSegmentFile.exists();
204cdf0e10cSrcweir 				System.out.println( "Checking cfs file " + aCfsName+ ": " + (bCfsFileOk ? "Found" : "Not found") );
205cdf0e10cSrcweir 				System.out.println( "Checking segment file " + aSegmentName+ ": " + (bSegmentFileOk ? "Found" : "Not found") );
206cdf0e10cSrcweir 			}
207cdf0e10cSrcweir 
208cdf0e10cSrcweir 			if( bExtensionMode || bExtension)
209cdf0e10cSrcweir 			{
210cdf0e10cSrcweir 				if( !bSrcDir )
211cdf0e10cSrcweir 				{
212cdf0e10cSrcweir 					deleteRecursively( aCaptionFilesDir );
213cdf0e10cSrcweir 					deleteRecursively( aContentFilesDir );
214cdf0e10cSrcweir 				}
215cdf0e10cSrcweir 			}
216cdf0e10cSrcweir 			else
217cdf0e10cSrcweir 			{
218cdf0e10cSrcweir 				if( nRet == -1 )
219cdf0e10cSrcweir 					deleteRecursively( aIndexDir );
220cdf0e10cSrcweir 
221cdf0e10cSrcweir 				if( bCfsFileOk && bSegmentFileOk )
222cdf0e10cSrcweir 					System.out.println( "Zipping ..." );
223cdf0e10cSrcweir 				File aDirToZipFile = new File( aDirToZipStr );
224cdf0e10cSrcweir 				createZipFile( aDirToZipFile, aTargetZipFileStr );
225cdf0e10cSrcweir 				deleteRecursively( aDirToZipFile );
226cdf0e10cSrcweir 			}
227cdf0e10cSrcweir 
228cdf0e10cSrcweir 			if( !bCfsFileOk )
229cdf0e10cSrcweir 			{
230cdf0e10cSrcweir 				System.out.println( "cfs file check failed, terminating..." );
231cdf0e10cSrcweir 				System.exit( -1 );
232cdf0e10cSrcweir 			}
233cdf0e10cSrcweir 
234cdf0e10cSrcweir 			if( !bSegmentFileOk )
235cdf0e10cSrcweir 			{
236cdf0e10cSrcweir 				System.out.println( "segment file check failed, terminating..." );
237cdf0e10cSrcweir 				System.exit( -1 );
238cdf0e10cSrcweir 			}
239cdf0e10cSrcweir 
240cdf0e10cSrcweir 			Date end = new Date();
241cdf0e10cSrcweir 			if( !bExtensionMode )
242cdf0e10cSrcweir 				System.out.println(end.getTime() - start.getTime() + " total milliseconds");
243cdf0e10cSrcweir         }
244cdf0e10cSrcweir 		catch (IOException e)
245cdf0e10cSrcweir 		{
246cdf0e10cSrcweir 			if( bExtensionMode )
247cdf0e10cSrcweir 				return;
248cdf0e10cSrcweir 
249cdf0e10cSrcweir 			System.out.println(" caught a " + e.getClass() +
250cdf0e10cSrcweir 				"\n with message: " + e.getMessage());
251cdf0e10cSrcweir 			System.exit( -1 );
252cdf0e10cSrcweir         }
253cdf0e10cSrcweir     }
254cdf0e10cSrcweir 
255cdf0e10cSrcweir 	private static int indexDocs(IndexWriter writer, String aModule, boolean bExtensionMode,
256cdf0e10cSrcweir 		File aCaptionFilesDir, File aContentFilesDir) throws IOException
257cdf0e10cSrcweir 	{
258cdf0e10cSrcweir         if( !aCaptionFilesDir.canRead() || !aCaptionFilesDir.isDirectory() )
259cdf0e10cSrcweir 		{
260cdf0e10cSrcweir 			if( !bExtensionMode )
261cdf0e10cSrcweir 	            System.out.println( "Not found: " + aCaptionFilesDir );
262cdf0e10cSrcweir             return -1;
263cdf0e10cSrcweir         }
264cdf0e10cSrcweir         if( !aContentFilesDir.canRead() || !aContentFilesDir.isDirectory() )
265cdf0e10cSrcweir 		{
266cdf0e10cSrcweir 			if( !bExtensionMode )
267cdf0e10cSrcweir 	            System.out.println( "Not found: " + aContentFilesDir );
268cdf0e10cSrcweir             return -1;
269cdf0e10cSrcweir         }
270cdf0e10cSrcweir 
271cdf0e10cSrcweir         String[] aCaptionFiles = aCaptionFilesDir.list();
272cdf0e10cSrcweir         List aCaptionFilesList = Arrays.asList( aCaptionFiles );
273cdf0e10cSrcweir         HashSet aCaptionFilesHashSet = new HashSet( aCaptionFilesList );
274cdf0e10cSrcweir 
275cdf0e10cSrcweir         String[] aContentFiles = aContentFilesDir.list();
276cdf0e10cSrcweir         List aContentFilesList = Arrays.asList( aContentFiles );
277cdf0e10cSrcweir         HashSet aContentFilesHashSet = new HashSet( aContentFilesList );
278cdf0e10cSrcweir 
279cdf0e10cSrcweir         // Loop over caption files and find corresponding content file
280cdf0e10cSrcweir 		if( !bExtensionMode )
281cdf0e10cSrcweir 	        System.out.println( "Indexing, adding files" );
282cdf0e10cSrcweir         int nCaptionFilesLen = aCaptionFiles.length;
283cdf0e10cSrcweir         for( int i = 0 ; i < nCaptionFilesLen ; i++ )
284cdf0e10cSrcweir 		{
285cdf0e10cSrcweir             String aCaptionFileStr = aCaptionFiles[i];
286cdf0e10cSrcweir             File aCaptionFile = new File( aCaptionFilesDir, aCaptionFileStr );
287cdf0e10cSrcweir             File aContentFile = null;
288cdf0e10cSrcweir             if( aContentFilesHashSet.contains( aCaptionFileStr ) )
289cdf0e10cSrcweir                 aContentFile = new File( aContentFilesDir, aCaptionFileStr );
290cdf0e10cSrcweir 
291cdf0e10cSrcweir 			if( !bExtensionMode )
292cdf0e10cSrcweir 				System.out.print( "." );
293cdf0e10cSrcweir             writer.addDocument( HelpFileDocument.Document( aModule, aCaptionFile, aContentFile ) );
294cdf0e10cSrcweir         }
295cdf0e10cSrcweir 
296cdf0e10cSrcweir         // Loop over content files to find remaining files not mapped to caption files
297cdf0e10cSrcweir         int nContentFilesLen = aContentFiles.length;
298cdf0e10cSrcweir         for( int i = 0 ; i < nContentFilesLen ; i++ )
299cdf0e10cSrcweir 		{
300cdf0e10cSrcweir             String aContentFileStr = aContentFiles[i];
301cdf0e10cSrcweir             if( !aCaptionFilesHashSet.contains( aContentFileStr ) )
302cdf0e10cSrcweir 			{
303cdf0e10cSrcweir                 // Not already handled in caption files loop
304cdf0e10cSrcweir                 File aCaptionFile = null;
305cdf0e10cSrcweir                 File aContentFile = new File( aContentFilesDir, aContentFileStr );
306cdf0e10cSrcweir 				if( !bExtensionMode )
307cdf0e10cSrcweir 					System.out.print( "." );
308cdf0e10cSrcweir                 writer.addDocument( HelpFileDocument.Document( aModule, aCaptionFile, aContentFile ) );
309cdf0e10cSrcweir             }
310cdf0e10cSrcweir         }
311cdf0e10cSrcweir         return 0;
312cdf0e10cSrcweir     }
313cdf0e10cSrcweir 
314cdf0e10cSrcweir     public static void createZipFile( File aDirToZip, String aTargetZipFileStr )
315cdf0e10cSrcweir             throws FileNotFoundException, IOException
316cdf0e10cSrcweir 	{
317cdf0e10cSrcweir         FileOutputStream fos = new FileOutputStream( aTargetZipFileStr );
318cdf0e10cSrcweir         ZipOutputStream zos = new ZipOutputStream( fos );
319cdf0e10cSrcweir 
320cdf0e10cSrcweir         File[] aChildrenFiles = aDirToZip.listFiles();
321cdf0e10cSrcweir         int nFileCount = aChildrenFiles.length;
322cdf0e10cSrcweir         for( int i = 0 ; i < nFileCount ; i++ )
323cdf0e10cSrcweir             addToZipRecursively( zos, aChildrenFiles[i], null );
324cdf0e10cSrcweir 
325cdf0e10cSrcweir         zos.close();
326cdf0e10cSrcweir     }
327cdf0e10cSrcweir 
328cdf0e10cSrcweir     public static void addToZipRecursively( ZipOutputStream zos, File aFile, String aBasePath )
329cdf0e10cSrcweir             throws FileNotFoundException, IOException
330cdf0e10cSrcweir 	{
331cdf0e10cSrcweir         if( aFile.isDirectory() )
332cdf0e10cSrcweir 		{
333cdf0e10cSrcweir             String aDirName = aFile.getName();
334cdf0e10cSrcweir             if( aDirName.equalsIgnoreCase( "caption" ) || aDirName.equalsIgnoreCase( "content" ) )
335cdf0e10cSrcweir                 return;
336cdf0e10cSrcweir 
337cdf0e10cSrcweir             File[] aChildrenFiles = aFile.listFiles();
338cdf0e10cSrcweir             String aNewBasePath = "";
339cdf0e10cSrcweir             if( aBasePath != null )
340cdf0e10cSrcweir                 aNewBasePath += aBasePath + File.separator;
341cdf0e10cSrcweir             aNewBasePath += aDirName;
342cdf0e10cSrcweir 
343cdf0e10cSrcweir             int nFileCount = aChildrenFiles.length;
344cdf0e10cSrcweir             for( int i = 0 ; i < nFileCount ; i++ )
345cdf0e10cSrcweir                 addToZipRecursively( zos, aChildrenFiles[i], aNewBasePath );
346cdf0e10cSrcweir 
347cdf0e10cSrcweir             return;
348cdf0e10cSrcweir         }
349cdf0e10cSrcweir 
350cdf0e10cSrcweir         // No directory
351cdf0e10cSrcweir         // read contents of file we are going to put in the zip
352cdf0e10cSrcweir         int fileLength = (int) aFile.length();
353cdf0e10cSrcweir         FileInputStream fis = new FileInputStream( aFile );
354cdf0e10cSrcweir         byte[] wholeFile = new byte[fileLength];
355cdf0e10cSrcweir         int bytesRead = fis.read( wholeFile, 0, fileLength );
356cdf0e10cSrcweir         fis.close();
357cdf0e10cSrcweir 
358cdf0e10cSrcweir         String aFileName = aFile.getName();
359cdf0e10cSrcweir         String aEntryName = "";
360cdf0e10cSrcweir         if( aBasePath != null )
361cdf0e10cSrcweir             aEntryName += aBasePath + "/";
362cdf0e10cSrcweir         aEntryName += aFileName;
363cdf0e10cSrcweir         ZipEntry aZipEntry = new ZipEntry( aEntryName );
364cdf0e10cSrcweir         aZipEntry.setTime( aFile.lastModified() );
365cdf0e10cSrcweir         aZipEntry.setSize( fileLength );
366cdf0e10cSrcweir 
367cdf0e10cSrcweir         int nMethod = ( aFileName.toLowerCase().endsWith( ".jar" ) )
368cdf0e10cSrcweir                 ? ZipEntry.STORED : ZipEntry.DEFLATED;
369cdf0e10cSrcweir         aZipEntry.setMethod( nMethod );
370cdf0e10cSrcweir 
371cdf0e10cSrcweir         CRC32 tempCRC = new CRC32();
372cdf0e10cSrcweir         tempCRC.update( wholeFile, 0, wholeFile.length );
373cdf0e10cSrcweir         aZipEntry.setCrc( tempCRC.getValue() );
374cdf0e10cSrcweir 
375cdf0e10cSrcweir         // write the contents into the zip element
376cdf0e10cSrcweir         zos.putNextEntry( aZipEntry );
377cdf0e10cSrcweir         zos.write( wholeFile, 0, fileLength );
378cdf0e10cSrcweir         zos.closeEntry();
379cdf0e10cSrcweir     }
380cdf0e10cSrcweir 
381cdf0e10cSrcweir     static public boolean deleteRecursively( File aFile )
382cdf0e10cSrcweir 	{
383cdf0e10cSrcweir         if( aFile.isDirectory() )
384cdf0e10cSrcweir 		{
385cdf0e10cSrcweir             File[] aChildrenFiles = aFile.listFiles();
386cdf0e10cSrcweir             int nFileCount = aChildrenFiles.length;
387cdf0e10cSrcweir             for( int i = 0 ; i < nFileCount ; i++ )
388cdf0e10cSrcweir 			{
389cdf0e10cSrcweir                 File aChildrenFile = aChildrenFiles[i];
390cdf0e10cSrcweir                 boolean bSuccess = deleteRecursively( aChildrenFile );
391cdf0e10cSrcweir                 if( !bSuccess )
392cdf0e10cSrcweir                     return false;
393cdf0e10cSrcweir             }
394cdf0e10cSrcweir         }
395cdf0e10cSrcweir 
396cdf0e10cSrcweir         return aFile.delete();
397cdf0e10cSrcweir     }
398cdf0e10cSrcweir }
399cdf0e10cSrcweir 
400