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 21 30 public class LeafConstraintsTag extends ContextReferrerTag implements NodeQueryContainer, QueryContainerReferrer { 31 32 private static final int ON_TEMPLATE = 1; 33 private static final int ON_TRUNK = 2; 34 private Attribute container = Attribute.NULL; 35 private Attribute onAttribute = Attribute.NULL; 36 private int on = 1; 37 private NodeQuery trunkClone; 38 39 protected GrowingTreeList tree; 40 41 public void setContainer(String c) throws JspTagException { 42 container = getAttribute(c); 43 } 44 45 public void setOn(String c) throws JspTagException { 46 onAttribute = getAttribute(c); 47 } 48 49 public Query getQuery() { 50 return getNodeQuery(); 51 } 52 public NodeQuery getNodeQuery() { 53 switch(on) { 54 case ON_TRUNK: 55 if (trunkClone == null) { 56 trunkClone = (NodeQuery) tree.getLeafQuery().clone(); 57 trunkClone.setConstraint(null); 58 } 59 return trunkClone; 60 case ON_TEMPLATE: 61 default: return tree.getLeafTemplate(); 62 } 63 } 64 65 public Cloud getCloudVar() throws JspTagException { 66 return getQuery().getCloud(); 67 } 68 69 70 public int doStartTag() throws JspTagException { 71 72 String o = onAttribute.getString(this); 73 if ("".equals(o)) { 74 on = ON_TEMPLATE; 75 } else if ("template".equals(o)) { 76 on = ON_TEMPLATE; 77 } else if ("trunk".equals(o)) { 78 on = ON_TRUNK; 79 } else { 80 throw new JspTagException ("Unknown value for 'on' attribute '" + o + "' (known are 'template' and 'trunk')"); 81 } 82 tree = ((TreeContainerTag) findParentTag(TreeContainerTag.class, (String ) container.getValue(this), true)).getTree(); 83 return EVAL_BODY; 84 } 85 86 public int doAfterBody() throws JspTagException { 87 if(trunkClone != null) { 88 tree.setLeafConstraint(trunkClone.getConstraint()); 89 } 90 tree = null; 92 trunkClone = null; 93 if (EVAL_BODY == EVAL_BODY_BUFFERED) { 94 try { 95 if (bodyContent != null) { 96 bodyContent.writeOut(bodyContent.getEnclosingWriter()); 97 } 98 } catch (java.io.IOException ioe){ 99 throw new JspTagException (ioe.toString()); 100 } 101 } 102 return SKIP_BODY; 103 } 104 105 } 106 | Popular Tags |