1 19 package net.sf.jbatchengine.batch.util; 20 21 import java.io.BufferedReader ; 22 import java.io.FileReader ; 23 import java.io.IOException ; 24 import java.util.HashMap ; 25 import java.util.Map ; 26 import java.util.regex.Pattern ; 27 28 import org.apache.commons.lang.StringUtils; 29 30 36 public class CommandFileParser { 37 38 45 public static String parse(String file) throws IOException { 46 BufferedReader br = new BufferedReader (new FileReader (file)); 47 48 String line = br.readLine(); 49 String command = null; 50 Map <String , String > variables = new HashMap <String , String >(); 51 52 String javahome = System.getProperty("java.home"); 54 variables.put("JAVA_HOME", javahome); 55 56 while (line != null) { 57 if (line.startsWith("rem") || line.startsWith("@")) { 58 } 60 else { 61 if (line.startsWith("set ")) { 62 Pattern gleichPattern = Pattern.compile("="); 63 String [] strings = gleichPattern.split(line, 2); 64 String left = strings[0]; 65 String right = strings[1]; 66 for (String key : variables.keySet()) { 67 right = StringUtils.replace(right, "%" + key + "%", (String ) variables.get(key)); 68 } 69 variables.put(left.substring(4), right); 70 } 71 else { 72 for (String key : variables.keySet()) { 73 line = StringUtils.replace(line, "%" + key + "%", (String ) variables.get(key)); 74 } 75 command = line; 76 } 77 } 78 line = br.readLine(); 79 } 80 81 return command; 82 } 83 } 84 | Popular Tags |