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 ; 8 import javax.servlet.jsp.tagext.TagSupport ; 9 10 11 15 public class UserTag extends TagSupport { 16 17 20 private static final long serialVersionUID = 222L; 21 22 25 private String var; 26 27 30 private boolean anonymous; 31 32 36 public void setAnonymous(boolean anonymous) { 37 this.anonymous = anonymous; 38 } 39 40 44 public void setVar(String var) { 45 this.var = var; 46 } 47 48 51 public int doEndTag() throws JspException { 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 67 public void release() { 68 super.release(); 69 this.var = null; 70 this.anonymous = false; 71 } 72 73 } 74 | Popular Tags |