1 16 package org.ajaxtags.tags; 17 18 import java.util.HashMap ; 19 import java.util.Iterator ; 20 import java.util.Map ; 21 22 28 public class OptionsBuilder { 29 30 private Map <String , String > parameters = new HashMap <String , String >(); 31 32 private Map <String , Boolean > parameterQuotes = new HashMap <String , Boolean >(); 33 34 public OptionsBuilder add(String parameter, String value, boolean quoted) { 35 this.parameters.put(parameter, value); 36 this.parameterQuotes.put(parameter, Boolean.valueOf(quoted)); 37 return this; 38 } 39 40 public OptionsBuilder remove(String parameter) { 41 this.parameters.remove(parameter); 42 this.parameterQuotes.remove(parameter); 43 return this; 44 } 45 46 @Override 47 public String toString() { 48 StringBuffer sb = new StringBuffer (); 49 for (Iterator <String > iter = this.parameters.keySet().iterator(); iter 50 .hasNext();) { 51 String key = iter.next(); 52 String value = this.parameters.get(key); 53 boolean quoted = this.parameterQuotes.get(key).booleanValue(); 54 sb.append(key).append(": "); 55 if (quoted) { 56 sb.append("\"").append(value).append("\""); 57 } else { 58 sb.append(value); 59 } 60 if (iter.hasNext()) { 61 sb.append(","); 62 } 63 sb.append("\n"); 64 } 65 return sb.toString(); 66 } 67 68 } 69
| Popular Tags
|