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.service.i18n.I18nService;
38 import fr.paris.lutece.portal.service.message.AdminMessage;
39 import fr.paris.lutece.portal.service.message.AdminMessageService;
40 import fr.paris.lutece.portal.service.plugin.Plugin;
41
42 import org.apache.commons.lang.StringUtils;
43
44 import java.util.List;
45 import java.util.Locale;
46
47 import javax.servlet.http.HttpServletRequest;
48
49
50
51
52
53
54
55 public class EntryTypeTextArea extends Entry
56 {
57 private final String _template_create = "admin/plugins/digglike/create_entry_type_text_area.html";
58 private final String _template_modify = "admin/plugins/digglike/modify_entry_type_text_area.html";
59 private final String _template_html_code_form = "admin/plugins/digglike/html_code_form_entry_type_text_area.html";
60 private final String _template_html_code_response = "admin/plugins/digglike/html_code_response_entry_type_text_area.html";
61
62
63
64
65
66
67 public String getTemplateHtmlCodeForm( )
68 {
69 return _template_html_code_form;
70 }
71
72
73
74
75
76
77
78 public String getRequestData( HttpServletRequest request, Locale locale )
79 {
80 String strTitle = request.getParameter( PARAMETER_TITLE );
81 String strHelpMessage = request.getParameter( PARAMETER_HELP_MESSAGE );
82 String strComment = request.getParameter( PARAMETER_COMMENT );
83 String strValue = request.getParameter( PARAMETER_VALUE );
84 String strMandatory = request.getParameter( PARAMETER_MANDATORY );
85 String strWidth = request.getParameter( PARAMETER_WIDTH );
86 String strHeight = request.getParameter( PARAMETER_HEIGHT );
87 String strMaxSizeEnter = request.getParameter( PARAMETER_MAX_SIZE_ENTER );
88 String strShowInDiggSubmitList = request.getParameter( PARAMETER_SHOW_IN_DIGG_SUBMIT_LIST );
89
90 int nWidth = -1;
91 int nHeight = -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 else if ( ( strHeight == null ) || strHeight.trim( ).equals( EMPTY_STRING ) )
106 {
107 strFieldError = FIELD_HEIGHT;
108 }
109
110 if ( !strFieldError.equals( EMPTY_STRING ) )
111 {
112 Object[] tabRequiredFields = { I18nService.getLocalizedString( strFieldError, locale ) };
113
114 return AdminMessageService.getMessageUrl( request, MESSAGE_MANDATORY_FIELD, tabRequiredFields,
115 AdminMessage.TYPE_STOP );
116 }
117
118 nHeight = DiggUtils.getIntegerParameter( strHeight );
119
120 if ( nHeight < 0 )
121 {
122 strFieldError = FIELD_HEIGHT;
123 }
124
125 nWidth = DiggUtils.getIntegerParameter( strWidth );
126
127 if ( nWidth < 0 )
128 {
129 strFieldError = FIELD_WIDTH;
130 }
131
132 nMaxSizeEnter = DiggUtils.getIntegerParameter( strMaxSizeEnter );
133
134 if ( !StringUtils.isEmpty( strMaxSizeEnter ) && ( nMaxSizeEnter < 0 ) )
135 {
136 strFieldError = FIELD_MAX_SIZE_ENTER;
137 }
138
139 if ( !strFieldError.equals( EMPTY_STRING ) )
140 {
141 Object[] tabRequiredFields = { I18nService.getLocalizedString( strFieldError, locale ) };
142
143 return AdminMessageService.getMessageUrl( request, MESSAGE_NUMERIC_FIELD, tabRequiredFields,
144 AdminMessage.TYPE_STOP );
145 }
146
147 this.setTitle( strTitle );
148 this.setHelpMessage( DiggUtils.trim( strHelpMessage ) );
149 this.setComment( strComment );
150
151 this.setDefaultValue( strValue );
152 this.setWidth( nWidth );
153 this.setHeight( nHeight );
154 this.setMaxSizeEnter( nMaxSizeEnter );
155
156 if ( strMandatory != null )
157 {
158 this.setMandatory( true );
159 }
160 else
161 {
162 this.setMandatory( false );
163 }
164
165 if ( strShowInDiggSubmitList != null )
166 {
167 this.setShowInDiggSubmitList( true );
168 }
169 else
170 {
171 this.setShowInDiggSubmitList( false );
172 }
173
174 return null;
175 }
176
177
178
179
180
181 public String getTemplateCreate( )
182 {
183 return _template_create;
184 }
185
186
187
188
189
190 public String getTemplateModify( )
191 {
192 return _template_modify;
193 }
194
195
196
197
198
199
200
201
202 public FormError getResponseData( HttpServletRequest request, List<Response> listResponse, Locale locale )
203 {
204 String strValueEntry = request.getParameter( DiggUtils.EMPTY_STRING + this.getIdEntry( ) ).trim( );
205 Response response = new Response( );
206 response.setEntry( this );
207
208 if ( strValueEntry != null )
209 {
210 if ( this.isMandatory( ) )
211 {
212 if ( strValueEntry.equals( DiggUtils.EMPTY_STRING ) )
213 {
214 FormError formError = new FormError( );
215 formError.setMandatoryError( true );
216 formError.setTitleQuestion( this.getTitle( ) );
217
218 return formError;
219 }
220 }
221
222 response.setValueResponse( strValueEntry );
223 }
224
225 listResponse.add( response );
226
227 return null;
228 }
229
230
231
232
233
234
235
236
237
238
239 public FormError getResponseData( int nIdDiggSubmit, HttpServletRequest request, List<Response> listResponse,
240 Locale locale, Plugin plugin )
241 {
242 return getResponseData( request, listResponse, locale );
243 }
244
245
246
247
248
249 public String getTemplateHtmlCodeResponse( )
250 {
251 return _template_html_code_response;
252 }
253 }