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.BodyTagSupport ; 23 24 import org.ajaxtags.helpers.AjaxHtmlHelper; 25 import org.apache.commons.lang.StringUtils; 26 import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager; 27 28 36 public class AjaxAreaTag extends BodyTagSupport { 37 38 41 private static final long serialVersionUID = -7940387487602588115L; 42 43 private String ajaxFlag = "ajax"; 44 45 private String style; 46 47 private String styleClass; 48 49 private String ajaxAnchors = "false"; 50 51 private boolean ajax = false; 52 53 56 public String getAjaxFlag() { 57 return this.ajaxFlag; 58 } 59 60 64 public void setAjaxFlag(String ajaxFlag) { 65 this.ajaxFlag = ajaxFlag; 66 } 67 68 71 public String getStyle() { 72 return this.style; 73 } 74 75 79 public void setStyle(String style) { 80 this.style = style; 81 } 82 83 86 public String getStyleClass() { 87 return this.styleClass; 88 } 89 90 94 public void setStyleClass(String styleClass) { 95 this.styleClass = styleClass; 96 } 97 98 101 public String getAjaxAnchors() { 102 return this.ajaxAnchors; 103 } 104 105 109 public void setAjaxAnchors(String ajaxAnchors) { 110 this.ajaxAnchors = ajaxAnchors; 111 } 112 113 116 @Override 117 public int doStartTag() throws JspException { 118 119 initParameters(); 120 121 if (this.ajax) { 122 try { 123 pageContext.getOut().clearBuffer(); 124 } catch (IOException ex) { 127 throw new JspException (ex.getMessage()); 128 } 129 } else { 130 JspWriter out = pageContext.getOut(); 131 try { 132 out.print("<div"); 133 if (StringUtils.isNotBlank(id)) { 134 out.print(" id='" + this.id + "'"); 135 } 136 if (StringUtils.isNotBlank(styleClass)) { 137 out.print(" class='" + this.styleClass + "'"); 138 } 139 if (StringUtils.isNotBlank(style)) { 140 out.print(" style='" + this.style + "'"); 141 } 142 out.print(">"); 143 } catch (IOException ex) { 144 throw new JspException (ex.getMessage()); 145 } 146 } 147 return EVAL_BODY_BUFFERED; 148 } 149 150 153 @Override 154 public int doEndTag() throws JspException { 155 JspWriter out = pageContext.getOut(); 156 String body = bodyContent.getString(); 157 try { 158 body = processContent(body); 159 out.println(body); 160 if (!this.ajax) { 161 out.println("</div>"); 162 } 163 } catch (IOException ex) { 164 throw new JspException (ex.getMessage()); 165 } 166 return this.ajax ? SKIP_PAGE : EVAL_PAGE; 167 } 168 169 172 @Override 173 public void release() { 174 this.ajaxFlag = null; 175 this.style = null; 176 this.ajaxAnchors = null; 177 this.styleClass = null; 178 super.release(); 179 } 180 181 186 protected void initParameters() throws JspException { 187 if (this.ajaxFlag != null) { 189 this.ajaxFlag = (String ) ExpressionEvaluatorManager.evaluate( 190 "ajaxFlag", this.ajaxFlag, String .class, this, 191 super.pageContext); 192 } 193 if (this.style != null) { 194 this.style = (String ) ExpressionEvaluatorManager.evaluate("style", 195 this.style, String .class, this, super.pageContext); 196 } 197 if (this.styleClass != null) { 198 this.styleClass = (String ) ExpressionEvaluatorManager.evaluate( 199 "styleClass", this.styleClass, String .class, this, 200 super.pageContext); 201 } 202 if (this.ajaxAnchors != null) { 203 this.ajaxAnchors = (String ) ExpressionEvaluatorManager.evaluate( 204 "ajaxAnchors", this.ajaxAnchors, String .class, this, 205 super.pageContext); 206 } 207 208 this.ajax = Boolean.valueOf( 209 pageContext.getRequest().getParameter(this.ajaxFlag)) 210 .booleanValue(); 211 } 212 213 219 protected String processContent(String content) { 220 return Boolean.valueOf(ajaxAnchors).booleanValue() ? AjaxHtmlHelper 221 .ajaxAnchors(content, this.id, this.ajaxFlag) : content; 222 } 223 224 } 225 | Popular Tags |