KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > killingar > forum > actions > hotlist > AreaGroup


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.hotlist;
27
28 import net.killingar.forum.internal.Area;
29 import net.killingar.forum.internal.IDItemImpl;
30 import net.killingar.forum.internal.managers.TimeManager;
31
32 import java.sql.SQLException JavaDoc;
33 import java.sql.Timestamp JavaDoc;
34 import java.util.ArrayList JavaDoc;
35 import java.util.Arrays JavaDoc;
36 import java.util.List JavaDoc;
37 import java.util.Map JavaDoc;
38
39 public class AreaGroup extends ActionHotlistSupport
40 {
41     TimeManager timemgr;
42     List JavaDoc areas;
43     long areaGroupID = -1;
44     net.killingar.forum.internal.AreaGroup areaGroup;
45
46     static class AreaData
47     {
48         private Area area;
49         private boolean unread;
50         private boolean hasArea;
51
52         AreaData(Area area, boolean unread, boolean hasArea)
53         {
54             this.area = area;
55             this.unread = unread;
56             this.hasArea = hasArea;
57         }
58
59         public boolean getUnread()
60         {
61             return unread;
62         }
63
64         public boolean getHasArea()
65         {
66             return hasArea;
67         }
68
69         public Area getArea()
70         {
71             return area;
72         }
73     }
74
75     public void setSession(Map JavaDoc map)
76     {
77         super.setSession(map);
78         synchronized (map)
79         {
80             try
81             {
82                 timemgr = (TimeManager)super.manager.getManager(TimeManager.class.getName());
83                 if (timemgr == null)
84                     addErrorMessage("failed to initialize time manager, null returned ");
85             }
86             catch (Exception JavaDoc exception)
87             {
88                 addErrorMessage("failed to initialize time manager, exception thrown: " + exception.toString());
89             }
90         }
91     }
92
93     public void setAreaGroupID(String JavaDoc s)
94     {
95         areaGroupID = Long.parseLong(s);
96     }
97
98     public List JavaDoc getAreas()
99     {
100         return areas;
101     }
102
103     public net.killingar.forum.internal.AreaGroup getAreaGroup()
104     {
105         return areaGroup;
106     }
107
108     protected void doValidation()
109     {
110         if (areaGroupID == -1)
111             addErrorMessage("no area id specified");
112         else
113         {
114             try
115             {
116                 areaGroup = super.areamgr.getAreaGroup(areaGroupID);
117             }
118             catch (Exception JavaDoc exception)
119             {
120                 exception.printStackTrace();
121                 addErrorMessage("failed to get area group, exception thrown: " + exception.toString());
122             }
123         }
124     }
125
126     protected String JavaDoc doExecute()
127     {
128         try
129         {
130             Area areas[] = super.areamgr.getAreasInGroup(areaGroupID);
131             Arrays.sort(areas);
132             boolean unread[] = getUnread(timemgr, areas);
133             this.areas = new ArrayList JavaDoc(areas.length);
134             for (int i = 0; i < areas.length; i++)
135                 this.areas.add(new AreaData(areas[i], unread[i], areaHotlistmgr.hasArea(areas[i].getId(), 0) || areaHotlistmgr.hasArea(areas[i].getId(), 1)));
136
137             return SUCCESS;
138         }
139         catch (Exception JavaDoc exception)
140         {
141             addErrorMessage("displaying area group failed, exception thrown (" + exception.toString() + ")");
142             exception.printStackTrace();
143             return ERROR;
144         }
145     }
146
147     private final boolean[] getUnread(TimeManager timemgr, Area areas[])
148         throws SQLException JavaDoc
149     {
150         long al[] = new long[areas.length];
151         for (int i = 0; i < al.length; i++)
152             al[i] = ((IDItemImpl)(areas[i])).ID;
153
154         Timestamp JavaDoc atimestamp[] = timemgr.getTimes(TimeManager.systemAreas, al);
155         Timestamp JavaDoc atimestamp1[] = timemgr.getUserDataTimes(TimeManager.systemAreas, al);
156         boolean aflag[] = new boolean[areas.length];
157         for (int j = 0; j < areas.length; j++)
158             aflag[j] = false;
159
160         for (int k = 0; k < areas.length; k++)
161             if (atimestamp1[k].before(atimestamp[k]))
162                 aflag[k] = true;
163
164         return aflag;
165     }
166 }
167
Popular Tags