KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > taglibs > UserTag


1 package info.magnolia.cms.taglibs;
2
3 import info.magnolia.cms.security.User;
4 import info.magnolia.cms.security.UserManager;
5 import info.magnolia.context.MgnlContext;
6
7 import javax.servlet.jsp.JspException JavaDoc;
8 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
9
10
11 /**
12  * @author fgiust
13  * @version $Revision: 6341 $ ($Author: philipp $)
14  */

15 public class UserTag extends TagSupport JavaDoc {
16
17     /**
18      * Stable serialVersionUID.
19      */

20     private static final long serialVersionUID = 222L;
21
22     /**
23      * Name of the pagecontext variable where the user will be set.
24      */

25     private String JavaDoc var;
26
27     /**
28      * Returns also anonymous users?
29      */

30     private boolean anonymous;
31
32     /**
33      * Setter for <code>anonymous</code>.
34      * @param anonymous The anonymous to set.
35      */

36     public void setAnonymous(boolean anonymous) {
37         this.anonymous = anonymous;
38     }
39
40     /**
41      * Setter for <code>var</code>.
42      * @param var The var to set.
43      */

44     public void setVar(String JavaDoc var) {
45         this.var = var;
46     }
47
48     /**
49      * @see javax.servlet.jsp.tagext.TagSupport#doEndTag()
50      */

51     public int doEndTag() throws JspException JavaDoc {
52
53         User user = MgnlContext.getUser();
54         if (user != null && (anonymous || !UserManager.ANONYMOUS_USER.equals(user.getName()))) {
55             pageContext.setAttribute(var, user);
56         }
57         else {
58             pageContext.removeAttribute(var);
59         }
60
61         return super.doEndTag();
62     }
63
64     /**
65      * @see javax.servlet.jsp.tagext.TagSupport#release()
66      */

67     public void release() {
68         super.release();
69         this.var = null;
70         this.anonymous = false;
71     }
72
73 }
74
Popular Tags