1 4 package com.openedit.util; 5 6 import java.io.File ; 7 import java.io.IOException ; 8 import java.util.ArrayList ; 9 import java.util.List ; 10 11 import com.openedit.OpenEditRuntimeException; 12 13 public abstract class JarReader 14 { 15 protected List fieldCompletedFiles; 16 17 public void processInClasspath(String inName) 18 { 19 try 22 { 23 String cp = System.getProperty("java.class.path"); 24 String [] files = cp.split(File.pathSeparator); 26 processFiles(files, inName); 27 } 28 catch ( Exception ex) 29 { 30 throw new OpenEditRuntimeException(ex); 31 } 32 } 33 protected void processFiles(String [] files, String inName) 34 { 35 if( files == null) 36 { 37 return; 38 } 39 FileUtils fileU = new FileUtils(); 40 41 try 42 { 43 File tmp = File.createTempFile("openedit", "cpdir"); 44 fileU.deleteAll(tmp ); 45 ZipUtil unzip = new ZipUtil(); 46 unzip.setFindFileName(inName); 47 unzip.setExitOnFirstFind(true); 48 for (int i = 0; i < files.length; i++) 49 { 50 File cpdir = new File ( files[i]); 51 if( getCompletedFiles().contains(cpdir)) 52 { 53 continue; 54 } 55 getCompletedFiles().add( cpdir ); 56 if( cpdir.isFile()) 57 { 58 tmp.mkdirs(); 59 unzip.unzip(cpdir, tmp); 60 cpdir = tmp; 61 } 62 File found = new File ( cpdir,inName ); 64 if( found.exists() ) 65 { 66 processFile(found); 67 } 68 fileU.deleteAll(tmp ); 69 } 70 } catch ( IOException ex) 71 { 72 throw new OpenEditRuntimeException(ex); 73 } 74 } 75 public void processInLibDir(File inLibDir, String inName) 76 { 77 File [] jars = inLibDir.listFiles(); 78 if( jars != null) 79 { 80 String [] names = new String [jars.length]; 81 for (int i = 0; i < jars.length; i++) 82 { 83 names[i] = jars[i].getAbsolutePath(); 84 } 85 processFiles(names, inName); 86 } 87 88 } 89 90 public abstract void processFile( File inFile); 91 92 public List getCompletedFiles() 93 { 94 if( fieldCompletedFiles == null) 95 { 96 fieldCompletedFiles = new ArrayList (); 97 } 98 return fieldCompletedFiles; 99 } 100 public void setCompletedFiles(List inCompletedFiles) 101 { 102 fieldCompletedFiles = inCompletedFiles; 103 } 104 } 105 | Popular Tags |