KickJava   Java API By Example, From Geeks To Geeks.

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


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.forum.internal.Comic;
29 import net.killingar.forum.internal.Event;
30 import net.killingar.forum.internal.User;
31 import net.killingar.forum.internal.managers.*;
32
33 import java.util.Date JavaDoc;
34
35 public class ViewContents
36    extends net.killingar.forum.actions.hotlist.ActionHotlistSupport
37 {
38     // Attributes -----------------------------------------------------
39
TodoManager todoMgr;
40     Timekeeper timekeeper;
41     PlanningManager planningMgr;
42     PollManager pollMgr;
43     TaskManager taskMgr;
44
45     // Types ----------------------------------------------------------
46

47     // Setters --------------------------------------------------------
48

49     // Getters --------------------------------------------------------
50
public boolean getHasUrgentTodos() throws Exception JavaDoc {return todoMgr.hasUrgentStuffTodo(manager.getUserID());}
51     public boolean getTimeKeeperRunning() throws Exception JavaDoc {return timekeeper.hasStartedTimes();}
52     public boolean getPlanningUnread() throws Exception JavaDoc {return planningMgr.isUnreadPlanning();}
53     public long getPlanningTime() throws Exception JavaDoc {return planningMgr.getTimeOnPlanning().getTime();}
54     public boolean getTasksUnread() throws Exception JavaDoc {return taskMgr.isUnread();}
55     public long getTasksTime() throws Exception JavaDoc {return taskMgr.getTime().getTime();}
56     public long getWikiTime() throws Exception JavaDoc {return timemgr.getUserTime(TimeManager.systemWiki).getTime();}
57     public boolean getPollsUnread() throws Exception JavaDoc {return pollMgr.isUnread();}
58
59     public boolean getWikiUnread() throws Exception JavaDoc
60     {
61         //if (getOption("subscribe to all wikis") != null)
62
return timemgr.getUserTime(TimeManager.systemWiki).before(timemgr.getSystemTime(TimeManager.systemWiki));
63         /*else
64         {
65             String[] contexts = itemlistmgr.getList("wiki/subscription/contexts");
66             for (int i = 0; i != contexts.length; i++)
67             {
68                 if (timemgr.getUserTime("wiki/"+contexts[i]).before(timemgr.getSystemTime("wiki/"+contexts[i])))
69                     return true;
70             }
71             String[] documents = itemlistmgr.getList("wiki/subscription/documents");
72             for (int i = 0; i != documents.length; i++)
73             {
74                 if (timemgr.getUserTime("wiki/"+documents[i]).before(timemgr.getSystemTime("wiki/"+documents[i])))
75                     return true;
76             }
77
78             return false;
79         }*/

80     }
81
82     public boolean getNewStrips() throws Exception JavaDoc
83     {
84         boolean newStrips = false;
85
86         ItemListManager itemLists = (ItemListManager)manager.getManager(ItemListManager.class.getName());
87
88         ComicManager cmgr = (ComicManager)manager.getManager(ComicManager.class.getName());
89         String JavaDoc comicHotlist[] = itemLists.getList("comics hotlist");
90         for (int i = 0; i < comicHotlist.length; i++)
91         {
92             Comic c = cmgr.getComic(Long.parseLong(comicHotlist[i]));
93             if (c != null)
94             {
95                 long pos = cmgr.getPosition(manager.getUserID(), c.ID);
96                 if (pos < c.latestID)
97                 {
98                     newStrips = true;
99                     break;
100                 }
101             }
102         }
103
104         return newStrips;
105     }
106
107     public String JavaDoc getPlanningWarning() throws Exception JavaDoc
108     {
109         String JavaDoc warning = "";
110         Event[] events = planningMgr.getEvents();
111         Date JavaDoc now = new Date JavaDoc();
112         for (int i = 0; i != events.length; i++)
113         {
114             // if the answer is no
115
if (planningMgr.getEventData(events[i].ID, manager.getUserID()).data != 2)
116             {
117                 long diffDays = (events[i].time.getTime()-now.getTime())/86400000L;
118                 if (diffDays >= 0)
119                 {
120                     if (diffDays == 0)
121                         warning = "notice ";
122                     else if (diffDays < 7)
123                         warning = "notice2 ";
124                 }
125                 warning+=diffDays;
126                 warning+=" ";
127                 warning+=events[i].name;
128                 warning+=" ";
129             }
130         }
131         return warning;
132     }
133
134     public String JavaDoc getBirthdaysWarning()
135     {
136         Date JavaDoc now = new Date JavaDoc();
137         String JavaDoc birthdaysWarning = "standard";
138
139         try
140         {
141             User users[] = manager.getCommonGroupUsers(manager.getUserID());
142             long days = 365, diff;
143             String JavaDoc test = null;
144             for (int i = 0; i < users.length; i++)
145             {
146                 if (users[i].birthdate != null && users[i].getId() != manager.getUserID())
147                 {
148                     diff = (new Date JavaDoc(now.getYear(), users[i].birthdate.getMonth(), users[i].birthdate.getDate()).getTime()-now.getTime())/86400000; //86400000=(1000*60*60*24)
149
int year = now.getYear()-users[i].birthdate.getYear();
150
151                     long userdays = diff; //86400000=(1000*60*60*24)
152
if (userdays < -5)
153                     {
154                         userdays += 365;
155                         year++;
156                         if (year%4 == 0 && year%400 != 0)
157                             userdays++;
158                     }
159
160                     if (userdays < days)
161                         days = userdays;
162                 }
163             }
164
165             if (days == 0)
166                 birthdaysWarning = "notice";
167             else if (days < 7 && days > 0)
168                 birthdaysWarning = "notice2";
169         }
170         catch (Exception JavaDoc e)
171         {
172             addErrorMessage("getting contents failed, exception thrown ("+e.toString()+")");
173             e.printStackTrace();
174             return "";
175         }
176
177         return birthdaysWarning;
178     }
179
180     // Implementation -------------------------------------------------
181
protected String JavaDoc doExecute()
182     {
183         // init variables
184
try
185         {
186             // todos
187
todoMgr = (TodoManager)manager.getManager(TodoManager.class.getName());
188             timekeeper = (Timekeeper)manager.getManager(Timekeeper.class.getName());
189             planningMgr = (PlanningManager)manager.getManager(PlanningManager.class.getName());
190             pollMgr = (PollManager)manager.getManager(PollManager.class.getName());
191             taskMgr = (TaskManager)manager.getManager(TaskManager.class.getName());
192
193             return SUCCESS;
194         }
195         catch (Exception JavaDoc e)
196         {
197             addErrorMessage("getting contents failed, exception thrown ("+e.toString()+")");
198             e.printStackTrace();
199             return ERROR;
200         }
201   }
202 }
203
Popular Tags