1 10 package org.mmbase.bridge.jsp.taglib.tree; 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.*; 17 import org.mmbase.bridge.jsp.taglib.util.*; 18 import org.mmbase.bridge.jsp.taglib.*; 19 import org.mmbase.bridge.util.*; 20 import org.mmbase.util.logging.*; 21 22 29 public class TreeContainerTag extends RelatedNodesContainerTag implements NodeQueryContainer, ContainerReferrer { 31 private static final Logger log = Logging.getLoggerInstance(TreeContainerTag.class); 32 33 protected Attribute maxDepth = Attribute.NULL; 34 protected Attribute container = Attribute.NULL; 35 private String jspVar; 36 37 public void setMaxdepth(String md) throws JspTagException { 38 maxDepth = getAttribute(md); 39 } 40 public void setContainer(String c) throws JspTagException { 41 container = getAttribute(c); 42 } 43 44 public void setJspvar(String jv) { 45 jspVar = jv; 46 } 47 48 protected GrowingTreeList tree; 49 50 public GrowingTreeList getTree() { 51 return tree; 52 } 53 54 55 public Query getQuery() { 56 return getNodeQuery(); 57 } 58 public NodeQuery getNodeQuery() { 59 return tree.getTemplate(); 60 } 61 62 66 static NodeQuery getStartQuery(ContextReferrerTag thisTag, Attribute containerAttribute, Attribute nodeAttribute) throws JspTagException { 67 NodeQuery query = null; 68 String container = containerAttribute.getString(thisTag); 69 String node = nodeAttribute.getString(thisTag); 70 if ("".equals(container) && "".equals(node)) { 71 log.debug("no node attribute, no container attribute, trying container first"); 72 NodeQueryContainer c = (NodeQueryContainer) thisTag.findParentTag(NodeQueryContainer.class, null, false); 73 if (c != null) { 74 query = c.getNodeQuery(); 75 } 76 } else if (! "".equals(container)) { 77 log.debug("container attribute, trying container"); 78 NodeQueryContainer c = (NodeQueryContainer) thisTag.findParentTag(NodeQueryContainer.class, container, true); 79 if (c != null) { 80 query = c.getNodeQuery(); 81 } 82 } 83 if (query == null) { log.debug("working as node-referrer"); 85 NodeProvider np = (NodeProvider) thisTag.findParentTag(NodeProvider.class, "".equals(node) ? null : node, ! "".equals(node)); 86 if (np == null) { 87 throw new TaglibException("No NodeQueryContainer nor a NodeProvider found in tree-tag"); 88 } else { 89 query = Queries.createNodeQuery(np.getNodeVar()); 90 } 91 } 92 return query; 93 94 } 95 96 97 void addBranch(NodeManager nodeManager, String r, String sd) { 98 tree.grow(nodeManager, r, sd); 99 } 100 101 public int doStartTag() throws JspTagException { 102 104 query = getStartQuery(this, container, parentNodeId); 105 106 107 if (nodeManager != Attribute.NULL) { 108 tree = new GrowingTreeList(query, 109 maxDepth.getInt(this, 5), 110 query.getCloud().getNodeManager(nodeManager.getString(this)), 111 role.getString(this), 112 searchDirs.getString(this)); 113 114 if (path != Attribute.NULL) throw new JspTagException ("Should specify either 'type' or 'path' attributes on treecontainer"); 115 } else { 116 tree = new GrowingTreeList(query, maxDepth.getInt(this, 5)); 117 if (path != Attribute.NULL) { 118 Queries.addPath(tree.getTemplate(), (String ) path.getValue(this), (String ) searchDirs.getValue(this)); 119 120 Step step = (Step) tree.getTemplate().getSteps().get(2); 122 if (query.getSteps().contains(step)) { 123 query.setNodeStep(step); 124 } 125 } 126 } 127 if (jspVar != null) { 128 pageContext.setAttribute(jspVar, tree); 129 } 130 return EVAL_BODY; 131 } 132 133 public int doAfterBody() throws JspTagException { 134 if (EVAL_BODY == EVAL_BODY_BUFFERED) { 135 try { 136 if (bodyContent != null) { 137 bodyContent.writeOut(bodyContent.getEnclosingWriter()); 138 } 139 } catch (java.io.IOException ioe){ 140 throw new JspTagException (ioe.toString()); 141 } 142 } 143 return SKIP_BODY; 144 } 145 public int doEndTag() throws JspTagException { 146 tree = null; 147 return super.doEndTag(); 148 } 149 150 } 151 | Popular Tags |