1 25 26 package net.killingar.forum.tags; 27 28 import net.killingar.forum.internal.AccessLevel; 29 import net.killingar.forum.internal.managers.ForumManager; 30 31 import javax.servlet.jsp.JspException ; 32 import javax.servlet.jsp.JspTagException ; 33 34 public class UserAccessTag extends webwork.view.taglib.WebWorkBodyTagSupport 35 { 36 private long access = 0, userID = -1; 37 38 public int doStartTag() throws JspException 39 { 40 try 41 { 42 ForumManager manager = (ForumManager)pageContext.getSession().getAttribute("manager"); 43 if (manager.hasAccess(manager.getUserID(), access) || userID == manager.getUserID()) 44 return EVAL_BODY_TAG; 45 else 46 return SKIP_BODY; 47 } 48 catch (Exception ex) 49 { 50 throw new JspTagException ("userAccessTag: " + ex.toString()); 52 } 54 } 55 56 public void setAccess(String a) 57 { 58 try 59 { 60 access = Long.parseLong(a); 61 } 62 catch(NumberFormatException e) 63 { 64 access = AccessLevel.parseAccessLevel(a); 65 } 66 } 67 68 public void setUserID(String a) 69 { 70 try 71 { 72 userID = Long.parseLong(a); 73 } 74 catch(NumberFormatException e) 75 { 76 try 77 { 78 userID = ((Long )findValue(a)).longValue(); 79 } 80 catch(ClassCastException e2) 81 { 82 userID = -1; } 84 } 85 } 86 87 public int doEndTag() throws JspTagException 88 { 89 try 90 { 91 if(bodyContent != null) 92 bodyContent.writeOut(bodyContent.getEnclosingWriter()); 93 94 bodyContent = null; 95 } 96 catch(java.io.IOException e) 97 { 98 throw new JspTagException ("exception thrown: " + e); 99 } 100 return EVAL_PAGE; 101 } 102 103 public int doAfterBody() throws JspTagException 104 { 105 return SKIP_BODY; 106 } 107 } 108 | Popular Tags |