KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.servlet.ServletRequest JavaDoc;
16
17 import com.openedit.WebPageRequest;
18
19
20 /**
21  * This filter only passes users that have a certain permission.
22  *
23  * @author Eric Galluzzo
24  */

25 public class RequestAttributeFilter implements Filter
26 {
27     protected String JavaDoc fieldAttribute;
28     protected String JavaDoc fieldEquals;
29
30     /**
31      * Construct a filter that passes all users.
32      *
33      * @see #setPermission(String)
34      */

35     public RequestAttributeFilter()
36     {
37         super();
38     }
39
40     /**
41      * Construct a filter that only passes users that have the given permission.
42      *
43      * @param inPermission The permission to check for
44      * @param inEq DOCME
45      */

46     public RequestAttributeFilter(String JavaDoc inPermission, String JavaDoc inEq)
47     {
48         setAttribute(inPermission);
49         setEquals(inEq);
50     }
51
52     /**
53      * Sets the permission to check for.
54      *
55      * @param permission The permission to check for
56      */

57     public void setAttribute(String JavaDoc permission)
58     {
59         fieldAttribute = permission;
60     }
61
62     /**
63      * Returns the permission to check for.
64      *
65      * @return String
66      */

67     public String JavaDoc getAttribute()
68     {
69         return fieldAttribute;
70     }
71
72     /**
73      * DOCUMENT ME!
74      *
75      * @param inString
76      */

77     public void setEquals(String JavaDoc inString)
78     {
79         fieldEquals = inString;
80     }
81
82     /**
83      * DOCUMENT ME!
84      *
85      * @return
86      */

87     public String JavaDoc getEquals()
88     {
89         return fieldEquals;
90     }
91
92     /**
93      * @see com.openedit.util.strainer.Filter#passes(java.lang.Object)
94      */

95     public boolean passes(Object JavaDoc inObj) throws FilterException, ClassCastException JavaDoc
96     {
97         WebPageRequest req = (WebPageRequest) inObj;
98         ServletRequest JavaDoc request = req.getRequest();
99
100         if (request == null)
101         {
102             return false;
103         }
104
105         String JavaDoc att = (String JavaDoc) request.getAttribute(getAttribute());
106
107         return (getAttribute() == null) || getEquals().equalsIgnoreCase(att);
108     }
109
110     public void accept( FilterVisitor inFilterVisitor ) throws FilterException
111     {
112         // TODO Auto-generated method stub
113

114     }
115
116     public Filter[] getFilters()
117     {
118         // TODO Auto-generated method stub
119
return null;
120     }
121 }
122
Popular Tags