KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.servlet.jsp.JspTagException JavaDoc;
13
14 import org.mmbase.bridge.*;
15 import org.mmbase.bridge.jsp.taglib.NodeReferrerTag;
16 import org.mmbase.bridge.jsp.taglib.util.Attribute;
17 import org.mmbase.bridge.util.Queries;
18 import org.mmbase.cache.CachePolicy;
19 import org.mmbase.storage.search.Step;
20 //import org.mmbase.util.logging.*;
21

22 /**
23  *
24  * @author Michiel Meeuwissen
25  * @since MMBase-1.7
26  * @version $Id: RelatedContainerTag.java,v 1.18 2006/07/04 12:16:09 michiel Exp $
27  */

28 public class RelatedContainerTag extends NodeReferrerTag implements QueryContainer {
29
30     // private static final Logger log = Logging.getLoggerInstance(RelatedContainerTag.class);
31

32     private Query query = null;
33     private Attribute cachePolicy = Attribute.NULL;
34     private Attribute path = Attribute.NULL;
35     private Attribute searchDirs = Attribute.NULL;
36     private Attribute fields = Attribute.NULL;
37     protected String JavaDoc jspVar = null;
38
39     public void setCachepolicy(String JavaDoc t) throws JspTagException JavaDoc {
40         cachePolicy = getAttribute(t);
41     }
42
43     public void setPath(String JavaDoc t) throws JspTagException JavaDoc {
44         path = getAttribute(t);
45     }
46
47     public void setSearchdirs(String JavaDoc s) throws JspTagException JavaDoc {
48         searchDirs = getAttribute(s);
49     }
50
51
52     public void setFields(String JavaDoc f) throws JspTagException JavaDoc {
53         fields = getAttribute(f);
54     }
55
56     /**
57      * @since MMBase-1.8.1
58      */

59     public void setJspvar(String JavaDoc jv) {
60         jspVar = jv;
61     }
62
63     public Query getQuery() {
64         if (query.isUsed()) query = (Query) query.clone();
65         return query;
66     }
67
68
69
70     public int doStartTag() throws JspTagException JavaDoc {
71         if (getReferid() != null) {
72             query = (Query) getContextProvider().getContextContainer().getObject(getReferid());
73         } else {
74             if (path == Attribute.NULL) {
75                 throw new JspTagException JavaDoc("Path attribute is mandatory");
76             }
77             Node node = getNode();
78             Cloud cloud = node.getCloud();
79             query = cloud.createQuery();
80
81             Step step = query.addStep(node.getNodeManager());
82             query.setAlias(step, node.getNodeManager().getName() + "0");
83             query.addNode(step, node);
84
85         }
86
87         if (getId() != null) { // write to context.
88
getContextProvider().getContextContainer().register(getId(), query);
89         }
90         if (jspVar != null) {
91             pageContext.setAttribute(jspVar, query);
92         }
93
94
95         if (cachePolicy != Attribute.NULL) {
96             query.setCachePolicy(CachePolicy.getPolicy(cachePolicy.getValue(this)));
97         }
98
99         Queries.addPath(query, (String JavaDoc) path.getValue(this), (String JavaDoc) searchDirs.getValue(this));
100
101         Queries.addFields(query, (String JavaDoc) fields.getValue(this));
102
103         return EVAL_BODY;
104     }
105
106     public int doAfterBody() throws JspTagException JavaDoc {
107         if(EVAL_BODY == EVAL_BODY_BUFFERED) {
108             try {
109                 if (bodyContent != null) {
110                     bodyContent.writeOut(bodyContent.getEnclosingWriter());
111                 }
112             } catch (java.io.IOException JavaDoc ioe){
113                 throw new JspTagException JavaDoc(ioe.toString());
114             }
115         }
116         return SKIP_BODY;
117     }
118     public int doEndTag() throws JspTagException JavaDoc {
119         query = null;
120         return super.doEndTag();
121     }
122
123     public Object JavaDoc getCurrent() {
124         return null;
125     }
126
127 }
128
Popular Tags