KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > bridge > jsp > taglib > functions > NodeListFunctionTag


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.functions;
11
12 import java.util.Collection JavaDoc;
13
14 import javax.servlet.jsp.*;
15
16 import org.mmbase.bridge.*;
17 import org.mmbase.bridge.jsp.taglib.*;
18 import org.mmbase.bridge.jsp.taglib.containers.FunctionContainerReferrer;
19 import org.mmbase.bridge.jsp.taglib.util.ContextContainer;
20 import org.mmbase.util.logging.*;
21
22 /**
23  * A function tag for functions returning a NodeList. The result is iterated.
24  *
25  * This is one of the most straightforward ListProvider/NodeProvider implementations, you could use it as a template.
26  *
27  * @author Michiel Meeuwissen
28  * @since MMBase-1.7
29  * @version $Id: NodeListFunctionTag.java,v 1.15 2006/07/17 15:38:47 johannes Exp $
30  */

31 public class NodeListFunctionTag extends AbstractFunctionTag implements ListProvider, FunctionContainerReferrer, NodeProvider {
32
33     private static final Logger log = Logging.getLoggerInstance(NodeListFunctionTag.class);
34
35     //cannot extend AbstractNodeList because we extend AbstractFunctionTag already.
36
//even proxies are no option because I do not instantiate nor call these tag objects.
37
//therefore, all this stuff with helpers.
38
private NodeProviderHelper nodeHelper = new NodeProviderHelper(this);
39     private NodeListHelper listHelper = new NodeListHelper(this, nodeHelper);
40
41
42     // implementation of NodeProvider
43
public Node getNodeVar() throws JspTagException {
44         return nodeHelper.getNodeVar();
45     }
46
47     public Query getGeneratingQuery() throws JspTagException {
48         return nodeHelper.getGeneratingQuery();
49     }
50     /**
51      * @since MMBase-1.8
52      */

53     public void setCommitonclose(String JavaDoc c) throws JspTagException {
54         nodeHelper.setCommitonclose(c);
55     }
56
57     public void setJspvar(String JavaDoc jv) {
58         nodeHelper.setJspvar(jv);
59     }
60
61     // implementation of ListProvider
62
public int size() {
63         return listHelper.size();
64     }
65
66     public int getIndex() {
67         return listHelper.getIndex();
68     }
69
70     public int getIndexOffset() {
71         return listHelper.getIndexOffset();
72     }
73
74     public boolean isChanged() {
75         return listHelper.isChanged();
76     }
77
78     public Object JavaDoc getCurrent() {
79         return listHelper.getCurrent();
80     }
81
82     public void remove() {
83         listHelper.remove();
84     }
85
86     // extra stuff (should perhaps be part of ListProvider interface)
87
public void setMax(String JavaDoc m) throws JspTagException {
88         listHelper.setMax(m);
89     }
90
91     public void setOffset(String JavaDoc o) throws JspTagException {
92         listHelper.setOffset(o);
93     }
94
95     public void setComparator(String JavaDoc c) throws JspTagException {
96         listHelper.setComparator(c);
97     }
98
99     public ContextContainer getContextContainer() throws JspTagException {
100         return listHelper.getContextContainer();
101     }
102
103     public int doStartTag() throws JspTagException {
104         NodeList list;
105         Object JavaDoc value = getFunctionValue(false);
106
107         /* should be something like:
108
109         NodeList list = Casting.toNodeList(getCloudVar(), value);
110
111         */

112         if (value instanceof NodeList) {
113             list = (NodeList) value;
114         } else {
115             list = getCloudVar().createNodeList();
116             if (value != null) {
117                 list.addAll((Collection JavaDoc) value);
118             }
119         }
120         listHelper.doStartTagHelper();
121         return listHelper.setReturnValues(list, true);
122     }
123
124     public int doAfterBody() throws JspException {
125         log.debug("doafterbody");
126         nodeHelper.doAfterBody();
127         return listHelper.doAfterBody();
128     }
129
130     public int doEndTag() throws JspTagException {
131         super.doEndTag();
132         listHelper.doEndTag();
133         return nodeHelper.doEndTag();
134     }
135
136     public void doFinally() {
137         listHelper.doFinally();
138         nodeHelper.doFinally();
139     }
140
141     public javax.servlet.jsp.jstl.core.LoopTagStatus getLoopStatus() {
142         return new ListProviderLoopTagStatus(this);
143     }
144 }
145
146
Popular Tags