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.digglike.business;
35
36 import fr.paris.lutece.plugins.digglike.utils.DiggUtils;
37 import fr.paris.lutece.portal.business.regularexpression.RegularExpression;
38 import fr.paris.lutece.portal.service.i18n.I18nService;
39 import fr.paris.lutece.portal.service.message.AdminMessage;
40 import fr.paris.lutece.portal.service.message.AdminMessageService;
41 import fr.paris.lutece.portal.service.plugin.Plugin;
42 import fr.paris.lutece.portal.service.regularexpression.RegularExpressionService;
43 import fr.paris.lutece.util.ReferenceList;
44 import fr.paris.lutece.util.html.Paginator;
45
46 import java.util.List;
47 import java.util.Locale;
48
49 import javax.servlet.http.HttpServletRequest;
50
51
52
53
54
55
56
57 public class EntryTypeText extends Entry
58 {
59 private final String _template_create = "admin/plugins/digglike/create_entry_type_text.html";
60 private final String _template_modify = "admin/plugins/digglike/modify_entry_type_text.html";
61 private final String _template_html_code_form = "admin/plugins/digglike/html_code_form_entry_type_text.html";
62 private final String _template_html_code_response = "admin/plugins/digglike/html_code_response_entry_type_text.html";
63
64
65
66
67
68
69 public String getTemplateHtmlCodeForm( )
70 {
71 return _template_html_code_form;
72 }
73
74
75
76
77
78
79
80 public String getRequestData( HttpServletRequest request, Locale locale )
81 {
82 String strTitle = request.getParameter( PARAMETER_TITLE );
83 String strHelpMessage = request.getParameter( PARAMETER_HELP_MESSAGE );
84 String strComment = request.getParameter( PARAMETER_COMMENT );
85 String strValue = request.getParameter( PARAMETER_VALUE );
86 String strMandatory = request.getParameter( PARAMETER_MANDATORY );
87 String strWidth = request.getParameter( PARAMETER_WIDTH );
88 String strMaxSizeEnter = request.getParameter( PARAMETER_MAX_SIZE_ENTER );
89 String strShowInDiggSubmitList = request.getParameter( PARAMETER_SHOW_IN_DIGG_SUBMIT_LIST );
90
91 int nWidth = -1;
92 int nMaxSizeEnter = -1;
93
94 String strFieldError = EMPTY_STRING;
95
96 if ( ( strTitle == null ) || strTitle.trim( ).equals( EMPTY_STRING ) )
97 {
98 strFieldError = FIELD_TITLE;
99 }
100
101 else if ( ( strWidth == null ) || strWidth.trim( ).equals( EMPTY_STRING ) )
102 {
103 strFieldError = FIELD_WIDTH;
104 }
105
106 if ( !strFieldError.equals( EMPTY_STRING ) )
107 {
108 Object[] tabRequiredFields = { I18nService.getLocalizedString( strFieldError, locale ) };
109
110 return AdminMessageService.getMessageUrl( request, MESSAGE_MANDATORY_FIELD, tabRequiredFields,
111 AdminMessage.TYPE_STOP );
112 }
113
114 try
115 {
116 nWidth = Integer.parseInt( strWidth );
117 }
118 catch ( NumberFormatException ne )
119 {
120 strFieldError = FIELD_WIDTH;
121 }
122
123 try
124 {
125 if ( ( strMaxSizeEnter != null ) && !strMaxSizeEnter.trim( ).equals( EMPTY_STRING ) )
126 {
127 nMaxSizeEnter = Integer.parseInt( strMaxSizeEnter );
128 }
129 }
130 catch ( NumberFormatException ne )
131 {
132 strFieldError = FIELD_MAX_SIZE_ENTER;
133 }
134
135 if ( !strFieldError.equals( EMPTY_STRING ) )
136 {
137 Object[] tabRequiredFields = { I18nService.getLocalizedString( strFieldError, locale ) };
138
139 return AdminMessageService.getMessageUrl( request, MESSAGE_NUMERIC_FIELD, tabRequiredFields,
140 AdminMessage.TYPE_STOP );
141 }
142
143 this.setTitle( strTitle );
144 this.setHelpMessage( DiggUtils.trim( strHelpMessage ) );
145 this.setComment( strComment );
146
147 this.setDefaultValue( strValue );
148 this.setWidth( nWidth );
149 this.setMaxSizeEnter( nMaxSizeEnter );
150
151 if ( strMandatory != null )
152 {
153 this.setMandatory( true );
154 }
155 else
156 {
157 this.setMandatory( false );
158 }
159
160 if ( strShowInDiggSubmitList != null )
161 {
162 this.setShowInDiggSubmitList( true );
163 }
164 else
165 {
166 this.setShowInDiggSubmitList( false );
167 }
168
169 return null;
170 }
171
172
173
174
175
176
177
178
179 public String getRequestData( HttpServletRequest request, Locale locale, Plugin plugin )
180 {
181 return getRequestData( request, locale );
182 }
183
184
185
186
187
188 public String getTemplateCreate( )
189 {
190 return _template_create;
191 }
192
193
194
195
196
197 public String getTemplateModify( )
198 {
199 return _template_modify;
200 }
201
202
203
204
205
206
207
208
209
210 public Paginator getPaginator( int nItemPerPage, String strBaseUrl, String strPageIndexParameterName,
211 String strPageIndex )
212 {
213 return new Paginator( this.getRegularExpressionList( ), nItemPerPage, strBaseUrl, strPageIndexParameterName,
214 strPageIndex );
215 }
216
217
218
219
220
221
222
223 public ReferenceList getReferenceListRegularExpression( IEntry entry, Plugin plugin )
224 {
225 ReferenceList refListRegularExpression = new ReferenceList( );
226
227 if ( RegularExpressionService.getInstance( ).isAvailable( ) )
228 {
229 List<RegularExpression> listRegularExpression = RegularExpressionService.getInstance( )
230 .getAllRegularExpression( );
231
232 for ( RegularExpression regularExpression : listRegularExpression )
233 {
234 if ( !entry.getRegularExpressionList( ).contains( regularExpression ) )
235 {
236 refListRegularExpression.addItem( regularExpression.getIdExpression( ),
237 regularExpression.getTitle( ) );
238 }
239 }
240 }
241
242 return refListRegularExpression;
243 }
244
245
246
247
248
249
250
251
252 public FormError getResponseData( HttpServletRequest request, List<Response> listResponse, Locale locale )
253 {
254 String strValueEntry = request.getParameter( DiggUtils.EMPTY_STRING + this.getIdEntry( ) ).trim( );
255 List<RegularExpression> listRegularExpression = this.getRegularExpressionList( );
256 Response response = new Response( );
257 response.setEntry( this );
258
259 if ( strValueEntry != null )
260 {
261 if ( this.isMandatory( ) )
262 {
263 if ( strValueEntry.equals( DiggUtils.EMPTY_STRING ) )
264 {
265 FormError formError = new FormError( );
266 formError.setMandatoryError( true );
267 formError.setTitleQuestion( this.getTitle( ) );
268
269 return formError;
270 }
271 }
272
273 if ( ( listRegularExpression != null ) && ( listRegularExpression.size( ) != 0 ) &&
274 RegularExpressionService.getInstance( ).isAvailable( ) )
275 {
276 for ( RegularExpression regularExpression : listRegularExpression )
277 {
278 if ( !RegularExpressionService.getInstance( ).isMatches( strValueEntry, regularExpression ) )
279 {
280 FormError formError = new FormError( );
281 formError.setMandatoryError( false );
282 formError.setTitleQuestion( this.getTitle( ) );
283 formError.setErrorMessage( regularExpression.getErrorMessage( ) );
284
285 return formError;
286 }
287 }
288 }
289
290 response.setValueResponse( strValueEntry );
291 }
292
293 listResponse.add( response );
294
295 return null;
296 }
297
298
299
300
301
302
303
304
305
306
307 public FormError getResponseData( int nIdDiggSubmit, HttpServletRequest request, List<Response> listResponse,
308 Locale locale, Plugin plugin )
309 {
310 return getResponseData( request, listResponse, locale );
311 }
312
313
314
315
316
317
318 public String getTemplateHtmlCodeResponse( )
319 {
320 return _template_html_code_response;
321 }
322 }