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.storage.search.*; 16 import org.mmbase.bridge.jsp.taglib.containers.ListNodesContainerTag; 17 import org.mmbase.bridge.jsp.taglib.util.Attribute; 18 import org.mmbase.bridge.util.Queries; 19 20 28 29 public class ListNodesTag extends AbstractNodeListTag { 30 31 protected Attribute type = Attribute.NULL; 32 protected Attribute container = Attribute.NULL; 33 34 protected Attribute path = Attribute.NULL; 35 protected Attribute element = Attribute.NULL; 36 protected Attribute searchDirs = Attribute.NULL; 37 protected Attribute nodes = Attribute.NULL; 38 39 protected Attribute distinct = Attribute.NULL; 40 41 public void setContainer(String c) throws JspTagException { 42 container = getAttribute(c); 43 } 44 45 48 public void setType(String t) throws JspTagException { 49 type = getAttribute(t); 50 } 51 52 53 56 public void setPath(String p) throws JspTagException { 57 path = getAttribute(p); 58 } 59 62 public void setElement(String e) throws JspTagException { 63 element = getAttribute(e); 64 } 65 68 public void setSearchdirs(String s) throws JspTagException { 69 searchDirs = getAttribute(s); 70 } 71 74 public void setNodes(String n) throws JspTagException { 75 nodes = getAttribute(n); 76 } 77 78 81 public void setDistinct(String d) throws JspTagException { 82 distinct = getAttribute(d); 83 } 84 85 86 87 90 protected NodeQuery getQuery() throws JspTagException { 91 ListNodesContainerTag c = (ListNodesContainerTag) findParentTag(ListNodesContainerTag.class, (String ) container.getValue(this), false); 92 93 NodeQuery query; 94 if (c == null || type != Attribute.NULL || path != Attribute.NULL) { 95 if (type == Attribute.NULL && path == Attribute.NULL) { 96 throw new JspTagException ("Attribute 'type' or 'path' must be provided in listnodes tag (unless referid is given, or used in listnodescontainer)"); 97 } 98 if (type != Attribute.NULL) { 99 if (path != Attribute.NULL) throw new JspTagException ("Should specify either 'type' or 'path' attributes on listnodes"); 100 NodeManager nodeManager = getCloudVar().getNodeManager(type.getString(this)); 101 query = nodeManager.createQuery(); 102 } else { 103 query = getCloudVar().createNodeQuery(); 104 Queries.addPath(query, (String ) path.getValue(this), (String ) searchDirs.getValue(this)); 105 106 if (element != Attribute.NULL) { 107 String alias = element.getString(this); 108 Step nodeStep = query.getStep(alias); 109 if (nodeStep == null) { 110 throw new JspTagException ("Could not set element to '" + alias + "' (no such step)"); 111 } 112 query.setNodeStep(nodeStep); 113 } else { 114 query.setNodeStep((Step) query.getSteps().get(0)); 116 } 117 } 118 } else { 119 query = (NodeQuery) c.getQuery(); 120 } 121 if (constraints != Attribute.NULL) { 122 Queries.addConstraints(query, (String ) constraints.getValue(this)); 123 } 124 if (orderby != Attribute.NULL) { 125 Queries.addSortOrders(query, (String ) orderby.getValue(this), (String ) directions.getValue(this)); 126 } 127 if (nodes != Attribute.NULL) { 128 Queries.addStartNodes(query, nodes.getString(this)); 129 } 130 if (distinct != Attribute.NULL) { 131 query.setDistinct(distinct.getBoolean(this, false)); 132 } 133 return query; 134 } 135 136 139 public int doStartTag() throws JspTagException { 140 int superresult = doStartTagHelper(); if (superresult != NOT_HANDLED) { 142 return superresult; 143 } 144 NodesAndTrim result = getNodesAndTrim(getQuery()); 145 return setReturnValues(result.nodeList, result.needsTrim); 146 147 } 148 149 } 150 | Popular Tags |