KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > bridge > jsp > taglib > containers > ListNodesContainerTag


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.containers;
11
12 import javax.servlet.jsp.JspTagException JavaDoc;
13
14 import org.mmbase.bridge.*;
15 import org.mmbase.bridge.util.Queries;
16 import org.mmbase.bridge.jsp.taglib.NodeReferrerTag;
17 import org.mmbase.bridge.jsp.taglib.util.Attribute;
18 import org.mmbase.cache.CachePolicy;
19 import org.mmbase.storage.search.*;
20
21 /**
22  * Container cognate for ListNodesTag.
23  *
24  * @author Michiel Meeuwissen
25  * @since MMBase-1.7
26  * @version $Id: ListNodesContainerTag.java,v 1.21 2006/07/04 12:16:09 michiel Exp $
27  */

28 public class ListNodesContainerTag extends NodeReferrerTag implements NodeQueryContainer {
29     // nodereferrer because RelatedNodesContainer extension
30

31     protected NodeQuery query = null;
32     protected Attribute cachePolicy = Attribute.NULL;
33     protected Attribute path = Attribute.NULL;
34     protected Attribute searchDirs = Attribute.NULL;
35     protected Attribute nodeManager = Attribute.NULL;
36     protected Attribute element = Attribute.NULL;
37     protected Attribute nodes = Attribute.NULL;
38     protected String JavaDoc jspVar = null;
39
40     /**
41      * @since MMBase-1.8.0
42      */

43     public void setCachepolicy(String JavaDoc t) throws JspTagException JavaDoc {
44         cachePolicy = getAttribute(t);
45     }
46
47     public void setType(String JavaDoc t) throws JspTagException JavaDoc {
48         nodeManager = getAttribute(t);
49     }
50
51     public void setPath(String JavaDoc t) throws JspTagException JavaDoc {
52         path = getAttribute(t);
53     }
54     public void setSearchdirs(String JavaDoc s) throws JspTagException JavaDoc {
55         searchDirs = getAttribute(s);
56     }
57
58     public void setElement(String JavaDoc e) throws JspTagException JavaDoc {
59         element = getAttribute(e);
60     }
61
62     /**
63      * @since MMBase-1.7.1
64      */

65     public void setNodes(String JavaDoc n) throws JspTagException JavaDoc {
66         nodes = getAttribute(n);
67     }
68
69     /**
70      * @since MMBase-1.8.1
71      */

72     public void setJspvar(String JavaDoc jv) {
73         jspVar = jv;
74     }
75
76
77     public Query getQuery() {
78         return getNodeQuery();
79     }
80
81     public NodeQuery getNodeQuery() {
82         if (query.isUsed()) query = (NodeQuery) query.clone();
83         return query;
84     }
85
86     // overridden from CloudReferrer.
87
public Cloud getCloudVar() throws JspTagException JavaDoc {
88         if (query == null) return super.getCloudVar(); // I think that this does not happen.
89
return query.getCloud();
90     }
91
92     public int doStartTag() throws JspTagException JavaDoc {
93         if (getReferid() != null) {
94             query = (NodeQuery) getContextProvider().getContextContainer().getObject(getReferid());
95             if (nodeManager != Attribute.NULL || path != Attribute.NULL || element != Attribute.NULL) {
96                 throw new JspTagException JavaDoc("Cannot use 'nodemanager', 'path' or 'element' attributes together with 'referid'");
97             }
98         } else {
99             if (nodeManager != Attribute.NULL) {
100                 query = super.getCloudVar().getNodeManager(nodeManager.getString(this)).createQuery();
101                 if (path != Attribute.NULL) throw new JspTagException JavaDoc("Should specify either 'type' or 'path' attributes on listnodescontainer");
102                 if (element != Attribute.NULL) throw new JspTagException JavaDoc("'element' can only be used in combination with 'path' attribute");
103             } else {
104                 if (path == Attribute.NULL) throw new JspTagException JavaDoc("Should specify either 'type' or 'path' attributes on listnodescontainer");
105
106                 query = super.getCloudVar().createNodeQuery();
107                 Queries.addPath(query, (String JavaDoc) path.getValue(this), (String JavaDoc) searchDirs.getValue(this));
108
109                 if (element != Attribute.NULL) {
110                     String JavaDoc alias = element.getString(this);
111                     Step nodeStep = query.getStep(alias);
112                     if (nodeStep == null) {
113                         throw new JspTagException JavaDoc("Could not set element to '" + alias + "' (no such step)");
114                     }
115                     query.setNodeStep(nodeStep);
116                 } else {
117                     // default to first step
118
query.setNodeStep((Step) query.getSteps().get(0));
119                 }
120             }
121         }
122         if (cachePolicy != Attribute.NULL) {
123             query.setCachePolicy(CachePolicy.getPolicy(cachePolicy.getValue(this)));
124         }
125
126         if (nodes != Attribute.NULL) {
127             Queries.addStartNodes(query, nodes.getString(this));
128         }
129
130         if (getId() != null) { // write to context.
131
getContextProvider().getContextContainer().register(getId(), query);
132         }
133         if (jspVar != null) {
134             pageContext.setAttribute(jspVar, query);
135         }
136
137         return EVAL_BODY;
138     }
139
140     public int doAfterBody() throws JspTagException JavaDoc {
141         if (EVAL_BODY == EVAL_BODY_BUFFERED) {
142             try {
143                 if (bodyContent != null) {
144                     bodyContent.writeOut(bodyContent.getEnclosingWriter());
145                 }
146             } catch (java.io.IOException JavaDoc ioe){
147                 throw new JspTagException JavaDoc(ioe.toString());
148             }
149         }
150         return SKIP_BODY;
151     }
152     public int doEndTag() throws JspTagException JavaDoc {
153         query = null;
154         return super.doEndTag();
155     }
156
157     public Object JavaDoc getCurrent() {
158         return null;
159     }
160
161 }
162
Popular Tags