1 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 ; 34 import java.util.ArrayList ; 35 import java.util.Arrays ; 36 import java.util.List ; 37 import java.util.Map ; 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 hotlist; 46 47 public List 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 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 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 75 { 76 hotlist = new ArrayList (); 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 areaTimes[] = timemanager.getTimes(TimeManager.systemAreas, hotlistIds); 88 Timestamp 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); hotlist = new ArrayList (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 |