GridBaseTag.java

00001 /*
00002  * JOnAS: Java(TM) Open Application Server
00003  * Copyright (C) 1999 Bull S.A.
00004  * Contact: jonas-team@objectweb.org
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00019  * USA
00020  *
00021  * Initial developer(s): Michel-Ange ANTON
00022  * --------------------------------------------------------------------------
00023  * $Id: GridBaseTag.java,v 1.4 2004/03/26 16:16:12 benoitf Exp $
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 // ----------------------------------------------------- Protected Constants
00039 
00040     protected final static String QUOTE = "\"";
00041 
00042 // ----------------------------------------------------- Instance Variables
00043 
00044     protected String ms_BodyText = null;
00045 
00046 // ----------------------------------------------------- Public Methods
00047 
00053     public int doStartTag()
00054         throws JspException {
00055         ms_BodyText = null;
00056         // Continue processing this page
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         // Before Tag option
00080         sb.append(prepareBeforeTag());
00081 
00082         // Create a ELEMENT element based on the parameters
00083         sb.append("<");
00084         sb.append(getHtmlElement());
00085         // Prepare this HTML elements attributes
00086         sb.append(prepareAttributes());
00087         sb.append(">");
00088 
00089         // Before Body Content option
00090         sb.append(prepareBeforeBody());
00091         // Add Body Content
00092         if (ms_BodyText != null) {
00093             sb.append(ms_BodyText);
00094         }
00095         else {
00096             sb.append(getDefaultBody());
00097         }
00098         // Before After Content option
00099         sb.append(prepareAfterBody());
00100         // End Tag
00101         sb.append("</");
00102         sb.append(getHtmlElement());
00103         sb.append(">");
00104 
00105         // After Tag option
00106         sb.append(prepareAfterTag());
00107 
00108         // Render this element to our writer
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         // Append Event Handler details
00127         sb.append(prepareEventHandlers());
00128         // Append Style details
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 // ----------------------------------------------------- Protected Methods
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 }

Generated on Tue Feb 15 15:05:34 2005 for JOnAS by  doxygen 1.3.9.1