KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > bridge > jsp > taglib > security > MayReadTag


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.security;
11
12 import org.mmbase.bridge.*;
13 import org.mmbase.bridge.jsp.taglib.util.Attribute;
14 import org.mmbase.bridge.jsp.taglib.Condition;
15 import org.mmbase.bridge.jsp.taglib.CloudReferrerTag;
16
17 import javax.servlet.jsp.JspTagException JavaDoc;
18
19
20 /**
21  * A very simple tag to check if node may be viewed
22  *
23  * @author Michiel Meeuwissen
24  * @version $Id: MayReadTag.java,v 1.1 2006/07/11 20:07:58 michiel Exp $
25  * @since MMBase-1.8.1
26  */

27
28 public class MayReadTag extends CloudReferrerTag implements Condition {
29
30     protected Attribute inverse = Attribute.NULL;
31     protected Attribute referid = Attribute.NULL;
32     protected Attribute number = Attribute.NULL;
33
34     public void setInverse(String JavaDoc b) throws JspTagException JavaDoc {
35         inverse = getAttribute(b);
36     }
37     public void setNumber(String JavaDoc n) throws JspTagException JavaDoc {
38         number = getAttribute(n);
39     }
40     public void setReferid(String JavaDoc r) throws JspTagException JavaDoc {
41         referid = getAttribute(r);
42     }
43     protected boolean getInverse() throws JspTagException JavaDoc {
44         return inverse.getBoolean(this, false);
45     }
46
47     public int doStartTag() throws JspTagException JavaDoc {
48         Cloud cloud = getCloudVar();
49         String JavaDoc n = number.getString(this);
50         String JavaDoc rid = referid.getString(this);
51         String JavaDoc nodeNumber;
52         if ("".equals(n)) {
53             nodeNumber = getString(rid);
54         } else {
55             nodeNumber = n;
56             if (! rid.equals("")) {
57                 throw new JspTagException JavaDoc("Cannot specify both 'number' and 'referid");
58             }
59         }
60         if (cloud.mayRead(nodeNumber) != getInverse()) {
61             return EVAL_BODY;
62         } else {
63             return SKIP_BODY;
64         }
65     }
66     public int doAfterBody() throws JspTagException JavaDoc {
67         if (EVAL_BODY == EVAL_BODY_BUFFERED) { // not needed if EVAL_BODY_INCLUDE
68
try{
69                 if(bodyContent != null) {
70                     bodyContent.writeOut(bodyContent.getEnclosingWriter());
71                 }
72             } catch(java.io.IOException JavaDoc e){
73                 throw new JspTagException JavaDoc("IO Error: " + e.getMessage());
74             }
75         }
76         return SKIP_BODY;
77     }
78 }
79
Popular Tags