KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.servlet.jsp.JspTagException JavaDoc;
13 import javax.servlet.jsp.JspException JavaDoc;
14
15 import org.mmbase.bridge.jsp.taglib.util.Attribute;
16
17 import org.mmbase.bridge.Cloud;
18
19 /**
20  * Lives under a cloudprovider. Can give information about the node,
21  * like what its name is.
22  *
23  * @author Michiel Meeuwissen
24  * @version $Id: CloudInfoTag.java,v 1.10 2006/06/23 11:39:50 michiel Exp $
25  * @since MMBase-1.8
26  */

27
28 public class CloudInfoTag extends CloudReferrerTag implements Writer {
29
30     private static final int TYPE_NAME = 0;
31     private static final int TYPE_USER = 1;
32     private static final int TYPE_RANK = 2;
33     private static final int TYPE_RANK_INT = 3;
34     private static final int TYPE_AUTHENTICATE = 4;
35     private static final int TYPE_MMBASEVERSION = 100;
36     private static final int TYPE_TAGLIBVERSION = 101;
37
38
39     private Attribute type = Attribute.NULL;
40
41     public void setType(String JavaDoc tu) throws JspTagException JavaDoc {
42         type = getAttribute(tu);
43     }
44
45     private int getType() throws JspTagException JavaDoc {
46         String JavaDoc t = type.getString(this).toLowerCase();
47         if ("name".equals(t)) {
48             return TYPE_NAME;
49         } else if ("user".equals(t)) {
50             return TYPE_USER;
51         } else if ("rank".equals(t)) {
52             return TYPE_RANK;
53         } else if ("rankint".equals(t)) {
54             return TYPE_RANK_INT;
55         } else if ("authenticate".equals(t)) {
56             return TYPE_AUTHENTICATE;
57         } else if ("mmbaseversion".equals(t)) {
58             return TYPE_MMBASEVERSION;
59         } else if ("taglibversion".equals(t)) {
60             return TYPE_TAGLIBVERSION;
61         } else {
62             throw new JspTagException JavaDoc("Unknown value for attribute type (" + t + ")");
63         }
64     }
65
66     public int doStartTag() throws JspTagException JavaDoc{
67
68         Cloud cloud = getCloudVar();
69
70         String JavaDoc show;
71
72         // set node if necessary:
73
switch(getType()) {
74         case TYPE_NAME:
75             show = cloud.getName();
76             break;
77         case TYPE_USER:
78             show = cloud.getUser().getIdentifier();
79             break;
80         case TYPE_RANK:
81             show = cloud.getUser().getRank().toString();
82             break;
83         case TYPE_RANK_INT:
84             show = "" + cloud.getUser().getRank().getInt();
85             break;
86         case TYPE_AUTHENTICATE:
87             show = "" + cloud.getUser().getAuthenticationType();
88             break;
89         case TYPE_MMBASEVERSION:
90             show = org.mmbase.Version.get();
91             break;
92         case TYPE_TAGLIBVERSION:
93             show = getTaglibVersion();
94             break;
95         default:
96             show = "";
97         }
98
99         
100         helper.setValue(show);
101         if (getId() != null) {
102             getContextProvider().getContextContainer().register(getId(), helper.getValue());
103         }
104         return EVAL_BODY_BUFFERED;
105     }
106
107     public int doAfterBody() throws JspException JavaDoc {
108         return helper.doAfterBody();
109     }
110
111     /**
112      * Write the value of the nodeinfo.
113      */

114     public int doEndTag() throws JspTagException JavaDoc {
115         helper.doEndTag();
116         return super.doEndTag();
117
118     }
119 }
120
Popular Tags