1 10 package org.mmbase.bridge.jsp.taglib; 11 12 import javax.servlet.jsp.JspTagException ; 13 14 import org.mmbase.bridge.*; 15 import org.mmbase.bridge.jsp.taglib.containers.RelatedNodesContainerTag; 16 import org.mmbase.bridge.jsp.taglib.util.Attribute; 17 import org.mmbase.bridge.util.Queries; 18 import org.mmbase.storage.search.*; 19 20 29 public class RelatedNodesTag extends AbstractNodeListTag { 30 31 protected Attribute type = Attribute.NULL; 32 protected Attribute path = Attribute.NULL; 33 protected Attribute element = Attribute.NULL; 34 protected Attribute role = Attribute.NULL; 35 protected Attribute searchDir = Attribute.NULL; protected Attribute searchDirs = Attribute.NULL; 38 protected Attribute container = Attribute.NULL; 39 40 public void setContainer(String c) throws JspTagException { 41 container = getAttribute(c); 42 } 43 44 47 public void setType(String type) throws JspTagException { 48 this.type = getAttribute(type); 49 } 50 53 public void setRole(String role) throws JspTagException { 54 this.role = getAttribute(role); 55 } 56 57 63 public void setSearchdir(String search) throws JspTagException { 64 searchDir = getAttribute(search); 65 } 66 67 70 public void setPath(String p) throws JspTagException { 71 path = getAttribute(p); 72 } 73 76 public void setElement(String e) throws JspTagException { 77 element = getAttribute(e); 78 } 79 82 public void setSearchdirs(String s) throws JspTagException { 83 searchDirs = getAttribute(s); 84 } 85 86 89 public int doStartTag() throws JspTagException { 90 int superresult = doStartTagHelper(); if (superresult != NOT_HANDLED) { 92 return superresult; 93 } 94 RelatedNodesContainerTag c = (RelatedNodesContainerTag) findParentTag(RelatedNodesContainerTag.class, (String ) container.getValue(this), false); 95 96 NodeQuery query; 97 if (type != Attribute.NULL || path != Attribute.NULL || c == null || parentNodeId != Attribute.NULL) { 98 99 Node parentNode = getNode(); 101 if (parentNode == null) { 102 throw new TaglibException("Could not find parent node!!"); 103 } 104 Cloud cloud; 105 { 106 CloudProvider cloudProvider = findCloudProvider(false); 108 cloud = cloudProvider != null ? cloudProvider.getCloudVar() : parentNode.getCloud(); 109 } 110 query = cloud.createNodeQuery(); 111 Step step1 = query.addStep(parentNode.getNodeManager()); 112 query.setAlias(step1, parentNode.getNodeManager().getName() + "0"); 113 query.addNode(step1, parentNode); 114 115 116 String searchDirections; 117 if (searchDir == Attribute.NULL) { searchDirections = (String ) searchDirs.getValue(this); 119 } else { 120 if (searchDirs != Attribute.NULL) { 121 throw new TaglibException("Cannot specify both 'searchdir' and 'searchdirs' attributes. "); 122 } 123 searchDirections = (String ) searchDir.getValue(this); 124 } 125 126 NodeManager otherManager; 127 if (path == Attribute.NULL) { 128 if (type == Attribute.NULL) { 129 otherManager = cloud.getNodeManager("object"); 130 } else { 131 if (element != Attribute.NULL) { 132 throw new TaglibException("Cannot specify both 'element' and 'type' attributes"); 133 } 134 otherManager = cloud.getNodeManager(type.getString(this)); 135 } 136 RelationStep step2 = query.addRelationStep(otherManager, (String ) role.getValue(this), searchDirections); 137 Step step3 = step2.getNext(); 138 query.setNodeStep(step3); } else { 140 if (role != Attribute.NULL) { 141 throw new TaglibException("Cannot specify both 'path' and 'role' attributes"); 142 } 143 Queries.addPath(query, (String ) path.getValue(this), searchDirections); 144 if (element != Attribute.NULL) { 145 String alias = element.getString(this); 146 Step nodeStep = query.getStep(alias); 147 if (nodeStep == null) { 148 throw new JspTagException ("Could not set element to '" + alias + "' (no such step)"); 149 } 150 query.setNodeStep(nodeStep); 151 } else { 152 query.setNodeStep((Step) query.getSteps().get(2)); 154 } 155 } 156 157 158 159 } else { 160 query = (NodeQuery) c.getQuery(); 161 } 162 if (constraints != Attribute.NULL) { 163 Queries.addConstraints(query, (String ) constraints.getValue(this)); 164 } 165 if (orderby != Attribute.NULL) { 166 Queries.addSortOrders(query, (String ) orderby.getValue(this), (String ) directions.getValue(this)); 167 } 168 169 NodesAndTrim result = getNodesAndTrim(query); 170 return setReturnValues(result.nodeList, result.needsTrim); 171 } 172 } 173 | Popular Tags |