1 23 package com.sun.enterprise.tools.admingui.util; 24 25 import java.io.*; 26 import java.io.IOException ; 27 import java.util.jar.*; 28 import java.util.zip.ZipEntry ; 29 30 import com.sun.enterprise.admin.server.core.AdminService; 31 32 35 public class FileUtil { 36 public static final String DEPLOY = "deploy"; 37 public static final String REDEPLOY = "redeploy"; 38 public static final String TRANSFORMATION_RULE = "transformationRule"; 39 public static final String INSTANCE_ROOT = System.getProperty("com.sun.aas.instanceRoot"); 40 public static final String GEN_XML_DIR = INSTANCE_ROOT + File.separator + "generated" + File.separator + "xml"; 41 public static final String GEN_XML_APP_DIR = GEN_XML_DIR + File.separator + "j2ee-apps"; 42 public static final String GEN_XML_MOD_DIR = GEN_XML_DIR + File.separator + "j2ee-modules"; 43 44 public static String getUploadDir() throws Exception { 45 return AdminService.getAdminService().getGUITempDirPath(); } 47 48 public static boolean isEARFile(File file) { 49 try { 50 JarFile jar = new JarFile(file); 51 ZipEntry result = jar.getEntry("META-INF/application.xml"); 52 jar.close(); 53 return result != null; 54 } catch (IOException ex) { 55 return false; 56 } 57 } 58 59 public static boolean isWARFile(File file) { 60 try { 61 JarFile jar = new JarFile(file); 62 ZipEntry result = jar.getEntry("WEB-INF/web.xml"); 63 jar.close(); 64 return result != null; 65 } catch (IOException ex) { 66 return false; 67 } 68 } 69 70 public static boolean isEJBJar(File file) { 71 try { 72 JarFile jar = new JarFile(file); 73 ZipEntry result = jar.getEntry("META-INF/ejb-jar.xml"); 74 jar.close(); 75 return result != null; 76 } catch (IOException ex) { 77 return false; 78 } 79 } 80 81 public static boolean isJarFile(File file) { 82 try { 85 boolean result = false; 86 87 if(file.getName().endsWith(".jar")) { 88 JarFile jar = new JarFile(file); 89 if ( jar != null ) { 90 result = jar.entries().hasMoreElements(); 91 } 92 jar.close(); 93 return result ; 94 } else { 95 return false; 96 } 97 98 } catch (IOException ex) { 99 return false; 100 } 101 } 102 103 public static boolean isRARFile(File file) { 104 try { 105 JarFile jar = new JarFile(file); 106 ZipEntry result = jar.getEntry("META-INF/ra.xml"); 107 jar.close(); 108 return result != null; 109 } catch (IOException ex) { 110 return false; 111 } 112 } 113 114 public static boolean isAppClientJar(File file) { 115 try { 116 JarFile jar = new JarFile(file); 117 ZipEntry result = jar.getEntry("META-INF/application-client.xml"); 118 jar.close(); 119 return result != null; 120 } catch (IOException ex) { 121 return false; 122 } 123 } 124 125 public static void extractMbeanJarFile(String domainRoot, String fileName ) throws IOException { 126 File f = new File(fileName); 127 if(FileUtil.isJarFile(f)) 128 { 129 JarExtract.extract(fileName, domainRoot+"/applications/mbeans"); 131 } 132 } 133 134 } 135 | Popular Tags |