1 /* 2 * Copyright (c) 2002-2014, Mairie de 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 /** 44 * LuteceFilter 45 */ 46 public class LuteceFilter implements Comparable<LuteceFilter> 47 { 48 public static final int ORDER_NOT_DEFINED = -1; 49 private String _strName; 50 private Filter _filter; 51 private String _strMapping; 52 private Plugin _plugin; 53 private int _nOrder = ORDER_NOT_DEFINED; 54 private Map<String, String> _mapInitParameters; 55 56 /** 57 * Constructor 58 * @param strName The name 59 * @param filter The filter class 60 * @param strMapping The mapping url pattern 61 * @param plugin The plugin 62 * @param mapInitParameters Init parameters as a map 63 */ 64 public LuteceFilter( String strName, Filter filter, String strMapping, Plugin plugin, 65 Map<String, String> mapInitParameters ) 66 { 67 _strName = strName; 68 _filter = filter; 69 _strMapping = strMapping; 70 _plugin = plugin; 71 _mapInitParameters = mapInitParameters; 72 } 73 74 /** 75 * Returns the Name 76 * 77 * @return The Name 78 */ 79 public String getName( ) 80 { 81 return _strName; 82 } 83 84 /** 85 * Sets the Name 86 * 87 * @param strName The Name 88 */ 89 public void setName( String strName ) 90 { 91 _strName = strName; 92 } 93 94 /** 95 * Returns the filter 96 * 97 * @return The filter 98 */ 99 public Filter getFilter( ) 100 { 101 return _filter; 102 } 103 104 /** 105 * Sets the filter 106 * 107 * @param filter The filter 108 */ 109 public void setFilter( Filter filter ) 110 { 111 _filter = filter; 112 } 113 114 /** 115 * Returns the Mapping 116 * 117 * @return The Mapping 118 */ 119 public String getMappingUrlPattern( ) 120 { 121 return _strMapping; 122 } 123 124 /** 125 * Sets the Mapping 126 * 127 * @param strMapping The Mapping 128 */ 129 public void setMappingUrlPattern( String strMapping ) 130 { 131 _strMapping = strMapping; 132 } 133 134 /** 135 * Returns the Plugin 136 * 137 * @return The Plugin 138 */ 139 public Plugin getPlugin( ) 140 { 141 return _plugin; 142 } 143 144 /** 145 * Sets the Plugin 146 * 147 * @param plugin The plugin 148 */ 149 public void setPlugin( Plugin plugin ) 150 { 151 _plugin = plugin; 152 } 153 154 /** 155 * Returns init parameters 156 * @return Init parameters in a map object 157 */ 158 public Map<String, String> getInitParameters( ) 159 { 160 return _mapInitParameters; 161 } 162 163 /** 164 * for debug purpose 165 * @return The name of the filter 166 */ 167 @Override 168 public String toString( ) 169 { 170 return getName( ); 171 } 172 173 /** 174 * 175 * Returns the order. 176 * {@link #getOrder()} == {@value #ORDER_NOT_DEFINED} means there is no priority set for the filter 177 * @return the order 178 */ 179 public int getOrder( ) 180 { 181 return _nOrder; 182 } 183 184 /** 185 * nOrder == == {@value #ORDER_NOT_DEFINED} means there is no priority set for the filter 186 * @param nOrder the order 187 */ 188 public void setOrder( int nOrder ) 189 { 190 _nOrder = nOrder; 191 } 192 193 /** 194 * 195 * {@inheritDoc} 196 */ 197 @Override 198 public int compareTo( LuteceFilter luteceFilter ) 199 { 200 if ( luteceFilter == null ) 201 { 202 return 1; 203 } 204 205 return luteceFilter.getOrder( ) - this.getOrder( ); 206 } 207 208 /** 209 * {@inheritDoc} 210 */ 211 @Override 212 public boolean equals( Object o ) 213 { 214 if ( !( o instanceof LuteceFilter ) ) 215 { 216 return false; 217 } 218 219 return super.equals( o ); 220 } 221 222 /** 223 * {@inheritDoc} 224 */ 225 @Override 226 public int hashCode( ) 227 { 228 return getOrder( ); 229 } 230 }