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.CloudReferrerTag; 16 import org.mmbase.bridge.jsp.taglib.util.Attribute; 17 import org.mmbase.bridge.util.Queries; 18 import org.mmbase.storage.search.*; 19 import java.util.*; 20 21 28 public class QueryTypeConstraintTag extends CloudReferrerTag implements QueryContainerReferrer { 29 30 32 protected Attribute container = Attribute.NULL; 33 34 protected Attribute element = Attribute.NULL; 35 protected Attribute name = Attribute.NULL; 36 37 protected Attribute inverse = Attribute.NULL; 38 protected Attribute descendants = Attribute.NULL; 39 40 public void setContainer(String c) throws JspTagException { 41 container = getAttribute(c); 42 } 43 44 public void setElement(String e) throws JspTagException { 45 element = getAttribute(e); 46 } 47 48 public void setName(String n) throws JspTagException { 49 name = getAttribute(n); 50 } 51 52 53 public void setInverse(String i) throws JspTagException { 54 inverse = getAttribute(i); 55 } 56 57 public void setDescendants(String d) throws JspTagException { 58 descendants = getAttribute(d); 59 } 60 61 62 protected SortedSet getOTypes(List names) throws JspTagException { 63 Cloud cloud = getCloudVar(); 64 SortedSet set = new TreeSet(); 65 Iterator i = names.iterator(); 66 boolean desc = descendants.getBoolean(this, true); 67 while (i.hasNext()) { 68 NodeManager nm = cloud.getNodeManager((String ) i.next()); 69 set.add(new Integer (nm.getNumber())); 70 if (desc) { 71 NodeManagerIterator j = nm.getDescendants().nodeManagerIterator(); 72 while (j.hasNext()) { 73 set.add(new Integer (j.nextNodeManager().getNumber())); 74 } 75 } 76 } 77 return set; 78 } 79 80 81 82 public int doStartTag() throws JspTagException { 83 QueryContainer c = (QueryContainer) findParentTag(QueryContainer.class, (String ) container.getValue(this)); 84 Query query = c.getQuery(); 85 String elementString = element.getString(this); 86 Step step; 87 if (elementString.equals("")) { 88 if (query instanceof NodeQuery) { 89 step = ((NodeQuery) query).getNodeStep(); 90 } else { 91 throw new JspTagException ("Don't know on what path element the type constraint must be applied. Use the 'element' attribute"); 92 } 93 } else { 94 step = query.getStep(elementString); 95 } 96 if (step == null) { 97 throw new JspTagException ("No element '" + element.getString(this) + "' in path '" + query.getSteps() + "'"); 98 } 99 StepField stepField = query.createStepField(step, "otype"); 100 101 Constraint newConstraint = query.createConstraint(stepField, getOTypes(name.getList(this))); 102 103 if (newConstraint != null) { 104 if (inverse.getBoolean(this, false)) { 105 query.setInverse(newConstraint, true); 106 } 107 108 QueryCompositeConstraintTag cons = (QueryCompositeConstraintTag) findParentTag(QueryCompositeConstraintTag.class, (String ) container.getValue(this), false); 112 if (cons != null) { 113 cons.addChildConstraint(newConstraint); 114 } else { 115 Queries.addConstraint(query, newConstraint); 116 } 117 } 118 119 return SKIP_BODY; 120 } 121 122 } 123 | Popular Tags |