1 25 26 package net.killingar.forum.actions.area; 27 28 import net.killingar.forum.internal.*; 29 30 import java.sql.Timestamp ; 31 import java.util.Iterator ; 32 33 public class View extends ActionAreaSupport 34 { 35 static final long NOT_SET = -1; 37 38 static final java.text.SimpleDateFormat dateFormatter = new java.text.SimpleDateFormat ("EEE' 'MMM' 'dd' 'HH:mm"); 40 41 Iterator messages = null; 42 long areaID = -1; 43 Area area = null; 44 boolean showHidden = false; 45 boolean showingUnread = false; 46 long time = NOT_SET, setTime = NOT_SET; 47 Timestamp timeTimestamp; Timestamp timeTimestamp2; private AreaInfo areaInfo; 50 long maxIndent = 0; 51 52 int startPageID = -1; 53 int pageID = -1; 54 55 protected AreaCustomizer areaCustomizer; 56 57 59 61 public void setAreaID (long areaID) { this.areaID = areaID; } 63 public void setPage (int pageID) { this.pageID = pageID; } 64 public void setShowHidden (boolean showHidden) { this.showHidden = showHidden; } 65 public void setTime (long time) { this.time = time; } 66 public void setSetTime (long time) { this.setTime = time; } 67 68 public boolean getShowingUnread(){ return showingUnread; } 70 public Iterator getMessages() { return messages; } 71 public Area getArea() { return area; } 72 public long getAreaID() { return areaID; } 73 public boolean getShowHidden() { return showHidden; } 74 public long getTime() { return time; } 75 76 public int getStartPage() { return startPageID+1; } 77 public int getEndPage() { return pageID+1; } 78 79 public int getStartPageID() { return startPageID; } 80 public int getPageID() { return pageID; } 81 public int getNumberOfPages(){ return areaInfo.pages.size(); } 82 public int getLastPage() { return areaInfo.numberOfPages-1; } 83 public long getPrevPage() { return startPageID-1; } 84 public long getNextPage() { return pageID+1; } 85 public AreaInfo getAreaInfo() { return areaInfo; } 86 87 public String getMessageView() { return areaCustomizer.getMessageView(); } 88 public String getView() { return areaCustomizer.getView(); } 89 public AreaCustomizer getAreaCustomizer() { return areaCustomizer; } 90 91 public long getColspan(int in) 93 { 94 return maxIndent+1-in; 95 } 96 97 public boolean getBodyEmpty(Message m) 98 { 99 return m.getBody() == null || m.getBody().length() == 0; 100 } 101 102 public boolean getDeleteAccess(Message message) throws java.sql.SQLException , AccessDeniedException 103 { 104 return 105 message.getOwnerID() == manager.getUserID() || 106 areamgr.hasAccess(manager.getUserID(), area.getAreaGroupID(), AccessLevel.removeMessage); 107 } 108 109 public boolean getUnread(Message m) 110 { 111 return m.lastChanged.after(timeTimestamp); } 113 114 public String getCssClass(Message m) 115 { 116 if (m.lastChanged.after(timeTimestamp2)) 117 return " unread"; 118 else if (m.lastChanged.after(timeTimestamp)) 119 return " unread2"; 120 else 121 return ""; 122 } 123 124 public boolean getEditable(long messageID) throws java.sql.SQLException , AccessDeniedException 125 { 126 ParentIDItemTreeNode node = areamgr.getMessageSubtree(areaID, messageID); 128 return ((Message)node.item).ownerID == manager.getUserID() && !node.hasSubnodes(); 129 } 130 131 protected void doValidation() 133 { 134 if (areaID == -1) 136 addErrorMessage("no area specified"); 137 else 138 { 139 try 140 { 141 area = areamgr.getArea(areaID); 142 } 143 catch(Exception e) 144 { 145 addErrorMessage("error getting area ("+e.getMessage()+")"); 146 } 147 148 if (area == null) 149 addErrorMessage("invalid area ID specified"); 150 } 151 } 152 153 protected String doExecute() 154 { 155 try 156 { 157 if (setTime != NOT_SET) 159 areamgr.setRead(areaID, new Timestamp (setTime)); 160 161 if (time == NOT_SET) 162 time = System.currentTimeMillis(); 163 164 ParentIDItemTreeNode messagesTree = areamgr.getMessagesTree(areaID); 166 167 areaInfo = new AreaInfo(areamgr, areaID, showHidden, new Timestamp (time)); 168 169 areaCustomizer = AbstractAreaCustomizer.getAreaCustomizer(areaInfo.area); 170 171 if (pageID == -1 || pageID >= getNumberOfPages()) 173 pageID = getNumberOfPages()-1; 174 if (pageID < 0) 175 pageID = 0; 176 177 if (areaInfo.firstnewID == 0 && areaInfo.lastMessage != null) 179 areaInfo.firstnewID = areaInfo.lastMessage.getId(); 180 181 startPageID = pageID; 183 for (int i = 0; i < areaInfo.pages.size() && i < pageID; i++) 184 { 185 if (((Page)areaInfo.pages.get(i)).getHasNewMessages()) 186 { 187 startPageID = i; 188 break; 189 } 190 } 191 192 195 Page page = (Page)areaInfo.pages.get(pageID); 197 Page startPage = (Page)areaInfo.pages.get(startPageID); 198 for ( 199 Iterator i = 200 new FilterMessagesIterator(showHidden, 201 new SubsetIterator(startPage.getStartIndex(), page.getEndIndex(), 202 new TreeIterator(messagesTree))); 203 i.hasNext();) 204 { 205 ParentIDItemTreeNode foo = (ParentIDItemTreeNode)i.next(); 206 if (foo.indent > maxIndent) 207 maxIndent = foo.indent; 208 } 209 210 if (startPage.getHasNewMessages()) 211 showingUnread = true; 212 213 messages = 215 new FilterMessagesIterator(showHidden, 216 new SubsetIterator(startPage.getStartIndex(), page.getEndIndex(), 217 new TreeIterator(messagesTree))); 218 219 if (time == NOT_SET) 221 time = areaInfo.areaTime.getTime(); 222 223 if (setTime == NOT_SET) 224 areamgr.setRead(areaID); 225 226 timeTimestamp = new Timestamp (time); 227 timeTimestamp2 = new Timestamp (areaInfo.areaTime.getTime()); 228 229 return SUCCESS; 230 } 231 catch (Exception e) 232 { 233 addErrorMessage("displaying area page failed, exception thrown ("+e.toString()+")"); 234 e.printStackTrace(); 235 return ERROR; 236 } 237 } 238 } | Popular Tags |