KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > bridge > jsp > taglib > containers > RelatedNodesContainerTag


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.bridge.jsp.taglib.containers;
11
12 import java.util.List JavaDoc;
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 //import org.mmbase.util.logging.*;
23

24 /**
25  * Container cognate of RelatedNodesTag
26  *
27  * @author Michiel Meeuwissen
28  * @since MMBase-1.7
29  * @version $Id: RelatedNodesContainerTag.java,v 1.14 2006/07/04 12:16:09 michiel Exp $
30  */

31 public class RelatedNodesContainerTag extends ListNodesContainerTag {
32
33     //private static final Logger log = Logging.getLoggerInstance(RelatedNodesContainerTag.class);
34

35     protected Attribute cachePolicy = Attribute.NULL;
36     protected Attribute role = Attribute.NULL;
37
38     /**
39      * @since MMBase-1.8
40      */

41     public void setCachepolicy(String JavaDoc t) throws JspTagException {
42         cachePolicy = getAttribute(t);
43     }
44
45     /**
46      * @param role a role
47      */

48     public void setRole(String JavaDoc 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                 // prefer cloud of current page, otherwise of node
64
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 JavaDoc 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 JavaDoc) role.getValue(this), (String JavaDoc) 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 JavaDoc newSteps = Queries.addPath(query, (String JavaDoc) path.getValue(this), (String JavaDoc) searchDirs.getValue(this));
90
91                 if (element != Attribute.NULL) {
92                     String JavaDoc 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                     // default to third step (first two are the node and the relation)
100
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) { // write to context.
109
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