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