KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > bridge > jsp > taglib > NodeInfoTag


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;
11
12 import org.mmbase.util.functions.*;
13 import org.mmbase.util.Casting;
14 import javax.servlet.jsp.JspTagException JavaDoc;
15 import javax.servlet.jsp.JspException JavaDoc;
16
17 import org.mmbase.bridge.jsp.taglib.util.Attribute;
18
19 import org.mmbase.bridge.*;
20
21 /**
22  * Lives under a nodeprovider. Can give information about the node,
23  * like what its nodemanager is.
24  *
25  * @author Michiel Meeuwissen
26  * @version $Id: NodeInfoTag.java,v 1.41.2.1 2006/10/03 21:13:40 michiel Exp $
27  */

28
29 public class NodeInfoTag extends NodeReferrerTag implements Writer {
30
31     private static final int TYPE_NODEMANAGER = 0;
32     private static final int TYPE_GUINODEMANAGER = 1;
33     private static final int TYPE_GUINODEMANAGER_PLURAL = 2;
34     private static final int TYPE_NODENUMBER = 3;
35     private static final int TYPE_GUI = 4;
36     private static final int TYPE_DESCRIPTION = 5;
37     private static final int TYPE_CONTEXT = 6;
38     private static final int TYPE_QUERY = 50; // for debug
39

40
41     private Attribute type = Attribute.NULL;
42
43     public void setType(String JavaDoc tu) throws JspTagException JavaDoc {
44         type = getAttribute(tu);
45     }
46
47     private int getType() throws JspTagException JavaDoc {
48         String JavaDoc t = type.getString(this).toLowerCase();
49         // note: 'nodemanager' and 'guinodemanager' values are deprecated
50
// use 'type' and 'guitype' instead
51
if ("nodemanager".equals(t) || "type".equals(t)) {
52             return TYPE_NODEMANAGER;
53         } else if ("guinodemanager".equals(t) || "guitype".equals(t)) {
54             return TYPE_GUINODEMANAGER;
55         } else if ("plural_guinodemanager".equals(t) || "plural_guitype".equals(t)) {
56             return TYPE_GUINODEMANAGER_PLURAL;
57         } else if ("description".equals(t)) {
58             return TYPE_DESCRIPTION;
59         } else if ("context".equals(t)) {
60             return TYPE_CONTEXT;
61         } else if ("number".equals(t)) {
62             return TYPE_NODENUMBER;
63         } else if ("gui".equals(t)) {
64             return TYPE_GUI;
65         } else if ("query".equals(t)) {
66             return TYPE_QUERY;
67         } else {
68             throw new JspTagException JavaDoc("Unknown value for attribute type (" + t + ")");
69         }
70     }
71
72     private Attribute nodeManagerAtt = Attribute.NULL;
73     public void setNodetype(String JavaDoc t) throws JspTagException JavaDoc {
74         nodeManagerAtt = getAttribute(t);
75     }
76
77     public int doStartTag() throws JspTagException JavaDoc{
78
79         NodeManager nodeManager = null;
80         if (nodeManagerAtt == Attribute.NULL) { // living as NodeReferrer
81
nodeManager = getNode().getNodeManager();
82         } else {
83             nodeManager = getCloudVar().getNodeManager(nodeManagerAtt.getString(this));
84         }
85         Object JavaDoc show = "";
86
87         // set node if necessary:
88
int t = getType();
89         switch(t) {
90         case TYPE_NODENUMBER:
91             if (nodeManagerAtt == Attribute.NULL) { // living as NodeReferrer
92
show = new Integer JavaDoc(getNode().getNumber());
93             } else {
94                 show = new Integer JavaDoc(nodeManager.getNumber());
95             }
96             break;
97         case TYPE_CONTEXT:
98             if (nodeManagerAtt == Attribute.NULL) { // living as NodeReferrer
99
show = getNode().getContext();
100             } else {
101                 show = nodeManager.getContext();
102             }
103             break;
104         case TYPE_NODEMANAGER:
105             show = nodeManager.getName();
106             break;
107         case TYPE_DESCRIPTION:
108             show = nodeManager.getDescription();
109             break;
110         case TYPE_GUINODEMANAGER:
111             show = nodeManager.getGUIName();
112             break;
113         case TYPE_GUINODEMANAGER_PLURAL:
114             show = nodeManager.getGUIName(10);
115             break;
116         case TYPE_GUI: {
117             if (nodeManagerAtt == Attribute.NULL) { // living as NodeReferrer
118
helper.useEscaper(false); // gui produces html
119
String JavaDoc sessionName = "";
120                 CloudTag ct = (CloudTag) findParentTag(CloudTag.class, null, false);
121                 if (ct != null) {
122                     sessionName = ct.getSessionName();
123                 }
124                 Node node = getNode();
125                 Function guiFunction = node.getFunction("gui");
126                 Parameters args = guiFunction.createParameters();
127                 if (args.containsParameter(Parameter.FIELD)) {
128                     args.set(Parameter.FIELD, ""); // lot of function implementations would not stand 'null' as field name value
129
}
130                 if (args.containsParameter("session")) {
131                     args.set("session", sessionName);
132                 }
133                 fillStandardParameters(args);
134                 show = Casting.toString(guiFunction.getFunctionValue(args));
135             } else {
136                 show = nodeManager.getGUIName();
137             }
138             break;
139         }
140         case TYPE_QUERY:
141             show = findNodeProvider().getGeneratingQuery();
142             break;
143         default:
144         }
145
146
147         helper.setValue(show);
148         if (getId() != null) {
149             getContextProvider().getContextContainer().register(getId(), helper.getValue());
150         }
151         return EVAL_BODY_BUFFERED;
152     }
153
154     public int doAfterBody() throws JspException JavaDoc {
155         return helper.doAfterBody();
156     }
157
158     /**
159      * Write the value of the nodeinfo.
160      */

161     public int doEndTag() throws JspTagException JavaDoc {
162         helper.doEndTag();
163         return super.doEndTag();
164
165     }
166 }
167
Popular Tags