1 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 ; 17 import org.mmbase.util.logging.Logger; 18 import org.mmbase.util.logging.Logging; 19 20 21 22 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 b) throws JspTagException { 38 inverse = getAttribute(b); 39 } 40 public void setSourcemanager(String n) throws JspTagException { 41 sourceManager = getAttribute(n); 42 } 43 public void setDestinationmanager(String n) throws JspTagException { 44 destinationManager = getAttribute(n); 45 } 46 public void setRole(String n) throws JspTagException { 47 role = getAttribute(n); 48 } 49 50 51 protected boolean getInverse() throws JspTagException { 52 return inverse.getBoolean(this, false); 53 } 54 55 protected NodeManager getNodeManager(Cloud cloud, Attribute a) throws JspTagException { 56 Object 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 ) { 62 return cloud.getNodeManager((String ) 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 { 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 { 87 if (EVAL_BODY == EVAL_BODY_BUFFERED) { try{ 89 if(bodyContent != null) { 90 bodyContent.writeOut(bodyContent.getEnclosingWriter()); 91 } 92 } catch(java.io.IOException e){ 93 throw new JspTagException ("IO Error: " + e.getMessage()); 94 } 95 } 96 return SKIP_BODY; 97 } 98 } 99 | Popular Tags |