1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.tomcat.util.descriptor.web;
18
19 import java.io.Serializable;
20 import java.util.HashMap;
21 import java.util.Map;
22
23 import javax.servlet.Filter;
24
25 import org.apache.tomcat.util.res.StringManager;
26
27
28 /**
29  * Representation of a filter definition for a web application, as represented
30  * in a <code>&lt;filter&gt;</code> element in the deployment descriptor.
31  *
32  * @author Craig R. McClanahan
33  */

34 public class FilterDef implements Serializable {
35
36     private static final long serialVersionUID = 1L;
37
38     private static final StringManager sm =
39         StringManager.getManager(Constants.PACKAGE_NAME);
40
41     // ------------------------------------------------------------- Properties
42
43
44     /**
45      * The description of this filter.
46      */

47     private String description = null;
48
49     public String getDescription() {
50         return this.description;
51     }
52
53     public void setDescription(String description) {
54         this.description = description;
55     }
56
57
58     /**
59      * The display name of this filter.
60      */

61     private String displayName = null;
62
63     public String getDisplayName() {
64         return this.displayName;
65     }
66
67     public void setDisplayName(String displayName) {
68         this.displayName = displayName;
69     }
70
71
72     /**
73      * The filter instance associated with this definition
74      */

75     private transient Filter filter = null;
76
77     public Filter getFilter() {
78         return filter;
79     }
80
81     public void setFilter(Filter filter) {
82         this.filter = filter;
83     }
84
85
86     /**
87      * The fully qualified name of the Java class that implements this filter.
88      */

89     private String filterClass = null;
90
91     public String getFilterClass() {
92         return this.filterClass;
93     }
94
95     public void setFilterClass(String filterClass) {
96         this.filterClass = filterClass;
97     }
98
99
100     /**
101      * The name of this filter, which must be unique among the filters
102      * defined for a particular web application.
103      */

104     private String filterName = null;
105
106     public String getFilterName() {
107         return this.filterName;
108     }
109
110     public void setFilterName(String filterName) {
111         if (filterName == null || filterName.equals("")) {
112             throw new IllegalArgumentException(
113                     sm.getString("filterDef.invalidFilterName", filterName));
114         }
115         this.filterName = filterName;
116     }
117
118
119     /**
120      * The large icon associated with this filter.
121      */

122     private String largeIcon = null;
123
124     public String getLargeIcon() {
125         return this.largeIcon;
126     }
127
128     public void setLargeIcon(String largeIcon) {
129         this.largeIcon = largeIcon;
130     }
131
132
133     /**
134      * The set of initialization parameters for this filter, keyed by
135      * parameter name.
136      */

137     private final Map<String, String> parameters = new HashMap<>();
138
139     public Map<String, String> getParameterMap() {
140         return this.parameters;
141     }
142
143
144     /**
145      * The small icon associated with this filter.
146      */

147     private String smallIcon = null;
148
149     public String getSmallIcon() {
150         return this.smallIcon;
151     }
152
153     public void setSmallIcon(String smallIcon) {
154         this.smallIcon = smallIcon;
155     }
156
157     private String asyncSupported = null;
158
159     public String getAsyncSupported() {
160         return asyncSupported;
161     }
162
163     public void setAsyncSupported(String asyncSupported) {
164         this.asyncSupported = asyncSupported;
165     }
166
167
168     // --------------------------------------------------------- Public Methods
169
170
171     /**
172      * Add an initialization parameter to the set of parameters associated
173      * with this filter.
174      *
175      * @param name The initialization parameter name
176      * @param value The initialization parameter value
177      */

178     public void addInitParameter(String name, String value) {
179
180         if (parameters.containsKey(name)) {
181             // The spec does not define this but the TCK expects the first
182             // definition to take precedence
183             return;
184         }
185         parameters.put(name, value);
186
187     }
188
189
190     /**
191      * Render a String representation of this object.
192      */

193     @Override
194     public String toString() {
195         StringBuilder sb = new StringBuilder("FilterDef[");
196         sb.append("filterName=");
197         sb.append(this.filterName);
198         sb.append(", filterClass=");
199         sb.append(this.filterClass);
200         sb.append("]");
201         return sb.toString();
202     }
203
204
205 }
206