1 26 27 package org.objectweb.jonas.webapp.taglib; 28 29 import java.io.IOException ; 30 31 import javax.servlet.jsp.JspException ; 32 import javax.servlet.jsp.JspWriter ; 33 34 import org.apache.struts.taglib.html.BaseHandlerTag; 35 36 abstract public class GridBaseTag extends BaseHandlerTag { 37 38 40 protected final static String QUOTE = "\""; 41 42 44 protected String ms_BodyText = null; 45 46 48 53 public int doStartTag() 54 throws JspException { 55 ms_BodyText = null; 56 return (EVAL_BODY_BUFFERED); 58 } 59 60 public int doAfterBody() 61 throws JspException { 62 if (bodyContent != null) { 63 String value = bodyContent.getString().trim(); 64 if (value.length() > 0) { 65 ms_BodyText = value; 66 } 67 } 68 return (SKIP_BODY); 69 } 70 71 76 public int doEndTag() 77 throws JspException { 78 StringBuffer sb = new StringBuffer (); 79 sb.append(prepareBeforeTag()); 81 82 sb.append("<"); 84 sb.append(getHtmlElement()); 85 sb.append(prepareAttributes()); 87 sb.append(">"); 88 89 sb.append(prepareBeforeBody()); 91 if (ms_BodyText != null) { 93 sb.append(ms_BodyText); 94 } 95 else { 96 sb.append(getDefaultBody()); 97 } 98 sb.append(prepareAfterBody()); 100 sb.append("</"); 102 sb.append(getHtmlElement()); 103 sb.append(">"); 104 105 sb.append(prepareAfterTag()); 107 108 JspWriter out = pageContext.getOut(); 110 try { 111 out.print(sb.toString()); 112 } 113 catch (IOException e) { 114 throw new JspException ("Exception in " + getClass().getName() + " doEndTag():" 115 + e.toString()); 116 } 117 return EVAL_PAGE; 118 } 119 120 123 protected String prepareAttributes() throws JspException { 124 StringBuffer sb = new StringBuffer (); 125 126 sb.append(prepareEventHandlers()); 128 sb.append(prepareStyles()); 130 131 return sb.toString(); 132 } 133 134 137 protected String prepareAttribute(String attribute, String value) { 138 return value == null ? "" : " " + attribute + "=" + QUOTE + value + QUOTE; 139 } 140 141 144 145 protected String prepareAttribute(String attribute, int value) { 146 return value == -1 ? "" : " " + attribute + "=" + QUOTE + value + QUOTE; 147 } 148 149 152 public void release() { 153 super.release(); 154 ms_BodyText = null; 155 } 156 157 159 abstract protected String getHtmlElement(); 160 161 protected String prepareBeforeTag() { 162 return ""; 163 } 164 165 protected String prepareAfterTag() { 166 return ""; 167 } 168 169 protected String prepareBeforeBody() { 170 return ""; 171 } 172 173 protected String prepareAfterBody() { 174 return ""; 175 } 176 177 protected String getDefaultBody() { 178 return ""; 179 } 180 } | Popular Tags |