@@ -0,0 +1,1896 @@
+package org.za.hem.ipsec_tools;%0A%0Aimport java.io.BufferedReader;%0Aimport java.io.File;%0Aimport java.io.FileNotFoundException;%0Aimport java.io.FileReader;%0Aimport java.io.FileWriter;%0Aimport java.io.IOException;%0Aimport java.io.Writer;%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0Aimport java.util.regex.Matcher;%0Aimport java.util.regex.Pattern;%0A%0Apublic class ConfigManager %7B%0A%09%0A%09public static final String PATTERN = %22%5C%5C$%5C%5C%7B(%5Ba-zA-Z0-9_%5D+)%5C%5C%7D%22;%0A%09private Pattern mPat;%0A%09private Map%3CString,String%3E mVariables;%0A%09%0A%09public ConfigManager() %7B%0A%09%09mVariables = new HashMap%3CString,String%3E();%0A%09%09mVariables.put(%22bindir%22, %22/data/data/org.za.hem.ipsec_tools/app_bin%22);%0A%09%09mVariables.put(%22extdir%22, %22/sdcard%22);%0A%09%09mVariables.put(%22local_addr%22, %22192.168.1.17%22);%0A%09%09mPat = Pattern.compile(PATTERN);%0A%09%7D%0A%09%0A%09public void AddVariable(String key, String value) %7B%0A%09%09mVariables.put(key, value);%0A%09%7D%0A%0A%09protected String substituteLine(String line) %7B%0A%09%09StringBuffer buf = new StringBuffer();%0A%09%09Matcher m = mPat.matcher(line);%0A%0A%09%09while (m.find()) %7B%0A%09%09%09String var = m.group(1);%0A%09%09%09String value;%0A%09%09%09%0A%09%09%09if (mVariables.containsKey(var)) %7B%0A%09%09%09%09value = mVariables.get(var);%0A%09%09%09%7D else %7B%0A%09%09%09%09value = %22%22;%0A%09%09%09%7D%0A%0A%09%09%09m.appendReplacement(buf, value);%0A%09%09%7D%0A%09%09m.appendTail(buf);%0A%09%09buf.append('%5Cn');%0A%0A%09%09return buf.toString();%0A%09%7D%0A%09%0A%09/**%0A%09 * @param args%0A%09 */%0A%09public void substitute(File input, File output) %7B%0A%0A%09%09try %7B%0A%09%09%09BufferedReader is = new BufferedReader(new FileReader(input));%0A%09%09%09Writer os = new FileWriter(input);%0A%09%0A%09%09%09try %7B%0A%09%09%09%09String line;%0A%09%09%09%09while ( (line = is.readLine()) != null) %7B%0A%09%09%09%09%09os.write(substituteLine(line));%0A%09%09%09%09%7D%09%09%09%09%0A%09%09%09%7D catch (FileNotFoundException e) %7B%0A%09%09%09%09// TODO Auto-generated catch block%0A%09%09%09%09e.printStackTrace();%0A%09%09%09%7D catch (IOException e) %7B%0A%09%09%09%09// TODO Auto-generated catch block%0A%09%09%09%09e.printStackTrace();%0A%09%09%09%7D finally %7B%0A%09%09%09%09is.close();%0A%09%09%09%09os.close();%0A%09%09%09%7D%0A%09%09%7D catch (IOException e) %7B%0A%09%09%09// Ignore error on close%0A%09%09%7D%0A%09%7D%0A%7D%0A

Add ConfigManager