1 53 54 106 107 package com.Yasna.forum; 108 109 import java.util.Date ; 110 import java.util.Iterator ; 111 112 117 public class ForumThreadProxy implements ForumThread { 118 119 private ForumThread thread; 120 private Authorization authorization; 121 private ForumPermissions permissions; 122 123 126 public ForumThreadProxy(ForumThread thread, Authorization authorization, 127 ForumPermissions permissions) 128 { 129 this.thread = thread; 130 this.authorization = authorization; 131 this.permissions = permissions; 132 } 133 134 public int getID() { 135 return thread.getID(); 136 } 137 138 public String getName() { 139 return thread.getName(); 140 } 141 142 public Date getCreationDate() { 143 return thread.getCreationDate(); 144 } 145 146 public void setCreationDate(Date creationDate) 147 throws UnauthorizedException 148 { 149 if (permissions.isSystemOrForumAdmin()) { 150 thread.setCreationDate(creationDate); 151 } 152 else throw new UnauthorizedException(); 153 } 154 155 public Date getModifiedDate() { 156 return thread.getModifiedDate(); 157 } 158 159 public void setModifiedDate(Date modifiedDate) 160 throws UnauthorizedException 161 { 162 if (permissions.isSystemOrForumAdmin()) { 163 thread.setModifiedDate(modifiedDate); 164 } 165 else throw new UnauthorizedException(); 166 } 167 168 public Forum getForum() { 169 Forum forum = thread.getForum(); 170 return new ForumProxy(forum, authorization, permissions); 171 } 172 173 public int getMessageCount() { 174 return thread.getMessageCount(); 175 } 176 public int getReadCount(){ 177 return thread.getReadCount(); 178 } 179 public void addReadCount(){ 180 thread.addReadCount(); 181 } 182 183 public ForumMessage getRootMessage() { 184 ForumMessage message = thread.getRootMessage(); 185 return new ForumMessageProxy(message, authorization, permissions); 186 } 187 188 public void addMessage(ForumMessage parentMessage, ForumMessage newMessage) throws UnauthorizedException 189 { 190 if ((permissions.isSystemOrForumAdmin() || permissions.get(ForumPermissions.CREATE_MESSAGE))&& !thread.isClosed()){ 192 thread.addMessage(parentMessage, newMessage); 193 } 194 else { 195 throw new UnauthorizedException(); 196 } 197 } 198 199 public void deleteMessage(ForumMessage message) 200 throws UnauthorizedException 201 { 202 if (permissions.isSystemOrForumAdmin() || 203 permissions.get(ForumPermissions.MODERATOR)) { 204 thread.deleteMessage(message); 205 } 206 else { 207 throw new UnauthorizedException(); 208 } 209 } 210 211 public void moveMessage(ForumMessage message, ForumThread newThread, 212 ForumMessage parentMessage) throws UnauthorizedException 213 { 214 if (permissions.isSystemOrForumAdmin() && ( 216 newThread.hasPermission(ForumPermissions.SYSTEM_ADMIN) || 217 newThread.hasPermission(ForumPermissions.FORUM_ADMIN))) 218 { 219 thread.moveMessage(message, newThread, parentMessage); 220 } 221 else { 222 throw new UnauthorizedException(); 223 } 224 } 225 226 public ForumMessage getMessage(int messageID) 227 throws ForumMessageNotFoundException 228 { 229 ForumMessage message = thread.getMessage(messageID); 230 return new ForumMessageProxy(message, authorization, permissions); 232 } 233 234 public boolean isApproved() { 235 return thread.isApproved(); 236 } 237 238 public void setApprovment(boolean approved) throws UnauthorizedException 239 { 240 if (permissions.isSystemOrForumAdmin() || 241 permissions.get(ForumPermissions.MODERATOR)) { 242 thread.setApprovment(approved); 243 } 244 else throw new UnauthorizedException(); 245 } 246 247 public TreeWalker treeWalker() { 248 return new TreeWalkerProxy(thread.treeWalker(), authorization, permissions); 249 } 250 251 public Iterator messages() { 252 Iterator iterator = thread.messages(); 253 return new MessageIteratorProxy(iterator, authorization, permissions); 254 } 255 256 public Iterator messages(int startIndex, int numResults) { 257 Iterator iterator = thread.messages(startIndex, numResults); 258 return new MessageIteratorProxy(iterator, authorization, permissions); 259 } 260 261 public boolean hasPermission(int type) { 262 return permissions.get(type); 263 } 264 265 public String toString() { 266 return thread.toString(); 267 } 268 269 275 public void insertIntoDb(java.sql.Connection con) 276 throws java.sql.SQLException 277 { 278 ((com.Yasna.forum.database.DbForumThread)thread).insertIntoDb(con); 279 } 280 public ThreadType getThreadType(){ 281 return thread.getThreadType(); 282 } 283 public boolean isSticky(){ 284 return thread.isSticky(); 285 } 286 public void setSticky(boolean param) throws UnauthorizedException{ 287 if (permissions.isSystemOrForumAdmin() || 288 permissions.get(ForumPermissions.MODERATOR)) { 289 thread.setSticky(param); 290 } 291 else throw new UnauthorizedException(); 292 } 293 public boolean isClosed(){ 294 return thread.isClosed(); 295 } 296 public void setClosed(boolean param) throws UnauthorizedException{ 297 if (permissions.isSystemOrForumAdmin() || 298 permissions.get(ForumPermissions.MODERATOR)) { 299 thread.setClosed(param); 300 } 301 else throw new UnauthorizedException(); 302 } 303 } 304 | Popular Tags |