KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.openedit.WebPageRequest;
16 import com.openedit.users.User;
17
18
19 /**
20  * This filter only passes users whose names match a given name.
21  *
22  * @author Eric Galluzzo
23  */

24 public class UserFilter implements Filter
25 {
26     protected String JavaDoc fieldUsername;
27
28     /**
29      * Construct a filter that passes all users.
30      *
31      * @see #setUsername(String)
32      */

33     public UserFilter()
34     {
35         super();
36     }
37
38     /**
39      * Construct a filter that only passes users with the given username.
40      *
41      * @param inUsername The username to pass
42      */

43     public UserFilter(String JavaDoc inUsername)
44     {
45         setUsername(inUsername);
46     }
47
48     /**
49      * Sets the username.
50      *
51      * @param username The username to set
52      */

53     public void setUsername(String JavaDoc username)
54     {
55         fieldUsername = username;
56     }
57
58     /**
59      * Returns the username.
60      *
61      * @return String
62      */

63     public String JavaDoc getUsername()
64     {
65         return fieldUsername;
66     }
67
68     /**
69      * @see com.openedit.util.strainer.Filter#passes(java.lang.Object)
70      */

71     public boolean passes(Object JavaDoc inObj) throws FilterException, ClassCastException JavaDoc
72     {
73         WebPageRequest req = (WebPageRequest) inObj;
74
75         User user = req.getUser();
76
77         return ((user != null) &&
78         ((getUsername() == null) || user.getUserName().equals(getUsername())));
79     }
80
81     public void accept( FilterVisitor inFilterVisitor ) throws FilterException
82     {
83         // TODO Auto-generated method stub
84

85     }
86
87     public Filter[] getFilters()
88     {
89         // TODO Auto-generated method stub
90
return null;
91     }
92 }
93
Popular Tags