View Javadoc

1   /*
2    * Copyright (c) 2002-2014, Mairie de Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
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   * class EntryTypeTextArea
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       * Get the HtmlCode  of   the entry
64       * @return the HtmlCode  of   the entry
65       *
66       * */
67      public String getTemplateHtmlCodeForm(  )
68      {
69          return _template_html_code_form;
70      }
71  
72      /**
73       * Get the request data
74       * @param request HttpRequest
75       * @param locale the locale
76       * @return null if all data requiered are in the request else the url of jsp error
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      * Get template create url of the entry
179      * @return template create url of the entry
180      */
181     public String getTemplateCreate(  )
182     {
183         return _template_create;
184     }
185 
186     /**
187      * Get the template modify url  of the entry
188      * @return template modify url  of the entry
189      */
190     public String getTemplateModify(  )
191     {
192         return _template_modify;
193     }
194 
195     /**
196      * save in the list of response the response associate to the entry in the form submit
197      * @param request HttpRequest
198      * @param listResponse the list of response associate to the entry in the form submit
199      * @param locale the locale
200      * @return a Form error object if there is an error in the response
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      * save in the list of response the response associate to the entry in the form submit
232      * @param nIdDiggSubmit The if of the DiggSubmit
233      * @param request HttpRequest
234      * @param listResponse the list of response associate to the entry in the form submit
235      * @param locale the locale
236      * @param plugin the plugin
237      * @return a Form error object if there is an error in the response
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      * Get the template of the html code of the response value  associate to the entry
247     * @return the template of the html code of the response value  associate to the entry
248      */
249     public String getTemplateHtmlCodeResponse(  )
250     {
251         return _template_html_code_response;
252     }
253 }