KickJava   Java API By Example, From Geeks To Geeks.

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


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.managers.AreaHotlistManager;
30 import net.killingar.forum.internal.managers.TimeManager;
31 import webwork.action.PrepareAction;
32
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 abstract class ActionHotlistSupport extends net.killingar.forum.actions.area.ActionAreaSupport implements PrepareAction
40 {
41     protected AreaHotlistManager areaHotlistmgr;
42     protected boolean showAllAreas = false;
43     protected boolean hasHiddenAreas = false;
44     protected int numberOfUnreadAreas = 0;
45     protected List JavaDoc hotlist;
46
47     public List JavaDoc getHotlist() {return hotlist;}
48     public boolean getShowAllAreas() {return showAllAreas;}
49     public boolean getHasHiddenAreas() {return hasHiddenAreas;}
50     public int getNumberOfUnreadAreas() { return numberOfUnreadAreas; };
51     public boolean getHotlistEmpty() {return hotlist.size() == 0; }
52
53     public void setShowAllAreas(boolean showAllAreas) {this.showAllAreas = showAllAreas;}
54
55     public void setSession(Map JavaDoc map)
56     {
57         super.setSession(map);
58         try
59         {
60             synchronized (map)
61             {
62                 areaHotlistmgr = (AreaHotlistManager)super.manager.getManager(AreaHotlistManager.class.getName());
63                 if(areaHotlistmgr == null)
64                     addErrorMessage("failed to initialize area manager, null returned");
65             }
66         }
67         catch (Exception JavaDoc exception)
68         {
69             addErrorMessage("failed to initialize area manager, exception thrown (" + exception.toString() + ")");
70             exception.printStackTrace();
71         }
72     }
73
74     public void prepare() throws Exception JavaDoc
75     {
76         hotlist = new ArrayList JavaDoc();
77         Area passiveHotlist[] = areaHotlistmgr.getFlatHotlist(0);
78         Area activeHotlist[] = areaHotlistmgr.getFlatHotlist(1);
79         long hotlistIds[] = new long[passiveHotlist.length + activeHotlist.length];
80         for (int i = 0; i < passiveHotlist.length; i++)
81             hotlistIds[i] = passiveHotlist[i].getId();
82
83         for (int j = 0; j < activeHotlist.length; j++)
84             hotlistIds[passiveHotlist.length + j] = activeHotlist[j].getId();
85
86         TimeManager timemanager = (TimeManager)super.manager.getManager(TimeManager.class.getName());
87         Timestamp JavaDoc areaTimes[] = timemanager.getTimes(TimeManager.systemAreas, hotlistIds);
88         Timestamp JavaDoc userAreaTimes[] = timemanager.getUserDataTimes(TimeManager.systemAreas, hotlistIds);
89         HotlistEntry ahotlistentry[] = new HotlistEntry[hotlistIds.length];
90         for (int k = 0; k < ahotlistentry.length; k++)
91         {
92             if (k < passiveHotlist.length)
93             {
94                 ahotlistentry[k] = new HotlistEntry(passiveHotlist[k], userAreaTimes[k], areaTimes[k], 0L, false);
95             }
96             else
97             {
98                 boolean unread = userAreaTimes[k].before(areaTimes[k]);
99                 if (!unread)
100                     hasHiddenAreas = true;
101                 ahotlistentry[k] = new HotlistEntry(activeHotlist[k - passiveHotlist.length], userAreaTimes[k], areaTimes[k], 1L, !unread);
102             }
103
104             if (userAreaTimes[k].before(areaTimes[k]))
105                 numberOfUnreadAreas++;
106         }
107
108         Arrays.sort(ahotlistentry); // something in this array is null
109
hotlist = new ArrayList JavaDoc(ahotlistentry.length);
110         for (int l = 0; l < ahotlistentry.length; l++)
111         {
112             if (ahotlistentry[l] != null)
113                 hotlist.add(ahotlistentry[l]);
114         }
115     }
116 }
117
Popular Tags