KickJava   Java API By Example, From Geeks To Geeks.

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


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