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.portal.business.regularexpression.RegularExpression;
37  import fr.paris.lutece.portal.service.plugin.Plugin;
38  import fr.paris.lutece.util.ReferenceList;
39  import fr.paris.lutece.util.html.Paginator;
40  import fr.paris.lutece.util.xml.XmlUtil;
41  
42  import java.util.List;
43  import java.util.Locale;
44  
45  import javax.servlet.http.HttpServletRequest;
46  
47  
48  /**
49   *
50   * class Entry
51   *
52   */
53  public class Entry implements IEntry
54  {
55      public static final String TAG_ENTRY = "entry";
56      public static final String TAG_ENTRY_ID = "id";
57      public static final String TAG_TITLE = "title";
58      public static final String TAG_TYPE = "type-id";
59  
60      //	parameters Entry 
61      protected static final String PARAMETER_TITLE = "title";
62      protected static final String PARAMETER_HELP_MESSAGE = "help_message";
63      protected static final String PARAMETER_COMMENT = "comment";
64      protected static final String PARAMETER_MANDATORY = "mandatory";
65      protected static final String PARAMETER_HEIGHT = "height";
66      protected static final String PARAMETER_WIDTH = "width";
67      protected static final String PARAMETER_VALUE = "value";
68      protected static final String PARAMETER_MAX_SIZE_ENTER = "max_size_enter";
69      protected static final String PARAMETER_SHOW_IN_DIGG_SUBMIT_LIST = "show_in_digg_submit_list";
70  
71      //	message
72      protected static final String MESSAGE_MANDATORY_FIELD = "digglike.message.mandatory.field";
73      protected static final String MESSAGE_NUMERIC_FIELD = "digglike.message.numeric.field";
74      protected static final String FIELD_TITLE = "digglike.createEntry.labelTitle";
75      protected static final String FIELD_INSERT_GROUP = "digglike.modifydigglike.manageEnter.labelInsertGroup";
76      protected static final String FIELD_HELP_MESSAGE = "digglike.createEntry.labelHelpMessage";
77      protected static final String FIELD_COMMENT = "digglike.createEntry.labelComment";
78      protected static final String FIELD_VALUE = "digglike.createEntry.labelValue";
79      protected static final String FIELD_PRESENTATION = "digglike.createEntry.labelPresentation";
80      protected static final String FIELD_MANDATORY = "digglike.createEntry.labelMandatory";
81      protected static final String FIELD_WIDTH = "digglike.createEntry.labelWidth";
82      protected static final String FIELD_HEIGHT = "digglike.createEntry.labelHeight";
83      protected static final String FIELD_MAX_SIZE_ENTER = "digglike.createEntry.labelMaxSizeEnter";
84  
85      //  Jsp Definition
86      protected static final String JSP_DOWNLOAD_FILE = "jsp/admin/plugins/digglike/DoDownloadFile.jsp";
87  
88      //MARK
89      protected static final String MARK_ENTRY = "entry";
90  
91      //Other constants
92      protected static final String EMPTY_STRING = "";
93      private int _nIdEntry;
94      private Digg _digg;
95      private EntryType _entryType;
96      private String _strTitle;
97      private String _strHelpMessage;
98      private String _strComment;
99      private boolean _bMandatory;
100     private int _nPosition;
101     private String _strDefaultValue;
102     private int _nHeight = -1;
103     private int _nWidth = -1;
104     private int _nMaxSizeEnter = -1;
105     private List<RegularExpression> _listRegularExpressionList;
106     private boolean _bShowInDiggSubmitList;
107     private List<EntryAdditionalAttribute> _listEntryAdditionalAttribute;
108 
109     /**
110      *  @return the entry comment
111      */
112     public String getComment(  )
113     {
114         return _strComment;
115     }
116 
117     /**
118      *  @return the type of the entry
119      */
120     public EntryType getEntryType(  )
121     {
122         return _entryType;
123     }
124 
125     /**
126      *  @return the entry  help message
127      */
128     public String getHelpMessage(  )
129     {
130         return _strHelpMessage;
131     }
132 
133     /**
134      * @return the  id of entry
135      */
136     public int getIdEntry(  )
137     {
138         return _nIdEntry;
139     }
140 
141     /**
142      * @return position entry
143      */
144     public int getPosition(  )
145     {
146         return _nPosition;
147     }
148 
149     /**
150      * @return title entry
151      */
152     public String getTitle(  )
153     {
154         return _strTitle;
155     }
156 
157     /**
158      * @return true if the question is mandatory
159      */
160     public boolean isMandatory(  )
161     {
162         return _bMandatory;
163     }
164 
165     /**
166      * @return true if the entry must be shown in digg submit list
167      */
168     public boolean isShowInDiggSubmitList(  )
169     {
170         return _bShowInDiggSubmitList;
171     }
172 
173     /**
174      * set entry comment
175      * @param comment entry comment
176      */
177     public void setComment( String comment )
178     {
179         _strComment = comment;
180     }
181 
182     /**
183      * set the type of the entry
184      * @param entryType the type of the entry
185      */
186     public void setEntryType( EntryType entryType )
187     {
188         _entryType = entryType;
189     }
190 
191     /**
192      * set  the entry  help message
193      * @param  helpMessage the entry  help message
194      */
195     public void setHelpMessage( String helpMessage )
196     {
197         _strHelpMessage = helpMessage;
198     }
199 
200     /**
201      * set the id of the entry
202      * @param idEntry  the id of the entry
203      */
204     public void setIdEntry( int idEntry )
205     {
206         _nIdEntry = idEntry;
207     }
208 
209     /**
210      * set true if the entry must be shown in digg submit list
211      * @param  show true if the entry must be shown in digg submit list
212      */
213     public void setShowInDiggSubmitList( boolean show )
214     {
215         _bShowInDiggSubmitList = show;
216     }
217 
218     /**
219      * set true if the question is mandatory
220      * @param  mandatory true if the question is mandatory
221      */
222     public void setMandatory( boolean mandatory )
223     {
224         _bMandatory = mandatory;
225     }
226 
227     /**
228      * set position entry
229      * @param  position  position entry
230      */
231     public void setPosition( int position )
232     {
233         _nPosition = position;
234     }
235 
236     /**
237      * set title entry
238      * @param  title title
239      */
240     public void setTitle( String title )
241     {
242         _strTitle = title;
243     }
244 
245     /**
246      *
247      * @return the digg of the entry
248      */
249     public Digg getDigg(  )
250     {
251         return _digg;
252     }
253 
254     /**
255      * set the digg of the entry
256      * @param digg the digg of the entry
257      */
258     public void setDigg( Digg digg )
259     {
260         this._digg = digg;
261     }
262 
263     /**
264     *
265     * @return a list of regular expression which is associate to the entry
266     */
267     public List<RegularExpression> getRegularExpressionList(  )
268     {
269         return _listRegularExpressionList;
270     }
271 
272     /**
273      * set a list of regular expression which is associate to the entry
274      * @param regularExpressionList a list of regular expression which is associate to the entry
275      */
276     public void setRegularExpressionList( List<RegularExpression> regularExpressionList )
277     {
278         _listRegularExpressionList = regularExpressionList;
279     }
280 
281     /**
282     *
283     * @return the value of the entry
284     */
285     public String getDefaultValue(  )
286     {
287         return _strDefaultValue;
288     }
289 
290     /**
291      * set the default value of the entry
292      * @param value the default value of the entry
293      */
294     public void setDefaultValue( String value )
295     {
296         _strDefaultValue = value;
297     }
298 
299     /**
300      *
301      * @return the width of the entry
302      */
303     public int getWidth(  )
304     {
305         return _nWidth;
306     }
307 
308     /**
309      * set the width of the entry
310      * @param width the width of the entry
311      */
312     public void setWidth( int width )
313     {
314         this._nWidth = width;
315     }
316 
317     /**
318      *
319      * @return  the height of the entry
320      */
321     public int getHeight(  )
322     {
323         return _nHeight;
324     }
325 
326     /**
327      * set the height of the entry
328      * @param height  the height of the entry
329      */
330     public void setHeight( int height )
331     {
332         _nHeight = height;
333     }
334 
335     /**
336     *
337     * @return the max size of enter user
338     */
339     public int getMaxSizeEnter(  )
340     {
341         return _nMaxSizeEnter;
342     }
343 
344     /**
345      * set the max size of enter user
346      * @param maxSizeEnter the max size of enter user
347      */
348     public void setMaxSizeEnter( int maxSizeEnter )
349     {
350         _nMaxSizeEnter = maxSizeEnter;
351     }
352 
353     /**
354      * Get the HtmlCode  of   the entry
355      * @return the HtmlCode  of   the entry
356      *
357      * */
358     public String getTemplateHtmlCodeForm(  )
359     {
360         return null;
361     }
362 
363     /**
364      * Get the template of the html code of the response value  associate to the entry
365      * @return the template of the html code of the response value  associate to the entry
366      */
367     public String getTemplateHtmlCodeResponse(  )
368     {
369         return EMPTY_STRING;
370     }
371 
372     /**
373      * Get the request data
374      * @param request HttpRequest
375      * @param locale the locale
376      * @return null if all data requiered are in the request else the url of jsp error
377      */
378     public String getRequestData( HttpServletRequest request, Locale locale )
379     {
380         return null;
381     }
382 
383     /**
384      * save in the list of response the response associate to the entry in the form submit
385      * @param request HttpRequest
386      * @param listResponse the list of response associate to the entry in the form submit
387      * @param locale the locale
388      * @return a Form error object if there is an error in the response
389      */
390     public FormError getResponseData( HttpServletRequest request, List<Response> listResponse, Locale locale )
391     {
392         return null;
393     }
394 
395     /**
396      * save in the list of response the response associate to the entry in the form submit
397      * @param nIdDiggSubmit the id of the DiggSubmit
398      * @param request HttpRequest
399      * @param listResponse the list of response associate to the entry in the form submit
400      * @param locale the locale
401      * @param plugin the plugin
402      * @return a Form error object if there is an error in the response
403      */
404     public FormError getResponseData( int nIdDiggSubmit, HttpServletRequest request, List<Response> listResponse,
405         Locale locale, Plugin plugin )
406     {
407         return null;
408     }
409 
410     /**
411      * Get template create url of the entry
412      * @return template create url of the entry
413      */
414     public String getTemplateCreate(  )
415     {
416         return null;
417     }
418 
419     /**
420      * Get the template modify url  of the entry
421      * @return template modify url  of the entry
422      */
423     public String getTemplateModify(  )
424     {
425         return null;
426     }
427 
428     /**
429      * The paginator who is use in the template modify of the entry
430      * @param nItemPerPage Number of items to display per page
431      * @param strBaseUrl The base Url for build links on each page link
432      * @param strPageIndexParameterName The parameter name for the page index
433      * @param strPageIndex The current page index
434      * @return the paginator who is use in the template modify of the entry
435      */
436     public Paginator getPaginator( int nItemPerPage, String strBaseUrl, String strPageIndexParameterName,
437         String strPageIndex )
438     {
439         return null;
440     }
441 
442     /**
443      * Get the list of regular expression  who is use in the template modify of the entry
444      * @param entry the entry
445      * @param plugin the plugin
446      * @return the regular expression list who is use in the template modify of the entry
447      */
448     public ReferenceList getReferenceListRegularExpression( IEntry entry, Plugin plugin )
449     {
450         return null;
451     }
452 
453     /**
454     *
455     * @return a list of additional attribute which is associate to the entry
456     */
457     public List<EntryAdditionalAttribute> getEntryAdditionalAttributeList(  )
458     {
459         return _listEntryAdditionalAttribute;
460     }
461 
462     /**
463      * set a list of additional attribute which is associate to the entry
464      * @param entryAdditionalAttributeList a list of additional attribute which is associate to the entry
465      */
466     public void setEntryAdditionalAttributeList( List<EntryAdditionalAttribute> entryAdditionalAttributeList )
467     {
468         _listEntryAdditionalAttribute = entryAdditionalAttributeList;
469     }
470 
471     @Override
472     public void getXml( Locale locale, StringBuffer strXml )
473     {
474         XmlUtil.beginElement( strXml, TAG_ENTRY );
475         XmlUtil.addElement( strXml, TAG_ENTRY_ID, this.getIdEntry(  ) );
476         XmlUtil.addElementHtml( strXml, TAG_TITLE, this.getTitle(  ) );
477 
478         if ( this.getEntryType(  ) != null )
479         {
480             XmlUtil.addElement( strXml, TAG_TYPE, this.getEntryType(  ).getIdType(  ) );
481         }
482 
483         XmlUtil.endElement( strXml, TAG_ENTRY );
484     }
485 }