1 6 7 package com.quikj.application.communicator.applications.webtalk.controller; 8 9 import javax.servlet.http.HttpServletRequest ; 10 import org.apache.struts.action.*; 11 import java.util.*; 12 13 17 public class FeatureManagementForm extends ActionForm 18 { 19 20 21 private String name; 22 23 24 private String submit = "Find"; 25 26 27 private String className; 28 29 30 private boolean active = false; 31 32 33 private String params; 34 35 36 private HashMap paramsList; 37 38 39 public FeatureManagementForm() 40 { 41 } 42 43 47 public String getName() 48 { 49 return this.name; 50 } 51 52 56 public void setName(String name) 57 { 58 this.name = name.trim(); 59 } 60 61 65 public String getSubmit() 66 { 67 return this.submit; 68 } 69 70 74 public void setSubmit(String submit) 75 { 76 this.submit = submit; 77 } 78 79 public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) 80 { 81 ActionErrors errors = new ActionErrors(); 83 84 if ((name == null) || (name.length() == 0)) 85 { 86 errors.add("name", new ActionError("error.feature.no.name")); 87 } 88 89 if (DataCheckUtility.followsTableIdRules(name) == false) 90 { 91 errors.add("name", new ActionError("error.feature.invalid.id")); 92 } 93 94 if ((submit.equals("Create") == true) || (submit.equals("Modify") == true)) 96 { 97 if ((className == null) || (className.length() == 0)) 98 { 99 errors.add("className", new ActionError("error.feature.no.className")); 100 } 101 102 processFeatureParams(getParams(), errors); 104 105 } 106 107 return errors; 108 } 109 110 public void reset() 111 { 112 name = null; 113 submit = "Find"; 114 className = null; 115 active = false; 116 params = null; 117 } 118 119 123 public String getClassName() 124 { 125 return this.className; 126 } 127 128 132 public void setClassName(String className) 133 { 134 this.className = className; 135 } 136 137 141 public boolean isActive() 142 { 143 return this.active; 144 } 145 146 150 public void setActive(boolean active) 151 { 152 this.active = active; 153 } 154 155 159 public String getParams() 160 { 161 return this.params; 162 } 163 164 168 public void setParams(String params) 169 { 170 this.params = params; 171 } 172 173 177 public HashMap getParamsList() 178 { 179 return this.paramsList; 180 } 181 182 186 public void setParamsList(HashMap paramsList) 187 { 188 this.paramsList = paramsList; 189 params = null; 190 191 if (paramsList != null) 192 { 193 Set key_set = paramsList.keySet(); 194 StringBuffer buf = new StringBuffer (); 195 196 for (Iterator i = key_set.iterator(); i.hasNext();) 197 { 198 String key = (String ) i.next(); 199 String value = (String ) paramsList.get(key); 200 201 buf.append(Utilities.escapeEqual(key) + "=" + Utilities.escapeEqual(value)); 202 if (i.hasNext() == true) 203 { 204 buf.append('\n'); 205 } 206 } 207 208 params = buf.toString(); 209 } 210 } 211 212 private void processFeatureParams(String input, ActionErrors errors) 213 { 214 225 226 if (input != null) 227 { 228 input = input.trim(); 229 if (input.length() > 0) 230 { 231 StringTokenizer strtok = new StringTokenizer(input, "\n"); 232 int num_pairs = strtok.countTokens(); 233 234 paramsList = new HashMap(); 235 236 for (int i = 0; i < num_pairs; i++) 237 { 238 String pair = strtok.nextToken(); 239 240 StringTokenizer pairtok = new StringTokenizer(pair, "=", true); 241 int num_subparms = pairtok.countTokens(); 242 243 if (num_subparms != 3) 244 { 245 errors.add("params", new ActionError("error.feature.params.pairtokens", 246 new Integer (i + 1))); 247 248 continue; 249 } 250 251 String input_key = pairtok.nextToken().trim(); 252 pairtok.nextToken(); 253 String input_value = pairtok.nextToken().trim(); 254 255 String key = Utilities.deEscapeEqual(input_key); 256 String value = Utilities.deEscapeEqual(input_value); 257 258 if (paramsList.containsKey(key) == true) 259 { 260 errors.add("params", new ActionError("error.feature.params.duplicatekey", 261 new Integer (i + 1))); 262 263 continue; 264 } 265 266 paramsList.put(key, value); 267 } 268 } 269 } 270 } 271 272 273 } 274 | Popular Tags |