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.jsp.taglib.NodeReferrerTag; 16 import org.mmbase.bridge.jsp.taglib.util.Attribute; 17 import org.mmbase.bridge.util.Queries; 18 import org.mmbase.cache.CachePolicy; 19 import org.mmbase.storage.search.Step; 20 22 28 public class RelatedContainerTag extends NodeReferrerTag implements QueryContainer { 29 30 32 private Query query = null; 33 private Attribute cachePolicy = Attribute.NULL; 34 private Attribute path = Attribute.NULL; 35 private Attribute searchDirs = Attribute.NULL; 36 private Attribute fields = Attribute.NULL; 37 protected String jspVar = null; 38 39 public void setCachepolicy(String t) throws JspTagException { 40 cachePolicy = getAttribute(t); 41 } 42 43 public void setPath(String t) throws JspTagException { 44 path = getAttribute(t); 45 } 46 47 public void setSearchdirs(String s) throws JspTagException { 48 searchDirs = getAttribute(s); 49 } 50 51 52 public void setFields(String f) throws JspTagException { 53 fields = getAttribute(f); 54 } 55 56 59 public void setJspvar(String jv) { 60 jspVar = jv; 61 } 62 63 public Query getQuery() { 64 if (query.isUsed()) query = (Query) query.clone(); 65 return query; 66 } 67 68 69 70 public int doStartTag() throws JspTagException { 71 if (getReferid() != null) { 72 query = (Query) getContextProvider().getContextContainer().getObject(getReferid()); 73 } else { 74 if (path == Attribute.NULL) { 75 throw new JspTagException ("Path attribute is mandatory"); 76 } 77 Node node = getNode(); 78 Cloud cloud = node.getCloud(); 79 query = cloud.createQuery(); 80 81 Step step = query.addStep(node.getNodeManager()); 82 query.setAlias(step, node.getNodeManager().getName() + "0"); 83 query.addNode(step, node); 84 85 } 86 87 if (getId() != null) { getContextProvider().getContextContainer().register(getId(), query); 89 } 90 if (jspVar != null) { 91 pageContext.setAttribute(jspVar, query); 92 } 93 94 95 if (cachePolicy != Attribute.NULL) { 96 query.setCachePolicy(CachePolicy.getPolicy(cachePolicy.getValue(this))); 97 } 98 99 Queries.addPath(query, (String ) path.getValue(this), (String ) searchDirs.getValue(this)); 100 101 Queries.addFields(query, (String ) fields.getValue(this)); 102 103 return EVAL_BODY; 104 } 105 106 public int doAfterBody() throws JspTagException { 107 if(EVAL_BODY == EVAL_BODY_BUFFERED) { 108 try { 109 if (bodyContent != null) { 110 bodyContent.writeOut(bodyContent.getEnclosingWriter()); 111 } 112 } catch (java.io.IOException ioe){ 113 throw new JspTagException (ioe.toString()); 114 } 115 } 116 return SKIP_BODY; 117 } 118 public int doEndTag() throws JspTagException { 119 query = null; 120 return super.doEndTag(); 121 } 122 123 public Object getCurrent() { 124 return null; 125 } 126 127 } 128 | Popular Tags |