KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > util > strainer > GroupFilter


1 /*
2 Copyright (c) 2003 eInnovation Inc. All rights reserved
3
4 This library is free software; you can redistribute it and/or modify it under the terms
5 of the GNU Lesser General Public License as published by the Free Software Foundation;
6 either version 2.1 of the License, or (at your option) any later version.
7
8 This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the GNU Lesser General Public License for more details.
11 */

12
13 package com.openedit.util.strainer;
14
15 import java.util.Iterator JavaDoc;
16
17 import com.openedit.WebPageRequest;
18 import com.openedit.users.Group;
19 import com.openedit.users.User;
20
21
22 /**
23  * This filter only passes users who are members of a certain group.
24  *
25  * @author Eric Galluzzo
26  */

27 public class GroupFilter implements Filter
28 {
29     protected String JavaDoc fieldGroupName;
30
31     /**
32      * Construct a filter that passes all users.
33      *
34      * @see #setGroupName(String)
35      */

36     public GroupFilter()
37     {
38         super();
39     }
40
41     /**
42      * Construct a filter that only passes users that are part of the group with the given name.
43      *
44      * @param inGroupName The group name to check for
45      */

46     public GroupFilter(String JavaDoc inGroupName)
47     {
48         setGroupName(inGroupName);
49     }
50
51     /**
52      * Sets the group name.
53      *
54      * @param groupName The group name to set
55      */

56     public void setGroupName(String JavaDoc groupName)
57     {
58         fieldGroupName = groupName;
59     }
60
61     /**
62      * Returns the group name.
63      *
64      * @return String
65      */

66     public String JavaDoc getGroupName()
67     {
68         return fieldGroupName;
69     }
70
71     /**
72      * @see com.openedit.util.strainer.Filter#passes(java.lang.Object)
73      */

74     public boolean passes(Object JavaDoc inObj) throws FilterException, ClassCastException JavaDoc
75     {
76         WebPageRequest req = (WebPageRequest) inObj;
77
78         User user = req.getUser();
79
80         if (user == null)
81         {
82             return false;
83         }
84
85         if (getGroupName() == null)
86         {
87             return true;
88         }
89
90         for (Iterator JavaDoc iter = user.getGroups().iterator(); iter.hasNext();)
91         {
92             Group group = (Group) iter.next();
93
94             if (group.getName().equals(getGroupName()))
95             {
96                 return true;
97             }
98         }
99
100         return false;
101     }
102
103     public void accept( FilterVisitor inFilterVisitor ) throws FilterException
104     {
105         // TODO Auto-generated method stub
106

107     }
108
109     public Filter[] getFilters()
110     {
111         // TODO Auto-generated method stub
112
return null;
113     }
114 }
115
Popular Tags