1 10 package org.mmbase.bridge.jsp.taglib.containers; 11 12 import java.util.*; 13 14 import javax.servlet.jsp.JspTagException ; 15 16 import org.mmbase.bridge.Query; 17 import org.mmbase.bridge.jsp.taglib.CloudReferrerTag; 18 import org.mmbase.bridge.jsp.taglib.util.Attribute; 19 import org.mmbase.bridge.util.Queries; 20 import org.mmbase.storage.search.*; 21 22 30 public class QueryCompositeConstraintTag extends CloudReferrerTag implements QueryContainerReferrer { 31 32 34 protected Attribute container = Attribute.NULL; 35 36 protected Attribute operator = Attribute.NULL; 37 38 private List constraints; 39 40 public void setContainer(String c) throws JspTagException { 41 container = getAttribute(c); 42 } 43 44 public void setOperator(String o) throws JspTagException { 45 operator = getAttribute(o); 46 } 47 48 protected int getOperator() throws JspTagException { 49 String op = operator.getString(this).toUpperCase(); 50 if (op.equals("OR")) { 51 return CompositeConstraint.LOGICAL_OR; 52 } else if (op.equals("AND") || op.equals("")) { 53 return CompositeConstraint.LOGICAL_AND; 54 } else { 55 throw new JspTagException ("Unknown Field Compare Operator '" + op + "'"); 56 } 57 } 58 59 public void addChildConstraint(Constraint cons) throws JspTagException { 60 constraints.add(cons); 61 } 62 63 private Constraint addConstraint(Query query, int op, List constraints) throws JspTagException { 64 Constraint newConstraint = null; 65 for (Iterator i = constraints.iterator(); i.hasNext();) { 66 Constraint constraint = (Constraint) i.next(); 67 if (newConstraint == null) { 68 newConstraint = constraint; 69 } else { 70 newConstraint = query.createConstraint(newConstraint, op, constraint); 71 } 72 } 73 if (newConstraint != null) { 74 QueryCompositeConstraintTag cons = (QueryCompositeConstraintTag) findParentTag(QueryCompositeConstraintTag.class, (String ) container.getValue(this), false); 78 if (cons != null) { 79 cons.addChildConstraint(newConstraint); 80 } else { 81 newConstraint = Queries.addConstraint(query, newConstraint); 82 } 83 } 84 return newConstraint; 85 } 86 87 public int doStartTag() throws JspTagException { 88 constraints = new ArrayList(); 89 return EVAL_BODY; 90 } 91 92 public int doAfterBody() throws JspTagException { 93 QueryContainer c = (QueryContainer) findParentTag(QueryContainer.class, (String ) container.getValue(this)); 94 Query query = c.getQuery(); 95 96 addConstraint(query, getOperator(), constraints); 97 if(EVAL_BODY == EVAL_BODY_BUFFERED) { 98 try { 99 if (bodyContent != null) { 100 bodyContent.writeOut(bodyContent.getEnclosingWriter()); 101 } 102 } catch (java.io.IOException ioe){ 103 throw new JspTagException (ioe.toString()); 104 } 105 } 106 return SKIP_BODY; 107 } 108 public int doEndTag() throws JspTagException { 109 constraints = null; 110 return super.doEndTag(); 111 } 112 113 114 115 } 116 | Popular Tags |