1 19 20 package org.netbeans.lib.cvsclient.response; 21 22 import java.io.*; 23 import java.util.*; 24 25 import org.netbeans.lib.cvsclient.util.*; 26 import org.netbeans.lib.cvsclient.util.SimpleStringPattern; 27 import org.netbeans.lib.cvsclient.command.KeywordSubstitutionOptions; 28 29 34 public class WrapperSendResponse implements Response { 35 36 public static Map parseWrappers(String line) { 37 StringTokenizer tokenizer = new StringTokenizer(line); 38 39 SimpleStringPattern pattern = new SimpleStringPattern(tokenizer.nextToken()); 41 42 String option, value; 44 45 Map wrappersMap = null; 46 47 while (tokenizer.hasMoreTokens()) { 48 option = tokenizer.nextToken(); 49 value = tokenizer.nextToken(); 50 51 if (option.equals("-k")) { 54 int first = value.indexOf('\''); 57 int last = value.lastIndexOf('\''); 58 if (first >=0 && last >= 0) { 59 value = value.substring(first+1, last); 60 } 61 62 KeywordSubstitutionOptions keywordOption = KeywordSubstitutionOptions.findKeywordSubstOption(value); 63 if (wrappersMap == null) { 64 if (!tokenizer.hasMoreTokens()) { 65 wrappersMap = Collections.singletonMap(pattern, keywordOption); 66 } else { 67 wrappersMap = new LinkedHashMap(); 68 wrappersMap.put(pattern, keywordOption); 69 } 70 } else { 71 wrappersMap.put(pattern, keywordOption); 72 } 73 } 74 } 75 return wrappersMap; 76 } 77 78 85 public void process(LoggedDataInputStream dis, ResponseServices services) 86 throws ResponseException { 87 try { 88 89 String wrapperSettings = dis.readLine(); 90 Map wrappers = parseWrappers(wrapperSettings); 91 for (Iterator it = wrappers.keySet().iterator(); it.hasNext(); ) { 92 StringPattern pattern = (StringPattern) it.next(); 93 KeywordSubstitutionOptions keywordOption = (KeywordSubstitutionOptions) wrappers.get(pattern); 94 services.addWrapper(pattern, keywordOption); 95 } 96 } 97 catch (EOFException ex) { 98 throw new ResponseException(ex, ResponseException.getLocalMessage("CommandException.EndOfFile", null)); } 100 catch (IOException ex) { 101 throw new ResponseException(ex); 102 } 103 catch (NoSuchElementException nse) { 104 throw new ResponseException(nse); 105 } 106 } 107 108 113 public boolean isTerminalResponse() { 114 return false; 115 } 116 117 } 118 | Popular Tags |