KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > bridge > jsp > taglib > HasRelationManagerTag


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;
11
12 import org.mmbase.bridge.jsp.taglib.util.Attribute;
13 import org.mmbase.bridge.jsp.taglib.Condition;
14 import org.mmbase.bridge.*;
15
16 import javax.servlet.jsp.JspTagException JavaDoc;
17 import org.mmbase.util.logging.Logger;
18 import org.mmbase.util.logging.Logging;
19
20
21
22 /**
23  * Straight-forward wrapper arround {@link org.mmbase.bridge.Cloud#hasRelationManager}.
24  *
25  * @author Michiel Meeuwissen
26  * @version $Id: HasRelationManagerTag.java,v 1.2 2005/11/23 10:26:31 michiel Exp $
27  * @since MMBase-1.8
28  */

29
30 public class HasRelationManagerTag extends CloudReferrerTag implements Condition {
31     private static final Logger log = Logging.getLoggerInstance(HasRelationManagerTag.class);
32     protected Attribute inverse = Attribute.NULL;
33     protected Attribute sourceManager = Attribute.NULL;
34     protected Attribute destinationManager = Attribute.NULL;
35     protected Attribute role = Attribute.NULL;
36
37     public void setInverse(String JavaDoc b) throws JspTagException JavaDoc {
38         inverse = getAttribute(b);
39     }
40     public void setSourcemanager(String JavaDoc n) throws JspTagException JavaDoc {
41         sourceManager = getAttribute(n);
42     }
43     public void setDestinationmanager(String JavaDoc n) throws JspTagException JavaDoc {
44         destinationManager = getAttribute(n);
45     }
46     public void setRole(String JavaDoc n) throws JspTagException JavaDoc {
47         role = getAttribute(n);
48     }
49
50
51     protected boolean getInverse() throws JspTagException JavaDoc {
52         return inverse.getBoolean(this, false);
53     }
54
55     protected NodeManager getNodeManager(Cloud cloud, Attribute a) throws JspTagException JavaDoc {
56         Object JavaDoc id = a.getValue(this);
57         if ("".equals(id)) id = null;
58         if (id == null) {
59             return cloud.getNodeManager("object");
60         } else {
61             if (id instanceof String JavaDoc) {
62                 return cloud.getNodeManager((String JavaDoc) id);
63             } else if (id instanceof NodeManager) {
64                 return (NodeManager) id;
65             } else if (id instanceof Node) {
66                 if (log.isDebugEnabled()) {
67                     log.debug("Taking nodemanager of node " + id);
68                 }
69                 return ((Node) id).getNodeManager();
70             } else {
71                 return cloud.getNodeManager(org.mmbase.util.Casting.toString(id));
72             }
73         }
74     }
75
76
77     public int doStartTag() throws JspTagException JavaDoc {
78         Cloud cloud = getCloudVar();
79         if (cloud.hasRelationManager(getNodeManager(cloud, sourceManager),
80                                      getNodeManager(cloud, destinationManager), role.getString(this)) != getInverse()) {
81             return EVAL_BODY;
82         } else {
83             return SKIP_BODY;
84         }
85     }
86     public int doAfterBody() throws JspTagException JavaDoc {
87         if (EVAL_BODY == EVAL_BODY_BUFFERED) { // not needed if EVAL_BODY_INCLUDE
88
try{
89                 if(bodyContent != null) {
90                     bodyContent.writeOut(bodyContent.getEnclosingWriter());
91                 }
92             } catch(java.io.IOException JavaDoc e){
93                 throw new JspTagException JavaDoc("IO Error: " + e.getMessage());
94             }
95         }
96         return SKIP_BODY;
97     }
98 }
99
Popular Tags