KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > bull > eclipse > jonas > actions > rar > OpenRarActionDelegate


1 /*
2  * Created on 2 juin 2003
3  *
4  * To change the template for this generated file go to
5  * Window>Preferences>Java>Code Generation>Code and Comments
6  */

7 package com.bull.eclipse.jonas.actions.rar;
8
9 /**
10  * @author Emmanuel RIAS
11  *
12  * To change the template for this generated type comment go to
13  * Window>Preferences>Java>Code Generation>Code and Comments
14  */

15
16 import java.io.File JavaDoc;
17 import java.io.IOException JavaDoc;
18 import java.util.Enumeration JavaDoc;
19 import java.util.zip.ZipEntry JavaDoc;
20 import java.util.zip.ZipFile JavaDoc;
21
22 import org.eclipse.core.resources.IResource;
23 import org.eclipse.jdt.internal.ui.JavaPlugin;
24 import org.eclipse.swt.widgets.FileDialog;
25
26 import com.bull.eclipse.jonas.JonasProject;
27 import com.bull.eclipse.jonas.actions.JonasProjectAbstractActionDelegate;
28 import com.bull.eclipse.jonas.utils.Zipper;
29
30 public class OpenRarActionDelegate extends JonasProjectAbstractActionDelegate {
31     
32     static String JavaDoc pathFilter = null;
33     static String JavaDoc[] filter = {"*.rar","*.war","*.jar"};
34     
35     
36     public boolean doActionOn(JonasProject prj) throws Exception JavaDoc {
37         FileDialog id = new FileDialog(
38                         JavaPlugin.getActiveWorkbenchShell());
39         if (pathFilter != null)
40             id.setFilterPath(pathFilter);
41         id.setFilterExtensions(filter);
42         id.open();
43         String JavaDoc fileName = id.getFileName();
44         pathFilter = id.getFilterPath();
45         File JavaDoc raDir = prj.getProject().getLocation().append("resourceAdapter").toFile();
46         boolean createDir = true;
47         if (!raDir.exists())
48             createDir = raDir.mkdir();
49         if (!createDir)
50             throw new IOException JavaDoc("Error until creation resource adapter directory");
51         File JavaDoc raFileDir = new File JavaDoc(raDir,fileName.substring(0,fileName.length()-4));
52         if (!raFileDir.exists())
53             createDir = raFileDir.mkdir();
54         if (!createDir)
55             throw new IOException JavaDoc("Error until creation file resource adapter directory");
56         File JavaDoc rarFile = new File JavaDoc(pathFilter,fileName);
57         ZipFile JavaDoc raFile = new ZipFile JavaDoc(rarFile);
58         Enumeration JavaDoc filesEntries = raFile.entries();
59         while (filesEntries.hasMoreElements()) {
60             Object JavaDoc entry = filesEntries.nextElement();
61             ZipEntry JavaDoc zipEntry = (ZipEntry JavaDoc) entry;
62             if (zipEntry.isDirectory()) {
63                 (new File JavaDoc(raFileDir,zipEntry.getName())).mkdirs();
64             } else {
65                 Zipper.unzip(zipEntry,raFile, new File JavaDoc(raFileDir,zipEntry.getName()));
66             }
67         }
68         raFile.close();
69         prj.getProject().refreshLocal( IResource.DEPTH_INFINITE, null );
70         
71         return false;
72     }
73
74
75 }
76
Popular Tags