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 EntryTypeUrl extends Entry
58 {
59 private final String _template_create = "admin/plugins/digglike/create_entry_type_url.html";
60 private final String _template_modify = "admin/plugins/digglike/modify_entry_type_url.html";
61 private final String _template_html_code_form = "admin/plugins/digglike/html_code_form_entry_type_url.html";
62 private final String _template_html_code_response = "admin/plugins/digglike/html_code_response_entry_type_url.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 public String getTemplateCreate( )
177 {
178 return _template_create;
179 }
180
181
182
183
184
185 public String getTemplateModify( )
186 {
187 return _template_modify;
188 }
189
190
191
192
193
194
195
196
197
198 public Paginator getPaginator( int nItemPerPage, String strBaseUrl, String strPageIndexParameterName,
199 String strPageIndex )
200 {
201 return new Paginator( this.getRegularExpressionList( ), nItemPerPage, strBaseUrl, strPageIndexParameterName,
202 strPageIndex );
203 }
204
205
206
207
208
209
210
211 public ReferenceList getReferenceListRegularExpression( IEntry entry, Plugin plugin )
212 {
213 ReferenceList refListRegularExpression = new ReferenceList( );
214
215 if ( RegularExpressionService.getInstance( ).isAvailable( ) )
216 {
217 List<RegularExpression> listRegularExpression = RegularExpressionService.getInstance( )
218 .getAllRegularExpression( );
219
220 for ( RegularExpression regularExpression : listRegularExpression )
221 {
222 if ( !entry.getRegularExpressionList( ).contains( regularExpression ) )
223 {
224 refListRegularExpression.addItem( regularExpression.getIdExpression( ),
225 regularExpression.getTitle( ) );
226 }
227 }
228 }
229
230 return refListRegularExpression;
231 }
232
233
234
235
236
237
238
239
240 public FormError getResponseData( HttpServletRequest request, List<Response> listResponse, Locale locale )
241 {
242 String strValueEntry = request.getParameter( DiggUtils.EMPTY_STRING + this.getIdEntry( ) ).trim( );
243 List<RegularExpression> listRegularExpression = this.getRegularExpressionList( );
244 Response response = new Response( );
245 response.setEntry( this );
246
247 if ( strValueEntry != null )
248 {
249 if ( this.isMandatory( ) )
250 {
251 if ( strValueEntry.equals( DiggUtils.EMPTY_STRING ) )
252 {
253 FormError formError = new FormError( );
254 formError.setMandatoryError( true );
255 formError.setTitleQuestion( this.getTitle( ) );
256
257 return formError;
258 }
259 }
260
261 if ( ( listRegularExpression != null ) && ( listRegularExpression.size( ) != 0 ) &&
262 RegularExpressionService.getInstance( ).isAvailable( ) )
263 {
264 for ( RegularExpression regularExpression : listRegularExpression )
265 {
266 if ( !RegularExpressionService.getInstance( ).isMatches( strValueEntry, regularExpression ) )
267 {
268 FormError formError = new FormError( );
269 formError.setMandatoryError( false );
270 formError.setTitleQuestion( this.getTitle( ) );
271 formError.setErrorMessage( regularExpression.getErrorMessage( ) );
272
273 return formError;
274 }
275 }
276 }
277
278 response.setValueResponse( strValueEntry );
279 }
280
281 listResponse.add( response );
282
283 return null;
284 }
285
286
287
288
289
290
291
292
293
294
295 public FormError getResponseData( int nIdDiggSubmit, HttpServletRequest request, List<Response> listResponse,
296 Locale locale, Plugin plugin )
297 {
298 return getResponseData( request, listResponse, locale );
299 }
300
301
302
303
304
305 public String getTemplateHtmlCodeResponse( )
306 {
307 return _template_html_code_response;
308 }
309 }