00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 package org.objectweb.jonas.webapp.taglib;
00028
00029 import java.io.IOException;
00030
00031 import javax.servlet.jsp.JspException;
00032 import javax.servlet.jsp.JspWriter;
00033
00034 import org.apache.struts.taglib.html.BaseHandlerTag;
00035
00036 abstract public class GridBaseTag extends BaseHandlerTag {
00037
00038
00039
00040 protected final static String QUOTE = "\"";
00041
00042
00043
00044 protected String ms_BodyText = null;
00045
00046
00047
00053 public int doStartTag()
00054 throws JspException {
00055 ms_BodyText = null;
00056
00057 return (EVAL_BODY_BUFFERED);
00058 }
00059
00060 public int doAfterBody()
00061 throws JspException {
00062 if (bodyContent != null) {
00063 String value = bodyContent.getString().trim();
00064 if (value.length() > 0) {
00065 ms_BodyText = value;
00066 }
00067 }
00068 return (SKIP_BODY);
00069 }
00070
00076 public int doEndTag()
00077 throws JspException {
00078 StringBuffer sb = new StringBuffer();
00079
00080 sb.append(prepareBeforeTag());
00081
00082
00083 sb.append("<");
00084 sb.append(getHtmlElement());
00085
00086 sb.append(prepareAttributes());
00087 sb.append(">");
00088
00089
00090 sb.append(prepareBeforeBody());
00091
00092 if (ms_BodyText != null) {
00093 sb.append(ms_BodyText);
00094 }
00095 else {
00096 sb.append(getDefaultBody());
00097 }
00098
00099 sb.append(prepareAfterBody());
00100
00101 sb.append("</");
00102 sb.append(getHtmlElement());
00103 sb.append(">");
00104
00105
00106 sb.append(prepareAfterTag());
00107
00108
00109 JspWriter out = pageContext.getOut();
00110 try {
00111 out.print(sb.toString());
00112 }
00113 catch (IOException e) {
00114 throw new JspException("Exception in " + getClass().getName() + " doEndTag():"
00115 + e.toString());
00116 }
00117 return EVAL_PAGE;
00118 }
00119
00123 protected String prepareAttributes() throws JspException {
00124 StringBuffer sb = new StringBuffer();
00125
00126
00127 sb.append(prepareEventHandlers());
00128
00129 sb.append(prepareStyles());
00130
00131 return sb.toString();
00132 }
00133
00137 protected String prepareAttribute(String attribute, String value) {
00138 return value == null ? "" : " " + attribute + "=" + QUOTE + value + QUOTE;
00139 }
00140
00145 protected String prepareAttribute(String attribute, int value) {
00146 return value == -1 ? "" : " " + attribute + "=" + QUOTE + value + QUOTE;
00147 }
00148
00152 public void release() {
00153 super.release();
00154 ms_BodyText = null;
00155 }
00156
00157
00158
00159 abstract protected String getHtmlElement();
00160
00161 protected String prepareBeforeTag() {
00162 return "";
00163 }
00164
00165 protected String prepareAfterTag() {
00166 return "";
00167 }
00168
00169 protected String prepareBeforeBody() {
00170 return "";
00171 }
00172
00173 protected String prepareAfterBody() {
00174 return "";
00175 }
00176
00177 protected String getDefaultBody() {
00178 return "";
00179 }
00180 }