1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.contextinclude.business;
35
36 import java.util.Arrays;
37 import java.util.List;
38 import java.util.Map;
39 import java.util.Map.Entry;
40
41 import javax.servlet.http.HttpServletRequest;
42
43 import javax.validation.constraints.Min;
44
45
46
47
48
49
50
51 public class Context
52 {
53 private int _nIdContext;
54 private String _strHtml;
55 @Min( 0 )
56 private int _nNbParams;
57 private int _nPriority;
58 private boolean _bStrict;
59 private boolean _bActive;
60 private Map<String, List<String>> _mapParameters;
61
62
63
64
65
66
67 public void setIdContext( int nIdContext )
68 {
69 this._nIdContext = nIdContext;
70 }
71
72
73
74
75
76
77 public int getIdContext( )
78 {
79 return _nIdContext;
80 }
81
82
83
84
85
86
87 public void setHtml( String strHtml )
88 {
89 this._strHtml = strHtml;
90 }
91
92
93
94
95
96
97 public String getHtml( )
98 {
99 return _strHtml;
100 }
101
102
103
104
105
106
107 public void setNbParams( int nNbParams )
108 {
109 this._nNbParams = nNbParams;
110 }
111
112
113
114
115
116
117 public int getNbParams( )
118 {
119 return _nNbParams;
120 }
121
122
123
124
125
126
127 public void setPriority( int nPriority )
128 {
129 this._nPriority = nPriority;
130 }
131
132
133
134
135
136
137 public int getPriority( )
138 {
139 return _nPriority;
140 }
141
142
143
144
145
146
147 public void setStrict( boolean bStrict )
148 {
149 this._bStrict = bStrict;
150 }
151
152
153
154
155
156
157 public boolean isStrict( )
158 {
159 return _bStrict;
160 }
161
162
163
164
165
166
167 public void setActive( boolean bActive )
168 {
169 this._bActive = bActive;
170 }
171
172
173
174
175
176
177 public boolean isActive( )
178 {
179 return _bActive;
180 }
181
182
183
184
185
186
187 public void setMapParameters( Map<String, List<String>> mapParameters )
188 {
189 this._mapParameters = mapParameters;
190 }
191
192
193
194
195
196
197 public Map<String, List<String>> getMapParameters( )
198 {
199 return _mapParameters;
200 }
201
202
203
204
205
206
207
208 public boolean isInvoked( HttpServletRequest request )
209 {
210
211 if ( request == null )
212 {
213 return false;
214 }
215
216
217 if ( _mapParameters == null )
218 {
219
220 if ( _bStrict )
221 {
222 return ( request.getParameterMap( ) == null ) || request.getParameterMap( ).isEmpty( );
223 }
224
225
226 return true;
227 }
228
229
230 if ( _bStrict )
231 {
232 if ( request.getParameterMap( ) == null )
233 {
234 return false;
235 }
236
237 if ( _mapParameters.size( ) != request.getParameterMap( ).size( ) )
238 {
239 return false;
240 }
241 }
242
243
244 for ( Entry<String, List<String>> params : _mapParameters.entrySet( ) )
245 {
246
247 String strKey = params.getKey( );
248 List<String> listValues = params.getValue( );
249
250
251 String[] listRequestValues = request.getParameterValues( strKey );
252
253 if ( listRequestValues != null )
254 {
255
256 if ( _bStrict )
257 {
258 if ( listRequestValues.length != listValues.size( ) )
259 {
260 return false;
261 }
262 }
263
264
265 for ( String strValue : listValues )
266 {
267 if ( !Arrays.asList( listRequestValues ).contains( strValue ) )
268 {
269 return false;
270 }
271 }
272 }
273 else
274 {
275 return false;
276 }
277 }
278
279 return true;
280 }
281 }