KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > killingar > forum > actions > comic > 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 /**
27  *
28  */

29 package net.killingar.forum.actions.comic;
30
31 import net.killingar.forum.internal.Comic;
32
33 import java.util.ArrayList JavaDoc;
34
35 public class List extends ActionComicsSupport
36 {
37     // Private --------------------------------------------------------
38

39     // Attributes -----------------------------------------------------
40
java.util.List JavaDoc subscribed = new ArrayList JavaDoc();
41     java.util.List JavaDoc ignored = new ArrayList JavaDoc();
42     boolean showIgnored = false;
43
44     // Methods --------------------------------------------------------
45

46     // Types ----------------------------------------------------------
47
static class ComicData implements Comparable JavaDoc
48     {
49         Comic comic;
50         boolean unread;
51         long position;
52
53         public ComicData(Comic comic, boolean unread, long position)
54         {
55             this.comic = comic;
56             this.unread = unread;
57             this.position = position;
58         }
59
60         public Comic getComic() { return comic; }
61         public boolean getUnread() { return unread; }
62         public long getPosition() { return position; }
63
64         public int compareTo(Object JavaDoc _o)
65         {
66             ComicData o = (ComicData)_o;
67             return comic.compareTo(o.comic);
68         }
69     }
70
71     // Setters --------------------------------------------------------
72
public void setShowIgnored(boolean showIgnored) { this.showIgnored = showIgnored; }
73
74     // Getters --------------------------------------------------------
75
public java.util.List JavaDoc getSubscribed() { return subscribed; }
76     public java.util.List JavaDoc getIgnored() { return ignored; }
77     public boolean getShowIgnored() { return showIgnored; }
78
79
80   // Implementation -------------------------------------------------
81
protected String JavaDoc doExecute()
82     {
83         try
84         {
85             Comic comics[] = comicmgr.getComics();
86
87             for (int i = 0; i < comics.length; i++)
88             {
89                 Comic c = comics[i];
90                 long pos = comicmgr.getPosition(manager.getUserID(), comics[i].ID);
91                 if (pos == 0 || pos == -1)
92                     pos = c.firstID;
93
94                 if (itemLists.hasItem("comics hotlist", Long.toString(comics[i].ID)))
95                 {
96                     subscribed.add(new ComicData(comics[i], pos < c.latestID, pos));
97                 }
98                 else
99                 {
100                     ignored.add(new ComicData(comics[i], pos < c.latestID, pos));
101                 }
102             }
103
104             java.util.Collections.sort(subscribed);
105             java.util.Collections.sort(ignored);
106
107             if (subscribed.size() == 0)
108                 showIgnored = true;
109         }
110         catch (Exception JavaDoc e)
111         {
112             e.printStackTrace();
113             addErrorMessage("executing "+getClass().toString()+" action failed, exception thrown: "+e.toString());
114             return ERROR;
115         }
116
117         return SUCCESS;
118     }
119 }
120
Popular Tags