1 25 26 27 package org.objectweb.jonas.common; 28 29 import java.io.File ; 30 import java.io.FileInputStream ; 31 import java.util.ArrayList ; 32 import java.util.Collections ; 33 import java.util.Properties ; 34 35 39 public class JModule { 40 43 public static final String EJBJAR_EXTENSION = "jar"; 44 public static final String RAR_EXTENSION = "rar"; 45 public static final String WAR_EXTENSION = "war"; 46 public static final String EAR_EXTENSION = "ear"; 47 48 51 public static final String EJBJAR_CHILD_DIR = "META-INF"; 52 public static final String RAR_CHILD_DIR = "META-INF"; 53 public static final String WAR_CHILD_DIR = "WEB-INF"; 54 public static final String EAR_CHILD_DIR = "META-INF"; 55 56 59 public static final String EJBJAR_CONFIRM_FILE = "ejb-jar.xml"; 60 public static final String RAR_CONFIRM_FILE = "ra.xml"; 61 public static final String WAR_CONFIRM_FILE = "web.xml"; 62 public static final String EAR_CONFIRM_FILE = "application.xml"; 63 64 67 public static final String PROPS_EXTENSION = "properties"; 68 69 70 73 public static final String CONF_DIR = "conf"; 74 75 public static ArrayList getFilesInDir(String dirName, String extension) throws Exception { 76 ArrayList al = new ArrayList (); 77 File file = new File (dirName); 78 String [] files = file.list(); 79 int pos; 80 String fileName; 81 if (files != null) { 82 for (int i = 0; i < files.length; i++) { 83 file = new File (dirName, files[i]); 84 if (file.isFile() == true) { 85 fileName = file.getName().toLowerCase(); 86 pos = fileName.lastIndexOf(extension); 87 if (pos > -1) { 88 if (pos == (fileName.length() - extension.length())) { 89 al.add(file.getName()); 90 } 91 } 92 } 93 } 94 } 95 Collections.sort(al); 96 return al; 97 } 98 99 public static ArrayList getDatasourcePropsInDir() throws Exception { 100 ArrayList al = getFilesInDir(JProp.getJonasBase() + File.separator + CONF_DIR, PROPS_EXTENSION); 102 String sPath; 104 Properties oProps = new Properties (); 105 boolean bDelete; 106 int i = 0; 107 while (i < al.size()) { 108 sPath = JProp.getJonasBase() + File.separator + CONF_DIR + File.separator 109 + al.get(i).toString(); 110 bDelete = true; 111 try { 112 oProps.clear(); 113 oProps.load(new FileInputStream (sPath)); 114 if (oProps.getProperty("datasource.name") != null) { 116 int iPos = al.get(i).toString().toLowerCase().lastIndexOf(".properties"); 118 al.set(i, al.get(i).toString().substring(0, iPos)); 119 i++; 121 bDelete = false; 122 } 123 } 124 catch (Exception e) { 125 } 127 finally { 128 if (bDelete == true) { 130 al.remove(i); 131 } 132 } 133 } 134 return al; 135 } 136 137 public static ArrayList getMailFactoryPropsInDir(String type) throws Exception { 138 ArrayList al = getFilesInDir(JProp.getJonasBase() + File.separator + CONF_DIR, PROPS_EXTENSION); 140 String sPath; 142 Properties oProps = new Properties (); 143 boolean bDelete; 144 int i = 0; 145 while (i < al.size()) { 146 sPath = JProp.getJonasBase() + File.separator + CONF_DIR + File.separator 147 + al.get(i).toString(); 148 bDelete = true; 149 try { 150 oProps.clear(); 151 oProps.load(new FileInputStream (sPath)); 152 if (oProps.getProperty("mail.factory.name") != null) { 154 boolean bToReturn; 155 if (type == null) { 156 bToReturn = true; 158 } else { 159 if (oProps.getProperty("mail.factory.type").equals(type) == true) { 161 bToReturn = true; 162 } else { 163 bToReturn = false; 164 } 165 } 166 if (bToReturn == true) { 167 int iPos = al.get(i).toString().toLowerCase().lastIndexOf(".properties"); 169 al.set(i, al.get(i).toString().substring(0, iPos)); 170 i++; 172 bDelete = false; 173 } 174 } 175 } 176 catch (Exception e) { 177 } 179 finally { 180 if (bDelete == true) { 182 al.remove(i); 183 } 184 } 185 } 186 return al; 187 } 188 public static ArrayList getMailFactoryPropsInDir() throws Exception { 189 return getMailFactoryPropsInDir(null); 190 } 191 192 public static void prefixAutoload(String autoloaddir, ArrayList p_List) { 193 String sDir = autoloaddir + File.separator; for (int i = 0; i < p_List.size(); i++) { 195 p_List.set(i, sDir + p_List.get(i)); 196 } 197 } 198 199 219 public static ArrayList getInstalledContainersInDir(String p_DirName, String p_Extension 220 , String p_DirChildConfirm, String p_FileConfirm) 221 throws Exception { 222 223 ArrayList al = new ArrayList (); 225 int iPos; 227 String sFilename; 228 File oDirChild; 229 File oFileConfirm; 230 File oFile = new File (p_DirName); 232 String [] asFiles = oFile.list(); 233 234 if (asFiles != null) { 235 for (int i = 0; i < asFiles.length; i++) { 237 oFile = new File (p_DirName, asFiles[i]); 238 if (oFile.isFile() == true) { 240 sFilename = oFile.getName().toLowerCase(); 241 iPos = sFilename.lastIndexOf(p_Extension); 242 if (iPos > -1) { 243 if (iPos == (sFilename.length() - p_Extension.length())) { 244 al.add(oFile.getCanonicalFile().toURL().getPath()); 245 } 246 } 247 } 248 else if (oFile.isDirectory() == true) { 250 oDirChild = new File (oFile, p_DirChildConfirm); 251 if ((oDirChild.exists() == true) && (oDirChild.isDirectory() == true)) { 252 oFileConfirm = new File (oDirChild, p_FileConfirm); 253 if (oFileConfirm.exists() == true) { 254 al.add(oFile.getCanonicalFile().toURL().getPath()); 255 } 256 } 257 } 258 } 259 } 260 return al; 261 } 262 263 } 264 | Popular Tags |