1 25 26 package net.killingar.forum.actions.areagroup; 27 28 import net.killingar.forum.internal.Area; 29 import net.killingar.forum.internal.IDItemImpl; 30 import net.killingar.forum.internal.managers.AreaManager; 31 import net.killingar.forum.internal.managers.TimeManager; 32 33 import java.sql.SQLException ; 34 import java.sql.Timestamp ; 35 36 public class View extends net.killingar.forum.actions.area.ActionAreaSupport 37 { 38 TimeManager timemgr; 39 java.util.List areas; 40 long areaGroupID = -1; 41 net.killingar.forum.internal.AreaGroup areaGroup; 42 43 public static class AreaData 44 { 45 Area area; 46 boolean unread; 47 48 public AreaData(Area area, boolean unread) 49 { 50 this.area = area; 51 this.unread = unread; 52 } 53 54 public Area getArea() {return area;} 55 public boolean getUnread() {return unread;} 56 } 57 58 public net.killingar.forum.internal.AreaGroup getAreaGroup() { return areaGroup; } 59 public java.util.List getAreas() { return areas; } 60 61 public void setAreaGroupID(long in) { areaGroupID = in; } 62 public void setSession(java.util.Map map) 63 { 64 super.setSession(map); 65 synchronized(map) 66 { 67 try 68 { 69 timemgr = (TimeManager)super.manager.getManager(TimeManager.class.getName()); 70 if(timemgr == null) 71 addErrorMessage("failed to initialize time manager, null returned "); 72 } 73 catch(Exception exception) 74 { 75 addErrorMessage("failed to initialize time manager, exception thrown: " + exception.toString()); 76 } 77 } 78 } 79 80 protected String doExecute() 81 { 82 try 83 { 84 Area areas[] = super.areamgr.getAreasInGroup(areaGroupID); 85 java.util.Arrays.sort(areas); 86 87 boolean unread[] = getUnread(super.areamgr, timemgr, areas); 88 this.areas = new java.util.ArrayList (areas.length); 89 for(int i = 0; i < areas.length; i++) 90 this.areas.add(new AreaData(areas[i], unread[i])); 91 92 return SUCCESS; 93 } 94 catch(Exception exception) 95 { 96 addErrorMessage("displaying area group failed, exception thrown (" + exception.toString() + ")"); 97 exception.printStackTrace(); 98 return ERROR; 99 } 100 } 101 102 protected void doValidation() 103 { 104 if(areaGroupID == -1) 105 addErrorMessage("no area id specified"); 106 else 107 { 108 try 109 { 110 areaGroup = super.areamgr.getAreaGroup(areaGroupID); 111 } 112 catch(Exception exception) 113 { 114 exception.printStackTrace(); 115 addErrorMessage("failed to get area group, exception thrown: " + exception.toString()); 116 } 117 } 118 } 119 120 private boolean[] getUnread(AreaManager areamanager, TimeManager timemanager, Area aarea[]) 121 throws SQLException 122 { 123 long al[] = new long[aarea.length]; 124 for(int i = 0; i < al.length; i++) 125 al[i] = ((IDItemImpl) (aarea[i])).ID; 126 127 Timestamp atimestamp[] = timemanager.getTimes(TimeManager.systemAreas, al); 128 Timestamp atimestamp1[] = timemanager.getUserDataTimes(TimeManager.systemAreas, al); 129 boolean aflag[] = new boolean[aarea.length]; 130 for(int j = 0; j < aarea.length; j++) 131 aflag[j] = false; 132 133 for(int k = 0; k < aarea.length; k++) 134 if(atimestamp1[k].before(atimestamp[k])) 135 aflag[k] = true; 136 137 return aflag; 138 } 139 } 140 | Popular Tags |