KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > killingar > forum > actions > areagroup > List


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.areagroup;
27
28 import net.killingar.forum.actions.Utils;
29 import net.killingar.forum.internal.Area;
30 import net.killingar.forum.internal.IDItemImpl;
31 import net.killingar.forum.internal.managers.AreaManager;
32 import net.killingar.forum.internal.managers.TimeManager;
33
34 import java.sql.SQLException JavaDoc;
35 import java.sql.Timestamp JavaDoc;
36
37 public class List extends net.killingar.forum.actions.area.ActionAreaSupport
38 {
39     TimeManager timemgr;
40     java.util.List JavaDoc areaGroups;
41     boolean addAreaGroupAccess;
42
43     public boolean getAddAreaGroupAccess() { return addAreaGroupAccess; }
44     public java.util.List JavaDoc getAreaGroups() { return areaGroups; }
45
46     public static class AreaGroupData
47     {
48         net.killingar.forum.internal.AreaGroup areaGroup;
49         String JavaDoc indent;
50         boolean unread;
51
52         public AreaGroupData(net.killingar.forum.internal.AreaGroup areaGroup, boolean unread, long indent)
53         {
54             this.areaGroup = areaGroup;
55             this.indent = Utils.buildStringOnlyIndent(indent);
56             this.unread = unread;
57         }
58
59         public net.killingar.forum.internal.AreaGroup getAreaGroup() { return areaGroup; }
60         public boolean getUnread() { return unread; }
61         public String JavaDoc getIndent() { return indent; }
62     }
63
64     protected String JavaDoc doExecute()
65     {
66         try
67         {
68             net.killingar.forum.internal.AreaGroup aareagroup[] = super.areamgr.getAreaGroups();
69             long al[] = new long[aareagroup.length];
70             Utils.buildFlatTree(aareagroup, al);
71             boolean aflag[] = getUnread(super.areamgr, timemgr, aareagroup);
72             areaGroups = new java.util.ArrayList JavaDoc(aareagroup.length);
73             addAreaGroupAccess = super.manager.hasAccess(super.manager.getUserID(), 1024L);
74             for (int i = 0; i < aareagroup.length; i++)
75             {
76                 areaGroups.add(new AreaGroupData(aareagroup[i], aflag[i], al[i]));
77                 if (super.areamgr.hasAccess(super.manager.getUserID(), aareagroup[i].getId(), 1024L))
78                     addAreaGroupAccess = true;
79             }
80
81             return SUCCESS;
82         }
83         catch(Exception JavaDoc exception)
84         {
85             addErrorMessage("displaying area groups failed, exception thrown (" + exception.toString() + ")");
86             exception.printStackTrace();
87             return ERROR;
88         }
89     }
90
91     private boolean[] getUnread(AreaManager areamanager, TimeManager timemanager, net.killingar.forum.internal.AreaGroup aareagroup[])
92             throws SQLException JavaDoc
93     {
94         Area aarea[] = areamanager.getAreas();
95         long al[] = new long[aarea.length];
96         for(int i = 0; i < al.length; i++)
97                 al[i] = ((IDItemImpl) (aarea[i])).ID;
98
99         Timestamp JavaDoc atimestamp[] = timemanager.getTimes(TimeManager.systemAreas, al);
100         Timestamp JavaDoc atimestamp1[] = timemanager.getUserDataTimes(TimeManager.systemAreas, al);
101         boolean aflag[] = new boolean[aareagroup.length];
102         for(int j = 0; j < aareagroup.length; j++)
103             aflag[j] = false;
104
105
106         for(int k = 0; k < aareagroup.length; k++)
107         {
108             for(int l = 0; l < aarea.length; l++)
109             {
110                 if(aarea[l].areaGroupID != ((IDItemImpl) (aareagroup[k])).ID || !atimestamp1[l].before(atimestamp[l]))
111                     continue;
112                 aflag[k] = true;
113                 break;
114             }
115         }
116         return aflag;
117     }
118
119     public void setSession(java.util.Map JavaDoc map)
120     {
121         super.setSession(map);
122         synchronized(map)
123         {
124             try
125             {
126                 timemgr = (TimeManager)super.manager.getManager(TimeManager.class.getName());
127                 if(timemgr == null)
128                     addErrorMessage("failed to initialize time manager, null returned ");
129             }
130             catch(Exception JavaDoc exception)
131             {
132                 addErrorMessage("failed to initialize time manager, exception thrown: " + exception.toString());
133             }
134         }
135     }
136 }
Popular Tags