KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > killingar > forum > actions > ActionForumSupport


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.actions;
27
28 import net.killingar.actions.ActionSupport;
29 import net.killingar.forum.internal.AccessLevel;
30 import net.killingar.forum.internal.User;
31 import net.killingar.forum.internal.managers.ForumManager;
32 import net.killingar.forum.internal.managers.ItemListManager;
33 import net.killingar.forum.internal.managers.OptionsManager;
34 import net.killingar.forum.internal.managers.TimeManager;
35 import webwork.action.SessionAware;
36
37 import java.util.Map JavaDoc;
38
39 public class ActionForumSupport
40    extends ActionSupport
41    implements SessionAware
42 {
43     protected long start;
44
45     protected static final String JavaDoc CHAIN = "chain";
46
47     // Attributes ----------------------------------------------------
48
protected Map JavaDoc session;
49     protected ForumManager manager;
50     protected OptionsManager optionmgr;
51     protected TimeManager timemgr;
52     protected ItemListManager itemlistmgr;
53
54     public User getCurrentUser() throws Exception JavaDoc { return manager.getUser(manager.getUserID()); }
55
56     public ForumManager getManager() { return manager; }
57     public OptionsManager getOptionsmgr() { return optionmgr; }
58     public ItemListManager getItemlistmgr() { return itemlistmgr; }
59
60     public void setManager(ForumManager in) { manager = in; }
61
62     //
63
public long getExecutionTime() { return System.currentTimeMillis()-start; }
64
65     public long getUnreadFromHereTime(java.util.Date JavaDoc inDate) { return inDate.getTime()-1; }
66
67     public boolean getHasAccess(String JavaDoc s) throws java.sql.SQLException JavaDoc
68     {
69         long access = AccessLevel.everything;
70         try
71         {
72             access = Long.parseLong(s);
73         }
74         catch (NumberFormatException JavaDoc e)
75         {
76             access = AccessLevel.parseAccessLevel(s);
77         }
78         return manager.hasAccess(manager.getUserID(), access);
79     }
80
81     public String JavaDoc execute() throws Exception JavaDoc
82     {
83     start = System.currentTimeMillis();
84         return super.execute();
85     }
86
87     public String JavaDoc getOption(String JavaDoc in) throws Exception JavaDoc
88     {
89         return optionmgr.get(in);
90     }
91
92     // SessionAware implementation ------------------------------------
93
public void setSession(Map JavaDoc session)
94     {
95         this.session = session;
96
97         // Get model
98
try
99         {
100             synchronized (session)
101             {
102                 manager = (net.killingar.forum.internal.managers.ForumManager)session.get("manager");
103                 if (manager == null)
104                 {
105                     manager = new net.killingar.forum.internal.managers.ForumManager();
106                     session.put("manager", manager);
107                 }
108
109                 optionmgr = (OptionsManager)manager.getManager(OptionsManager.class.getName());
110                 timemgr = (TimeManager)manager.getManager(TimeManager.class.getName());
111                 itemlistmgr = (ItemListManager)manager.getManager(ItemListManager.class.getName());
112
113                 String JavaDoc locale = (String JavaDoc)optionmgr.get("locale");
114                 session.put("locale", locale);
115             }
116         }
117         catch (Exception JavaDoc e)
118         {
119             addErrorMessage("failed to initialize forum manager, exception thrown ("+e.toString()+")");
120         }
121
122         super.setSession(session);
123     }
124 }
Popular Tags