1 25 26 package net.killingar.forum.actions.areagroup; 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 37 public class List extends net.killingar.forum.actions.area.ActionAreaSupport 38 { 39 TimeManager timemgr; 40 java.util.List areaGroups; 41 boolean addAreaGroupAccess; 42 43 public boolean getAddAreaGroupAccess() { return addAreaGroupAccess; } 44 public java.util.List getAreaGroups() { return areaGroups; } 45 46 public static class AreaGroupData 47 { 48 net.killingar.forum.internal.AreaGroup areaGroup; 49 String indent; 50 boolean unread; 51 52 public AreaGroupData(net.killingar.forum.internal.AreaGroup areaGroup, boolean unread, long indent) 53 { 54 this.areaGroup = areaGroup; 55 this.indent = Utils.buildStringOnlyIndent(indent); 56 this.unread = unread; 57 } 58 59 public net.killingar.forum.internal.AreaGroup getAreaGroup() { return areaGroup; } 60 public boolean getUnread() { return unread; } 61 public String getIndent() { return indent; } 62 } 63 64 protected String doExecute() 65 { 66 try 67 { 68 net.killingar.forum.internal.AreaGroup aareagroup[] = super.areamgr.getAreaGroups(); 69 long al[] = new long[aareagroup.length]; 70 Utils.buildFlatTree(aareagroup, al); 71 boolean aflag[] = getUnread(super.areamgr, timemgr, aareagroup); 72 areaGroups = new java.util.ArrayList (aareagroup.length); 73 addAreaGroupAccess = super.manager.hasAccess(super.manager.getUserID(), 1024L); 74 for (int i = 0; i < aareagroup.length; i++) 75 { 76 areaGroups.add(new AreaGroupData(aareagroup[i], aflag[i], al[i])); 77 if (super.areamgr.hasAccess(super.manager.getUserID(), aareagroup[i].getId(), 1024L)) 78 addAreaGroupAccess = true; 79 } 80 81 return SUCCESS; 82 } 83 catch(Exception exception) 84 { 85 addErrorMessage("displaying area groups failed, exception thrown (" + exception.toString() + ")"); 86 exception.printStackTrace(); 87 return ERROR; 88 } 89 } 90 91 private boolean[] getUnread(AreaManager areamanager, TimeManager timemanager, net.killingar.forum.internal.AreaGroup aareagroup[]) 92 throws SQLException 93 { 94 Area aarea[] = areamanager.getAreas(); 95 long al[] = new long[aarea.length]; 96 for(int i = 0; i < al.length; i++) 97 al[i] = ((IDItemImpl) (aarea[i])).ID; 98 99 Timestamp atimestamp[] = timemanager.getTimes(TimeManager.systemAreas, al); 100 Timestamp atimestamp1[] = timemanager.getUserDataTimes(TimeManager.systemAreas, al); 101 boolean aflag[] = new boolean[aareagroup.length]; 102 for(int j = 0; j < aareagroup.length; j++) 103 aflag[j] = false; 104 105 106 for(int k = 0; k < aareagroup.length; k++) 107 { 108 for(int l = 0; l < aarea.length; l++) 109 { 110 if(aarea[l].areaGroupID != ((IDItemImpl) (aareagroup[k])).ID || !atimestamp1[l].before(atimestamp[l])) 111 continue; 112 aflag[k] = true; 113 break; 114 } 115 } 116 return aflag; 117 } 118 119 public void setSession(java.util.Map map) 120 { 121 super.setSession(map); 122 synchronized(map) 123 { 124 try 125 { 126 timemgr = (TimeManager)super.manager.getManager(TimeManager.class.getName()); 127 if(timemgr == null) 128 addErrorMessage("failed to initialize time manager, null returned "); 129 } 130 catch(Exception exception) 131 { 132 addErrorMessage("failed to initialize time manager, exception thrown: " + exception.toString()); 133 } 134 } 135 } 136 } | Popular Tags |