1 53 54 106 107 package com.Yasna.forum; 108 109 import com.Yasna.forum.util.ClientIP; 110 import com.Yasna.forum.Exceptions.RapidPostingException; 111 import com.Yasna.forum.Exceptions.UserBlackListedException; 112 113 import java.util.Date ; 114 import java.util.Iterator ; 115 import java.util.Enumeration ; 116 117 128 public class ForumProxy implements Forum { 129 130 private Forum forum; 131 private Authorization authorization; 132 private ForumPermissions permissions; 133 134 141 public ForumProxy(Forum forum, Authorization authorization, 142 ForumPermissions permissions) 143 { 144 this.forum = forum; 145 this.authorization = authorization; 146 this.permissions = permissions; 147 } 148 149 151 public int getID() { 152 return forum.getID(); 153 } 154 155 public String getName() { 156 return forum.getName(); 157 } 158 159 public void setName(String name) throws UnauthorizedException, 160 ForumAlreadyExistsException 161 { 162 if (permissions.isSystemOrForumAdmin()) { 163 forum.setName(name); 164 } 165 else { 166 throw new UnauthorizedException(); 167 } 168 } 169 170 public String getDescription() { 171 return forum.getDescription(); 172 } 173 174 public void setDescription(String description) 175 throws UnauthorizedException 176 { 177 if (permissions.isSystemOrForumAdmin()) { 178 forum.setDescription(description); 179 } 180 else { 181 throw new UnauthorizedException(); 182 } 183 } 184 185 public Date getCreationDate() { 186 return forum.getCreationDate(); 187 } 188 189 public void setCreationDate(Date creationDate) 190 throws UnauthorizedException 191 { 192 if (permissions.isSystemOrForumAdmin()) { 193 forum.setCreationDate(creationDate); 194 } 195 else { 196 throw new UnauthorizedException(); 197 } 198 } 199 200 public Date getModifiedDate() { 201 return forum.getModifiedDate(); 202 } 203 204 public void setModifiedDate(Date modifiedDate) 205 throws UnauthorizedException 206 { 207 if (permissions.isSystemOrForumAdmin()) { 208 forum.setModifiedDate(modifiedDate); 209 } 210 else { 211 throw new UnauthorizedException(); 212 } 213 } 214 215 public String getProperty(String name) { 216 return forum.getProperty(name); 217 } 218 219 public void setProperty(String name, String value) 220 throws UnauthorizedException 221 { 222 if (permissions.isSystemOrForumAdmin()) { 223 forum.setProperty(name, value); 224 } 225 else { 226 throw new UnauthorizedException(); 227 } 228 } 229 230 public Enumeration propertyNames() { 231 return forum.propertyNames(); 232 } 233 234 public ForumThread createThread(ForumMessage rootMessage,ThreadType type) 235 throws UnauthorizedException 236 { 237 if (permissions.get(ForumPermissions.CREATE_THREAD)) 238 { 239 ForumThread thread = forum.createThread(rootMessage,type); 240 return new ForumThreadProxy(thread, authorization, permissions); 241 } 242 else { 243 throw new UnauthorizedException(); 244 } 245 } 246 247 public ForumMessage createMessage(User user,ClientIP clientIP) 248 throws UnauthorizedException,RapidPostingException, UserBlackListedException 249 { 250 if (permissions.get(ForumPermissions.CREATE_MESSAGE) || 251 permissions.get(ForumPermissions.CREATE_THREAD) ) 252 { 253 if (user.hasPermission(ForumPermissions.USER_ADMIN) || 256 user.isAnonymous() ) 257 { 258 ForumMessage message = forum.createMessage(user,clientIP); 259 return new ForumMessageProxy(message, authorization, permissions); 260 } 261 else { 262 throw new UnauthorizedException(); 263 } 264 265 } 266 else { 267 throw new UnauthorizedException(); 268 } 269 } 270 public ForumMessage createDummyMessage(User user) 271 throws UnauthorizedException 272 { 273 if (permissions.get(ForumPermissions.CREATE_MESSAGE) || 274 permissions.get(ForumPermissions.CREATE_THREAD) ) 275 { 276 if (user.hasPermission(ForumPermissions.USER_ADMIN) || 279 user.isAnonymous() ) 280 { 281 ForumMessage message = forum.createDummyMessage(user); 282 return new ForumMessageProxy(message, authorization, permissions); 283 } 284 else { 285 throw new UnauthorizedException(); 286 } 287 288 } 289 else { 290 throw new UnauthorizedException(); 291 } 292 } 293 294 public void deleteThread(ForumThread thread) throws UnauthorizedException 295 { 296 if (permissions.isSystemOrForumAdmin() || permissions.get(ForumPermissions.MODERATOR)) { 297 forum.deleteThread(thread); 298 } 299 else { 300 throw new UnauthorizedException(); 301 } 302 } 303 304 public void moveThread(ForumThread thread, Forum newForum) throws 305 UnauthorizedException, IllegalArgumentException 306 { 307 if (permissions.isSystemOrForumAdmin() && ( 309 newForum.hasPermission(ForumPermissions.SYSTEM_ADMIN) || 310 newForum.hasPermission(ForumPermissions.FORUM_ADMIN))) 311 { 312 forum.moveThread(thread, newForum); 313 } 314 else { 315 throw new UnauthorizedException(); 316 } 317 } 318 319 public void addThread(ForumThread thread) throws UnauthorizedException 320 { 321 if (permissions.get(ForumPermissions.CREATE_THREAD)) { 322 forum.addThread(thread); 323 } 324 else { 325 throw new UnauthorizedException(); 326 } 327 } 328 329 public ForumThread getThread(int threadID) throws ForumThreadNotFoundException 330 { 331 ForumThread thread = forum.getThread(threadID); 332 return new ForumThreadProxy(thread, authorization, permissions); 334 } 335 336 public Iterator threads() { 337 Iterator iterator = forum.threads(); 338 return new ThreadIteratorProxy(iterator, authorization, permissions); 339 } 340 341 public Iterator threads(int startIndex, int numResults, int sortBy) { 342 Iterator iterator = forum.threads(startIndex, numResults, sortBy); 343 return new ThreadIteratorProxy(iterator, authorization, permissions); 344 } 345 346 public int getThreadCount() { 347 return forum.getThreadCount(); 348 } 349 350 public int getMessageCount() { 351 return forum.getMessageCount(); 352 } 353 354 public Query createQuery() { 355 return new QueryProxy(forum.createQuery(), authorization, permissions); 356 } 357 358 public void addUserPermission(User user, int permissionType) 359 throws UnauthorizedException 360 { 361 if (permissionType == ForumPermissions.SYSTEM_ADMIN) { 364 throw new UnauthorizedException(); 365 } 366 if (permissions.isSystemOrForumAdmin()) { 367 forum.addUserPermission(user, permissionType); 368 } 369 else { 370 throw new UnauthorizedException(); 371 } 372 } 373 374 public void removeUserPermission(User user, int permissionType) 375 throws UnauthorizedException 376 { 377 if (permissions.isSystemOrForumAdmin()) { 378 forum.removeUserPermission(user, permissionType); 379 } 380 else { 381 throw new UnauthorizedException(); 382 } 383 } 384 385 public int [] usersWithPermission(int permissionType) 386 throws UnauthorizedException 387 { 388 if (permissions.isSystemOrForumAdmin()) { 389 return forum.usersWithPermission(permissionType); 390 } 391 else { 392 throw new UnauthorizedException(); 393 } 394 } 395 396 public void addGroupPermission(Group group, int permissionType) 397 throws UnauthorizedException 398 { 399 if (permissionType == ForumPermissions.SYSTEM_ADMIN) { 402 throw new UnauthorizedException(); 403 } 404 if (permissions.isSystemOrForumAdmin()) { 405 forum.addGroupPermission(group, permissionType); 406 } 407 else { 408 throw new UnauthorizedException(); 409 } 410 } 411 412 public void removeGroupPermission(Group group, int permissionType) 413 throws UnauthorizedException 414 { 415 if (permissions.isSystemOrForumAdmin()) { 416 forum.removeGroupPermission(group, permissionType); 417 } 418 else { 419 throw new UnauthorizedException(); 420 } 421 } 422 423 public int[] groupsWithPermission(int permissionType) 424 throws UnauthorizedException 425 { 426 if (permissions.isSystemOrForumAdmin()) { 427 return forum.groupsWithPermission(permissionType); 428 } 429 else { 430 throw new UnauthorizedException(); 431 } 432 } 433 434 public ForumMessageFilter[] getForumMessageFilters() 435 throws UnauthorizedException 436 { 437 if (permissions.isSystemOrForumAdmin()) { 438 return forum.getForumMessageFilters(); 439 } 440 else { 441 throw new UnauthorizedException(); 442 } 443 } 444 445 public void addForumMessageFilter(ForumMessageFilter filter) 446 throws UnauthorizedException 447 { 448 if (permissions.isSystemOrForumAdmin()) { 449 forum.addForumMessageFilter(filter); 450 } 451 else { 452 throw new UnauthorizedException(); 453 } 454 } 455 456 public void addForumMessageFilter(ForumMessageFilter filter, int index) 457 throws UnauthorizedException 458 { 459 if (permissions.isSystemOrForumAdmin()) { 460 forum.addForumMessageFilter(filter, index); 461 } 462 else { 463 throw new UnauthorizedException(); 464 } 465 } 466 467 public void removeForumMessageFilter(int index) 468 throws UnauthorizedException 469 { 470 if (permissions.isSystemOrForumAdmin()) { 471 forum.removeForumMessageFilter(index); 472 } 473 else { 474 throw new UnauthorizedException(); 475 } 476 } 477 478 public ForumMessage applyFilters(ForumMessage message) { 479 return forum.applyFilters(message); 480 } 481 482 public ForumPermissions getPermissions(Authorization authorization) { 483 return forum.getPermissions(authorization); 484 } 485 486 public boolean hasPermission(int type) { 487 return permissions.get(type); 488 } 489 490 public boolean isModerated() { 491 return forum.isModerated(); 492 } 493 494 public void setModerated(boolean moderated) throws UnauthorizedException { 495 if (permissions.isSystemOrForumAdmin()) { 496 forum.setModerated(moderated); 497 } 498 else { 499 throw new UnauthorizedException(); 500 } 501 } 502 503 public String toString() { 504 return forum.toString(); 505 } 506 public boolean isArticleForum(){ 507 return forum.isArticleForum(); 508 } 509 public void addArticleMap(String pageKey,ForumThread thread) throws UnauthorizedException{ 510 forum.addArticleMap(pageKey,thread); 511 } 512 public int forumOrder(){ 513 return forum.forumOrder(); 514 } 515 public void setForumOrder(int param) throws UnauthorizedException{ 516 if (permissions.isSystemOrForumAdmin()) { 517 forum.setForumOrder(param); 518 } 519 else { 520 throw new UnauthorizedException(); 521 } 522 } 523 524 } 525 526 | Popular Tags |