1 10 package org.mmbase.bridge.jsp.taglib.containers; 11 12 import javax.servlet.jsp.JspTagException ; 13 14 import org.mmbase.bridge.*; 15 import org.mmbase.bridge.util.Queries; 16 import org.mmbase.bridge.jsp.taglib.NodeReferrerTag; 17 import org.mmbase.bridge.jsp.taglib.util.Attribute; 18 import org.mmbase.cache.CachePolicy; 19 import org.mmbase.storage.search.*; 20 21 28 public class ListNodesContainerTag extends NodeReferrerTag implements NodeQueryContainer { 29 31 protected NodeQuery query = null; 32 protected Attribute cachePolicy = Attribute.NULL; 33 protected Attribute path = Attribute.NULL; 34 protected Attribute searchDirs = Attribute.NULL; 35 protected Attribute nodeManager = Attribute.NULL; 36 protected Attribute element = Attribute.NULL; 37 protected Attribute nodes = Attribute.NULL; 38 protected String jspVar = null; 39 40 43 public void setCachepolicy(String t) throws JspTagException { 44 cachePolicy = getAttribute(t); 45 } 46 47 public void setType(String t) throws JspTagException { 48 nodeManager = getAttribute(t); 49 } 50 51 public void setPath(String t) throws JspTagException { 52 path = getAttribute(t); 53 } 54 public void setSearchdirs(String s) throws JspTagException { 55 searchDirs = getAttribute(s); 56 } 57 58 public void setElement(String e) throws JspTagException { 59 element = getAttribute(e); 60 } 61 62 65 public void setNodes(String n) throws JspTagException { 66 nodes = getAttribute(n); 67 } 68 69 72 public void setJspvar(String jv) { 73 jspVar = jv; 74 } 75 76 77 public Query getQuery() { 78 return getNodeQuery(); 79 } 80 81 public NodeQuery getNodeQuery() { 82 if (query.isUsed()) query = (NodeQuery) query.clone(); 83 return query; 84 } 85 86 public Cloud getCloudVar() throws JspTagException { 88 if (query == null) return super.getCloudVar(); return query.getCloud(); 90 } 91 92 public int doStartTag() throws JspTagException { 93 if (getReferid() != null) { 94 query = (NodeQuery) getContextProvider().getContextContainer().getObject(getReferid()); 95 if (nodeManager != Attribute.NULL || path != Attribute.NULL || element != Attribute.NULL) { 96 throw new JspTagException ("Cannot use 'nodemanager', 'path' or 'element' attributes together with 'referid'"); 97 } 98 } else { 99 if (nodeManager != Attribute.NULL) { 100 query = super.getCloudVar().getNodeManager(nodeManager.getString(this)).createQuery(); 101 if (path != Attribute.NULL) throw new JspTagException ("Should specify either 'type' or 'path' attributes on listnodescontainer"); 102 if (element != Attribute.NULL) throw new JspTagException ("'element' can only be used in combination with 'path' attribute"); 103 } else { 104 if (path == Attribute.NULL) throw new JspTagException ("Should specify either 'type' or 'path' attributes on listnodescontainer"); 105 106 query = super.getCloudVar().createNodeQuery(); 107 Queries.addPath(query, (String ) path.getValue(this), (String ) searchDirs.getValue(this)); 108 109 if (element != Attribute.NULL) { 110 String alias = element.getString(this); 111 Step nodeStep = query.getStep(alias); 112 if (nodeStep == null) { 113 throw new JspTagException ("Could not set element to '" + alias + "' (no such step)"); 114 } 115 query.setNodeStep(nodeStep); 116 } else { 117 query.setNodeStep((Step) query.getSteps().get(0)); 119 } 120 } 121 } 122 if (cachePolicy != Attribute.NULL) { 123 query.setCachePolicy(CachePolicy.getPolicy(cachePolicy.getValue(this))); 124 } 125 126 if (nodes != Attribute.NULL) { 127 Queries.addStartNodes(query, nodes.getString(this)); 128 } 129 130 if (getId() != null) { getContextProvider().getContextContainer().register(getId(), query); 132 } 133 if (jspVar != null) { 134 pageContext.setAttribute(jspVar, query); 135 } 136 137 return EVAL_BODY; 138 } 139 140 public int doAfterBody() throws JspTagException { 141 if (EVAL_BODY == EVAL_BODY_BUFFERED) { 142 try { 143 if (bodyContent != null) { 144 bodyContent.writeOut(bodyContent.getEnclosingWriter()); 145 } 146 } catch (java.io.IOException ioe){ 147 throw new JspTagException (ioe.toString()); 148 } 149 } 150 return SKIP_BODY; 151 } 152 public int doEndTag() throws JspTagException { 153 query = null; 154 return super.doEndTag(); 155 } 156 157 public Object getCurrent() { 158 return null; 159 } 160 161 } 162 | Popular Tags |