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 import webwork.util.ServletValueStack; 31 32 import javax.servlet.jsp.JspException ; 33 import javax.servlet.jsp.JspTagException ; 34 import javax.servlet.jsp.tagext.BodyTagSupport ; 35 36 public class AccessTag extends BodyTagSupport 37 { 38 protected ServletValueStack stack; 39 40 private long access = 0; 41 private long ownerID = -1; 42 43 protected ServletValueStack getStack() 44 { 45 if (stack == null) { 46 stack = ServletValueStack.getStack(pageContext); 47 } 48 else 49 { 50 stack.setContext(pageContext); 54 } 55 return stack; 56 } 57 58 protected Object findValue(String aName) 59 { 60 return getStack().findValue(aName); 61 } 62 63 public void setOwnerID(String attr) 64 { 65 ownerID = ((Long )findValue(attr)).longValue(); 66 } 67 68 public int doStartTag() throws JspException 69 { 70 try 71 { 72 ForumManager manager = (ForumManager)pageContext.getSession().getAttribute("manager"); 73 if (manager.hasAccess(manager.getUserID(), access)) 74 return EVAL_BODY_TAG; 75 else if (ownerID != -1 && ownerID == manager.getUserID()) 76 return EVAL_BODY_TAG; 77 else 78 return SKIP_BODY; 79 } 80 catch (Exception ex) 81 { 82 throw new JspTagException ("accessTag: " + ex); 84 } 86 } 87 88 public void setOwner(String s) 89 { 90 Object o = findValue(s); 91 if (o != null) 92 ownerID = ((Long )findValue(s)).longValue(); 93 } 94 95 public void setAccess(String s) 96 { 97 try 98 { 99 access = Long.parseLong(s); 100 } 101 catch (NumberFormatException e) 102 { 103 access = AccessLevel.parseAccessLevel(s); 104 } 105 } 106 107 public int doEndTag() throws JspTagException 108 { 109 try 110 { 111 if (bodyContent != null) 112 bodyContent.writeOut(bodyContent.getEnclosingWriter()); 113 114 bodyContent = null; 115 } 116 catch (java.io.IOException e) 117 { 118 throw new JspTagException (e.toString()); 119 } 120 return EVAL_PAGE; 121 } 122 123 public int doAfterBody() throws JspTagException 124 { 125 return SKIP_BODY; 126 } 127 } 128 | Popular Tags |