1 25 package org.nemesis.forum.proxy; 26 27 import java.sql.SQLException ; 28 import java.util.Date ; 29 import java.util.Iterator ; 30 31 import org.nemesis.forum.Authorization; 32 import org.nemesis.forum.Forum; 33 import org.nemesis.forum.ForumPermissions; 34 import org.nemesis.forum.ForumThread; 35 import org.nemesis.forum.Message; 36 import org.nemesis.forum.TreeWalker; 37 import org.nemesis.forum.impl.DbForumThread; 38 import org.nemesis.forum.config.Constants; 39 import org.nemesis.forum.exception.ForumMessageNotFoundException; 40 import org.nemesis.forum.exception.UnauthorizedException; 41 42 47 public class ForumThreadProxy implements ForumThread { 48 49 private ForumThread thread; 50 private Authorization authorization; 51 private ForumPermissions permissions; 52 53 56 public ForumThreadProxy(ForumThread thread, Authorization authorization, ForumPermissions permissions) { 57 this.thread = thread; 58 this.authorization = authorization; 59 this.permissions = permissions; 60 } 61 62 public int getID() { 63 return thread.getID(); 64 } 65 66 public String getName() { 67 return thread.getName(); 68 } 69 70 public boolean isApproved() { 71 return thread.isApproved(); 72 } 73 74 public void setApproved(boolean approved) throws UnauthorizedException { 75 if (permissions.isSystemOrForumAdmin() || permissions.get(Constants.MODERATOR)) { 76 thread.setApproved(approved); 77 } else { 78 throw new UnauthorizedException(); 79 } 80 } 81 82 public Date getCreationDate() { 83 return thread.getCreationDate(); 84 } 85 86 public void setCreationDate(Date creationDate) throws UnauthorizedException { 87 if (permissions.isSystemOrForumAdmin()) { 88 thread.setCreationDate(creationDate); 89 } else 90 throw new UnauthorizedException(); 91 } 92 93 public Date getModifiedDate() { 94 return thread.getModifiedDate(); 95 } 96 97 public void setModifiedDate(Date modifiedDate) throws UnauthorizedException { 98 if (permissions.isSystemOrForumAdmin()) { 99 thread.setModifiedDate(modifiedDate); 100 } else 101 throw new UnauthorizedException(); 102 } 103 104 public Forum getForum() { 105 Forum forum = thread.getForum(); 106 return new ForumProxy(forum, authorization, permissions); 107 } 108 109 public int getMessageCount() { 110 return thread.getMessageCount(); 111 } 112 113 public int getMessageCount(boolean approved) { 114 return thread.getMessageCount(approved); 115 } 116 117 118 public Message getRootMessage() { 119 Message message = thread.getRootMessage(); 120 return new MessageProxy(message, authorization, permissions); 121 } 122 123 public void addMessage(Message parentMessage, Message newMessage) { 124 thread.addMessage(parentMessage, newMessage); 125 } 126 127 public void deleteMessage(Message message) throws UnauthorizedException { 128 if (permissions.isSystemOrForumAdmin() || permissions.get(Constants.MODERATOR)) { 129 thread.deleteMessage(message); 130 } else { 131 throw new UnauthorizedException(); 132 } 133 } 134 135 public void moveMessage(Message message, ForumThread newThread, Message parentMessage) 136 throws UnauthorizedException { 137 if (permissions.isSystemOrForumAdmin() 139 && (newThread.hasPermission(Constants.SYSTEM_ADMIN) || newThread.hasPermission(Constants.FORUM_ADMIN))) { 140 thread.moveMessage(message, newThread, parentMessage); 141 } else { 142 throw new UnauthorizedException(); 143 } 144 } 145 146 public Message getMessage(int messageID) throws ForumMessageNotFoundException { 147 Message message = thread.getMessage(messageID); 148 return new MessageProxy(message, authorization, permissions); 150 } 151 152 public TreeWalker treeWalker() { 153 return new TreeWalkerProxy(thread.treeWalker(), authorization, permissions); 154 } 155 156 public TreeWalker treeWalker(boolean approved) { 157 return new TreeWalkerProxy(thread.treeWalker(approved), authorization, permissions); 158 } 159 160 public Iterator messages() { 161 Iterator iterator = thread.messages(); 162 return new MessageIteratorProxy(iterator, authorization, permissions); 163 } 164 165 public Iterator messages(int startIndex, int numResults) { 166 Iterator iterator = thread.messages(startIndex, numResults); 167 return new MessageIteratorProxy(iterator, authorization, permissions); 168 } 169 170 public Iterator messages(boolean approved) { 171 Iterator iterator = thread.messages(approved); 172 return new MessageIteratorProxy(iterator, authorization, permissions); 173 } 174 175 public Iterator messages(boolean approved,int startIndex, int numResults) { 176 Iterator iterator = thread.messages(approved,startIndex, numResults); 177 return new MessageIteratorProxy(iterator, authorization, permissions); 178 } 179 180 public boolean hasPermission(int type) { 181 return permissions.get(type); 182 } 183 184 public String toString() { 185 return thread.toString(); 186 } 187 188 194 public void insertIntoDb(java.sql.Connection con) throws SQLException { 195 ((DbForumThread) thread).insertIntoDb(con); 196 } 197 } 198 | Popular Tags |