KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nemesis > forum > proxy > ForumIteratorProxy


1 /*
2  * NEMESIS-FORUM.
3  * Copyright (C) 2002 David Laurent(lithium2@free.fr). All rights reserved.
4  *
5  * Copyright (c) 2000 The Apache Software Foundation. All rights reserved.
6  *
7  * Copyright (C) 2001 Yasna.com. All rights reserved.
8  *
9  * Copyright (C) 2000 CoolServlets.com. All rights reserved.
10  *
11  * NEMESIS-FORUM. is free software; you can redistribute it and/or
12  * modify it under the terms of the Apache Software License, Version 1.1,
13  * or (at your option) any later version.
14  *
15  * NEMESIS-FORUM core framework, NEMESIS-FORUM backoffice, NEMESIS-FORUM frontoffice
16  * application are parts of NEMESIS-FORUM and are distributed under
17  * same terms of licence.
18  *
19  *
20  * NEMESIS-FORUM includes software developed by the Apache Software Foundation (http://www.apache.org/)
21  * and software developed by CoolServlets.com (http://www.coolservlets.com).
22  * and software developed by Yasna.com (http://www.yasna.com).
23  *
24  */

25 package org.nemesis.forum.proxy;
26
27 import java.util.ArrayList JavaDoc;
28 import java.util.Iterator JavaDoc;
29
30 import org.nemesis.forum.Authorization;
31 import org.nemesis.forum.Forum;
32 import org.nemesis.forum.ForumPermissions;
33 import org.nemesis.forum.config.Constants;
34
35 /**
36  * Protection proxy for Forum iterators. This is a special case iterator proxy
37  * because users might not have read access to some of the forums that we
38  * need to proxy. The expected behavior is that only forums that users <b>do</b>
39  * have read access for will be returned. Therefore, we need to read in the
40  * results and only return an iterator for forums that the user can read.
41  */

42 class ForumIteratorProxy extends IteratorProxy {
43
44     private ArrayList JavaDoc forums = new ArrayList JavaDoc();
45
46     public ForumIteratorProxy(
47         Iterator JavaDoc iterator,
48         Authorization authorization,
49         ForumPermissions permissions) {
50         //Dummy call to super-class. This specialized iterator proxy doesn't
51
//use the superclass like the other iterators do.
52
super(iterator, authorization, permissions);
53
54         while (iterator.hasNext()) {
55             Forum forum = (Forum) iterator.next();
56             ForumPermissions forumPermissions =
57                 forum.getPermissions(authorization);
58             //Create a new permissions object with the combination of the
59
//permissions of this object and tempPermissions.
60
//Check and see if the user has READ permissions. If not, throw an
61
//an UnauthorizedException.
62

63             //AJOUT systemadmin
64
if (forumPermissions.get(Constants.READ)
65             || forumPermissions.get(Constants.SYSTEM_ADMIN)
66             || forumPermissions.get(Constants.FORUM_ADMIN)
67             || forumPermissions.get(Constants.MODERATOR)
68             ) {
69                 ForumProxy proxy =
70                     new ForumProxy(forum, authorization, forumPermissions);
71                 forums.add(proxy);
72             }
73         }
74
75         this.iterator = forums.listIterator();
76     }
77
78     public Object JavaDoc next() throws java.util.NoSuchElementException JavaDoc {
79         return iterator.next();
80     }
81 }
82
Popular Tags