001: //** Copyright Statement ***************************************************
002: //The Salmon Open Framework for Internet Applications (SOFIA)
003: // Copyright (C) 1999 - 2002, Salmon LLC
004: //
005: // This program is free software; you can redistribute it and/or
006: // modify it under the terms of the GNU General Public License version 2
007: // as published by the Free Software Foundation;
008: //
009: // This program is distributed in the hope that it will be useful,
010: // but WITHOUT ANY WARRANTY; without even the implied warranty of
011: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: // GNU General Public License for more details.
013: //
014: // You should have received a copy of the GNU General Public License
015: // along with this program; if not, write to the Free Software
016: // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: //
018: // For more information please visit http://www.salmonllc.com
019: //** End Copyright Statement ***************************************************
020: package com.salmonllc.jsp.tags;
021:
022: /////////////////////////
023: //$Archive: /SOFIA/SourceCode/com/salmonllc/jsp/tags/BaseEmptyTag.java $
024: //$Author: Len $
025: //$Revision: 25 $
026: //$Modtime: 11/10/04 10:51a $
027: /////////////////////////
028:
029: import java.io.PrintWriter;
030: import java.net.SocketException;
031:
032: import javax.servlet.jsp.*;
033: import javax.servlet.jsp.tagext.*;
034:
035: import com.salmonllc.html.HtmlComponent;
036: import com.salmonllc.jsp.JspController;
037: import com.salmonllc.util.MessageLog;
038:
039: /**
040: * This tag is the ancestor of all the empty tags in the library
041: */
042:
043: public abstract class BaseEmptyTag extends TagSupport {
044: private String _name;
045: private String _visible;
046: private BaseTagHelper _helper = new BaseTagHelper(this );
047:
048: public static final int CONV_DONT_CONVERT = 4; //Just return the tag to dreamweaver as it is
049: public static final int CONV_DEFAULT = 5; //Do the default conversion on the tag (for empty tags)
050:
051: /**
052: * This method must be implemented by each subclass of this tag. Each tag except NestedTags has an Html or Jsp Component associated with it. This method must be implemented to insure that the correct component gets created.
053: */
054:
055: public abstract HtmlComponent createComponent();
056:
057: public void afterInit(HtmlComponent comp) {
058: }
059:
060: /**
061: * This method is part of the JSP Tag Library Specification
062: */
063: public int doStartTag() throws JspException {
064:
065: try {
066: if (_helper.isInitializing()) {
067: HtmlComponent comp = createComponent();
068: if (comp != null) {
069: _helper.addComponent(comp);
070: if (_visible != null)
071: comp.setVisible(BaseTagHelper.stringToBoolean(
072: _visible, true));
073: afterInit(comp);
074: }
075: } else {
076: JspController jc = _helper.getController();
077: if (!jc.getDoPostRedirected()) {
078: if (jc.getHideAllComponents()
079: && !(this instanceof HtmlBodyTag || this instanceof HtmlEndBodyTag))
080: return BodyTag.SKIP_BODY;
081: if (jc.getCurrentRequest().getMethod()
082: .equals("GET")
083: || jc.getDisableRedirect()
084: || jc.isRequestFromForward()
085: || _helper.getTagContext()
086: .getDreamWeaverMode()) {
087: HtmlComponent comp = _helper.getComponent();
088: if (comp == null)
089: generateComponentHTML(pageContext.getOut());
090: else if (comp.getVisible())
091: generateComponentHTML(pageContext.getOut());
092: }
093: }
094: }
095: } catch (SocketException e) {
096: // ignore java.net.SocketException
097: MessageLog.writeInfoMessage(
098: "SocketException would have been thrown", this );
099: return BodyTag.SKIP_BODY;
100: } catch (Exception e) {
101: MessageLog.writeErrorMessage("doStartTag", e, this );
102: throw new JspException(e.getMessage());
103: }
104: return Tag.EVAL_BODY_INCLUDE;
105:
106: }
107:
108: /**
109: * This method is called when necessary to generate the required html for a tag. It should be overridden by tags that have more Html to generate (generally tags that require several passes to complete). A tag shouldn't generate any Html itself, but should instead delagate that to the Html or JSP component within it.
110: */
111:
112: protected void generateComponentHTML(JspWriter w) throws Exception {
113: HtmlComponent comp = _helper.getComponent();
114: int startRow = -1;
115: int endRow = -1;
116: DataTableTag dt = _helper.getDataTableTag();
117: ListTag l = _helper.getListTag();
118: if (l != null
119: && dt != null
120: && (DataTableTag) findAncestorWithClass(l,
121: DataTableTag.class) == dt) {
122: dt = null;
123: }
124: if (dt != null) {
125: if (dt.getMode() == BaseBodyTag.MODE_HEADER) {
126: startRow = -1;
127: endRow = -1;
128: } else {
129: startRow = dt.getStartRow();
130: endRow = dt.getEndRow();
131: }
132: } else {
133: if (l != null) {
134: startRow = l.getRow();
135: endRow = l.getRow();
136: }
137: }
138:
139: if (comp != null) {
140: if (startRow == -1 && endRow == -1)
141: comp.generateHTML(new PrintWriter(w), -1);
142: else if (comp != null)
143: comp.generateHTML(new PrintWriter(w), startRow, endRow);
144: }
145:
146: }
147:
148: /**
149: * This method returns the tag helper class for the custom tag.
150: */
151: public BaseTagHelper getHelper() {
152: return _helper;
153: }
154:
155: /**
156: * This method returns the name attribute for the tag.
157: */
158: public String getName() {
159: return _name;
160: }
161:
162: /**
163: * This method returns the Page Context object associated with the tag
164: */
165: public PageContext getPageContext() {
166: return pageContext;
167: }
168:
169: /**
170: * Returns the type of DreamWeaver conversion that this tag uses.
171: * Valid values are
172: *
173: * <BR> CONV_DEFAULT : Do the default conversion on the tag
174: * <BR> CONT_DONT_CONVERT : Don't convert to Dreamweaver, always return the original tag
175: */
176: public int getTagConvertType() {
177: return CONV_DEFAULT;
178: }
179:
180: /**
181: * This method returns the visible attribute for the tag
182: */
183: public String getVisible() {
184: return _visible;
185: }
186:
187: /**
188: * This method is part of the JSP tag lib specification.
189: */
190:
191: public void release() {
192: super .release();
193: _name = null;
194: _visible = null;
195:
196: }
197:
198: /**
199: * This method returns the name attribute for the tag.
200: */
201: public void setName(String newName) {
202: _name = newName;
203: }
204:
205: /**
206: * This method sets the visible attribute for the tag
207: */
208: public void setVisible(String val) {
209: _visible = val;
210: }
211: }
|