1 7 package com.bull.eclipse.jonas.actions.rar; 8 9 15 16 import java.io.File ; 17 import java.io.IOException ; 18 import java.util.Enumeration ; 19 import java.util.zip.ZipEntry ; 20 import java.util.zip.ZipFile ; 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 pathFilter = null; 33 static String [] filter = {"*.rar","*.war","*.jar"}; 34 35 36 public boolean doActionOn(JonasProject prj) throws Exception { 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 fileName = id.getFileName(); 44 pathFilter = id.getFilterPath(); 45 File 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 ("Error until creation resource adapter directory"); 51 File raFileDir = new File (raDir,fileName.substring(0,fileName.length()-4)); 52 if (!raFileDir.exists()) 53 createDir = raFileDir.mkdir(); 54 if (!createDir) 55 throw new IOException ("Error until creation file resource adapter directory"); 56 File rarFile = new File (pathFilter,fileName); 57 ZipFile raFile = new ZipFile (rarFile); 58 Enumeration filesEntries = raFile.entries(); 59 while (filesEntries.hasMoreElements()) { 60 Object entry = filesEntries.nextElement(); 61 ZipEntry zipEntry = (ZipEntry ) entry; 62 if (zipEntry.isDirectory()) { 63 (new File (raFileDir,zipEntry.getName())).mkdirs(); 64 } else { 65 Zipper.unzip(zipEntry,raFile, new File (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 |