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.ForumPermissions; 33 import org.nemesis.forum.ForumThread; 34 import org.nemesis.forum.Message; 35 import org.nemesis.forum.User; 36 import org.nemesis.forum.config.Constants; 37 import org.nemesis.forum.exception.UnauthorizedException; 38 39 42 public class MessageProxy implements Message { 43 44 private Message message; 45 private Authorization authorization; 46 private ForumPermissions permissions; 47 48 52 public MessageProxy(Message message, Authorization authorization, ForumPermissions permissions) { 53 this.message = message; 54 this.authorization = authorization; 55 this.permissions = permissions; 56 } 57 58 60 public int getID() { 61 return message.getID(); 62 } 63 64 public boolean isApproved() { 65 return message.isApproved(); 66 } 67 68 69 public void setApproved(boolean approved) throws UnauthorizedException { 70 if (permissions.isSystemOrForumAdmin() || permissions.get(Constants.MODERATOR)) { 71 message.setApproved(approved); 72 } else { 73 throw new UnauthorizedException(); 74 } 75 } 76 77 public Date getCreationDate() { 78 return message.getCreationDate(); 79 } 80 81 public void setCreationDate(Date creationDate) throws UnauthorizedException { 82 if (permissions.isSystemOrForumAdmin()) { 83 this.message.setCreationDate(creationDate); 84 } else { 85 throw new UnauthorizedException(); 86 } 87 } 88 89 public Date getModifiedDate() { 90 return message.getModifiedDate(); 91 } 92 93 public void setModifiedDate(Date modifiedDate) throws UnauthorizedException { 94 if (permissions.isSystemOrForumAdmin()) { 95 this.message.setModifiedDate(modifiedDate); 96 } else { 97 throw new UnauthorizedException(); 98 } 99 } 100 101 public String getSubject() { 102 return message.getSubject(); 103 } 104 105 public String getUnfilteredSubject() { 106 return message.getUnfilteredSubject(); 107 } 108 109 public void setSubject(String subject) throws UnauthorizedException { 110 if (permissions.isSystemOrForumAdmin() || getUser().hasPermission(Constants.USER_ADMIN)) { 111 this.message.setSubject(subject); 112 } else { 113 throw new UnauthorizedException(); 114 } 115 } 116 117 public String getBody() { 118 return message.getBody(); 119 } 120 121 public String getUnfilteredBody() { 122 return message.getUnfilteredBody(); 123 } 124 125 public void setBody(String body) throws UnauthorizedException { 126 if (permissions.isSystemOrForumAdmin() || getUser().hasPermission(Constants.USER_ADMIN)) { 127 this.message.setBody(body); 128 } else { 129 throw new UnauthorizedException(); 130 } 131 } 132 133 public User getUser() { 134 User user = message.getUser(); 135 ForumPermissions userPermissions = user.getPermissions(authorization); 136 ForumPermissions newPermissions = new ForumPermissions(permissions, userPermissions); 137 return new UserProxy(user, authorization, newPermissions); 138 } 139 140 public String getProperty(String name) { 141 return message.getProperty(name); 142 } 143 144 public String getUnfilteredProperty(String name) { 145 return message.getUnfilteredProperty(name); 146 } 147 148 public void setProperty(String name, String value) { 149 message.setProperty(name, value); 150 } 151 152 public Iterator propertyNames() { 153 return message.propertyNames(); 154 } 155 156 public boolean isAnonymous() { 157 return message.isAnonymous(); 158 } 159 160 public ForumThread getForumThread() { 161 return message.getForumThread(); 162 } 163 164 public boolean hasPermission(int type) { 165 return permissions.get(type); 166 } 167 168 170 175 public String toString() { 176 return message.toString(); 177 } 178 179 186 public void insertIntoDb(java.sql.Connection con, ForumThread thread) throws SQLException { 187 ((org.nemesis.forum.impl.DbForumMessage) message).insertIntoDb(con, thread); 188 } 189 190 196 public void setApproved2(boolean approved) throws UnauthorizedException { 197 message.setApproved(approved); 198 } 199 200 } 201 | Popular Tags |