1 25 26 package net.killingar.forum.actions.hotlist; 27 28 import net.killingar.forum.actions.Utils; 29 import net.killingar.forum.internal.Area; 30 import net.killingar.forum.internal.IDItemImpl; 31 import net.killingar.forum.internal.managers.AreaManager; 32 import net.killingar.forum.internal.managers.TimeManager; 33 34 import java.sql.SQLException ; 35 import java.sql.Timestamp ; 36 import java.util.ArrayList ; 37 import java.util.List ; 38 import java.util.Map ; 39 40 public class AreaGroups extends ActionHotlistSupport implements webwork.action.ParameterAware 41 { 42 TimeManager timemgr; 43 List areaGroups; 44 boolean addAreaGroupAccess; 45 Map parameters; 46 47 public void setSession(Map map) 48 { 49 super.setSession(map); 50 synchronized (map) 51 { 52 try 53 { 54 timemgr = (TimeManager)super.manager.getManager(TimeManager.class.getName()); 55 if (timemgr == null) 56 addErrorMessage("failed to initialize time manager, null returned "); 57 } 58 catch (Exception exception) 59 { 60 addErrorMessage("failed to initialize time manager, exception thrown: " + exception.toString()); 61 } 62 } 63 } 64 65 public void setParameters(Map parameters) { this.parameters = parameters; } 66 public List getAreaGroups() { return areaGroups; } 67 public boolean getAddAreaGroupAccess() { return addAreaGroupAccess; } 68 69 static class AreaGroupData 70 { 71 net.killingar.forum.internal.AreaGroup areaGroup; 72 boolean unread; 73 String indent; 74 boolean subscribePassive; 75 boolean subscribeActive; 76 boolean subscribeNone; 77 78 public net.killingar.forum.internal.AreaGroup getAreaGroup() { return areaGroup; } 79 public boolean getUnread() { return unread; } 80 public String getIndent() { return indent; } 81 public boolean getSubscribePassive() { return subscribePassive; } 82 public boolean getSubscribeActive() { return subscribeActive; } 83 public boolean getSubscribeNone() { return subscribeNone; } 84 85 AreaGroupData(net.killingar.forum.internal.AreaGroup areagroup, boolean unread, long indent, boolean subscribePassive, boolean subscribeActive) 86 { 87 areaGroup = areagroup; 88 this.unread = unread; 89 this.indent = Utils.buildStringOnlyIndent(indent); 90 this.subscribePassive = subscribePassive; 91 this.subscribeActive = subscribeActive; 92 if (!subscribePassive && !subscribeActive) 93 subscribeNone = true; 94 else 95 subscribeNone = false; 96 } 97 } 98 99 public void prepare() throws Exception 100 { 101 net.killingar.forum.internal.AreaGroup areaGroups[] = super.areamgr.getAreaGroups(); 102 103 long indent[] = new long[areaGroups.length]; 104 Utils.buildFlatTree(areaGroups, indent); 105 106 for (int k = 0; k < areaGroups.length; k++) 107 if (areaGroups[k] == null) 108 throw new NullPointerException (Long.toString(k)); 109 110 boolean unread[] = getUnread(super.areamgr, timemgr, areaGroups); 111 this.areaGroups = new ArrayList (areaGroups.length); 112 addAreaGroupAccess = super.manager.hasAccess(super.manager.getUserID(), 1024L); 113 114 if (parameters.containsKey("save")) 115 { 116 for (int i = 0; i < areaGroups.length; i++) 117 { 118 String key = Long.toString(areaGroups[i].getId()); 119 if (parameters.containsKey(key)) 120 { 121 String [] values = (String [])parameters.get(key); 122 123 if (values != null && values.length != 0) 124 { 125 Area[] areas = areamgr.getAreasInGroup(areaGroups[i].getId()); 126 boolean passive[] = new boolean[areas.length]; 127 boolean active[] = new boolean[areas.length]; 128 129 for (int j = 0; j < areas.length; j++) 130 { 131 passive[j] = areaHotlistmgr.hasArea(areas[j].getId(), 1); 132 active[j] = areaHotlistmgr.hasArea(areas[j].getId(), 0); 133 } 134 135 boolean changed = false; 136 137 if (values[0].equals("passive")) 138 { 139 if (!areaHotlistmgr.hasAreaGroup(areaGroups[i].getId(), 1)) 140 { 141 areaHotlistmgr.removeAreaGroup(areaGroups[i].getId(), 0); 142 areaHotlistmgr.addAreaGroup(areaGroups[i].getId(), 1); 143 144 changed = true; 145 } 146 } 147 else if (values[0].equals("active")) 148 { 149 if (!areaHotlistmgr.hasAreaGroup(areaGroups[i].getId(), 0)) 150 { 151 areaHotlistmgr.removeAreaGroup(areaGroups[i].getId(), 1); 152 areaHotlistmgr.addAreaGroup(areaGroups[i].getId(), 0); 153 154 changed = true; 155 } 156 } 157 else if (values[0].equals("none")) 158 { 159 if (areaHotlistmgr.hasAreaGroup(areaGroups[i].getId(), 0) || areaHotlistmgr.hasAreaGroup(areaGroups[i].getId(), 1)) 160 { 161 areaHotlistmgr.removeAreaGroup(areaGroups[i].getId(), 0); 162 areaHotlistmgr.removeAreaGroup(areaGroups[i].getId(), 1); 163 164 changed = true; 165 } 166 } 167 168 if (changed) 170 { 171 for (int j = 0; j < areas.length; j++) 172 { 173 areaHotlistmgr.removeArea(areas[j].getId(), 0); 174 areaHotlistmgr.removeArea(areas[j].getId(), 1); 175 176 if (passive[j]) 177 { 178 areaHotlistmgr.addArea(areas[j].getId(), 1); 179 } 180 else if (active[j]) 181 { 182 areaHotlistmgr.addArea(areas[j].getId(), 0); 183 } 184 } 186 } 187 } 188 } 189 } 190 } 191 192 for (int i = 0; i < areaGroups.length; i++) 193 { 194 this.areaGroups.add(new AreaGroupData(areaGroups[i], unread[i], indent[i], areaHotlistmgr.hasAreaGroup(areaGroups[i].getId(), 1), areaHotlistmgr.hasAreaGroup(areaGroups[i].getId(), 0))); 195 if (super.areamgr.hasAccess(super.manager.getUserID(), areaGroups[i].getId(), 1024L)) 196 addAreaGroupAccess = true; 197 } 198 } 199 200 protected String doExecute() 201 { 202 return SUCCESS; 203 } 204 205 private final boolean[] getUnread(AreaManager areamanager, TimeManager timemanager, net.killingar.forum.internal.AreaGroup aareagroup[]) 206 throws SQLException 207 { 208 Area aarea[] = areamanager.getAreas(); 209 long al[] = new long[aarea.length]; 210 for (int i = 0; i < al.length; i++) 211 al[i] = ((IDItemImpl)(aarea[i])).ID; 212 213 Timestamp atimestamp[] = timemanager.getTimes(TimeManager.systemAreas, al); 214 Timestamp atimestamp1[] = timemanager.getUserDataTimes(TimeManager.systemAreas, al); 215 boolean aflag[] = new boolean[aareagroup.length]; 216 for (int j = 0; j < aareagroup.length; j++) 217 aflag[j] = false; 218 219 for (int k = 0; k < aareagroup.length; k++) 220 { 221 for (int l = 0; l < aarea.length; l++) 222 { 223 if (aarea[l].areaGroupID != 224 aareagroup[k].ID) 225 continue; 226 if (atimestamp1[l] == null || !atimestamp1[l].before(atimestamp[l])) 227 continue; 228 aflag[k] = true; 229 break; 230 } 231 } 232 233 return aflag; 234 } 235 } 236 | Popular Tags |