1 10 package org.mmbase.bridge.jsp.taglib.containers; 11 12 import java.util.List ; 13 14 import javax.servlet.jsp.*; 15 16 import org.mmbase.bridge.*; 17 import org.mmbase.bridge.jsp.taglib.util.Attribute; 18 import org.mmbase.bridge.jsp.taglib.CloudProvider; 19 import org.mmbase.bridge.util.Queries; 20 import org.mmbase.cache.CachePolicy; 21 import org.mmbase.storage.search.*; 22 24 31 public class RelatedNodesContainerTag extends ListNodesContainerTag { 32 33 35 protected Attribute cachePolicy = Attribute.NULL; 36 protected Attribute role = Attribute.NULL; 37 38 41 public void setCachepolicy(String t) throws JspTagException { 42 cachePolicy = getAttribute(t); 43 } 44 45 48 public void setRole(String role) throws JspTagException { 49 this.role = getAttribute(role); 50 } 51 52 53 public int doStartTag() throws JspTagException { 54 if (getReferid() != null) { 55 query = (NodeQuery) getContextProvider().getContextContainer().getObject(getReferid()); 56 if (nodeManager != Attribute.NULL || role != Attribute.NULL || searchDirs != Attribute.NULL || path != Attribute.NULL || element != Attribute.NULL) { 57 throw new JspTagException("Cannot use 'nodemanager', 'role', 'searchdirs', 'path' or 'element' attributes together with 'referid'"); 58 } 59 } else { 60 Node node = getNode(); 61 Cloud cloud; 62 { 63 CloudProvider cloudProvider = findCloudProvider(false); 65 cloud = cloudProvider != null ? cloudProvider.getCloudVar() : node.getCloud(); 66 } 67 query = cloud.createNodeQuery(); 68 69 Step step = query.addStep(node.getNodeManager()); 70 query.setAlias(step, node.getNodeManager().getName() + "0"); 71 query.addNode(step, node); 72 73 if (nodeManager != Attribute.NULL || role != Attribute.NULL) { 74 75 String nodeManagerName; 76 if (nodeManager == Attribute.NULL) { 77 nodeManagerName = "object"; 78 } else { 79 nodeManagerName = nodeManager.getString(this); 80 } 81 RelationStep relationStep = query.addRelationStep(cloud.getNodeManager(nodeManagerName), 82 (String ) role.getValue(this), (String ) searchDirs.getValue(this)); 83 query.setNodeStep(relationStep.getNext()); 84 if (path != Attribute.NULL) throw new JspTagException("Should specify either 'type' or 'path' attributes on relatednodescontainer"); 85 if (element != Attribute.NULL) throw new JspTagException("'element' can only be used in combination with 'path' attribute"); 86 } else { 87 if (path == Attribute.NULL) throw new JspTagException("Should specify either 'type' or 'path' attributes on relatednodescontainer"); 88 89 List newSteps = Queries.addPath(query, (String ) path.getValue(this), (String ) searchDirs.getValue(this)); 90 91 if (element != Attribute.NULL) { 92 String alias = element.getString(this); 93 Step nodeStep = Queries.searchStep(newSteps, alias); 94 if (nodeStep == null) { 95 throw new JspTagException("Could not set element to '" + alias + "' (no such (new) step)"); 96 } 97 query.setNodeStep(nodeStep); 98 } else { 99 query.setNodeStep((Step) query.getSteps().get(2)); 101 } 102 } 103 } 104 if (cachePolicy != Attribute.NULL) { 105 query.setCachePolicy(CachePolicy.getPolicy(cachePolicy.getValue(this))); 106 } 107 108 if (getId() != null) { getContextProvider().getContextContainer().register(getId(), query); 110 } 111 if (jspVar != null) { 112 pageContext.setAttribute(jspVar, query); 113 } 114 return EVAL_BODY; 115 } 116 117 118 119 } 120 | Popular Tags |