001: //** Copyright Statement ***************************************************
002: //The Salmon Open Framework for Internet Applications (SOFIA)
003: // Copyright (C) 1999 - 2003, 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:
021: package com.salmonllc.jsp.tags;
022:
023: import java.io.IOException;
024: import java.io.PrintWriter;
025: import java.io.Serializable;
026: import java.util.Stack;
027: import java.util.Vector;
028:
029: import javax.servlet.jsp.JspWriter;
030:
031: import com.salmonllc.jsp.JspContainer;
032: import com.salmonllc.jsp.JspController;
033:
034: /**
035: * This object is used internally by the framework to store tag library context information for the dureation of a single page request.It should not be used outside the framework.
036: */
037: public class TagContext implements Serializable {
038:
039: private JspController _controllerClass;
040: private boolean _initializing;
041: private boolean _dreamWeaverMode;
042: private boolean _refIndexPrinted = false;
043: private boolean _printVars;
044: private boolean _generateCode;
045: private Vector _validatorAttributes;
046: private String _controller;
047: public static final String TAG_CONTEXT_REQ_KEY = "$$$PageTag$$$";
048: private Stack _containerStack = new Stack();
049: private Stack _tagStack = new Stack();
050:
051: public TagContext() {
052: super ();
053: }
054:
055: public TagContext(String controller) {
056: _controller = controller;
057: }
058:
059: public void pushContainer(JspContainer cont) {
060: _containerStack.push(cont);
061: }
062:
063: public void popContainer() {
064: if (!_containerStack.isEmpty())
065: _containerStack.pop();
066: }
067:
068: public JspContainer getCurrentContainer() {
069: if (_containerStack.isEmpty())
070: return null;
071: else
072: return (JspContainer) _containerStack.peek();
073: }
074:
075: /**
076: * Returns the controllerClass.
077: * @return JspController
078: */
079: public JspController getControllerObject() {
080: return _controllerClass;
081: }
082:
083: /**
084: * Sets the controllerClass.
085: * @param controllerClass The controllerClass to set
086: */
087: public void setControllerObject(JspController controllerClass) {
088: _controllerClass = controllerClass;
089: }
090:
091: /**
092: * Returns the initializing.
093: * @return boolean
094: */
095: public boolean isInitializing() {
096: return _initializing;
097: }
098:
099: /**
100: * Sets the initializing.
101: * @param initializing The initializing to set
102: */
103: public void setInitializing(boolean initializing) {
104: _initializing = initializing;
105: }
106:
107: /**
108: * Returns the dreamWeaverMode.
109: * @return boolean
110: */
111: public boolean getDreamWeaverMode() {
112: return _dreamWeaverMode;
113: }
114:
115: /**
116: * Returns the refIndexPrinted.
117: * @return boolean
118: */
119: public boolean getRefIndexPrinted() {
120: return _refIndexPrinted;
121: }
122:
123: /**
124: * Sets the dreamWeaverMode.
125: * @param dreamWeaverMode The dreamWeaverMode to set
126: */
127: public void setDreamWeaverMode(boolean dreamWeaverMode) {
128: _dreamWeaverMode = dreamWeaverMode;
129: }
130:
131: /**
132: * Sets the refIndexPrinted.
133: * @param refIndexPrinted The refIndexPrinted to set
134: */
135: public void setRefIndexPrinted(boolean refIndexPrinted) {
136: _refIndexPrinted = refIndexPrinted;
137: }
138:
139: /**
140: * Returns the generateCode.
141: * @return boolean
142: */
143: public boolean isGenerateCode() {
144: return _generateCode;
145: }
146:
147: /**
148: * Returns the printVars.
149: * @return boolean
150: */
151: public boolean isPrintingVars() {
152: return _printVars;
153: }
154:
155: /**
156: * Sets the generateCode.
157: * @param generateCode The generateCode to set
158: */
159: public void setGenerateCode(boolean generateCode) {
160: _generateCode = generateCode;
161: }
162:
163: /**
164: * Sets the printVars.
165: * @param printVars The printVars to set
166: */
167: public void setPrintingVars(boolean printVars) {
168: _printVars = printVars;
169: }
170:
171: /**
172: * This adds a tag to the list of validator tags maintained by the page tag
173: */
174: public void addValidatorTag(ValidatorTag.Attributes att) {
175: if (_validatorAttributes == null)
176: _validatorAttributes = new Vector();
177:
178: _validatorAttributes.addElement(att);
179:
180: }
181:
182: /**
183: * Returns all the validator attributes used in this tag
184: */
185: public Vector getValidatorAttributes() {
186: return _validatorAttributes;
187: }
188:
189: void printVars(JspWriter p) throws IOException {
190: _controllerClass.printVars(new PrintWriter(p));
191: }
192:
193: void generateCode(JspWriter p) throws IOException {
194: _controllerClass.generateCode(new PrintWriter(p), _controller);
195: }
196:
197: void pushTag(BaseBodyTag tag) {
198: _tagStack.push(tag);
199: }
200:
201: BaseBodyTag popTag() {
202: return (BaseBodyTag) _tagStack.pop();
203: }
204:
205: public BaseBodyTag findAncestorWithClass(Class tagClass) {
206: if (_tagStack.isEmpty())
207: return null;
208: for (int i = (_tagStack.size() - 1); i >= 0; i--) {
209: BaseBodyTag t = (BaseBodyTag) _tagStack.elementAt(i);
210: if (tagClass.isInstance(t))
211: return t;
212: }
213: return null;
214: }
215: }
|