View Javadoc
1   /*
2    * Copyright (c) 2002-2022, City of Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.portal.service.filter;
35  
36  import fr.paris.lutece.portal.service.plugin.Plugin;
37  
38  import java.util.Map;
39  
40  import javax.servlet.Filter;
41  
42  /**
43   * LuteceFilter
44   */
45  public class LuteceFilter implements Comparable<LuteceFilter>
46  {
47      public static final int ORDER_NOT_DEFINED = -1;
48      private String _strName;
49      private Filter _filter;
50      private String _strMapping;
51      private Plugin _plugin;
52      private int _nOrder = ORDER_NOT_DEFINED;
53      private Map<String, String> _mapInitParameters;
54  
55      /**
56       * Constructor
57       * 
58       * @param strName
59       *            The name
60       * @param filter
61       *            The filter class
62       * @param strMapping
63       *            The mapping url pattern
64       * @param plugin
65       *            The plugin
66       * @param mapInitParameters
67       *            Init parameters as a map
68       */
69      public LuteceFilter( String strName, Filter filter, String strMapping, Plugin plugin, Map<String, String> mapInitParameters )
70      {
71          _strName = strName;
72          _filter = filter;
73          _strMapping = strMapping;
74          _plugin = plugin;
75          _mapInitParameters = mapInitParameters;
76      }
77  
78      /**
79       * Returns the Name
80       *
81       * @return The Name
82       */
83      public String getName( )
84      {
85          return _strName;
86      }
87  
88      /**
89       * Sets the Name
90       *
91       * @param strName
92       *            The Name
93       */
94      public void setName( String strName )
95      {
96          _strName = strName;
97      }
98  
99      /**
100      * Returns the filter
101      *
102      * @return The filter
103      */
104     public Filter getFilter( )
105     {
106         return _filter;
107     }
108 
109     /**
110      * Sets the filter
111      *
112      * @param filter
113      *            The filter
114      */
115     public void setFilter( Filter filter )
116     {
117         _filter = filter;
118     }
119 
120     /**
121      * Returns the Mapping
122      *
123      * @return The Mapping
124      */
125     public String getMappingUrlPattern( )
126     {
127         return _strMapping;
128     }
129 
130     /**
131      * Sets the Mapping
132      *
133      * @param strMapping
134      *            The Mapping
135      */
136     public void setMappingUrlPattern( String strMapping )
137     {
138         _strMapping = strMapping;
139     }
140 
141     /**
142      * Returns the Plugin
143      *
144      * @return The Plugin
145      */
146     public Plugin getPlugin( )
147     {
148         return _plugin;
149     }
150 
151     /**
152      * Sets the Plugin
153      *
154      * @param plugin
155      *            The plugin
156      */
157     public void setPlugin( Plugin plugin )
158     {
159         _plugin = plugin;
160     }
161 
162     /**
163      * Returns init parameters
164      * 
165      * @return Init parameters in a map object
166      */
167     public Map<String, String> getInitParameters( )
168     {
169         return _mapInitParameters;
170     }
171 
172     /**
173      * for debug purpose
174      * 
175      * @return The name of the filter
176      */
177     @Override
178     public String toString( )
179     {
180         return getName( );
181     }
182 
183     /**
184      *
185      * Returns the order. {@link #getOrder()} == {@value #ORDER_NOT_DEFINED} means there is no priority set for the filter
186      * 
187      * @return the order
188      */
189     public int getOrder( )
190     {
191         return _nOrder;
192     }
193 
194     /**
195      * nOrder == == {@value #ORDER_NOT_DEFINED} means there is no priority set for the filter
196      * 
197      * @param nOrder
198      *            the order
199      */
200     public void setOrder( int nOrder )
201     {
202         _nOrder = nOrder;
203     }
204 
205     /**
206      *
207      * {@inheritDoc}
208      */
209     @Override
210     public int compareTo( LuteceFilter luteceFilter )
211     {
212         if ( luteceFilter == null )
213         {
214             return 1;
215         }
216 
217         return luteceFilter.getOrder( ) - this.getOrder( );
218     }
219 
220     /**
221      * {@inheritDoc}
222      */
223     @Override
224     public boolean equals( Object o )
225     {
226         if ( !( o instanceof LuteceFilter ) )
227         {
228             return false;
229         }
230 
231         return super.equals( o );
232     }
233 
234     /**
235      * {@inheritDoc}
236      */
237     @Override
238     public int hashCode( )
239     {
240         return getOrder( );
241     }
242 }