KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.servlet.jsp.JspTagException JavaDoc;
13
14 import org.mmbase.bridge.*;
15 import org.mmbase.storage.search.*;
16 import org.mmbase.bridge.jsp.taglib.containers.ListNodesContainerTag;
17 import org.mmbase.bridge.jsp.taglib.util.Attribute;
18 import org.mmbase.bridge.util.Queries;
19
20 /**
21  * ListNodesTag, provides functionality for listing single nodes in MMBase
22  *
23  * @author Kees Jongenburger
24  * @author Michiel Meeuwissen
25  * @author Pierre van Rooden
26  * @version $Id: ListNodesTag.java,v 1.28 2005/11/23 10:29:39 michiel Exp $
27  */

28
29 public class ListNodesTag extends AbstractNodeListTag {
30
31     protected Attribute type = Attribute.NULL;
32     protected Attribute container = Attribute.NULL;
33
34     protected Attribute path = Attribute.NULL;
35     protected Attribute element = Attribute.NULL;
36     protected Attribute searchDirs = Attribute.NULL;
37     protected Attribute nodes = Attribute.NULL;
38
39     protected Attribute distinct = Attribute.NULL;
40
41     public void setContainer(String JavaDoc c) throws JspTagException JavaDoc {
42         container = getAttribute(c);
43     }
44
45     /**
46      * @param t The name of a node manager
47      */

48     public void setType(String JavaDoc t) throws JspTagException JavaDoc {
49         type = getAttribute(t);
50     }
51
52
53     /**
54      * @since MMBase-1.7.1
55      */

56     public void setPath(String JavaDoc p) throws JspTagException JavaDoc {
57         path = getAttribute(p);
58     }
59     /**
60      * @since MMBase-1.7.1
61      */

62     public void setElement(String JavaDoc e) throws JspTagException JavaDoc {
63         element = getAttribute(e);
64     }
65     /**
66      * @since MMBase-1.7.1
67      */

68     public void setSearchdirs(String JavaDoc s) throws JspTagException JavaDoc {
69         searchDirs = getAttribute(s);
70     }
71     /**
72      * @since MMBase-1.7.1
73      */

74     public void setNodes(String JavaDoc n) throws JspTagException JavaDoc {
75        nodes = getAttribute(n);
76     }
77
78     /**
79      * @since MMBase-1.8
80      */

81     public void setDistinct(String JavaDoc d) throws JspTagException JavaDoc {
82         distinct = getAttribute(d);
83     }
84
85
86
87     /**
88      * @since MMBase-1.7
89      */

90     protected NodeQuery getQuery() throws JspTagException JavaDoc {
91         ListNodesContainerTag c = (ListNodesContainerTag) findParentTag(ListNodesContainerTag.class, (String JavaDoc) container.getValue(this), false);
92
93         NodeQuery query;
94         if (c == null || type != Attribute.NULL || path != Attribute.NULL) {
95             if (type == Attribute.NULL && path == Attribute.NULL) {
96                 throw new JspTagException JavaDoc("Attribute 'type' or 'path' must be provided in listnodes tag (unless referid is given, or used in listnodescontainer)");
97             }
98             if (type != Attribute.NULL) {
99                 if (path != Attribute.NULL) throw new JspTagException JavaDoc("Should specify either 'type' or 'path' attributes on listnodes");
100                 NodeManager nodeManager = getCloudVar().getNodeManager(type.getString(this));
101                 query = nodeManager.createQuery();
102             } else {
103                 query = getCloudVar().createNodeQuery();
104                 Queries.addPath(query, (String JavaDoc) path.getValue(this), (String JavaDoc) searchDirs.getValue(this));
105             
106                 if (element != Attribute.NULL) {
107                     String JavaDoc alias = element.getString(this);
108                     Step nodeStep = query.getStep(alias);
109                     if (nodeStep == null) {
110                         throw new JspTagException JavaDoc("Could not set element to '" + alias + "' (no such step)");
111                     }
112                     query.setNodeStep(nodeStep);
113                 } else {
114                     // default to first step
115
query.setNodeStep((Step) query.getSteps().get(0));
116                 }
117             }
118         } else {
119             query = (NodeQuery) c.getQuery();
120         }
121         if (constraints != Attribute.NULL) {
122             Queries.addConstraints(query, (String JavaDoc) constraints.getValue(this));
123         }
124         if (orderby != Attribute.NULL) {
125             Queries.addSortOrders(query, (String JavaDoc) orderby.getValue(this), (String JavaDoc) directions.getValue(this));
126         }
127         if (nodes != Attribute.NULL) {
128             Queries.addStartNodes(query, nodes.getString(this));
129         }
130         if (distinct != Attribute.NULL) {
131             query.setDistinct(distinct.getBoolean(this, false));
132         }
133         return query;
134     }
135
136     /**
137      * Performs the search
138      */

139     public int doStartTag() throws JspTagException JavaDoc {
140         int superresult = doStartTagHelper(); // the super-tag handles the use of referid...
141
if (superresult != NOT_HANDLED) {
142             return superresult;
143         }
144         NodesAndTrim result = getNodesAndTrim(getQuery());
145         return setReturnValues(result.nodeList, result.needsTrim);
146
147     }
148
149 }
150
Popular Tags