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.directory.business;
35
36 import fr.paris.lutece.plugins.directory.service.DirectoryPlugin;
37 import fr.paris.lutece.plugins.directory.utils.DirectoryErrorException;
38 import fr.paris.lutece.plugins.directory.utils.DirectoryUtils;
39 import fr.paris.lutece.portal.service.i18n.I18nService;
40 import fr.paris.lutece.portal.service.message.AdminMessage;
41 import fr.paris.lutece.portal.service.message.AdminMessageService;
42 import fr.paris.lutece.portal.service.plugin.Plugin;
43 import fr.paris.lutece.portal.service.plugin.PluginService;
44
45 import org.apache.commons.lang.StringUtils;
46
47 import java.util.ArrayList;
48 import java.util.List;
49 import java.util.Locale;
50
51 import javax.servlet.http.HttpServletRequest;
52
53
54
55
56
57
58 public class EntryTypeTextArea extends Entry
59 {
60 private final String _template_create = "admin/plugins/directory/entrytypetextarea/create_entry_type_text_area.html";
61 private final String _template_modify = "admin/plugins/directory/entrytypetextarea/modify_entry_type_text_area.html";
62 private final String _template_html_code_form_entry = "admin/plugins/directory/entrytypetextarea/html_code_form_entry_type_text_area.html";
63 private final String _template_html_code_form_search_entry = "admin/plugins/directory/entrytypetextarea/html_code_form_search_entry_type_text_area.html";
64 private final String _template_html_code_entry_value = "admin/plugins/directory/entrytypetextarea/html_code_entry_value_type_text_area.html";
65 private final String _template_html_front_code_form_entry = "skin/plugins/directory/entrytypetextarea/html_code_form_entry_type_text_area.html";
66 private final String _template_html_front_code_form_search_entry = "skin/plugins/directory/entrytypetextarea/html_code_form_search_entry_type_text_area.html";
67 private final String _template_html_front_code_entry_value = "skin/plugins/directory/entrytypetextarea/html_code_entry_value_type_text_area.html";
68
69
70
71
72 @Override
73 public String getTemplateHtmlFormEntry( boolean isDisplayFront )
74 {
75 if ( isDisplayFront )
76 {
77 return _template_html_front_code_form_entry;
78 }
79
80 return _template_html_code_form_entry;
81 }
82
83
84
85
86 @Override
87 public String getTemplateHtmlRecordFieldValue( boolean isDisplayFront )
88 {
89 if ( isDisplayFront )
90 {
91 return _template_html_front_code_entry_value;
92 }
93
94 return _template_html_code_entry_value;
95 }
96
97
98
99
100 @Override
101 public String getTemplateHtmlFormSearchEntry( boolean isDisplayFront )
102 {
103 if ( isDisplayFront )
104 {
105 return _template_html_front_code_form_search_entry;
106 }
107
108 return _template_html_code_form_search_entry;
109 }
110
111
112
113
114 @Override
115 public String getEntryData( HttpServletRequest request, Locale locale )
116 {
117 String strTitle = request.getParameter( PARAMETER_TITLE );
118 String strHelpMessage = ( request.getParameter( PARAMETER_HELP_MESSAGE ) != null ) ? request.getParameter( PARAMETER_HELP_MESSAGE ).trim( ) : null;
119 String strHelpMessageSearch = ( request.getParameter( PARAMETER_HELP_MESSAGE_SEARCH ) != null ) ? request.getParameter( PARAMETER_HELP_MESSAGE_SEARCH )
120 .trim( ) : null;
121 String strComment = request.getParameter( PARAMETER_COMMENT );
122 String strValue = request.getParameter( PARAMETER_VALUE );
123 String strMandatory = request.getParameter( PARAMETER_MANDATORY );
124 String strIndexed = request.getParameter( PARAMETER_INDEXED );
125 String strDocumentTitle = request.getParameter( PARAMETER_INDEXED_AS_TITLE );
126 String strDocumentSummary = request.getParameter( PARAMETER_INDEXED_AS_SUMMARY );
127 String strShowInAdvancedSearch = request.getParameter( PARAMETER_SHOWN_IN_ADVANCED_SEARCH );
128 String strShowInResultList = request.getParameter( PARAMETER_SHOWN_IN_RESULT_LIST );
129 String strShowInResultRecord = request.getParameter( PARAMETER_SHOWN_IN_RESULT_RECORD );
130 String strWidth = request.getParameter( PARAMETER_WIDTH );
131 String strHeight = request.getParameter( PARAMETER_HEIGHT );
132 String strShowInHistory = request.getParameter( PARAMETER_SHOWN_IN_HISTORY );
133 String strShowInExport = request.getParameter( PARAMETER_SHOWN_IN_EXPORT );
134 String strShowInCompleteness = request.getParameter( PARAMETER_SHOWN_IN_COMPLETENESS );
135
136 int nWidth = DirectoryUtils.convertStringToInt( strWidth );
137 int nHeight = DirectoryUtils.convertStringToInt( strHeight );
138
139 String strFieldError = DirectoryUtils.EMPTY_STRING;
140
141 if ( ( strTitle == null ) || strTitle.trim( ).equals( DirectoryUtils.EMPTY_STRING ) )
142 {
143 strFieldError = FIELD_TITLE;
144 }
145
146 else
147 if ( ( strWidth == null ) || strWidth.trim( ).equals( DirectoryUtils.EMPTY_STRING ) )
148 {
149 strFieldError = FIELD_WIDTH;
150 }
151 else
152 if ( ( strHeight == null ) || strHeight.trim( ).equals( DirectoryUtils.EMPTY_STRING ) )
153 {
154 strFieldError = FIELD_HEIGHT;
155 }
156
157 if ( !strFieldError.equals( DirectoryUtils.EMPTY_STRING ) )
158 {
159 Object [ ] tabRequiredFields = {
160 I18nService.getLocalizedString( strFieldError, locale )
161 };
162
163 return AdminMessageService.getMessageUrl( request, MESSAGE_MANDATORY_FIELD, tabRequiredFields, AdminMessage.TYPE_STOP );
164 }
165
166 if ( nWidth == -1 )
167 {
168 strFieldError = FIELD_WIDTH;
169 }
170
171 else
172 if ( nHeight == -1 )
173 {
174 strFieldError = FIELD_HEIGHT;
175 }
176
177 if ( !strFieldError.equals( DirectoryUtils.EMPTY_STRING ) )
178 {
179 Object [ ] tabRequiredFields = {
180 I18nService.getLocalizedString( strFieldError, locale )
181 };
182
183 return AdminMessageService.getMessageUrl( request, MESSAGE_NUMERIC_FIELD, tabRequiredFields, AdminMessage.TYPE_STOP );
184 }
185
186 this.setTitle( strTitle );
187 this.setHelpMessage( strHelpMessage );
188 this.setHelpMessageSearch( strHelpMessageSearch );
189 this.setComment( strComment );
190
191 if ( this.getFields( ) == null )
192 {
193 ArrayList<Field> listFields = new ArrayList<Field>( );
194 Field field = new Field( );
195 listFields.add( field );
196 this.setFields( listFields );
197 }
198
199 this.getFields( ).get( 0 ).setValue( strValue );
200 this.getFields( ).get( 0 ).setWidth( nWidth );
201 this.getFields( ).get( 0 ).setHeight( nHeight );
202 this.setMandatory( strMandatory != null );
203 this.setIndexed( strIndexed != null );
204 this.setIndexedAsTitle( strDocumentTitle != null );
205 this.setIndexedAsSummary( strDocumentSummary != null );
206 this.setShownInAdvancedSearch( strShowInAdvancedSearch != null );
207 this.setShownInResultList( strShowInResultList != null );
208 this.setShownInResultRecord( strShowInResultRecord != null );
209 this.setShownInHistory( strShowInHistory != null );
210 this.setShownInExport( strShowInExport != null );
211 this.setShownInCompleteness( strShowInCompleteness != null );
212
213 return null;
214 }
215
216
217
218
219 @Override
220 public String getTemplateCreate( )
221 {
222 return _template_create;
223 }
224
225
226
227
228 @Override
229 public String getTemplateModify( )
230 {
231 return _template_modify;
232 }
233
234
235
236
237 @Override
238 public void getRecordFieldData( Record record, List<String> lstValue, boolean bTestDirectoryError, boolean bAddNewValue, List<RecordField> listRecordField,
239 Locale locale ) throws DirectoryErrorException
240 {
241 Plugin plugin = PluginService.getPlugin( DirectoryPlugin.PLUGIN_NAME );
242
243 String strValueEntry = ( ( lstValue != null ) && ( lstValue.size( ) > 0 ) ) ? lstValue.get( 0 ) : null;
244 RecordField recordField = new RecordField( );
245 recordField.setEntry( this );
246
247 if ( ( record != null ) && bAddNewValue )
248 {
249 RecordFieldFilter recordFieldFilter = new RecordFieldFilter( );
250 recordFieldFilter.setIdDirectory( record.getDirectory( ).getIdDirectory( ) );
251 recordFieldFilter.setIdEntry( this.getIdEntry( ) );
252 recordFieldFilter.setIdRecord( record.getIdRecord( ) );
253
254 List<RecordField> recordFieldList = RecordFieldHome.getRecordFieldList( recordFieldFilter, plugin );
255
256 if ( ( recordFieldList != null ) && !recordFieldList.isEmpty( ) && StringUtils.isNotBlank( recordFieldList.get( 0 ).getValue( ) ) )
257 {
258 strValueEntry = recordFieldList.get( 0 ).getValue( ) + ", " + strValueEntry;
259 }
260 }
261
262 if ( strValueEntry != null )
263 {
264 if ( bTestDirectoryError && this.isMandatory( ) && strValueEntry.equals( DirectoryUtils.EMPTY_STRING ) )
265 {
266 throw new DirectoryErrorException( this.getTitle( ) );
267 }
268
269 recordField.setValue( strValueEntry );
270 }
271
272 listRecordField.add( recordField );
273 }
274
275
276
277
278 @Override
279 public boolean isSortable( )
280 {
281 return true;
282 }
283
284
285
286
287 @Override
288 public boolean isAnonymizable( )
289 {
290 return true;
291 }
292 }