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.mylutece.business.attribute;
35
36 import fr.paris.lutece.portal.service.plugin.Plugin;
37 import fr.paris.lutece.portal.service.template.AppTemplateService;
38 import fr.paris.lutece.util.html.HtmlTemplate;
39
40 import java.util.ArrayList;
41 import java.util.HashMap;
42 import java.util.List;
43 import java.util.Locale;
44 import java.util.Map;
45
46 import javax.servlet.http.HttpServletRequest;
47
48
49
50
51
52
53 public abstract class AbstractAttribute implements IAttribute
54 {
55
56 private static final String MARK_ATTRIBUTE = "attribute";
57 private static final String MARK_DEFAULT_VALUES_LIST = "default_values_list";
58
59
60 private static final String PARAMETER_ATTRIBUTE = "attribute";
61
62
63 private static final String CONSTANT_UNDERSCORE = "_";
64 protected int _nIdAttribute;
65 protected boolean _bMandatory;
66 protected String _strTitle;
67 protected String _strHelpMessage;
68 protected int _nPosition;
69 protected AttributeType _attributeType;
70 protected List<AttributeField> _listAttributeFields;
71 protected Plugin _plugin;
72 protected boolean _bIsShownInSearch;
73 protected boolean _bAnonymize;
74
75
76
77
78 public AbstractAttribute( )
79 {
80 }
81
82
83
84
85
86
87 public int getIdAttribute( )
88 {
89 return _nIdAttribute;
90 }
91
92
93
94
95
96
97
98 public void setIdAttribute( int nIdAttribute )
99 {
100 _nIdAttribute = nIdAttribute;
101 }
102
103
104
105
106
107
108 public boolean isMandatory( )
109 {
110 return _bMandatory;
111 }
112
113
114
115
116
117
118
119 public void setMandatory( boolean bMandatory )
120 {
121 _bMandatory = bMandatory;
122 }
123
124
125
126
127
128
129 public List<AttributeField> getListAttributeFields( )
130 {
131 return _listAttributeFields;
132 }
133
134
135
136
137
138
139
140 public void setListAttributeFields( List<AttributeField> listAttributeFields )
141 {
142 _listAttributeFields = listAttributeFields;
143 }
144
145
146
147
148
149
150 public String getTitle( )
151 {
152 return _strTitle;
153 }
154
155
156
157
158
159
160
161 public void setTitle( String strTitle )
162 {
163 _strTitle = strTitle;
164 }
165
166
167
168
169
170
171 public String getHelpMessage( )
172 {
173 return _strHelpMessage;
174 }
175
176
177
178
179
180
181
182 public void setHelpMessage( String strHelpMessage )
183 {
184 _strHelpMessage = strHelpMessage;
185 }
186
187
188
189
190
191
192 public int getPosition( )
193 {
194 return _nPosition;
195 }
196
197
198
199
200
201
202
203 public void setPosition( int nPosition )
204 {
205 _nPosition = nPosition;
206 }
207
208
209
210
211
212
213 public AttributeType getAttributeType( )
214 {
215 return _attributeType;
216 }
217
218
219
220
221
222
223
224 public void setAttributeType( AttributeType attributeType )
225 {
226 _attributeType = attributeType;
227 }
228
229
230
231
232
233
234
235
236 public String getHtmlFormAttribute( Locale locale )
237 {
238 Map<String, Object> model = new HashMap<String, Object>( );
239 model.put( MARK_ATTRIBUTE, this );
240
241 HtmlTemplate template = AppTemplateService.getTemplate( getTemplateHtmlFormAttribute( ), locale, model );
242
243 return template.getHtml( );
244 }
245
246
247
248
249
250
251
252
253
254
255 public String getHtmlFormAttribute( Locale locale, List<MyLuteceUserField> listDefaultValues )
256 {
257 Map<String, Object> model = new HashMap<String, Object>( );
258 model.put( MARK_ATTRIBUTE, this );
259 model.put( MARK_DEFAULT_VALUES_LIST, listDefaultValues );
260
261 HtmlTemplate template = AppTemplateService.getTemplate( getTemplateHtmlFormAttribute( ), locale, model );
262
263 return template.getHtml( );
264 }
265
266
267
268
269
270
271
272
273
274
275 public String getHtmlFormSearchAttribute( MyLuteceUserFieldFilter auFieldFilter, Locale locale )
276 {
277 Map<String, Object> model = new HashMap<String, Object>( );
278 List<MyLuteceUserField> listUserFields = auFieldFilter.getListUserFields( );
279 List<MyLuteceUserField> selectedUserFields = null;
280
281 if ( ( listUserFields != null ) && ( listUserFields.size( ) != 0 ) )
282 {
283 selectedUserFields = new ArrayList<MyLuteceUserField>( );
284
285 for ( MyLuteceUserField userField : listUserFields )
286 {
287 if ( userField.getAttribute( ).getIdAttribute( ) == _nIdAttribute )
288 {
289 selectedUserFields.add( userField );
290 }
291 }
292 }
293
294 model.put( MARK_DEFAULT_VALUES_LIST, selectedUserFields );
295 model.put( MARK_ATTRIBUTE, this );
296
297 HtmlTemplate template = AppTemplateService.getTemplate( getTemplateHtmlFormSearchAttribute( ), locale, model );
298
299 return template.getHtml( );
300 }
301
302
303
304
305
306
307 public Plugin getPlugin( )
308 {
309 return _plugin;
310 }
311
312
313
314
315
316
317
318 public void setPlugin( Plugin plugin )
319 {
320 _plugin = plugin;
321 }
322
323
324
325
326
327
328 public boolean getAnonymize( )
329 {
330 return _bAnonymize;
331 }
332
333
334
335
336
337
338
339 public void setAnonymize( boolean bAnonymize )
340 {
341 _bAnonymize = bAnonymize;
342 }
343
344
345
346
347
348
349 public boolean isShownInSearch( )
350 {
351 return _bIsShownInSearch;
352 }
353
354
355
356
357
358
359
360 public void setShownInSearch( boolean bIsShownInSearch )
361 {
362 _bIsShownInSearch = bIsShownInSearch;
363 }
364
365
366
367
368
369
370
371
372
373
374 public List<MyLuteceUserField> getUserFieldsData( HttpServletRequest request, int nIdUser )
375 {
376 String [ ] values = request.getParameterValues( PARAMETER_ATTRIBUTE + CONSTANT_UNDERSCORE + _nIdAttribute );
377
378 return getUserFieldsData( values, nIdUser );
379 }
380 }