KickJava   Java API By Example, From Geeks To Geeks.

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


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.NodeReferrerTag;
16
17 import javax.servlet.jsp.JspTagException JavaDoc;
18
19
20 /**
21  * A very simple tag to check if node may be changed.
22  *
23  * @author Michiel Meeuwissen
24  * @version $Id: MayWriteTag.java,v 1.10 2006/04/11 22:55:09 michiel Exp $
25  */

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