KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > killingar > forum > tags > AreaAccessTag


1 /* Copyright 2000-2005 Anders Hovmöller
2  *
3  * The person or persons who have associated their work with
4  * this document (the "Dedicator") hereby dedicate the entire
5  * copyright in the work of authorship identified below (the
6  * "Work") to the public domain.
7  *
8  * Dedicator makes this dedication for the benefit of the
9  * public at large and to the detriment of Dedicator's heirs
10  * and successors. Dedicator intends this dedication to be an
11  * overt act of relinquishment in perpetuity of all present
12  * and future rights under copyright law, whether vested or
13  * contingent, in the Work. Dedicator understands that such
14  * relinquishment of all rights includes the relinquishment of
15  * all rights to enforce (by lawsuit or otherwise) those
16  * copyrights in the Work.
17  *
18  * Dedicator recognizes that, once placed in the public
19  * domain, the Work may be freely reproduced, distributed,
20  * transmitted, used, modified, built upon, or otherwise
21  * exploited by anyone for any purpose, commercial or non-
22  * commercial, and in any way, including by methods that have
23  * not yet been invented or conceived.
24  */

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