1 10 package org.mmbase.applications.community.taglib; 11 12 import java.util.*; 13 14 import javax.servlet.jsp.JspTagException ; 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 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 thread) throws JspTagException { 46 this.thread = getAttribute(thread); 47 } 48 49 public void setType(String type) throws JspTagException { this.type = getAttribute(type); 51 } 52 protected String getType() throws JspTagException { 53 if (type == Attribute.NULL) return "message"; 54 return type.getString(this); 55 } 56 57 public void setFields(String fields) throws JspTagException { 58 fieldList = getAttribute(fields); 59 } 60 protected List getFields(String 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 maxdepth) throws JspTagException { 74 this.maxdepth = getAttribute(maxdepth); 75 } 76 77 public void setStartafternode(String startafternode) throws JspTagException { 78 this.startafternode = getAttribute(startafternode); 79 } 80 81 public void setStartaftersequence(String startaftersequence) throws JspTagException { 82 this.startaftersequence = getAttribute(startaftersequence); 83 } 84 85 public void setOpenTag(String tag) throws JspTagException { 86 this.openTag = getAttribute(tag); 87 } 88 89 public void setCloseTag(String tag) throws JspTagException { 90 this.closeTag = getAttribute(tag); 91 } 92 93 96 public int doStartTag() throws JspTagException { 97 int superresult = doStartTagHelper(); if (superresult != NOT_HANDLED) { 99 return superresult; 100 } 101 102 if (thread == Attribute.NULL) throw new JspTagException ("Attribute thread has not been specified"); 103 104 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 118 try { 119 Cloud cloud = getCloudVar(); 120 params.put("CLOUD", cloud); 121 } catch (JspTagException 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 |