KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > bridge > jsp > taglib > functions > BooleanFunctionTag


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.bridge.jsp.taglib.functions;
11
12 import javax.servlet.jsp.JspTagException JavaDoc;
13
14 import org.mmbase.bridge.jsp.taglib.*;
15 import org.mmbase.bridge.jsp.taglib.containers.FunctionContainerReferrer;
16 import org.mmbase.bridge.jsp.taglib.util.Attribute;
17 import org.mmbase.util.Casting;
18
19 /**
20  * A Function tag for a function with a 'boolean' result. It is a Condition tag, which means that
21  * its body is or is not executed, in this case depending on the result of the function.
22  *
23  * @author Michiel Meeuwissen
24  * @since MMBase-1.7
25  * @version $Id: BooleanFunctionTag.java,v 1.4 2005/01/30 16:46:38 nico Exp $
26  */

27 public class BooleanFunctionTag extends AbstractFunctionTag implements Condition, FunctionContainerReferrer {
28
29     protected Attribute inverse = Attribute.NULL;
30
31     public void setInverse(String JavaDoc b) throws JspTagException JavaDoc {
32         inverse = getAttribute(b);
33     }
34
35     protected boolean getInverse() throws JspTagException JavaDoc {
36         return inverse.getBoolean(this, false);
37     }
38
39     public int doStartTag() throws JspTagException JavaDoc {
40         Object JavaDoc value = getFunctionValue();
41         boolean booleanValue = Casting.toBoolean(value);
42         return (booleanValue != getInverse()) ? EVAL_BODY_BUFFERED : SKIP_BODY;
43     }
44
45
46     public int doAfterBody() throws JspTagException JavaDoc {
47         try{
48             if(bodyContent != null) {
49                 bodyContent.writeOut(bodyContent.getEnclosingWriter());
50             }
51         } catch(java.io.IOException JavaDoc e){
52             throw new TaglibException(e);
53         }
54         return EVAL_PAGE;
55     }
56
57
58 }
59
Popular Tags