KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > killingar > actions > wiki > Recent


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.actions.wiki;
27
28 import com.portalwizard.silo.Version;
29
30 public class Recent extends WikiAction
31 {
32     java.util.List JavaDoc documents;
33     java.util.Date JavaDoc fromTime;
34     boolean allContexts = false;
35     boolean sort = true;
36
37     public java.util.Date JavaDoc getTime() { return fromTime; }
38     public java.util.List JavaDoc getDocuments() { return documents; }
39     public void setAllContexts(boolean in) { allContexts = in; }
40     public boolean getAllContexts() { return allContexts; }
41
42     public void setTime(java.util.Date JavaDoc in) { fromTime = in; }
43     public void setSort(boolean in) { sort = in; }
44
45     static class DocComparator implements java.util.Comparator JavaDoc
46     {
47         public int compare(Object JavaDoc o1, Object JavaDoc o2)
48         {
49             return ((RecentDoc)o2).getVersion().getCreatetime().compareTo(((RecentDoc)o1).getVersion().getCreatetime());
50         }
51
52         public boolean equals(Object JavaDoc obj)
53         {
54             return obj instanceof DocComparator;
55         }
56     }
57
58     static class RecentDoc
59     {
60         Version v;
61         boolean unread;
62
63     public RecentDoc(Version v, boolean unread)
64         {
65             this.v = v;
66             this.unread = unread;
67         }
68
69         public Version getVersion() {return v;}
70         public boolean getUnread() {return unread;}
71     }
72
73     protected String JavaDoc doExecute() throws Exception JavaDoc
74     {
75         //testTime = System.currentTimeMillis();
76

77         java.util.List JavaDoc contexts;
78         if (allContexts)
79             contexts = dvm.findAllContexts();
80         else
81         {
82             contexts = new java.util.ArrayList JavaDoc();
83             contexts.add(context);
84         }
85
86         documents = new java.util.ArrayList JavaDoc();
87
88         for (java.util.Iterator JavaDoc c = contexts.iterator(); c.hasNext(); )
89         {
90             String JavaDoc context = (String JavaDoc)c.next();
91             java.util.List JavaDoc keys = dvm.findDockeys(context);
92
93             String JavaDoc key = null;
94             for (java.util.Iterator JavaDoc i = keys.iterator(); i.hasNext(); )
95             {
96                 key = (String JavaDoc)i.next();
97
98                 Version v = vm.get(context, key);
99
100                 documents.add(new RecentDoc(v, fromTime == null || (v.getCreatetime().after(fromTime))));
101             }
102         }
103
104
105         if (sort)
106             java.util.Collections.sort(documents, new DocComparator());
107
108         //testTime = System.currentTimeMillis()-testTime;
109

110         return SUCCESS;
111     }
112 }
113
Popular Tags