KickJava   Java API By Example, From Geeks To Geeks.

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


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.JspTagException JavaDoc;
12
13 import org.mmbase.bridge.*;
14 import org.mmbase.bridge.util.NodeWrapper;
15
16 import org.mmbase.bridge.jsp.taglib.util.Attribute;
17 import org.mmbase.util.logging.*;
18
19 /**
20  * Like listnodes tag, but is is also a node-referrer, and substracts the related nodes of the referred node.
21  *
22  * @author Michiel Meeuwissen
23  * @version $Id: UnRelatedNodesTag.java,v 1.9 2005/03/14 19:02:35 michiel Exp $
24  * @since MMBase-1.7
25  */

26
27 public class UnRelatedNodesTag extends ListNodesTag {
28     private static final Logger log = Logging.getLoggerInstance(UnRelatedNodesTag.class);
29
30     protected Attribute role = Attribute.NULL;
31     protected Attribute searchDir = Attribute.NULL;
32     protected Attribute excludeSelf = Attribute.NULL;
33
34
35     public void setRole(String JavaDoc role) throws JspTagException JavaDoc {
36         this.role = getAttribute(role);
37     }
38
39     public void setSearchdir(String JavaDoc search) throws JspTagException JavaDoc {
40         searchDir = getAttribute(search);
41     }
42
43     public void setExcludeself(String JavaDoc e) throws JspTagException JavaDoc {
44         excludeSelf = getAttribute(e);
45     }
46
47
48
49     /**
50      * Performs the search
51      */

52     public int doStartTag() throws JspTagException JavaDoc {
53         int superresult = doStartTagHelper(); // the super-tag handles the use of referid...
54
if (superresult != NOT_HANDLED) {
55             return superresult;
56         }
57         // obtain a reference to the node through a parent tag
58
Node parentNode = getNode();
59
60         if (parentNode == null) {
61             throw new JspTagException JavaDoc("Could not find parent node!!");
62         }
63
64         NodeQuery query = getQuery();
65
66         NodeList relatedNodes = parentNode.getRelatedNodes(query.getNodeManager(), (String JavaDoc) role.getValue(this), (String JavaDoc) searchDir.getValue(this));
67
68         NodesAndTrim result = getNodesAndTrim(query, relatedNodes.size() + 1); // query a bit more in case relatedNodes are subtracted
69

70
71         if (excludeSelf.getBoolean(this, false)) {
72             result.nodeList.remove(parentNode);
73         }
74         result.nodeList.removeAll(relatedNodes);
75
76         return setReturnValues(result.nodeList, result.needsTrim);
77
78     }
79
80
81 }
82
83
Popular Tags