001: ///////////////////////////////
002: // Makumba, Makumba tag library
003: // Copyright (C) 2000-2003 http://www.makumba.org
004: //
005: // This library is free software; you can redistribute it and/or
006: // modify it under the terms of the GNU Lesser General Public
007: // License as published by the Free Software Foundation; either
008: // version 2.1 of the License, or (at your option) any later version.
009: //
010: // This library is distributed in the hope that it will be useful,
011: // but WITHOUT ANY WARRANTY; without even the implied warranty of
012: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: // Lesser General Public License for more details.
014: //
015: // You should have received a copy of the GNU Lesser General Public
016: // License along with this library; if not, write to the Free Software
017: // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: //
019: // -------------
020: // $Id: ValueTag.java 1678 2007-09-24 15:36:19Z manuel_gay $
021: // $Name$
022: /////////////////////////////////////
023:
024: package org.makumba.list.tags;
025:
026: import javax.servlet.jsp.JspException;
027:
028: import org.makumba.LogicException;
029: import org.makumba.MakumbaSystem;
030: import org.makumba.analyser.PageCache;
031: import org.makumba.list.engine.valuecomputer.ValueComputer;
032:
033: /**
034: * mak:value tag
035: *
036: * @author Cristian Bogdan
037: *
038: */
039: public class ValueTag extends GenericListTag {
040:
041: private static final long serialVersionUID = 1L;
042:
043: private String expr;
044:
045: private String var;
046:
047: private String printVar;
048:
049: public void setExpr(String expr) {
050: this .expr = expr;
051: }
052:
053: public void setVar(String var) {
054: this .var = var;
055: }
056:
057: public void setPrintVar(String var) {
058: this .printVar = var;
059: }
060:
061: public String getExpr() {
062: return expr;
063: }
064:
065: public String getPrintVar() {
066: return printVar;
067: }
068:
069: public String getVar() {
070: return var;
071: }
072:
073: /**
074: * Sets tagKey to uniquely identify this tag. Called at analysis time before doStartAnalyze() and at runtime before
075: * doMakumbaStartTag()
076: *
077: * @param pageCache
078: * the page cache of the current page
079: */
080: public void setTagKey(PageCache pageCache) {
081: addToParentListKey(expr.trim());
082: }
083:
084: /**
085: * Determines the ValueComputer and caches it with the tagKey
086: * @param pageCache the page cache of the current page
087: */
088: public void doStartAnalyze(PageCache pageCache) {
089: pageCache.cache(GenericListTag.VALUE_COMPUTERS, tagKey,
090: ValueComputer.getValueComputerAtAnalysis(this , QueryTag
091: .getParentListKey(this , pageCache), expr,
092: pageCache));
093: }
094:
095: /**
096: * Tells the ValueComputer to finish analysis, and sets the types for var and printVar.
097: * @param pageCache the page cache of the current page
098: */
099: public void doEndAnalyze(PageCache pageCache) {
100: ValueComputer vc = (ValueComputer) pageCache.retrieve(
101: GenericListTag.VALUE_COMPUTERS, tagKey);
102: vc.doEndAnalyze(pageCache);
103:
104: if (var != null)
105: setType(pageCache, var, vc.getType());
106:
107: if (printVar != null)
108: setType(pageCache, printVar, MakumbaSystem.makeFieldOfType(
109: printVar, "char"));
110: }
111:
112: /**
113: * Asks the ValueComputer to present the expression
114: * @param pageCache the page cache of the current page
115: * @throws JspException
116: * @throws LogicException
117: * */
118: public int doAnalyzedStartTag(PageCache pageCache)
119: throws JspException, org.makumba.LogicException {
120: ((ValueComputer) pageCache.retrieve(
121: GenericListTag.VALUE_COMPUTERS, tagKey)).print(this ,
122: pageCache);
123:
124: expr = printVar = var = null;
125: return EVAL_BODY_INCLUDE;
126: }
127:
128: /**
129: * Computes a string
130: * @return A String holding the value in a form useful for debugging
131: */
132: public String toString() {
133: return "VALUE expr=" + expr + " parameters: " + params;
134: }
135:
136: }
|