1 25 26 package net.killingar.forum.actions.hotlist; 27 28 import net.killingar.forum.internal.Area; 29 import net.killingar.forum.internal.IDItemImpl; 30 import net.killingar.forum.internal.managers.TimeManager; 31 32 import java.sql.SQLException ; 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 class AreaGroup extends ActionHotlistSupport 40 { 41 TimeManager timemgr; 42 List areas; 43 long areaGroupID = -1; 44 net.killingar.forum.internal.AreaGroup areaGroup; 45 46 static class AreaData 47 { 48 private Area area; 49 private boolean unread; 50 private boolean hasArea; 51 52 AreaData(Area area, boolean unread, boolean hasArea) 53 { 54 this.area = area; 55 this.unread = unread; 56 this.hasArea = hasArea; 57 } 58 59 public boolean getUnread() 60 { 61 return unread; 62 } 63 64 public boolean getHasArea() 65 { 66 return hasArea; 67 } 68 69 public Area getArea() 70 { 71 return area; 72 } 73 } 74 75 public void setSession(Map map) 76 { 77 super.setSession(map); 78 synchronized (map) 79 { 80 try 81 { 82 timemgr = (TimeManager)super.manager.getManager(TimeManager.class.getName()); 83 if (timemgr == null) 84 addErrorMessage("failed to initialize time manager, null returned "); 85 } 86 catch (Exception exception) 87 { 88 addErrorMessage("failed to initialize time manager, exception thrown: " + exception.toString()); 89 } 90 } 91 } 92 93 public void setAreaGroupID(String s) 94 { 95 areaGroupID = Long.parseLong(s); 96 } 97 98 public List getAreas() 99 { 100 return areas; 101 } 102 103 public net.killingar.forum.internal.AreaGroup getAreaGroup() 104 { 105 return areaGroup; 106 } 107 108 protected void doValidation() 109 { 110 if (areaGroupID == -1) 111 addErrorMessage("no area id specified"); 112 else 113 { 114 try 115 { 116 areaGroup = super.areamgr.getAreaGroup(areaGroupID); 117 } 118 catch (Exception exception) 119 { 120 exception.printStackTrace(); 121 addErrorMessage("failed to get area group, exception thrown: " + exception.toString()); 122 } 123 } 124 } 125 126 protected String doExecute() 127 { 128 try 129 { 130 Area areas[] = super.areamgr.getAreasInGroup(areaGroupID); 131 Arrays.sort(areas); 132 boolean unread[] = getUnread(timemgr, areas); 133 this.areas = new ArrayList (areas.length); 134 for (int i = 0; i < areas.length; i++) 135 this.areas.add(new AreaData(areas[i], unread[i], areaHotlistmgr.hasArea(areas[i].getId(), 0) || areaHotlistmgr.hasArea(areas[i].getId(), 1))); 136 137 return SUCCESS; 138 } 139 catch (Exception exception) 140 { 141 addErrorMessage("displaying area group failed, exception thrown (" + exception.toString() + ")"); 142 exception.printStackTrace(); 143 return ERROR; 144 } 145 } 146 147 private final boolean[] getUnread(TimeManager timemgr, Area areas[]) 148 throws SQLException 149 { 150 long al[] = new long[areas.length]; 151 for (int i = 0; i < al.length; i++) 152 al[i] = ((IDItemImpl)(areas[i])).ID; 153 154 Timestamp atimestamp[] = timemgr.getTimes(TimeManager.systemAreas, al); 155 Timestamp atimestamp1[] = timemgr.getUserDataTimes(TimeManager.systemAreas, al); 156 boolean aflag[] = new boolean[areas.length]; 157 for (int j = 0; j < areas.length; j++) 158 aflag[j] = false; 159 160 for (int k = 0; k < areas.length; k++) 161 if (atimestamp1[k].before(atimestamp[k])) 162 aflag[k] = true; 163 164 return aflag; 165 } 166 } 167 | Popular Tags |