KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > applications > community > taglib > TreeTag


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.applications.community.taglib;
11
12 import java.util.*;
13
14 import javax.servlet.jsp.JspTagException JavaDoc;
15
16 import org.mmbase.bridge.*;
17 import org.mmbase.bridge.jsp.taglib.*;
18 import org.mmbase.bridge.jsp.taglib.util.Attribute;
19 import org.mmbase.util.logging.Logger;
20 import org.mmbase.util.logging.Logging;
21
22 /**
23  * TreeTag, provides functionality for listing messages in community.
24  *
25  * @author Pierre van Rooden
26  * @author Michiel Meeuwissen
27  * @version $Id: TreeTag.java,v 1.18 2006/08/30 18:06:26 michiel Exp $
28  */

29  
30 public class TreeTag extends AbstractNodeListTag {
31    
32     private static final Logger log = Logging.getLoggerInstance(TreeTag.class);
33
34     private Attribute thread = Attribute.NULL;
35     private Attribute fieldList= Attribute.NULL;
36     private Attribute maxdepth= Attribute.NULL;
37     private Attribute startafternode = Attribute.NULL;
38     private Attribute startaftersequence = Attribute.NULL;
39     private Attribute type = Attribute.NULL;
40     private Attribute openTag = Attribute.NULL;
41     private Attribute closeTag = Attribute.NULL;
42
43     protected Module community = null;
44
45     public void setThread(String JavaDoc thread) throws JspTagException JavaDoc {
46         this.thread = getAttribute(thread);
47     }
48
49     public void setType(String JavaDoc type) throws JspTagException JavaDoc { // not used
50
this.type = getAttribute(type);
51     }
52     protected String JavaDoc getType() throws JspTagException JavaDoc {
53         if (type == Attribute.NULL) return "message";
54         return type.getString(this);
55     }
56
57     public void setFields(String JavaDoc fields) throws JspTagException JavaDoc {
58         fieldList = getAttribute(fields);
59     }
60     protected List getFields(String JavaDoc fields) {
61         List res = new ArrayList();
62         StringTokenizer st = new StringTokenizer(fields, ",");
63         while(st.hasMoreTokens()){
64             res.add(st.nextToken().trim());
65         }
66         return res;
67     }
68
69     private List getDefaultFields() {
70         return getFields("number,listhead,depth,listtail,subject,timestamp,replycount,info");
71     }
72
73     public void setMaxdepth(String JavaDoc maxdepth) throws JspTagException JavaDoc {
74         this.maxdepth = getAttribute(maxdepth);
75     }
76
77     public void setStartafternode(String JavaDoc startafternode) throws JspTagException JavaDoc {
78         this.startafternode = getAttribute(startafternode);
79     }
80
81     public void setStartaftersequence(String JavaDoc startaftersequence) throws JspTagException JavaDoc {
82         this.startaftersequence = getAttribute(startaftersequence);
83     }
84
85     public void setOpenTag(String JavaDoc tag) throws JspTagException JavaDoc {
86         this.openTag = getAttribute(tag);
87     }
88
89     public void setCloseTag(String JavaDoc tag) throws JspTagException JavaDoc {
90         this.closeTag = getAttribute(tag);
91     }
92
93     /**
94      *
95      */

96     public int doStartTag() throws JspTagException JavaDoc {
97       int superresult = doStartTagHelper(); // the super-tag handles the use of referid...
98
if (superresult != NOT_HANDLED) {
99             return superresult;
100         }
101
102         if (thread == Attribute.NULL) throw new JspTagException JavaDoc("Attribute thread has not been specified");
103
104         //this is where we do the seach
105
community = getCloudContext().getModule("communityprc");
106         Hashtable params = new Hashtable();
107         params.put("NODE", thread.getString(this));
108
109         List fields;
110         if (fieldList == Attribute.NULL) {
111             fields = getDefaultFields();
112         } else {
113             fields = getFields(fieldList.getString(this));
114         }
115         params.put("FIELDS", new Vector(fields));
116         // if you don't supply Vector but the ArrayList, then it goes terrible wrong (without clear message).
117

118         try {
119             Cloud cloud = getCloudVar();
120             params.put("CLOUD", cloud);
121         } catch (JspTagException JavaDoc e) {
122             log.debug(e.toString());
123         }
124
125         Attribute max = listHelper.getMax();
126         Attribute offset = listHelper.getOffset();
127         if (orderby != Attribute.NULL) params.put("SORTFIELDS", orderby.getString(this));
128         if (directions != Attribute.NULL) params.put("SORTDIRS", directions.getString(this));
129         if (maxdepth != Attribute.NULL) params.put("MAXDEPTH", maxdepth.getString(this));
130         if (offset != Attribute.NULL) params.put("FROMCOUNT", "" + offset.getInt(this, 0));
131         if (max != Attribute.NULL) params.put("MAXCOUNT", max.getString(this));
132         if (startafternode != Attribute.NULL) {
133             params.put("STARTAFTERNODE", startafternode.getString(this));
134         } else if (startaftersequence != Attribute.NULL) {
135             params.put("STARTAFTERSEQUENCE",startaftersequence.getString(this));
136         }
137         if (openTag != Attribute.NULL) params.put("OPENTAG", openTag.getString(this));
138         if (closeTag != Attribute.NULL) params.put("CLOSETAG", closeTag.getString(this));
139
140         NodeList nodes = community.getList("TREE", params,
141                                            pageContext.getRequest(),
142                                            pageContext.getResponse());
143         if (log.isDebugEnabled()) {
144             log.debug("Found " + nodes + " with " + params);
145         }
146         return setReturnValues(nodes, false);
147     }
148
149 }
150
151
Popular Tags