KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.servlet.jsp.JspTagException JavaDoc;
13 import org.mmbase.bridge.Node;
14 import org.mmbase.bridge.RelationManager;
15 import org.mmbase.bridge.jsp.taglib.Condition;
16 import org.mmbase.bridge.jsp.taglib.util.Attribute;
17
18 import org.mmbase.util.logging.Logger;
19 import org.mmbase.util.logging.Logging;
20
21
22 /**
23  * A very simple tag to check if a relation may be created. It needs two nodes.
24  *
25  * @author Jaco de Groot
26  * @author Michiel Meeuwissen
27  * @version $Id: MayCreateRelationTag.java,v 1.13 2006/04/11 22:55:02 michiel Exp $
28  */

29
30 public class MayCreateRelationTag extends MayWriteTag implements Condition {
31     
32     private static final Logger log = Logging.getLoggerInstance(MayCreateRelationTag.class);
33
34     private Attribute role = Attribute.NULL;
35     private Attribute source = Attribute.NULL;
36     private Attribute destination = Attribute.NULL;
37
38     public void setRole(String JavaDoc r) throws JspTagException JavaDoc {
39         role = getAttribute(r);
40     }
41
42     public void setSource(String JavaDoc s) throws JspTagException JavaDoc {
43         source = getAttribute(s);
44     }
45
46     public void setDestination(String JavaDoc d) throws JspTagException JavaDoc {
47         destination = getAttribute(d);
48     }
49
50     public int doStartTag() throws JspTagException JavaDoc {
51         String JavaDoc roleStr = role.getString(this);
52         RelationManager rm = getCloudVar().getRelationManager(roleStr);
53         Node sourceNode = getNode(source.getString(this));
54         Node destinationNode = getNode(destination.getString(this));
55         
56         boolean hasRelationManager = getCloudVar().hasRelationManager(sourceNode.getNodeManager(),
57                                                             destinationNode.getNodeManager(), roleStr);
58         if ((hasRelationManager && rm.mayCreateRelation(sourceNode, destinationNode)) != getInverse()) {
59             return EVAL_BODY;
60         } else {
61             return SKIP_BODY;
62         }
63
64     }
65 }
66
Popular Tags