1 10 package org.mmbase.bridge.jsp.taglib; 11 12 import javax.servlet.jsp.JspTagException ; 13 14 import org.mmbase.bridge.*; 15 import org.mmbase.bridge.jsp.taglib.containers.*; 16 import org.mmbase.bridge.jsp.taglib.util.Attribute; 17 import org.mmbase.bridge.util.Queries; 18 import org.mmbase.util.logging.*; 19 20 29 30 public class ListTag extends AbstractNodeListTag implements ClusterNodeProvider { 31 private static final Logger log = Logging.getLoggerInstance(ListTag.class); 32 33 protected Attribute nodes = Attribute.NULL; 34 protected Attribute path = Attribute.NULL; 35 protected Attribute distinct = Attribute.NULL; 36 protected Attribute search = Attribute.NULL; 37 protected Attribute fields = Attribute.NULL; 38 protected Attribute container = Attribute.NULL; 39 40 43 public void setFields(String fields) throws JspTagException { 44 this.fields = getAttribute(fields); 45 } 46 47 public void setContainer(String c) throws JspTagException { 48 container = getAttribute(c); 49 } 50 51 58 public void setNodes(String nodes) throws JspTagException { 59 this.nodes = getAttribute(nodes); 62 } 63 64 67 public void setPath(String path) throws JspTagException { 68 this.path = getAttribute(path); 69 } 70 71 77 public void setSearchdir(String search) throws JspTagException { 78 this.search = getAttribute(search); 79 if (log.isDebugEnabled()) 80 log.debug("Setting search dir to " + this.search); 81 } 82 83 86 public void setDistinct(String distinct) throws JspTagException { 87 this.distinct = getAttribute(distinct); 88 } 89 90 93 protected String getSearchNodes() throws JspTagException { 94 if (nodes != Attribute.NULL) { 95 return nodes.getString(this); 96 } else { 97 return ""; 98 } 99 } 100 101 104 protected String getPath() throws JspTagException { 105 return path.getString(this); 106 } 107 108 protected QueryContainer getListContainer() throws JspTagException { 109 return (QueryContainer) findParentTag(ListContainerTag.class, (String ) container.getValue(this), false); 110 } 111 112 115 public int doStartTag() throws JspTagException { 116 int superresult = doStartTagHelper(); 117 if (superresult != NOT_HANDLED) { 118 return superresult; 119 } 120 QueryContainer c = getListContainer(); 121 122 123 Query query; 124 if (c == null || path != Attribute.NULL) { 125 if (path == Attribute.NULL) { 127 throw new JspTagException ("Path attribute is mandatory if referid not speficied"); 128 } 129 130 String distinctString = distinct.getString(this).toLowerCase(); 131 boolean searchDistinct = false; 132 if ("true".equals(distinctString) || "yes".equals(distinctString)) { 133 searchDistinct = true; 134 } 135 136 137 String searchString = search.getString(this).toUpperCase(); 138 if (searchString.equals("")) { 139 searchString = "BOTH"; 140 } else if ( 141 !searchString.equals("BOTH") 142 && !searchString.equals("EITHER") 143 && !searchString.equals("SOURCE") 144 && !searchString.equals("DESTINATION") 145 && !searchString.equals("ALL")) { 146 throw new JspTagException ("Search should be one of BOTH, SOURCE, " + "DESTINATION, EITHER, or ALL (value found was " + searchString + ")"); 147 } 148 149 if (log.isDebugEnabled()) { 150 log.debug("pathstring " + path.getString(this)); 151 log.debug("directions " + directions); 152 log.debug("searchString " + searchString); 153 } 154 155 query = Queries.createQuery(getCloudVar(), 156 getSearchNodes(), 157 getPath(), 158 fields.getString(this), 159 (String ) constraints.getValue(this), 160 (String ) orderby.getValue(this), 161 (String ) directions.getValue(this), 162 searchString, 163 searchDistinct); 164 } else { if (path != Attribute.NULL || search != Attribute.NULL) { 166 throw new JspTagException ("search and path attributes not supported within a container."); 167 } 168 169 query = c.getQuery(); 170 if (constraints != Attribute.NULL) { 171 Queries.addConstraints(query, (String ) constraints.getValue(this)); 172 } 173 if (orderby != Attribute.NULL) { 174 Queries.addSortOrders(query, (String ) orderby.getValue(this), (String ) directions.getValue(this)); 175 } 176 177 if (fields != Attribute.NULL) { 178 query.removeFields(); 179 Queries.addFields(query, fields.getString(this)); 180 } 181 if (distinct != Attribute.NULL) { 182 query.setDistinct(distinct.getBoolean(this, false)); 183 } 184 if (nodes != Attribute.NULL) { 185 Queries.addStartNodes(query, nodes.getString(this)); 186 } 187 188 } 189 190 NodesAndTrim result = getNodesAndTrim(query); 191 return setReturnValues(result.nodeList, result.needsTrim); 192 193 } 194 195 } 196 | Popular Tags |