1 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 documents; 33 java.util.Date fromTime; 34 boolean allContexts = false; 35 boolean sort = true; 36 37 public java.util.Date getTime() { return fromTime; } 38 public java.util.List 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 in) { fromTime = in; } 43 public void setSort(boolean in) { sort = in; } 44 45 static class DocComparator implements java.util.Comparator 46 { 47 public int compare(Object o1, Object o2) 48 { 49 return ((RecentDoc)o2).getVersion().getCreatetime().compareTo(((RecentDoc)o1).getVersion().getCreatetime()); 50 } 51 52 public boolean equals(Object 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 doExecute() throws Exception 74 { 75 77 java.util.List contexts; 78 if (allContexts) 79 contexts = dvm.findAllContexts(); 80 else 81 { 82 contexts = new java.util.ArrayList (); 83 contexts.add(context); 84 } 85 86 documents = new java.util.ArrayList (); 87 88 for (java.util.Iterator c = contexts.iterator(); c.hasNext(); ) 89 { 90 String context = (String )c.next(); 91 java.util.List keys = dvm.findDockeys(context); 92 93 String key = null; 94 for (java.util.Iterator i = keys.iterator(); i.hasNext(); ) 95 { 96 key = (String )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 110 return SUCCESS; 111 } 112 } 113 | Popular Tags |