1 19 20 package com.sslexplorer.input.tags; 21 22 import java.util.StringTokenizer ; 23 24 import javax.servlet.jsp.JspException ; 25 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 import org.apache.struts.taglib.TagUtils; 29 30 import com.sslexplorer.core.CoreUtil; 31 32 52 public class MultiEntryListBoxTag extends AbstractMultiFieldTag { 53 54 final static Log log = LogFactory.getLog(MultiEntryListBoxTag.class); 55 56 58 protected String entrySize; 59 protected String entryTitleKey; 60 protected String entryStyleClass; 61 protected String entryName; 62 protected String targetUnique; 63 protected String indicator; 64 protected boolean includeUserAttributes; 65 protected boolean includeSession; 66 protected boolean showReplacementVariables; 67 protected String replacementVariablesTitleKey; 68 protected String variables; 69 protected String replacementVariablesBundle; 70 71 74 public MultiEntryListBoxTag() { 75 super(); 76 this.type = "hidden"; 77 targetUnique = "true"; 78 indicator = null; 79 name = null; 80 showReplacementVariables = false; 81 replacementVariablesBundle = null; 82 includeSession = true; 83 includeUserAttributes = true; 84 setStyleId("multiEntry"); 85 setRows("5"); 86 87 } 88 89 94 public int doStartTag() throws JspException { 95 96 String entryTitle = null; 97 if (entryTitleKey != null) { 98 entryTitle = TagUtils.getInstance().message(pageContext, getBundle(), getLocale(), entryTitleKey, new String [] {}); 99 100 if (entryTitle == null) { 101 JspException e = new JspException (messages.getMessage("message.message", "\"" + entryTitleKey + "\"")); 102 TagUtils.getInstance().saveException(pageContext, e); 103 throw e; 104 } 105 } 106 107 String targetTitle = prepareTargetTitle(); 108 109 StringBuffer results = new StringBuffer ("<div "); 110 results.append(prepareStyles()); 111 results.append(">"); 112 results.append(this.renderInputElement()); 113 results.append("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">"); 114 if (entryTitle != null || targetTitle != null) { 115 results.append("<tr class=\"header\"><td class=\"entry\">"); 116 if (entryTitle != null) { 117 results.append(entryTitle); 118 } 119 results.append("</td><td class=\"actions\"/><td class=\"target\">"); 120 if (targetTitle != null) { 121 results.append(targetTitle); 122 } 123 results.append("</td></tr>"); 124 } 125 results.append("<tr class=\"body\"><td class=\"entry\">"); 126 results.append(renderEntryComponent()); 127 results.append("</td><td class=\"actions\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">"); 128 results.append("<tr><td>"); 129 results.append(renderAddComponent()); 130 results.append("</td></tr><tr><td>"); 131 results.append(renderRemoveSelectedComponent()); 132 if (isAllowReordering()) { 133 results.append("</td></tr><tr><td>"); 134 results.append(renderUpComponent()); 135 results.append("</td></tr><tr><td>"); 136 results.append(renderDownComponent()); 137 } 138 results.append("</td></tr></table></td><td class=\"target\">"); 139 results.append(renderTargetComponent()); 140 results.append("</td></tr></table></div>"); 141 TagUtils.getInstance().write(this.pageContext, results.toString()); 142 143 return (EVAL_BODY_BUFFERED); 144 } 145 146 151 public String getEntrySize() { 152 return entrySize; 153 } 154 155 160 public void setEntrySize(String entrySize) { 161 this.entrySize = entrySize; 162 } 163 164 169 public String getEntryTitleKey() { 170 return entryTitleKey; 171 } 172 173 178 public void setEntryTitleKey(String entryTitleKey) { 179 this.entryTitleKey = entryTitleKey; 180 } 181 182 187 public void setEntryStyleClass(String entryStyleClass) { 188 this.entryStyleClass = entryStyleClass; 189 } 190 191 196 public void setEntryName(String entryName) { 197 this.entryName = entryName; 198 } 199 200 211 public void setIndicator(String indicator) { 212 this.indicator = indicator; 213 } 214 215 222 public void setReplacementVariablesTitleKey(String replacementVariablesTitleKey) { 223 this.replacementVariablesTitleKey = replacementVariablesTitleKey; 224 } 225 226 234 public void setReplacementVariablesBundle(String replacementVariablesBundle) { 235 this.replacementVariablesBundle = replacementVariablesBundle; 236 } 237 238 243 public void setVariables(String variables) { 244 this.variables = variables; 245 } 246 247 254 public void setIncludeUserAttributes(boolean includeUserAttributes) { 255 this.includeUserAttributes = includeUserAttributes; 256 } 257 258 264 public void setIncludeSession(boolean includeSession) { 265 this.includeSession = includeSession; 266 } 267 268 273 public void setShowReplacementVariables(boolean showReplacementVariables) { 274 this.showReplacementVariables = showReplacementVariables; 275 } 276 277 282 public void release() { 283 super.release(); 284 this.type = "hidden"; 285 entryName = null; 286 targetUnique = "true"; 287 indicator = null; 288 setStyleId("multiEntry"); 289 setRows("5"); 290 variables = null; 291 includeUserAttributes = true; 292 includeSession = true; 293 showReplacementVariables = false; 294 replacementVariablesBundle = null; 295 } 296 297 protected String renderEntryComponent() throws JspException { 298 StringBuffer results = new StringBuffer ("<input type=\"text\""); 299 results.append(prepareDisabled()); 300 results.append(" id=\""); 301 String entryId = prepareEntryId(); 302 results.append(entryId); 303 results.append("\""); 304 results.append(" class=\""); 305 results.append(showReplacementVariables ? (indicator != null && !indicator.equals("") ? "twoButtons" : "oneButton") 306 : (indicator != null && !indicator.equals("") ? "oneButton" : "noButtons")); 307 results.append("\""); 308 if (entrySize != null && !entrySize.equals("")) { 309 results.append(" size=\""); 310 results.append(entrySize); 311 results.append("\""); 312 } 313 if (entryName != null && !entryName.equals("")) { 314 results.append(" name=\""); 315 results.append(entryName); 316 results.append("\""); 317 } 318 results.append("/>"); 319 if (showReplacementVariables) { 320 results.append(VariablesTag.generateReplacementVariableChooserFragment(replacementVariablesTitleKey, pageContext, 321 replacementVariablesBundle == null ? "navigation" : replacementVariablesBundle, getLocale(), entryId, 322 variables, includeSession, includeUserAttributes, false)); 323 } 324 if (indicator != null && !indicator.equals("")) { 325 results.append("<span id=\""); 326 results.append(indicator); 327 results.append("\" style=\"display:none;\"><img SRC=\""); 328 results.append(CoreUtil.getThemePath(pageContext.getSession())); 329 results.append("/images/indicator.gif\"/></span>"); 330 } 331 return results.toString(); 332 333 } 334 335 protected String renderAddComponent() throws JspException { 336 StringBuffer results = new StringBuffer ("<input class=\"multiAdd\""); 337 results.append(prepareDisabled()); 338 results.append(" onclick=\"multiEntryAddEntry("); 339 results.append("document.getElementById('"); 340 if (indexed) { 341 this.prepareIndex(results, name); 342 } 343 results.append(property); 344 results.append("'), document.getElementById('"); 345 results.append(prepareTargetId()); 346 results.append("'), document.getElementById('"); 347 results.append(prepareEntryId()); 348 results.append("'),'"); 349 results.append(targetUnique); 350 results.append("');\" type=\"button\" value=\""); 351 results.append(prepareAdd()); 352 results.append("\"/>"); 353 return results.toString(); 354 } 355 356 protected String renderRemoveSelectedComponent() throws JspException { 357 StringBuffer results = new StringBuffer ("<input class=\"multiRemove\""); 358 results.append(prepareDisabled()); 359 results.append(" onclick=\"multiEntryRemoveSelectedEntry("); 360 results.append("document.getElementById('"); 361 if (indexed) { 362 this.prepareIndex(results, name); 363 } 364 results.append(property); 365 results.append("'), document.getElementById('"); 366 results.append(prepareTargetId()); 367 results.append("'), document.getElementById('"); 368 results.append(prepareEntryId()); 369 results.append("'));\" type=\"button\" value=\""); 370 results.append(prepareRemove()); 371 results.append("\"/>"); 372 return results.toString(); 373 } 374 375 protected String prepareEntryId() throws JspException { 376 StringBuffer results = new StringBuffer ("entryValue_"); 377 if (indexed) { 378 prepareIndex(results, name); 379 } 380 results.append(property); 381 return results.toString(); 382 } 383 384 protected String renderTargetComponent() throws JspException { 385 StringBuffer results = new StringBuffer ("<select multiple id=\""); 386 results.append(prepareTargetId()); 387 results.append("\""); 388 if (rows != null) { 389 results.append(" size=\""); 390 results.append(rows); 391 results.append("\""); 392 } 393 results.append(">"); 394 Object value = TagUtils.getInstance().lookup(pageContext, name, property, null); 395 if (value == null || !(value instanceof String )) { 396 log.error("Name / property attributes (" + name + "/" + property + ") must specify a newline (\\n) separated string."); 397 } 398 else { 399 StringTokenizer t = new StringTokenizer (value.toString(), "\n"); 400 while (t.hasMoreTokens()) { 401 String val = t.nextToken(); 402 results.append("<option value=\""); 403 results.append(val); 404 results.append("\">"); 405 results.append(val); 406 results.append("</option>"); 407 } 408 } 409 results.append("</select>"); 410 return results.toString(); 411 412 } 413 414 protected String renderInputElement() throws JspException { 415 StringBuffer results = new StringBuffer ("<input type=\""); 416 results.append(this.type); 417 results.append("\" name=\""); 418 419 if (indexed) { 420 this.prepareIndex(results, name); 421 } 422 423 results.append(property); 424 results.append("\""); 425 426 if (entryStyleClass != null) { 427 results.append(" class=\""); 428 results.append(entryStyleClass); 429 results.append("\""); 430 } 431 432 results.append(" id=\""); 433 if (indexed) { 434 this.prepareIndex(results, name); 435 } 436 437 results.append(property); 438 results.append("\""); 439 440 results.append(" value=\""); 441 if (value != null) { 442 results.append(this.formatValue(value)); 443 444 } else if (redisplay || !"password".equals(type)) { 445 Object value = TagUtils.getInstance().lookup(pageContext, name, property, null); 446 447 results.append(this.formatValue(value)); 448 } 449 results.append('"'); 450 results.append(prepareDisabled()); 451 results.append(this.prepareEventHandlers()); 452 results.append(this.getElementClose()); 453 return results.toString(); 454 } 455 } 456 | Popular Tags |