1 19 package org.netbeans.lib.cvsclient.command; 20 21 import org.netbeans.lib.cvsclient.util.SimpleStringPattern; 22 import org.netbeans.lib.cvsclient.ClientServices; 23 24 import java.io.*; 25 import java.util.Map ; 26 import java.util.StringTokenizer ; 27 28 31 public class WrapperUtils { 32 33 40 private static void parseWrappers(BufferedReader reader, Map theMap) 41 throws IOException { 42 43 String line; 44 while ((line = reader.readLine()) != null){ 45 StringTokenizer tokenizer = new StringTokenizer (line); 46 47 SimpleStringPattern pattern = new SimpleStringPattern(tokenizer.nextToken()); 49 50 String option, value; 52 53 while (tokenizer.hasMoreTokens()) { 54 option = tokenizer.nextToken(); 55 value = tokenizer.nextToken(); 56 57 if (option.equals("-k")) { 60 int first = value.indexOf('\''); 63 int last = value.lastIndexOf('\''); 64 if (first >=0 && last >= 0) { 65 value = value.substring(first+1, last); 66 } 67 68 KeywordSubstitutionOptions keywordOption = KeywordSubstitutionOptions.findKeywordSubstOption(value); 69 if (!theMap.containsKey(pattern)) { 70 theMap.put(pattern, keywordOption); 71 } 72 } 73 } 74 } 75 } 76 77 84 public static void readWrappersFromFile(File file, Map wrapperMap) throws IOException, FileNotFoundException{ 85 parseWrappers(new BufferedReader(new FileReader(file)), wrapperMap); 86 } 87 88 95 private static void readWrappersFromProperty(String envVar, Map wrapperMap) throws IOException { 96 String propertyValue = System.getenv(envVar); 97 if (propertyValue != null) 98 { 99 parseWrappers(new BufferedReader(new StringReader(propertyValue)), wrapperMap); 100 } 101 } 102 103 108 public static Map mergeWrapperMap(ClientServices client) throws CommandException 109 { 110 String wrapperSource = null; 111 Map wrappersMap = new java.util.HashMap (client.getWrappersMap()); 112 try 113 { 114 File home = new File(System.getProperty("user.home")); File wrappers = new File(home, "./cvswrappers"); 117 wrapperSource = CommandException.getLocalMessage("WrapperUtils.clientDotWrapper.text"); 119 if (wrappers.exists()) { 120 readWrappersFromFile(wrappers, wrappersMap); 121 } 122 123 wrapperSource = CommandException.getLocalMessage("WrapperUtils.environmentWrapper.text"); 125 readWrappersFromProperty("CVSWRAPPERS", wrappersMap); } 128 catch (FileNotFoundException fnex) { 129 } 132 catch (Exception ioex) { 133 Object [] parms = new Object [1]; 134 parms[0] = wrapperSource; 135 String localizedMessage = CommandException.getLocalMessage("WrapperUtils.wrapperError.text", parms); throw new CommandException(ioex, localizedMessage); 137 } 138 139 return wrappersMap; 140 } 141 142 143 } 144 | Popular Tags |