KickJava   Java API By Example, From Geeks To Geeks.

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


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 import javax.servlet.jsp.*;
12
13 import org.mmbase.bridge.*;
14 import org.mmbase.bridge.jsp.taglib.util.Attribute;
15 import org.mmbase.util.logging.*;
16
17 /**
18  * The CountRelationsTag can be used as a child of a 'NodeProvider' tag to
19  * show the number of relations the node has.
20  *
21  * @author Jaco de Groot
22  * @author Michiel Meeuwissen
23  * @version $Id: CountRelationsTag.java,v 1.25 2005/06/20 16:03:38 michiel Exp $
24  */

25
26 public class CountRelationsTag extends NodeReferrerTag implements Writer {
27
28     private static final Logger log = Logging.getLoggerInstance(CountRelationsTag.class);
29     private Attribute type = Attribute.NULL;
30     private Attribute searchDir = Attribute.NULL;
31     private Attribute role = Attribute.NULL;
32
33     /**
34      * Set the type of related nodes wich should be counted. If not set all
35      * related nodes are counted.
36      */

37     public void setType(String JavaDoc type) throws JspTagException {
38         this.type = getAttribute(type);
39     }
40
41     public void setSearchdir(String JavaDoc s) throws JspTagException {
42         searchDir = getAttribute(s);
43     }
44
45     public void setRole(String JavaDoc r) throws JspTagException {
46         role = getAttribute(r);
47     }
48
49     public int doStartTag() throws JspTagException {
50         
51         if (getReferid() != null) {
52             helper.setValue(getContextProvider().getContextContainer().getObject(getReferid()));
53         } else {
54             log.debug("Search the node.");
55             Node node = getNode();
56             Cloud cloud = node.getCloud();
57             NodeManager other =
58                 type == Attribute.NULL ?
59                 cloud.getNodeManager("object") :
60                 cloud.getNodeManager(type.getString(this));
61             String JavaDoc direction = (String JavaDoc) searchDir.getValue(this);
62             if (direction == null) direction = "BOTH";
63             helper.setValue(new Integer JavaDoc(node.countRelatedNodes(other, (String JavaDoc) role.getValue(this), direction)));
64         }
65         if (getId() != null) {
66             getContextProvider().getContextContainer().register(getId(), helper.getValue());
67         }
68         return EVAL_BODY_BUFFERED;
69     }
70
71     public int doAfterBody() throws JspException {
72         return helper.doAfterBody();
73     }
74
75     public int doEndTag() throws JspTagException {
76         helper.doEndTag();
77         return super.doEndTag();
78
79     }
80 }
81
Popular Tags