KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > applications > community > taglib > TestChannelTag


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.applications.community.taglib;
11
12 import javax.servlet.jsp.JspTagException JavaDoc;
13
14 import org.mmbase.bridge.Node;
15 import org.mmbase.bridge.Module;
16
17 import org.mmbase.bridge.jsp.taglib.NodeTag;
18
19 /**
20  *
21  * As NodeTag, but the body is evaluated only if the condiiton specified evalueates
22  * to true.
23  *
24  * @author Pierre van Rooden
25  * @version $Id: TestChannelTag.java,v 1.4 2003/06/18 20:03:57 michiel Exp $
26  */

27  
28 public class TestChannelTag extends NodeTag {
29
30     public final static String JavaDoc OPEN = "OPEN";
31     public final static String JavaDoc READONLY = "READONLY";
32     public final static String JavaDoc CLOSED = "CLOSED";
33
34     String JavaDoc condition=OPEN;
35     boolean reverse=false;
36
37     public void setChannel(String JavaDoc c) throws JspTagException JavaDoc {
38         setNumber(c);
39     }
40
41     public void setCondition(String JavaDoc c) throws JspTagException JavaDoc {
42         condition=getAttributeValue(c).toUpperCase();
43         if (!condition.equals(OPEN) &&
44             !condition.equals(CLOSED) &&
45             !condition.equals(READONLY)) {
46             throw new JspTagException JavaDoc("Condition need be one of OPEN, CLOSED or READONLY.");
47         }
48     }
49
50     public void setReverse(boolean r) {
51         reverse=r;
52     }
53
54     /**
55      *
56      */

57     public int doStartTag() throws JspTagException JavaDoc {
58         if (super.doStartTag()==EVAL_BODY_BUFFERED) {
59             Node node=getNodeVar();
60             Module community=getCloudContext().getModule("communityprc");
61             String JavaDoc state=community.getInfo("CHANNEL-"+node.getNumber()+"-ISOPEN",pageContext.getRequest(),pageContext.getResponse());
62             boolean result=state.equalsIgnoreCase(condition);
63             if (result!=reverse)
64                 return EVAL_BODY_BUFFERED;
65         }
66         return SKIP_BODY;
67     }
68
69 }
70
Popular Tags