1 17 package org.ajaxtags.tags; 18 19 import java.io.IOException ; 20 21 import javax.servlet.jsp.JspException ; 22 import javax.servlet.jsp.JspWriter ; 23 import javax.servlet.jsp.tagext.TagSupport ; 24 25 import org.apache.commons.lang.StringUtils; 26 import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager; 27 28 35 public class AjaxPortletTag extends TagSupport { 36 37 public AjaxPortletTag() { 38 withBar = true; 39 } 40 41 private String var; 42 43 private boolean startMinimize; 44 45 public void setStartMinimize(boolean startMinimize) { 46 this.startMinimize = startMinimize; 47 } 48 49 public boolean getStartMinimize() { 50 return this.startMinimize; 51 } 52 53 private String attachTo; 54 55 private String baseUrl; 56 57 private String source; 58 59 private String parameters; 60 61 private String classNamePrefix; 62 63 private String title; 64 65 private String imageClose; 66 67 private String imageMaximize; 68 69 private String imageMinimize; 70 71 private String imageRefresh; 72 73 private String refreshPeriod; 74 75 private String executeOnLoad; 76 77 private String expireDays; 78 79 private String expireHours; 80 81 private String expireMinutes; 82 83 private String preFunction; 84 85 private String postFunction; 86 87 private String errorFunction; 88 89 private String parser; 90 91 public String getBaseUrl() { 92 return baseUrl; 93 } 94 95 public void setBaseUrl(String baseUrl) { 96 this.baseUrl = baseUrl; 97 } 98 99 public String getClassNamePrefix() { 100 return classNamePrefix; 101 } 102 103 public void setClassNamePrefix(String classNamePrefix) { 104 this.classNamePrefix = classNamePrefix; 105 } 106 107 public String getImageClose() { 108 return imageClose; 109 } 110 111 public void setImageClose(String imageClose) { 112 this.imageClose = imageClose; 113 } 114 115 public String getPreFunction() { 116 return preFunction; 117 } 118 119 public void setPreFunction(String preFunction) { 120 this.preFunction = preFunction; 121 } 122 123 public String getExecuteOnLoad() { 124 return executeOnLoad; 125 } 126 127 public void setExecuteOnLoad(String executeOnLoad) { 128 this.executeOnLoad = executeOnLoad; 129 } 130 131 public String getExpireDays() { 132 return expireDays; 133 } 134 135 public void setExpireDays(String expireDays) { 136 this.expireDays = expireDays; 137 } 138 139 public String getExpireHours() { 140 return expireHours; 141 } 142 143 public void setExpireHours(String expireHours) { 144 this.expireHours = expireHours; 145 } 146 147 public String getExpireMinutes() { 148 return expireMinutes; 149 } 150 151 public void setExpireMinutes(String expireMinutes) { 152 this.expireMinutes = expireMinutes; 153 } 154 155 public String getErrorFunction() { 156 return errorFunction; 157 } 158 159 public void setErrorFunction(String errorFunction) { 160 this.errorFunction = errorFunction; 161 } 162 163 public String getImageMaximize() { 164 return imageMaximize; 165 } 166 167 public void setImageMaximize(String imageMaximize) { 168 this.imageMaximize = imageMaximize; 169 } 170 171 public String getImageMinimize() { 172 return imageMinimize; 173 } 174 175 public void setImageMinimize(String imageMinimize) { 176 this.imageMinimize = imageMinimize; 177 } 178 179 public String getParameters() { 180 return parameters; 181 } 182 183 public void setParameters(String parameters) { 184 this.parameters = parameters; 185 } 186 187 public String getPostFunction() { 188 return postFunction; 189 } 190 191 public void setPostFunction(String postFunction) { 192 this.postFunction = postFunction; 193 } 194 195 public String getImageRefresh() { 196 return imageRefresh; 197 } 198 199 public void setImageRefresh(String imageRefresh) { 200 this.imageRefresh = imageRefresh; 201 } 202 203 public String getParser() { 204 return parser; 205 } 206 207 public void setParser(String parser) { 208 this.parser = parser; 209 } 210 211 public String getRefreshPeriod() { 212 return refreshPeriod; 213 } 214 215 public void setRefreshPeriod(String refreshPeriod) { 216 this.refreshPeriod = refreshPeriod; 217 } 218 219 public String getSource() { 220 return source; 221 } 222 223 public void setSource(String source) { 224 this.source = source; 225 } 226 227 public String getTitle() { 228 return title; 229 } 230 231 public void setTitle(String title) { 232 this.title = title; 233 } 234 235 public String getVar() { 236 return var; 237 } 238 239 public void setVar(String var) { 240 this.var = var; 241 } 242 243 public String getAttachTo() { 244 return attachTo; 245 } 246 247 public void setAttachTo(String attachTo) { 248 this.attachTo = attachTo; 249 } 250 251 @Override  252 public int doStartTag() throws JspException { 253 this.baseUrl = (String ) ExpressionEvaluatorManager.evaluate("baseUrl", 255 this.baseUrl, String .class, this, super.pageContext); 256 if (this.parameters != null) { 257 this.parameters = (String ) ExpressionEvaluatorManager.evaluate( 258 "parameters", this.parameters, String .class, this, 259 super.pageContext); 260 } 261 if (this.classNamePrefix != null) { 262 this.classNamePrefix = (String ) ExpressionEvaluatorManager 263 .evaluate("classNamePrefix", this.classNamePrefix, 264 String .class, this, super.pageContext); 265 } 266 267 if (this.var != null) { 269 this.var = (String ) ExpressionEvaluatorManager.evaluate("var", 270 this.var, String .class, this, super.pageContext); 271 } 272 if (this.attachTo != null) { 273 this.attachTo = (String ) ExpressionEvaluatorManager.evaluate( 274 "attachTo", this.attachTo, String .class, this, 275 super.pageContext); 276 } 277 if (this.source != null) { 278 this.source = (String ) ExpressionEvaluatorManager.evaluate( 279 "source", this.source, String .class, this, 280 super.pageContext); 281 } 282 if (this.title != null) { 283 this.title = (String ) ExpressionEvaluatorManager.evaluate("title", 284 this.title, String .class, this, super.pageContext); 285 } 286 if (this.imageClose != null) { 287 this.imageClose = (String ) ExpressionEvaluatorManager.evaluate( 288 "imageClose", this.imageClose, String .class, this, 289 super.pageContext); 290 } 291 if (this.imageMaximize != null) { 292 this.imageMaximize = (String ) ExpressionEvaluatorManager.evaluate( 293 "imageMaximize", this.imageMaximize, String .class, this, 294 super.pageContext); 295 } 296 if (this.imageMinimize != null) { 297 this.imageMinimize = (String ) ExpressionEvaluatorManager.evaluate( 298 "imageMinimize", this.imageMinimize, String .class, this, 299 super.pageContext); 300 } 301 if (this.imageRefresh != null) { 302 this.imageRefresh = (String ) ExpressionEvaluatorManager.evaluate( 303 "imageRefresh", this.imageRefresh, String .class, this, 304 super.pageContext); 305 } 306 if (this.refreshPeriod != null) { 307 this.refreshPeriod = (String ) ExpressionEvaluatorManager.evaluate( 308 "refreshPeriod", this.refreshPeriod, String .class, this, 309 super.pageContext); 310 } 311 if (this.executeOnLoad != null) { 312 this.executeOnLoad = (String ) ExpressionEvaluatorManager.evaluate( 313 "executeOnLoad", this.executeOnLoad, String .class, this, 314 super.pageContext); 315 } 316 if (this.postFunction != null) { 317 this.postFunction = (String ) ExpressionEvaluatorManager.evaluate( 318 "postFunction", this.postFunction, String .class, this, 319 super.pageContext); 320 } 321 if (this.errorFunction != null) { 322 this.errorFunction = (String ) ExpressionEvaluatorManager.evaluate( 323 "errorFunction", this.errorFunction, String .class, this, 324 super.pageContext); 325 } 326 if (this.preFunction != null) { 327 this.preFunction = (String ) ExpressionEvaluatorManager.evaluate( 328 "preFunction", this.preFunction, String .class, this, 329 super.pageContext); 330 } 331 if (!this.withBar) { 332 this.imageClose = null; 333 this.imageMaximize = null; 334 this.imageMinimize = null; 335 this.imageRefresh = null; 336 } 337 return SKIP_BODY; 338 } 339 340 @Override  341 public int doEndTag() throws JspException { 342 OptionsBuilder options = new OptionsBuilder(); 343 options.add("source", this.source, true); 344 options.add("classNamePrefix", this.classNamePrefix, true); 345 options.add("title", this.title, true); 346 if (this.imageClose != null) 347 options.add("imageClose", this.imageClose, true); 348 if (this.imageMaximize != null) 349 options.add("imageMaximize", this.imageMaximize, true); 350 if (this.imageMinimize != null) 351 options.add("imageMinimize", this.imageMinimize, true); 352 if (this.imageRefresh != null) 353 options.add("imageRefresh", this.imageRefresh, true); 354 if (this.parameters != null) 355 options.add("parameters", this.parameters, true); 356 if (this.refreshPeriod != null) 357 options.add("refreshPeriod", this.refreshPeriod, true); 358 if (this.executeOnLoad != null) 359 options.add("executeOnLoad", this.executeOnLoad, true); 360 if (this.expireDays != null) 361 options.add("expireDays", this.expireDays, true); 362 if (this.expireHours != null) 363 options.add("expireHours", this.expireHours, true); 364 if (this.expireMinutes != null) 365 options.add("expireMinutes", this.expireMinutes, true); 366 if (this.postFunction != null) 367 options.add("postFunction", this.postFunction, false); 368 if (this.preFunction != null) 369 options.add("preFunction", this.preFunction, false); 370 if (this.errorFunction != null) 371 options.add("errorFunction", this.errorFunction, false); 372 if (this.parser != null) 373 options.add("parser", this.parser, false); 374 if (this.startMinimize) 375 options.add("startMinimize", String.valueOf(this.startMinimize), 376 false); 377 if (this.withBar) 378 options.add("withBar", String.valueOf(this.withBar), false); 379 380 StringBuffer script = new StringBuffer (); 381 script.append("<div id=\"").append(this.source).append("\" class=\"") 383 .append(this.classNamePrefix).append("Box\">"); 384 if (this.withBar) { 386 script.append("<div id=\"").append(this.source).append( 387 "Tools\" class=\"").append(this.classNamePrefix).append( 388 "Tools\">"); 389 if (this.imageRefresh != null) { 390 script.append("<img id=\"").append(this.source).append( 391 "Refresh\" class=\"").append(this.classNamePrefix) 392 .append("Refresh\" SRC=\"").append(this.imageRefresh) 393 .append("\"/>"); 394 } 395 if (this.imageMaximize != null && this.imageMinimize != null) { 396 script.append("<img id=\"").append(this.source).append( 397 "Size\" class=\"").append(this.classNamePrefix).append( 398 "Size\" SRC=\"").append(this.imageMinimize).append( 399 "\"/>"); 400 } 401 if (this.imageClose != null) { 402 script.append("<img id=\"").append(this.source).append( 403 "Close\" class=\"").append(this.classNamePrefix) 404 .append("Close\" SRC=\"").append(this.imageClose) 405 .append("\"/>"); 406 } 407 script.append("</div>"); 408 } 409 script.append("<div id=\"").append(this.source).append( 411 "Title\" class=\"").append(this.classNamePrefix).append( 412 "Title\">").append(this.title).append("</div>"); 413 script.append("<div id=\"").append(this.source).append( 415 "Content\" class=\"").append(this.classNamePrefix).append( 416 "Content\"></div>"); 417 script.append("</div>\n"); 418 script.append("<script type=\"text/javascript\">\n"); 419 420 if (StringUtils.isNotEmpty(this.attachTo)) { 421 script.append(this.attachTo).append("."); 422 if (StringUtils.isNotEmpty(this.var)) { 423 script.append(this.var); 424 } else { 425 script.append("aj_").append(this.source); 426 } 427 } else if (StringUtils.isNotEmpty(this.var)) { 428 script.append("var ").append(this.var); 429 } else { 430 script.append("var aj_").append(this.source); 431 } 432 433 script.append(" = new AjaxJspTag.Portlet(\n").append("\"").append( 434 this.baseUrl).append("\", {\n").append(options.toString()) 435 .append("});\n").append("</script>\n\n"); 436 437 JspWriter writer = pageContext.getOut(); 438 try { 439 writer.println(script); 440 } catch (IOException e) { 441 throw new JspException (e.getMessage()); 442 } 443 return EVAL_PAGE; 444 } 445 446 @Override  447 public void release() { 448 this.var = null; 449 this.startMinimize = false; 450 this.withBar = false; 451 this.attachTo = null; 452 this.baseUrl = null; 453 this.source = null; 454 this.parameters = null; 455 this.classNamePrefix = null; 456 this.title = null; 457 this.imageClose = null; 458 this.imageMaximize = null; 459 this.imageMinimize = null; 460 this.imageRefresh = null; 461 this.refreshPeriod = null; 462 this.executeOnLoad = null; 463 this.expireDays = null; 464 this.expireHours = null; 465 this.expireMinutes = null; 466 this.postFunction = null; 467 this.preFunction = null; 468 this.errorFunction = null; 469 this.parser = null; 470 super.release(); 471 } 472 473 public boolean getWithBar() { 474 return withBar; 475 } 476 477 private boolean withBar; 478 479 public void setWithBar(boolean withBar) { 480 this.withBar = withBar; 481 } 482 483 } 484 | Popular Tags |