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 34 public class AjaxCalloutTag extends TagSupport { 35 36 private boolean doPost; 37 38 private String var; 39 40 private String attachTo; 41 42 private String baseUrl; 43 44 private String source; 45 46 private String sourceClass; 47 48 private String parameters; 49 50 private String title; 51 52 private String overlib; 53 54 private String postFunction; 55 56 private String preFunction; 57 58 private String emptyFunction; 59 60 private String errorFunction; 61 62 private String openEventType; 63 64 private String closeEventType; 65 66 public String getCloseEventType() { 67 return closeEventType; 68 } 69 70 public void setCloseEventType(String closeEvent) { 71 this.closeEventType = closeEvent; 72 } 73 74 public String getOpenEventType() { 75 return openEventType; 76 } 77 78 public void setOpenEventType(String openEvent) { 79 this.openEventType = openEvent; 80 } 81 82 public String getBaseUrl() { 83 return baseUrl; 84 } 85 86 public void setBaseUrl(String baseUrl) { 87 this.baseUrl = baseUrl; 88 } 89 90 public String getEmptyFunction() { 91 return emptyFunction; 92 } 93 94 public void setEmptyFunction(String emptyFunction) { 95 this.emptyFunction = emptyFunction; 96 } 97 98 public String getErrorFunction() { 99 return errorFunction; 100 } 101 102 public void setErrorFunction(String errorFunction) { 103 this.errorFunction = errorFunction; 104 } 105 106 public String getVar() { 107 return var; 108 } 109 110 public void setVar(String var) { 111 this.var = var; 112 } 113 114 public String getAttachTo() { 115 return attachTo; 116 } 117 118 public void setAttachTo(String attachTo) { 119 this.attachTo = attachTo; 120 } 121 122 public String getOverlib() { 123 return overlib; 124 } 125 126 public void setOverlib(String overlib) { 127 this.overlib = overlib; 128 } 129 130 public String getParameters() { 131 return parameters; 132 } 133 134 public void setParameters(String parameters) { 135 this.parameters = parameters; 136 } 137 138 public String getPreFunction() { 139 return preFunction; 140 } 141 142 public void setPreFunction(String preFunction) { 143 this.preFunction = preFunction; 144 } 145 146 public String getPostFunction() { 147 return postFunction; 148 } 149 150 public void setPostFunction(String postFunction) { 151 this.postFunction = postFunction; 152 } 153 154 public String getSource() { 155 return source; 156 } 157 158 public void setSource(String source) { 159 this.source = source; 160 } 161 162 public String getSourceClass() { 163 return sourceClass; 164 } 165 166 public void setSourceClass(String sourceClass) { 167 this.sourceClass = sourceClass; 168 } 169 170 public String getTitle() { 171 return title; 172 } 173 174 public void setTitle(String title) { 175 this.title = title; 176 } 177 178 @Override 179 public int doStartTag() throws JspException { 180 this.baseUrl = (String ) ExpressionEvaluatorManager.evaluate("baseUrl", 182 this.baseUrl, String .class, this, super.pageContext); 183 this.parameters = (String ) ExpressionEvaluatorManager.evaluate( 184 "parameters", this.parameters, String .class, this, 185 super.pageContext); 186 if (this.title != null) { 187 this.title = (String ) ExpressionEvaluatorManager.evaluate("title", 188 this.title, String .class, this, super.pageContext); 189 } 190 191 if (this.var != null) { 193 this.var = (String ) ExpressionEvaluatorManager.evaluate("var", 194 this.var, String .class, this, super.pageContext); 195 } 196 if (this.attachTo != null) { 197 this.attachTo = (String ) ExpressionEvaluatorManager.evaluate( 198 "attachTo", this.attachTo, String .class, this, 199 super.pageContext); 200 } 201 if (this.source != null) { 202 this.source = (String ) ExpressionEvaluatorManager.evaluate( 203 "source", this.source, String .class, this, 204 super.pageContext); 205 } 206 if (this.sourceClass != null) { 207 this.sourceClass = (String ) ExpressionEvaluatorManager.evaluate( 208 "sourceClass", this.sourceClass, String .class, this, 209 super.pageContext); 210 } 211 if (this.title != null) { 212 this.title = (String ) ExpressionEvaluatorManager.evaluate("title", 213 this.title, String .class, this, super.pageContext); 214 } 215 if (this.overlib != null) { 216 this.overlib = (String ) ExpressionEvaluatorManager.evaluate( 217 "overlib", this.overlib, String .class, this, 218 super.pageContext); 219 } 220 if (this.postFunction != null) { 221 this.postFunction = (String ) ExpressionEvaluatorManager.evaluate( 222 "postFunction", this.postFunction, String .class, this, 223 super.pageContext); 224 } 225 if (this.errorFunction != null) { 226 this.errorFunction = (String ) ExpressionEvaluatorManager.evaluate( 227 "errorFunction", this.errorFunction, String .class, this, 228 super.pageContext); 229 } 230 if (this.emptyFunction != null) { 231 this.emptyFunction = (String ) ExpressionEvaluatorManager.evaluate( 232 "emptyFunction", this.emptyFunction, String .class, this, 233 super.pageContext); 234 } 235 if (this.openEventType != null) { 236 this.openEventType = (String ) ExpressionEvaluatorManager.evaluate( 237 "openEvent", this.openEventType, String .class, this, 238 super.pageContext); 239 } 240 if (this.closeEventType != null) { 241 this.closeEventType = (String ) ExpressionEvaluatorManager.evaluate( 242 "closeEvent", this.closeEventType, String .class, this, 243 super.pageContext); 244 } 245 return SKIP_BODY; 246 } 247 248 @Override 249 public int doEndTag() throws JspException { 250 OptionsBuilder options = new OptionsBuilder(); 251 if (this.source != null) { 252 options.add("source", this.source, true); 253 } else { 254 options.add("sourceClass", this.sourceClass, true); 255 } 256 options.add("parameters", this.parameters, true); 257 if (this.title != null) 258 options.add("title", this.title, true); 259 if (this.overlib != null) 260 options.add("overlib", this.overlib, true); 261 if (this.postFunction != null) 262 options.add("postFunction", this.postFunction, false); 263 if (this.emptyFunction != null) 264 options.add("emptyFunction", this.emptyFunction, false); 265 if (this.errorFunction != null) 266 options.add("errorFunction", this.errorFunction, false); 267 if (this.openEventType != null) 268 options.add("openEvent", this.openEventType, true); 269 if (this.closeEventType != null) 270 options.add("closeEvent", this.closeEventType, true); 271 272 options.add("doPost", String.valueOf(this.doPost), false); 273 274 StringBuffer script = new StringBuffer (); 275 script.append("<script type=\"text/javascript\">\n"); 276 if (StringUtils.isNotEmpty(this.var)) { 277 if (StringUtils.isNotEmpty(this.attachTo)) { 278 script.append(this.attachTo).append(".").append(this.var); 279 } else { 280 script.append("var ").append(this.var); 281 } 282 script.append(" = "); 283 } 284 script.append("new AjaxJspTag.Callout(\n").append("\"").append( 285 this.baseUrl).append("\", {\n").append(options.toString()) 286 .append("});\n").append("</script>\n\n"); 287 288 JspWriter writer = pageContext.getOut(); 289 try { 290 writer.println(script); 291 } catch (IOException e) { 292 throw new JspException (e.getMessage()); 293 } 294 return EVAL_PAGE; 295 } 296 297 @Override 298 public void release() { 299 this.var = null; 300 this.doPost = false; 301 this.attachTo = null; 302 this.baseUrl = null; 303 this.source = null; 304 this.sourceClass = null; 305 this.parameters = null; 306 this.title = null; 307 this.overlib = null; 308 this.postFunction = null; 309 this.emptyFunction = null; 310 this.errorFunction = null; 311 this.openEventType = null; 312 this.closeEventType = null; 313 super.release(); 314 } 315 316 public boolean getDoPost() { 317 return doPost; 318 } 319 320 public void setDoPost(boolean doPost) { 321 this.doPost = doPost; 322 } 323 324 } 325
| Popular Tags
|