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.web;
35  
36  import java.io.IOException;
37  import java.util.ArrayList;
38  import java.util.Collection;
39  import java.util.HashMap;
40  import java.util.List;
41  import java.util.Locale;
42  import java.util.Map;
43  
44  import javax.servlet.http.HttpServletRequest;
45  import javax.servlet.http.HttpSession;
46  
47  import org.apache.commons.lang.StringUtils;
48  
49  import fr.paris.lutece.plugins.digglike.business.Category;
50  import fr.paris.lutece.plugins.digglike.business.CategoryHome;
51  import fr.paris.lutece.plugins.digglike.business.CommentSubmit;
52  import fr.paris.lutece.plugins.digglike.business.Digg;
53  import fr.paris.lutece.plugins.digglike.business.DiggFilter;
54  import fr.paris.lutece.plugins.digglike.business.DiggHome;
55  import fr.paris.lutece.plugins.digglike.business.DiggSubmit;
56  import fr.paris.lutece.plugins.digglike.business.DiggSubmitState;
57  import fr.paris.lutece.plugins.digglike.business.DiggSubmitStateHome;
58  import fr.paris.lutece.plugins.digglike.business.DiggSubmitType;
59  import fr.paris.lutece.plugins.digglike.business.DiggSubmitTypeHome;
60  import fr.paris.lutece.plugins.digglike.business.DiggUserInfo;
61  import fr.paris.lutece.plugins.digglike.business.FormError;
62  import fr.paris.lutece.plugins.digglike.business.ReportedMessage;
63  import fr.paris.lutece.plugins.digglike.business.ReportedMessageHome;
64  import fr.paris.lutece.plugins.digglike.business.Response;
65  import fr.paris.lutece.plugins.digglike.business.SearchFields;
66  import fr.paris.lutece.plugins.digglike.business.SubmitFilter;
67  import fr.paris.lutece.plugins.digglike.business.VoteHome;
68  import fr.paris.lutece.plugins.digglike.business.VoteType;
69  import fr.paris.lutece.plugins.digglike.business.VoteTypeHome;
70  import fr.paris.lutece.plugins.digglike.service.CommentSubmitService;
71  import fr.paris.lutece.plugins.digglike.service.DiggSubmitService;
72  import fr.paris.lutece.plugins.digglike.service.DiggUserInfoService;
73  import fr.paris.lutece.plugins.digglike.service.DigglikeService;
74  import fr.paris.lutece.plugins.digglike.service.ICommentSubmitService;
75  import fr.paris.lutece.plugins.digglike.service.IDiggSubmitService;
76  import fr.paris.lutece.plugins.digglike.service.digglikesearch.DigglikeSearchService;
77  import fr.paris.lutece.plugins.digglike.service.subscription.DigglikeSubscriptionProviderService;
78  import fr.paris.lutece.plugins.digglike.utils.DiggUtils;
79  import fr.paris.lutece.portal.service.captcha.CaptchaSecurityService;
80  import fr.paris.lutece.portal.service.content.XPageAppService;
81  import fr.paris.lutece.portal.service.i18n.I18nService;
82  import fr.paris.lutece.portal.service.message.SiteMessage;
83  import fr.paris.lutece.portal.service.message.SiteMessageException;
84  import fr.paris.lutece.portal.service.message.SiteMessageService;
85  import fr.paris.lutece.portal.service.plugin.Plugin;
86  import fr.paris.lutece.portal.service.plugin.PluginService;
87  import fr.paris.lutece.portal.service.portal.PortalService;
88  import fr.paris.lutece.portal.service.security.LuteceUser;
89  import fr.paris.lutece.portal.service.security.SecurityService;
90  import fr.paris.lutece.portal.service.security.UserNotSignedException;
91  import fr.paris.lutece.portal.service.template.AppTemplateService;
92  import fr.paris.lutece.portal.service.util.AppLogService;
93  import fr.paris.lutece.portal.service.util.AppPathService;
94  import fr.paris.lutece.portal.service.util.AppPropertiesService;
95  import fr.paris.lutece.portal.web.LocalVariables;
96  import fr.paris.lutece.portal.web.xpages.XPage;
97  import fr.paris.lutece.portal.web.xpages.XPageApplication;
98  import fr.paris.lutece.util.ReferenceList;
99  import fr.paris.lutece.util.html.HtmlTemplate;
100 import fr.paris.lutece.util.html.Paginator;
101 import fr.paris.lutece.util.url.UrlItem;
102 
103 
104 /**
105  * This class manages Form page.
106  */
107 public class DiggApp implements XPageApplication
108 {
109     public static final String ANCHOR_DIGG_SUBMIT = "digg";
110     public static final String ANCHOR_FRAMESET_CONTENT_DIGG = "frameset_content_digg";
111     public static final String PARAMETER_CLEAR_FILTER = "clear_filter";
112     public static final String PARAMETER_DIGG_DETAIL = "digg_detail";
113     public static final String ACTION_VIEW_DIGG_SUBMIT = "view_digg_submit";
114 
115     // markers
116     private static final String MARK_DIGG = "digg";
117     private static final String MARK_CONTENT_DIGG = "content_digg";
118     private static final String MARK_LIST_DIGG_SUBMIT = "list_digg_submit";
119     private static final String MARK_LABEL_DIGG = "label_digg";
120     private static final String MARK_HEADER_DIGG = "header_digg";
121     private static final String MARK_LIST_CATEGORIES_DIGG = "list_categories_digg";
122     private static final String MARK_ID_DIGG = "id_digg";
123     private static final String MARK_DIGG_LIST = "list_digg";
124     private static final String MARK_LIST_SUBMIT_TOP_COMMENT = "list_top_comment_digg";
125     private static final String MARK_LIST_SUBMIT_TOP_POPULARITY_DIGG = "list_top_popularity_digg";
126     private static final String MARK_ID_DIGG_SUBMIT = "id_digg_submit";
127     private static final String MARK_LIST_COMMENT_SUBMIT_DIGG = "list_comment";
128     private static final String MARK_LIST_SUB_COMMENT_SUBMIT_DIGG = "list_sub_comment";
129     private static final String MARK_DIGG_COMMENT = "digg_comment";
130     private static final String MARK_AUTHORIZED_COMMENT = "authorized_comment";
131     private static final String MARK_AUTHORIZED_VOTE = "authorized_vote";
132     private static final String MARK_DISPLAY_COMMENT_IN_LIST = "display_comment_in_list";
133     private static final String MARK_ENABLE_DIGG_REPORTS = "enable_digg_reports";
134     private static final String MARK_DIGG_SUBMIT = "digg_submit";
135     private static final String MARK_COMMENT_SUBMIT = "comment_submit";
136     private static final String MARK_LUTECE_USER = "lutece_user";
137     private static final String MARK_LUTECE_USER_CONNECTED = "lutece_user_connected";
138     private static final String MARK_UNAVAILABILITY_MESSAGE = "unavailability_message";
139     private static final String MARK_NUMBER_SHOWN_CHARACTERS = "number_shown_characters";
140     private static final String MARK_DISABLE_NEW_DIGG_SUBMIT = "disable_new_digg_submit";
141     private static final String MARK_DISABLE_NEW_COMMENT_SUBMIT = "disable_new_comment_submit";
142     private static final String MARK_QUERY = "query";
143     private static final String MARK_ID_FILTER_CATEGORY_DIGG = "id_filter_category";
144     private static final String MARK_ID_FILTER_TYPE = "id_filter_type";
145     private static final String MARK_TYPE_SELECTED = "type_selected";
146     private static final String MARK_ID_FILTER_PERIOD = "id_filter_period";
147     private static final String MARK_LIST_DIGG_SUBMIT_SORT = "list_digg_submit_sort";
148     private static final String MARK_LIST_FILTER_BY_PERIOD = "list_filter_by_period";
149     private static final String MARK_ID_DIGG_SUBMIT_SORT = "id_digg_submit_sort";
150     private static final String MARK_SHOW_CATEGORY_BLOCK = "show_category_block";
151     private static final String MARK_SHOW_TOP_SCORE_BLOCK = "show_top_score_block";
152     private static final String MARK_SHOW_TOP_COMMENT_BLOCK = "show_top_comment_block";
153     private static final String MARK_DIGG_SUBMIT_VOTE_TYPE = "digg_submit_vote_type";
154   
155     private static final String MARK_PAGINATOR = "paginator";
156     private static final String MARK_JCAPTCHA = "jcaptcha";
157     private static final String MARK_MAX_AMOUNT_COMMENTS = "number_comments";
158     private static final String MARK_MAX_AMOUNT_COMMENTS_CHAR = "cumber_char_comments";
159     private static final String MARK_NB_ITEMS_PER_PAGE = "nb_items_per_page";
160     private static final String MARK_ACTIVE_EDITOR_BBCODE = "active_editor_bbcode";
161     private static final String MARK_VIEW = "view";
162     private static final String MARK_USER_SUBSCRIBED = "user_subscribed";
163     private static final String MARK_IS_EXTEND_INSTALLED = "isExtendInstalled";
164 
165     // templates
166     private static final String TEMPLATE_XPAGE_FRAME_DIGG = "skin/plugins/digglike/digg_frame.html";
167     private static final String TEMPLATE_XPAGE_LIST_SUBMIT_DIGG = "skin/plugins/digglike/digg_list_submit.html";
168     private static final String TEMPLATE_XPAGE_FORM_DIGG = "skin/plugins/digglike/digg_form.html";
169     private static final String TEMPLATE_XPAGE_LIST_DIGG = "skin/plugins/digglike/digg_list.html";
170     private static final String TEMPLATE_XPAGE_DETAIL_SUBMIT_DIGG = "skin/plugins/digglike/digg_detail.html";
171     private static final String TEMPLATE_XPAGE_DIGG_REPORTED = "skin/plugins/digglike/digg_reported.html";
172     private static final String TEMPLATE_XPAGE_DIGG_SUB_COMMENT = "skin/plugins/digglike/digg_sub_comment.html";
173     private static final String TEMPLATE_XPAGE_COMMENT_SUBMIT_DIGG = "skin/plugins/digglike/digg_comment.html";
174     private static final String JCAPTCHA_PLUGIN = "jcaptcha";
175 
176     // properties for page titles and path label
177     private static final String PROPERTY_XPAGE_PAGETITLE = "digglike.xpage.pagetitle";
178     private static final String PROPERTY_XPAGE_PATHLABEL = "digglike.xpage.pathlabel";
179     private static final String PROPERTY_NUMBER_DIGG_SUBMIT_VALUE_SHOWN_CHARACTERS = "digglike.diggSubmitValue.NumberShownCharacters";
180     private static final String PROPERTY_PAGE_APPLICATION_ID = "digglike.xpage.applicationId";
181     private static final String PROPERTY_ITEM_PER_PAGE = "digglike.itemsPerPage.front";
182 
183     // request parameters
184     private static final String PARAMETER_ID_DIGG = "id_digg";
185     private static final String PARAMETER_ID_SUBMIT_DIGG = "id_digg_submit";
186     private static final String PARAMETER_COMMENT_DIGG = "digg_comment";
187     private static final String PARAMETER_COMMENT_VALUE_DIGG = "comment_value";
188     private static final String PARAMETER_REPORTED_VALUE = "reported_value";
189     private static final String PARAMETER_ID_FILTER_PERIOD = "id_filter_period";
190     private static final String PARAMETER_ID_DIGG_SUBMIT_SORT = "id_digg_submit_sort";
191     private static final String PARAMETER_VOTE_DIGG = "vote";
192     private static final String PARAMETER_ID_FILTER_CATEGORY_DIGG = "id_filter_category";
193     private static final String PARAMETER_ID_FILTER_DIGG_SUBMIT_TYPE = "id_filter_type";
194     private static final String PARAMETER_LUTECE_USER_NAME_FILTER = "lutece_user_name_filter";
195     private static final String PARAMETER_ID_CATEGORY_DIGG = "id_category";
196     private static final String PARAMETER_ID_TYPE_DIGG = "id_type";
197     private static final String PARAMETER_VOTED = "voted";
198     private static final String PARAMETER_QUERY = "query";
199     private static final String PARAMETER_FILTER_PAGE_INDEX = "filter_page_index";
200     private static final String PARAMETER_PAGE_INDEX = "page_index";
201     private static final String PARAMETER_COMMENT_ID_PARENT = "id_digg_comment";
202     private static final String PARAMETER_ACTION = "action";
203     private static final String PARAMETER_VIEW = "view";
204     private static final String PARAMETER_TERMS_OF_USE = "terms_of_use";
205     private static final String PARAMETER_PAGE = "page";
206 
207     // message
208     private static final String MESSAGE_FORM_ERROR = "digglike.message.formError";
209     private static final String MESSAGE_MANDATORY_QUESTION = "digglike.message.mandatory.question";
210     private static final String MESSAGE_ERROR = "digglike.message.Error";
211     private static final String MESSAGE_MANDATORY_COMMENT = "digglike.message.mandatoryComment";
212     private static final String MESSAGE_MANDATORY_REPORTED = "digglike.message.mandatoryReported";
213     private static final String MESSAGE_CAPTCHA_ERROR = "digglike.message.captchaError";
214     private static final String MESSAGE_NEW_DIGG_SUBMIT = "digglike.message.newDiggSubmit";
215     private static final String MESSAGE_NEW_DIGG_SUBMIT_DISABLE = "digglike.message.newDiggSubmitDisable";
216     private static final String MESSAGE_MESSAGE_SUBMIT_SAVE_ERROR = "digglike.message.submitSaveError";
217     private static final String MESSAGE_NEW_COMMENT_SUBMIT = "digglike.message.newCommentSubmit";
218     private static final String MESSAGE_NEW_COMMENT_SUBMIT_DISABLE = "digglike.message.newCommentSubmitDisable";
219     private static final String MESSAGE_NEW_REPORTED_SUBMIT = "digglike.message.newReportedSubmit";
220     private static final String MESSAGE_ERROR_NO_CATEGORY = "digglike.message.errorNoCategorySelected";
221     private static final String MESSAGE_ERROR_NO_DIGG_SUBMIT_TYPE_SELECTED = "digglike.message.errorNoDiggSubmitTypeSelected";
222     private static final String MESSAGE_ERROR_MUST_SELECTED_TERMS_OF_USE = "digglike.message.youMustSelectTermsOfUse";
223     private static final String MESSAGE_ACCESS_DENIED = "digglike.message.accessDenied";
224 
225     // XPAGE URL
226 
227     // constant
228     private static final String EMPTY_STRING = "";
229     private static final String CONSTANTE_PARAMETER_TRUE_VALUE = "1";
230     private static final String PATH_TYPE_VOTE_FOLDER = "skin/plugins/digglike/";
231     private static final String ACTION_VIEW_DIGG_LIST = "view_digg_list";
232     private static final String ACTION_VIEW_DIGG_SUBMIT_LIST = "view_digg_submit_list";
233     private static final String ACTION_CREATE_DIGG_SUBMIT = "create_digg_submit";
234     private static final String ACTION_DO_CREATE_DIGG_SUBMIT = "do_create_digg_submit";
235     private static final String ACTION_DO_CREATE_COMMENT = "do_create_comment";
236     private static final String ACTION_DO_CREATE_REPORT = "do_create_report";
237     private static final String ACTION_DO_VOTE = "do_vote";
238     private static final String ACTION_CREATE_REPORT = "create_report";
239     private static final String ACTION_CREATE_SUB_COMMENT = "create_sub_comment";
240     private static final String ACTION_SUBSCRIBE_DIGG = "subscribe_digg";
241     private static final String ACTION_UNSUBSCRIBE_DIGG = "unsubscribe_digg";
242     private static final String CONSTANT_VIEW_LIST_DIGG_SUBMIT = "view_digg_submit_list";
243     private static final String CONSTANT_VIEW_DIGG_SUBMIT = "view_digg_submit";
244     private static final String CONSTANT_VIEW_REPORT = "view_report";
245     private static final String CONSTANT_VIEW_CREATE_DIGG_SUBMIT = "view_create_digg_submit";
246     private static final String CONSTANT_DIGG = "digg";
247 
248     // session filter
249     private static final String SESSION_SEARCH_FIELDS = "search_fields";
250 
251     // properties
252     private int _nDefaultItemsPerPage = AppPropertiesService.getPropertyInt( PROPERTY_ITEM_PER_PAGE, 50 );
253     private Plugin _plugin;
254     private int _nIdDiggSubmitStatePublish = DiggUtils.CONSTANT_ID_NULL;
255     private UrlItem _urlDiggXpageHome;
256     private int _nNumberShownCharacters = DiggUtils.CONSTANT_ID_NULL;
257     private IDiggSubmitService _diggSubmitService = DiggSubmitService.getService(  );
258     private ICommentSubmitService _commentSubmitService = CommentSubmitService.getService(  );
259 
260     /**
261      * Returns the DiggLike XPage result content depending on the request
262      * parameters and the current mode.
263      *
264      * @param request the {@link HttpServletRequest}
265      * @param nMode the mode
266      * @param plugin {@link Plugin}
267      * @return {@link XPage}
268      * @throws UserNotSignedException {@link UserNotSignedException}
269      * @throws SiteMessageException {@link SiteMessageException}
270      */
271     public XPage getPage( HttpServletRequest request, int nMode, Plugin plugin )
272         throws UserNotSignedException, SiteMessageException
273     {
274         XPage page = new XPage(  );
275         init( request, plugin );
276 
277         if ( request.getParameter( PARAMETER_CLEAR_FILTER ) != null )
278         {
279             //clear all filter in session
280             clearSessionFilter( request.getSession(  ) );
281         }
282 
283         String strAction = request.getParameter( PARAMETER_ACTION );
284 
285         if ( ACTION_VIEW_DIGG_LIST.equals( strAction ) )
286         {
287             page = getViewDiggList( page, nMode, request );
288         }
289         else if ( ACTION_VIEW_DIGG_SUBMIT_LIST.equals( strAction ) )
290         {
291             page = getViewDiggSubmitList( page, nMode, request );
292         }
293 
294         else if ( ACTION_VIEW_DIGG_SUBMIT.equals( strAction ) )
295         {
296             page = getViewDiggSubmit( page, nMode, request );
297         }
298 
299         else if ( ACTION_CREATE_DIGG_SUBMIT.equals( strAction ) )
300         {
301             page = getViewCreateDiggSubmit( page, nMode, request );
302         }
303         else if ( ACTION_CREATE_REPORT.equals( strAction ) )
304         {
305             page = getViewCreateReport( page, nMode, request );
306         }
307         else if ( ACTION_CREATE_SUB_COMMENT.equals( strAction ) )
308         {
309             page = getViewCreateSubComment( page, nMode, request );
310         }
311 
312         else if ( ACTION_DO_CREATE_DIGG_SUBMIT.equals( strAction ) )
313         {
314             doCreateDiggSubmit( page, nMode, request );
315             page = getViewDiggSubmitList( page, nMode, request );
316         }
317         else if ( ACTION_DO_CREATE_COMMENT.equals( strAction ) )
318         {
319             doCreateComment( page, nMode, request );
320             page = getViewDiggSubmit( page, nMode, request );
321         }
322         else if ( ACTION_DO_CREATE_REPORT.equals( strAction ) )
323         {
324             doReport( page, nMode, request );
325             page = getViewDiggSubmit( page, nMode, request );
326         }
327 
328         else if ( ACTION_DO_VOTE.equals( strAction ) )
329         {
330             doVote( page, nMode, request );
331 
332             String strView = request.getParameter( PARAMETER_VIEW );
333 
334             if ( ( strView != null ) && strView.equals( CONSTANT_VIEW_DIGG_SUBMIT ) )
335             {
336                 page = getViewDiggSubmit( page, nMode, request );
337             }
338             else
339             {
340                 page = getViewDiggSubmitList( page, nMode, request );
341             }
342         }
343         else if ( ACTION_SUBSCRIBE_DIGG.equals( strAction ) )
344         {
345             doSubscribeDigg( request );
346         }
347         else if ( ACTION_UNSUBSCRIBE_DIGG.equals( strAction ) )
348         {
349             doUnsubscribeDigg( request );
350         }
351         else
352         {
353             if ( ( request.getParameter( PARAMETER_ID_DIGG ) != null ) ||
354                     ( DigglikeService.getInstance().getIdDefaultDigg(  ) != DiggUtils.CONSTANT_ID_NULL ) )
355             {
356                 page = getViewDiggSubmitList( page, nMode, request );
357             }
358             else
359             {
360                 page = getViewDiggList( page, nMode, request );
361             }
362         }
363 
364         return page;
365     }
366 
367     /**
368      * Display Digg List
369      * @param request the {@link HttpServletRequest}
370      * @param nMode the mode
371      * @param page {@link XPage}
372      * @return {@link XPage}
373      * @throws UserNotSignedException {@link UserNotSignedException}
374      * @throws SiteMessageException {@link SiteMessageException}
375      */
376     public XPage getViewDiggList( XPage page, int nMode, HttpServletRequest request )
377         throws UserNotSignedException, SiteMessageException
378     {
379         Map<String, Object> model = new HashMap<String, Object>(  );
380         LuteceUser luteceUserConnected = SecurityService.getInstance(  ).getRegisteredUser( request );
381 
382         String strContentDigg = EMPTY_STRING;
383         page.setTitle( I18nService.getLocalizedString( PROPERTY_XPAGE_PAGETITLE, request.getLocale(  ) ) );
384         page.setPathLabel( I18nService.getLocalizedString( PROPERTY_XPAGE_PATHLABEL, request.getLocale(  ) ) );
385 
386         // show the diggs list
387         String strCurrentPageIndexDigg = "";
388         strCurrentPageIndexDigg = Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX,
389                 strCurrentPageIndexDigg );
390 
391         int nItemsPerPageDigg = _nDefaultItemsPerPage;
392         nItemsPerPageDigg = Paginator.getItemsPerPage( request, Paginator.PARAMETER_ITEMS_PER_PAGE, nItemsPerPageDigg,
393                 _nDefaultItemsPerPage );
394 
395         strContentDigg = getHtmlListDigg( request.getLocale(  ), _plugin, strCurrentPageIndexDigg, nItemsPerPageDigg,
396                 getNewUrlItemPage(  ), luteceUserConnected );
397 
398         model.put( MARK_CONTENT_DIGG, strContentDigg );
399 
400         page.setContent( strContentDigg );
401 
402         return page;
403     }
404 
405     /**
406      * Display DiggSubmit List
407      * @param request the {@link HttpServletRequest}
408      * @param nMode the mode
409      * @param page {@link XPage}
410      * @return {@link XPage}
411      * @throws UserNotSignedException {@link UserNotSignedException}
412      * @throws SiteMessageException {@link SiteMessageException}
413      */
414     public XPage getViewDiggSubmitList( XPage page, int nMode, HttpServletRequest request )
415         throws UserNotSignedException, SiteMessageException
416     {
417         String strIdDigg = request.getParameter( PARAMETER_ID_DIGG );
418 
419         int nIdDigg = DiggUtils.getIntegerParameter( strIdDigg );
420         Digg digg = DiggHome.findByPrimaryKey( nIdDigg, _plugin );
421         LuteceUser luteceUserConnected = SecurityService.getInstance(  ).getRegisteredUser( request );
422 
423         Map<String, Object> model = new HashMap<String, Object>(  );
424         model.put( MARK_VIEW, CONSTANT_VIEW_LIST_DIGG_SUBMIT );
425 
426         if ( digg == null )
427         {
428             digg = DiggHome.findByPrimaryKey(DigglikeService.getInstance(). getIdDefaultDigg(  ), _plugin );
429         }
430 
431         //testAuthorizationAccess
432         testUserAuthorizationAccess( digg, request, luteceUserConnected );
433 
434         if ( luteceUserConnected != null )
435         {
436             model.put( MARK_LUTECE_USER_CONNECTED, luteceUserConnected );
437 
438             String strIdFilterCategory = request.getParameter( PARAMETER_ID_FILTER_CATEGORY_DIGG );
439             int nIdCategory = -1;
440 
441             if ( StringUtils.isNotEmpty( strIdFilterCategory ) && StringUtils.isNumeric( strIdFilterCategory ) )
442             {
443                 nIdCategory = Integer.parseInt( strIdFilterCategory );
444             }
445 
446             if ( nIdCategory > 0 )
447             {
448                 model.put( MARK_USER_SUBSCRIBED,
449                     DigglikeSubscriptionProviderService.getService(  )
450                                                        .hasUserSubscribedToDiggCategory( luteceUserConnected,
451                         nIdCategory ) );
452             }
453             else
454             {
455                 model.put( MARK_USER_SUBSCRIBED,
456                     DigglikeSubscriptionProviderService.getService(  )
457                                                        .hasUserSubscribedToDigg( luteceUserConnected, nIdDigg ) );
458             }
459         }
460 
461         UrlItem urlDiggXpage = getNewUrlItemPage(  );
462         urlDiggXpage.addParameter( PARAMETER_ACTION, CONSTANT_VIEW_LIST_DIGG_SUBMIT );
463         urlDiggXpage.addParameter( PARAMETER_ID_DIGG, nIdDigg );
464 
465         SearchFields searchFields = getSearchFields( request );
466         addDiggPageFrameset( getHtmlListDiggSubmit( request.getLocale(  ), _plugin, digg, searchFields, urlDiggXpage,
467                 luteceUserConnected ), request, page, digg, model, searchFields, luteceUserConnected );
468 
469         return page;
470     }
471 
472     /**
473      * Display view DiggSubmit
474      * @param request the {@link HttpServletRequest}
475      * @param nMode the mode
476      * @param page {@link XPage}
477      * @return {@link XPage}
478      * @throws UserNotSignedException {@link UserNotSignedException}
479      * @throws SiteMessageException {@link SiteMessageException}
480      */
481     public XPage getViewDiggSubmit( XPage page, int nMode, HttpServletRequest request )
482         throws UserNotSignedException, SiteMessageException
483     {
484         Map<String, Object> model = new HashMap<String, Object>(  );
485         LuteceUser luteceUserConnected = SecurityService.getInstance(  ).getRegisteredUser( request );
486         String strIdSubmitDigg = request.getParameter( PARAMETER_ID_SUBMIT_DIGG );
487         int nIdSubmitDigg = DiggUtils.getIntegerParameter( strIdSubmitDigg );
488         DiggSubmit diggSubmit = _diggSubmitService.findByPrimaryKey( nIdSubmitDigg, true, _plugin );
489         diggSubmit.setDigg( DiggHome.findByPrimaryKey( diggSubmit.getDigg(  ).getIdDigg(  ), _plugin ) );
490 
491         //testAuthorizationAccess
492         testUserAuthorizationAccess( diggSubmit.getDigg(  ), request, luteceUserConnected );
493 
494         model.put( MARK_VIEW, CONSTANT_VIEW_DIGG_SUBMIT );
495 
496         SearchFields searchFields = getSearchFields( request );
497         addDiggPageFrameset( getHtmlDiggSubmitDetail( request, nMode, _plugin, diggSubmit, luteceUserConnected ),
498             request, page, diggSubmit.getDigg(  ), model, searchFields, luteceUserConnected );
499 
500         return page;
501     }
502 
503     /**
504      * Display create DiggSubmit Form
505      * @param request the {@link HttpServletRequest}
506      * @param nMode the mode
507      * @param page {@link XPage}
508      * @return {@link XPage}
509      * @throws UserNotSignedException {@link UserNotSignedException}
510      * @throws SiteMessageException {@link SiteMessageException}
511      */
512     public XPage getViewCreateDiggSubmit( XPage page, int nMode, HttpServletRequest request )
513         throws UserNotSignedException, SiteMessageException
514     {
515        
516     	
517     	LuteceUser luteceUserConnected = SecurityService.getInstance(  ).getRegisteredUser( request );
518     	String strIdDigg = request.getParameter( PARAMETER_ID_DIGG );
519         int nIdDigg = DiggUtils.getIntegerParameter( strIdDigg );
520         Digg digg = DiggHome.findByPrimaryKey( nIdDigg, _plugin );
521 
522         if ( digg.isActiveDiggSubmitAuthentification(  ) && SecurityService.isAuthenticationEnable(  ) )
523         {
524             luteceUserConnected = SecurityService.getInstance(  ).getRemoteUser( request );
525 
526             if ( luteceUserConnected == null )
527             {
528                 throw new UserNotSignedException(  );
529             }
530 
531             //testAuthorizationAccess
532             testUserAuthorizationAccess( digg, request, luteceUserConnected );
533         }
534 
535         
536         
537         
538         
539     	Map<String, Object> model = new HashMap<String, Object>(  );
540         model.put( MARK_VIEW, CONSTANT_VIEW_CREATE_DIGG_SUBMIT );
541         
542         SearchFields searchFields = getSearchFields( request );
543         addDiggPageFrameset( getHtmlForm( request, nMode, _plugin, digg, searchFields.getIdFilterCategory(  ) ),
544             request, page, digg, model, searchFields, luteceUserConnected );
545 
546         return page;
547     }
548     
549     /**
550      * Display create sub comment
551      * @param request the {@link HttpServletRequest}
552      * @param nMode the mode
553      * @param page {@link XPage}
554      * @return {@link XPage}
555      * @throws UserNotSignedException {@link UserNotSignedException}
556      * @throws SiteMessageException {@link SiteMessageException}
557      */
558     public XPage getViewCreateSubComment( XPage page, int nMode, HttpServletRequest request )
559         throws UserNotSignedException, SiteMessageException
560     {
561     	
562     	
563     	String strIdParentComment = request.getParameter( PARAMETER_COMMENT_ID_PARENT );
564         int nIdParentComment = DiggUtils.getIntegerParameter( strIdParentComment );
565         LuteceUser luteceUserConnected = SecurityService.getInstance(  ).getRegisteredUser( request );
566         
567         String strIdDigg = request.getParameter( PARAMETER_ID_DIGG );
568         int nIdDigg = DiggUtils.getIntegerParameter( strIdDigg );
569         Digg digg = DiggHome.findByPrimaryKey( nIdDigg, _plugin );
570         
571         if ( digg.isActiveCommentAuthentification(  ) && SecurityService.isAuthenticationEnable(  ) )
572         {
573             luteceUserConnected = SecurityService.getInstance(  ).getRemoteUser( request );
574 
575             if ( luteceUserConnected == null )
576             {
577                 throw new UserNotSignedException(  );
578             }
579 
580             //testAuthorizationAccess
581             testUserAuthorizationAccess( digg, request, luteceUserConnected );
582         }
583         
584         Map<String, Object> model = new HashMap<String, Object>(  );
585         
586         CaptchaSecurityService captchaSecurityService = new CaptchaSecurityService(  );
587 
588         
589         if ( digg!=null  && digg.isActiveCaptcha(  ) && PluginService.isPluginEnable( JCAPTCHA_PLUGIN ) )
590         {
591             model.put( MARK_JCAPTCHA, captchaSecurityService.getHtmlCode(  ) );
592         }
593         
594         model.put( MARK_LUTECE_USER_CONNECTED, luteceUserConnected );
595         model.put(MARK_ID_DIGG, strIdDigg);
596         CommentSubmit commentSubmit = _commentSubmitService.findByPrimaryKey(nIdParentComment, _plugin);
597         model.put(MARK_COMMENT_SUBMIT, commentSubmit);
598         model.put( MARK_DISABLE_NEW_COMMENT_SUBMIT, digg.isDisableNewComment(  ) );
599         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_XPAGE_DIGG_SUB_COMMENT, request.getLocale(  ), model );
600         page.setTitle( I18nService.getLocalizedString( PROPERTY_XPAGE_PAGETITLE, request.getLocale(  ) ) );
601         page.setPathLabel( I18nService.getLocalizedString( PROPERTY_XPAGE_PATHLABEL, request.getLocale(  ) ) );
602         page.setContent( template.getHtml(  ) );
603         
604         return page;
605     }
606 
607     /**
608      * Display create Report form
609      * @param request the {@link HttpServletRequest}
610      * @param nMode the mode
611      * @param page {@link XPage}
612      * @return {@link XPage}
613      * @throws UserNotSignedException {@link UserNotSignedException}
614      * @throws SiteMessageException {@link SiteMessageException}
615      */
616     public XPage getViewCreateReport( XPage page, int nMode, HttpServletRequest request )
617         throws UserNotSignedException, SiteMessageException
618     {
619         Map<String, Object> model = new HashMap<String, Object>(  );
620         LuteceUser luteceUserConnected = SecurityService.getInstance(  ).getRegisteredUser( request );
621         String strIdSubmitDigg = request.getParameter( PARAMETER_ID_SUBMIT_DIGG );
622         int nIdSubmitDigg = DiggUtils.getIntegerParameter( strIdSubmitDigg );
623         DiggSubmit diggSubmit = _diggSubmitService.findByPrimaryKey( nIdSubmitDigg, true, _plugin );
624         diggSubmit.setDigg( DiggHome.findByPrimaryKey( diggSubmit.getDigg(  ).getIdDigg(  ), _plugin ) );
625         model.put( MARK_VIEW, CONSTANT_VIEW_REPORT );
626 
627         SearchFields searchFields = getSearchFields( request );
628         addDiggPageFrameset( getHtmlReported( request, nMode, _plugin, diggSubmit ), request, page,
629             diggSubmit.getDigg(  ), model, searchFields, luteceUserConnected );
630 
631         return page;
632     }
633 
634     /**
635      * Perform Action create Digg Submit
636      * @param request the {@link HttpServletRequest}
637      * @param nMode the mode
638      * @param page {@link XPage}
639      * @throws UserNotSignedException {@link UserNotSignedException}
640      * @throws SiteMessageException {@link SiteMessageException}
641      */
642     public void doCreateDiggSubmit( XPage page, int nMode, HttpServletRequest request )
643         throws UserNotSignedException, SiteMessageException
644     {
645         String strIdDigg = request.getParameter( PARAMETER_ID_DIGG );
646 
647         int nIdDigg = DiggUtils.getIntegerParameter( strIdDigg );
648         LuteceUser luteceUserConnected = null;
649 
650         Digg digg = DiggHome.findByPrimaryKey( nIdDigg, _plugin );
651 
652         if ( digg.isActiveDiggSubmitAuthentification(  ) && SecurityService.isAuthenticationEnable(  ) )
653         {
654             luteceUserConnected = SecurityService.getInstance(  ).getRemoteUser( request );
655 
656             if ( luteceUserConnected == null )
657             {
658                 throw new UserNotSignedException(  );
659             }
660 
661             //testAuthorizationAccess
662             testUserAuthorizationAccess( digg, request, luteceUserConnected );
663         }
664 
665         String strIdCategory = request.getParameter( PARAMETER_ID_CATEGORY_DIGG );
666         String strIdType = request.getParameter( PARAMETER_ID_TYPE_DIGG );
667         String strMessage = MESSAGE_NEW_DIGG_SUBMIT;
668         int nIdCategory = DiggUtils.getIntegerParameter( strIdCategory );
669         int nIdType = DiggUtils.getIntegerParameter( strIdType );
670         String strTermsOfUse = request.getParameter( PARAMETER_TERMS_OF_USE );
671 
672         //Check if  terms of used is selected 
673         if ( digg.isEnableTermsOfUse(  ) && ( strTermsOfUse == null ) )
674         {
675             SiteMessageService.setMessage( request, MESSAGE_ERROR_MUST_SELECTED_TERMS_OF_USE, SiteMessage.TYPE_STOP );
676         }
677 
678         //Check if a category is selected (in the case or the digg has some categories)
679         if ( !digg.getCategories(  ).isEmpty(  ) )
680         {
681             if ( ( strIdCategory == null ) || strIdCategory.equals( Integer.toString( DiggUtils.CONSTANT_ID_NULL ) ) )
682             {
683                 SiteMessageService.setMessage( request, MESSAGE_ERROR_NO_CATEGORY, SiteMessage.TYPE_STOP );
684             }
685         }
686 
687         //Check if a type is selected (in the case or the digg has some type)
688         if ( !digg.getDiggSubmitTypes(  ).isEmpty(  ) )
689         {
690             if ( ( strIdType == null ) || strIdType.equals( Integer.toString( DiggUtils.CONSTANT_ID_NULL ) ) )
691             {
692                 SiteMessageService.setMessage( request, MESSAGE_ERROR_NO_DIGG_SUBMIT_TYPE_SELECTED,
693                     SiteMessage.TYPE_STOP );
694             }
695         }
696 
697         DiggSubmit diggSubmit = doInsertDiggSubmit( request, nMode, _plugin, digg, nIdCategory, nIdType,
698                 luteceUserConnected );
699 
700         if ( digg.isDisableNewDiggSubmit(  ) )
701         {
702             strMessage = MESSAGE_NEW_DIGG_SUBMIT_DISABLE;
703         }
704 
705         if ( digg.isEnableMailNewDiggSubmit(  ) && ( digg.getIdMailingListDiggSubmit(  ) != DiggUtils.CONSTANT_ID_NULL ) )
706         {
707             DiggUtils.sendNotificationNewDiggSubmit( digg, diggSubmit, request.getLocale(  ), request );
708         }
709 
710         Map<String, Object> parameters = new HashMap<String, Object>(  );
711         parameters.put( PARAMETER_ID_DIGG, nIdDigg );
712         parameters.put( PARAMETER_ACTION, CONSTANT_VIEW_LIST_DIGG_SUBMIT );
713 
714         if ( !StringUtils.isEmpty( digg.getConfirmationMessage(  ) ) )
715         {
716             Object[] args = { ( digg.getConfirmationMessage(  ) == null ) ? "" : digg.getConfirmationMessage(  ) };
717             SiteMessageService.setMessage( request, strMessage, args, null, getNewUrlItemPage(  ).getUrl(  ), null,
718                 SiteMessage.TYPE_INFO, parameters );
719         }
720     }
721 
722     /**
723      * Do subscribe to a digg or a digg submit. If the parameter
724      * {@link #PARAMETER_ID_SUBMIT_DIGG} has a value, then subscribe to the digg
725      * submit, otherwise subscribe to the digg
726      * @param request The request
727      * @throws SiteMessageException If the digg or the digg submit does not
728      *             exist
729      */
730     public void doSubscribeDigg( HttpServletRequest request )
731         throws SiteMessageException
732     {
733         LuteceUser luteceUserConnected = SecurityService.getInstance(  ).getRegisteredUser( request );
734         String strIdSubmitDigg = request.getParameter( PARAMETER_ID_SUBMIT_DIGG );
735 
736         UrlItem urlItem = new UrlItem( request.getRequestURL(  ).toString(  ) );
737         urlItem.addParameter( PARAMETER_PAGE, CONSTANT_DIGG );
738         urlItem.addParameter( PARAMETER_ID_DIGG, request.getParameter( PARAMETER_ID_DIGG ) );
739 
740         if ( StringUtils.isNotEmpty( strIdSubmitDigg ) )
741         {
742             int nIdSubmitDigg = DiggUtils.getIntegerParameter( strIdSubmitDigg );
743             DiggSubmit diggSubmit = _diggSubmitService.findByPrimaryKey( nIdSubmitDigg, true, _plugin );
744 
745             if ( diggSubmit == null )
746             {
747                 SiteMessageService.setMessage( request, MESSAGE_ERROR, SiteMessage.TYPE_STOP );
748 
749                 return;
750             }
751 
752             DigglikeSubscriptionProviderService.getService(  )
753                                                .createDiggSubmitSubscription( luteceUserConnected, nIdSubmitDigg );
754 
755             urlItem.addParameter( PARAMETER_ID_SUBMIT_DIGG, strIdSubmitDigg );
756             urlItem.addParameter( PARAMETER_ACTION, ACTION_VIEW_DIGG_SUBMIT );
757         }
758         else
759         {
760             String strIdFilterCategory = request.getParameter( PARAMETER_ID_FILTER_CATEGORY_DIGG );
761             int nIdCategory = -1;
762 
763             if ( StringUtils.isNotEmpty( strIdFilterCategory ) && StringUtils.isNumeric( strIdFilterCategory ) )
764             {
765                 nIdCategory = Integer.parseInt( strIdFilterCategory );
766             }
767 
768             if ( nIdCategory > 0 )
769             {
770                 if ( CategoryHome.findByPrimaryKey( nIdCategory, _plugin ) == null )
771                 {
772                     SiteMessageService.setMessage( request, MESSAGE_ERROR, SiteMessage.TYPE_STOP );
773 
774                     return;
775                 }
776 
777                 DigglikeSubscriptionProviderService.getService(  )
778                                                    .createDiggCategorySubscription( luteceUserConnected, nIdCategory );
779                 urlItem.addParameter( PARAMETER_ID_FILTER_CATEGORY_DIGG, strIdFilterCategory );
780             }
781             else
782             {
783                 String strIdDigg = request.getParameter( PARAMETER_ID_DIGG );
784                 int nIdDigg = DiggUtils.getIntegerParameter( strIdDigg );
785 
786                 if ( DiggHome.findByPrimaryKey( nIdDigg, _plugin ) == null )
787                 {
788                     SiteMessageService.setMessage( request, MESSAGE_ERROR, SiteMessage.TYPE_STOP );
789 
790                     return;
791                 }
792 
793                 DigglikeSubscriptionProviderService.getService(  ).createDiggSubscription( luteceUserConnected, nIdDigg );
794             }
795 
796             urlItem.addParameter( PARAMETER_ACTION, ACTION_VIEW_DIGG_SUBMIT_LIST );
797         }
798 
799         try
800         {
801             LocalVariables.getResponse(  ).sendRedirect( urlItem.getUrl(  ) );
802         }
803         catch ( IOException e )
804         {
805             AppLogService.error( e.getMessage(  ), e );
806             SiteMessageService.setMessage( request, MESSAGE_ERROR, SiteMessage.TYPE_STOP );
807         }
808     }
809 
810     /**
811      * Do unsubscribe to a digg or a digg submit. If the parameter
812      * {@link #PARAMETER_ID_SUBMIT_DIGG} has a value, then unsubscribe to the
813      * digg submit, otherwise unsubscribe to the digg
814      * @param request The request
815      * @throws SiteMessageException If the digg or the digg submit does not
816      *             exist
817      */
818     public void doUnsubscribeDigg( HttpServletRequest request )
819         throws SiteMessageException
820     {
821         LuteceUser luteceUserConnected = SecurityService.getInstance(  ).getRegisteredUser( request );
822         String strIdSubmitDigg = request.getParameter( PARAMETER_ID_SUBMIT_DIGG );
823 
824         UrlItem urlItem = new UrlItem( request.getRequestURL(  ).toString(  ) );
825         urlItem.addParameter( PARAMETER_PAGE, CONSTANT_DIGG );
826         urlItem.addParameter( PARAMETER_ID_DIGG, request.getParameter( PARAMETER_ID_DIGG ) );
827 
828         if ( StringUtils.isNotEmpty( strIdSubmitDigg ) )
829         {
830             int nIdSubmitDigg = DiggUtils.getIntegerParameter( strIdSubmitDigg );
831             DiggSubmit diggSubmit = _diggSubmitService.findByPrimaryKey( nIdSubmitDigg, true, _plugin );
832 
833             if ( diggSubmit == null )
834             {
835                 SiteMessageService.setMessage( request, MESSAGE_ERROR, SiteMessage.TYPE_STOP );
836 
837                 return;
838             }
839 
840             DigglikeSubscriptionProviderService.getService(  )
841                                                .removeDiggSubmitSubscription( luteceUserConnected, nIdSubmitDigg );
842 
843             urlItem.addParameter( PARAMETER_ID_SUBMIT_DIGG, strIdSubmitDigg );
844             urlItem.addParameter( PARAMETER_ACTION, ACTION_VIEW_DIGG_SUBMIT );
845         }
846         else
847         {
848             String strIdFilterCategory = request.getParameter( PARAMETER_ID_FILTER_CATEGORY_DIGG );
849             int nIdCategory = -1;
850 
851             if ( StringUtils.isNotEmpty( strIdFilterCategory ) && StringUtils.isNumeric( strIdFilterCategory ) )
852             {
853                 nIdCategory = Integer.parseInt( strIdFilterCategory );
854             }
855 
856             if ( nIdCategory > 0 )
857             {
858                 if ( CategoryHome.findByPrimaryKey( nIdCategory, _plugin ) == null )
859                 {
860                     SiteMessageService.setMessage( request, MESSAGE_ERROR, SiteMessage.TYPE_STOP );
861 
862                     return;
863                 }
864 
865                 DigglikeSubscriptionProviderService.getService(  )
866                                                    .createDiggCategorySubscription( luteceUserConnected, nIdCategory );
867                 urlItem.addParameter( PARAMETER_ID_FILTER_CATEGORY_DIGG, strIdFilterCategory );
868             }
869             else
870             {
871                 String strIdDigg = request.getParameter( PARAMETER_ID_DIGG );
872                 int nIdDigg = DiggUtils.getIntegerParameter( strIdDigg );
873                 Digg digg = DiggHome.findByPrimaryKey( nIdDigg, _plugin );
874 
875                 if ( digg == null )
876                 {
877                     SiteMessageService.setMessage( request, MESSAGE_ERROR, SiteMessage.TYPE_STOP );
878 
879                     return;
880                 }
881 
882                 DigglikeSubscriptionProviderService.getService(  ).removeDiggSubscription( luteceUserConnected, nIdDigg );
883             }
884 
885             urlItem.addParameter( PARAMETER_ACTION, ACTION_VIEW_DIGG_SUBMIT_LIST );
886         }
887 
888         try
889         {
890             LocalVariables.getResponse(  ).sendRedirect( urlItem.getUrl(  ) );
891         }
892         catch ( IOException e )
893         {
894             AppLogService.error( e.getMessage(  ), e );
895             SiteMessageService.setMessage( request, MESSAGE_ERROR, SiteMessage.TYPE_STOP );
896         }
897     }
898 
899     /**
900      * Perform Action create Comment
901      * @param request the {@link HttpServletRequest}
902      * @param nMode the mode
903      * @param page {@link XPage}
904      * @throws UserNotSignedException {@link UserNotSignedException}
905      * @throws SiteMessageException {@link SiteMessageException}
906      */
907     public void doCreateComment( XPage page, int nMode, HttpServletRequest request )
908         throws UserNotSignedException, SiteMessageException
909     {
910         String strIdSubmitDigg = request.getParameter( PARAMETER_ID_SUBMIT_DIGG );
911         int nIdSubmitDigg = DiggUtils.getIntegerParameter( strIdSubmitDigg );
912         DiggSubmit diggSubmit = _diggSubmitService.findByPrimaryKey( nIdSubmitDigg, true, _plugin );
913         Digg digg = null;
914 
915         if ( diggSubmit != null )
916         {
917             digg = DiggHome.findByPrimaryKey( diggSubmit.getDigg(  ).getIdDigg(  ), _plugin );
918             diggSubmit.setDigg( digg );
919         }
920 
921         LuteceUser luteceUserConnected = null;
922 
923         if ( ( digg == null ) || ( diggSubmit == null ) || !digg.isAuthorizedComment(  ) ||
924                 diggSubmit.isDisableComment(  ) )
925         {
926             SiteMessageService.setMessage( request, MESSAGE_ERROR, SiteMessage.TYPE_STOP );
927 
928             return;
929         }
930 
931         if ( digg.isActiveCommentAuthentification(  ) && SecurityService.isAuthenticationEnable(  ) )
932         {
933             luteceUserConnected = SecurityService.getInstance(  ).getRemoteUser( request );
934 
935             if ( luteceUserConnected == null )
936             {
937                 throw new UserNotSignedException(  );
938             }
939 
940             //testAuthorizationAccess
941             testUserAuthorizationAccess( digg, request, luteceUserConnected );
942         }
943 
944         String strCommentValueDigg = request.getParameter( PARAMETER_COMMENT_VALUE_DIGG );
945         String strMessage = MESSAGE_NEW_COMMENT_SUBMIT;
946         String strIdParentComment = request.getParameter( PARAMETER_COMMENT_ID_PARENT );
947         int nIdParentComment = SubmitFilter.ID_PARENT_NULL;
948 
949         if ( ( strIdParentComment != null ) && ( !strIdParentComment.trim(  ).equals( EMPTY_STRING ) ) )
950         {
951             nIdParentComment = DiggUtils.getIntegerParameter( strIdParentComment );
952         }
953 
954         if ( ( strCommentValueDigg == null ) || strCommentValueDigg.trim(  ).equals( EMPTY_STRING ) )
955         {
956             SiteMessageService.setMessage( request, MESSAGE_MANDATORY_COMMENT, SiteMessage.TYPE_STOP );
957         }
958 
959         if ( digg.isActiveCaptcha(  ) && PluginService.isPluginEnable( JCAPTCHA_PLUGIN ) )
960         {
961             CaptchaSecurityService captchaSecurityService = new CaptchaSecurityService(  );
962 
963             if ( !captchaSecurityService.validate( request ) )
964             {
965                 SiteMessageService.setMessage( request, MESSAGE_CAPTCHA_ERROR, SiteMessage.TYPE_STOP );
966             }
967         }
968 
969         CommentSubmit commentSubmit = doInsertComment( request, diggSubmit, strCommentValueDigg, _plugin,
970                 luteceUserConnected, nIdParentComment );
971 
972         if ( digg.isEnableMailNewCommentSubmit(  ) &&
973                 ( digg.getIdMailingListDiggSubmit(  ) != DiggUtils.CONSTANT_ID_NULL ) )
974         {
975             DiggUtils.sendNotificationNewCommentSubmit( digg, commentSubmit, request.getLocale(  ), request );
976             strMessage = MESSAGE_NEW_COMMENT_SUBMIT_DISABLE;
977         }
978 
979         if ( !StringUtils.isEmpty( digg.getConfirmationMessage(  ) ) )
980         {
981             Map<String, Object> parameters = new HashMap<String, Object>(  );
982 
983             parameters.put( PARAMETER_ID_SUBMIT_DIGG, nIdSubmitDigg );
984             parameters.put( PARAMETER_ID_DIGG, digg.getIdDigg(  ) );
985             parameters.put( PARAMETER_COMMENT_DIGG, CONSTANTE_PARAMETER_TRUE_VALUE );
986             parameters.put( PARAMETER_ACTION, CONSTANT_VIEW_DIGG_SUBMIT );
987 
988             Object[] args = { ( digg.getConfirmationMessage(  ) == null ) ? "" : digg.getConfirmationMessage(  ) };
989             SiteMessageService.setMessage( request, strMessage, args, null, getNewUrlItemPage(  ).getUrl(  ), null,
990                 SiteMessage.TYPE_INFO, parameters );
991         }
992     }
993 
994     /**
995      *
996      * Perform Action Report
997      * @param request the {@link HttpServletRequest}
998      * @param nMode the mode
999      * @param page {@link XPage}
1000      * @throws UserNotSignedException {@link UserNotSignedException}
1001      * @throws SiteMessageException {@link SiteMessageException}
1002      */
1003     public void doReport( XPage page, int nMode, HttpServletRequest request )
1004         throws UserNotSignedException, SiteMessageException
1005     {
1006         String strIdSubmitDigg = request.getParameter( PARAMETER_ID_SUBMIT_DIGG );
1007         int nIdSubmitDigg = DiggUtils.getIntegerParameter( strIdSubmitDigg );
1008 
1009         DiggSubmit diggSubmit = _diggSubmitService.findByPrimaryKey( nIdSubmitDigg, true, _plugin );
1010         Digg digg = null;
1011 
1012         if ( diggSubmit != null )
1013         {
1014             digg = DiggHome.findByPrimaryKey( diggSubmit.getDigg(  ).getIdDigg(  ), _plugin );
1015             diggSubmit.setDigg( digg );
1016         }
1017 
1018         String strReportedValue = request.getParameter( PARAMETER_REPORTED_VALUE );
1019 
1020         if ( ( strReportedValue == null ) || strReportedValue.trim(  ).equals( EMPTY_STRING ) )
1021         {
1022             SiteMessageService.setMessage( request, MESSAGE_MANDATORY_REPORTED, SiteMessage.TYPE_STOP );
1023         }
1024 
1025         if ( ( diggSubmit == null ) || ( digg == null ) || !digg.isEnableReports(  ) )
1026         {
1027             SiteMessageService.setMessage( request, MESSAGE_ERROR, SiteMessage.TYPE_STOP );
1028 
1029             return;
1030         }
1031 
1032         LuteceUser luteceUserConnected = null;
1033 
1034         if ( digg.isActiveCommentAuthentification(  ) && SecurityService.isAuthenticationEnable(  ) )
1035         {
1036             luteceUserConnected = SecurityService.getInstance(  ).getRemoteUser( request );
1037 
1038             if ( luteceUserConnected == null )
1039             {
1040                 throw new UserNotSignedException(  );
1041             }
1042 
1043             //testAuthorizationAccess
1044             testUserAuthorizationAccess( digg, request, luteceUserConnected );
1045         }
1046 
1047         DiggUtils.doReportDiggSubmit( diggSubmit, _plugin );
1048 
1049         ReportedMessage reportedMessage = new ReportedMessage(  );
1050         reportedMessage.setDiggSubmit( diggSubmit );
1051         reportedMessage.setValue( strReportedValue );
1052 
1053         ReportedMessageHome.create( reportedMessage, _plugin );
1054 
1055         if ( digg.isEnableMailNewReportedSubmit(  ) &&
1056                 ( digg.getIdMailingListDiggSubmit(  ) != DiggUtils.CONSTANT_ID_NULL ) )
1057         {
1058             DiggUtils.sendNotificationNewReportedMessage( digg, reportedMessage, request.getLocale(  ), request );
1059         }
1060 
1061         Map<String, Object> parameters = new HashMap<String, Object>(  );
1062         parameters.put( PARAMETER_ID_SUBMIT_DIGG, nIdSubmitDigg );
1063         parameters.put( PARAMETER_ID_DIGG, digg.getIdDigg(  ) );
1064         parameters.put( PARAMETER_ACTION, CONSTANT_VIEW_DIGG_SUBMIT );
1065 
1066         UrlItem urlItemPage = getNewUrlItemPage(  );
1067         urlItemPage.setAnchor( ANCHOR_DIGG_SUBMIT + nIdSubmitDigg );
1068 
1069         SiteMessageService.setMessage( request, MESSAGE_NEW_REPORTED_SUBMIT, null, null, urlItemPage.getUrl(  ), null,
1070             SiteMessage.TYPE_INFO, parameters );
1071     }
1072 
1073     /**
1074      * Perform Action Vote
1075      * @param request the {@link HttpServletRequest}
1076      * @param nMode the mode
1077      * @param page {@link XPage}
1078      * @throws UserNotSignedException {@link UserNotSignedException}
1079      * @throws SiteMessageException {@link SiteMessageException}
1080      */
1081     public void doVote( XPage page, int nMode, HttpServletRequest request )
1082         throws UserNotSignedException, SiteMessageException
1083     {
1084         String strVote = request.getParameter( PARAMETER_VOTE_DIGG );
1085         String strIdSubmitDigg = request.getParameter( PARAMETER_ID_SUBMIT_DIGG );
1086         int nIdSubmitDigg = DiggUtils.getIntegerParameter( strIdSubmitDigg );
1087         DiggSubmit diggSubmit = _diggSubmitService.findByPrimaryKey( nIdSubmitDigg, true, _plugin );
1088         Digg digg = DiggHome.findByPrimaryKey( diggSubmit.getDigg(  ).getIdDigg(  ), _plugin );
1089         diggSubmit.setDigg( digg );
1090 
1091         LuteceUser luteceUserConnected = null;
1092 
1093         if ( digg.isLimitNumberVote(  ) )
1094         {
1095             if ( digg.isActiveVoteAuthentification(  ) && SecurityService.isAuthenticationEnable(  ) )
1096             {
1097                 luteceUserConnected = SecurityService.getInstance(  ).getRemoteUser( request );
1098 
1099                 if ( luteceUserConnected == null )
1100                 {
1101                     throw new UserNotSignedException(  );
1102                 }
1103                 else if ( ( digg.getRole(  ) != null ) &&
1104                         !SecurityService.getInstance(  ).isUserInRole( request, digg.getRole(  ) ) )
1105                 {
1106                     SiteMessageService.setMessage( request, MESSAGE_ACCESS_DENIED, SiteMessage.TYPE_STOP );
1107                 }
1108 
1109                 if ( VoteHome.getUserNumberVoteOnDiggSubmit( nIdSubmitDigg, luteceUserConnected.getName(  ), _plugin ) == 0 )
1110                 {
1111                     doVote( strVote, nIdSubmitDigg, _plugin, luteceUserConnected.getName(  ) );
1112                 }
1113             }
1114             else if ( request.getSession(  ).getAttribute( EMPTY_STRING + nIdSubmitDigg ) == null )
1115             {
1116                 doVote( strVote, nIdSubmitDigg, _plugin, null );
1117                 request.getSession(  ).setAttribute( EMPTY_STRING + nIdSubmitDigg, PARAMETER_VOTED );
1118             }
1119         }
1120         else
1121         {
1122             doVote( strVote, nIdSubmitDigg, _plugin, null );
1123         }
1124     }
1125 
1126     /**
1127      * Increment score
1128      *
1129      * @param strVote
1130      *            the value to add at score
1131      * @param nIdSubmitDigg
1132      *            the id of the digg submit
1133      * @param plugin
1134      *            the plugin
1135      * @param strUserKey
1136      *            the user key
1137      */
1138     private void doVote( String strVote, int nIdSubmitDigg, Plugin plugin, String strUserKey )
1139     {
1140         // Increment vote
1141         int nScore;
1142 
1143         if ( ( strVote != null ) && strVote.equals( "-2" ) )
1144         {
1145             nScore = Integer.parseInt( strVote );
1146             DiggUtils.doVoteDiggSubmit( nIdSubmitDigg, nScore, strUserKey, plugin );
1147         }
1148         else if ( ( strVote != null ) && strVote.equals( "-1" ) )
1149         {
1150             nScore = Integer.parseInt( strVote );
1151             DiggUtils.doVoteDiggSubmit( nIdSubmitDigg, nScore, strUserKey, plugin );
1152         }
1153         else if ( ( strVote != null ) && strVote.equals( "1" ) )
1154         {
1155             nScore = Integer.parseInt( strVote );
1156             DiggUtils.doVoteDiggSubmit( nIdSubmitDigg, nScore, strUserKey, plugin );
1157         }
1158         else if ( ( strVote != null ) && strVote.equals( "2" ) )
1159         {
1160             nScore = Integer.parseInt( strVote );
1161             DiggUtils.doVoteDiggSubmit( nIdSubmitDigg, nScore, strUserKey, plugin );
1162         }
1163     }
1164 
1165     /**
1166      * return the html list of digg submit
1167      * @param locale the locale
1168      * @param plugin the plugin
1169      * @param digg the digg
1170      * @param searchFields the searchFields
1171      * @param urlDiggXPage the url of the Xpage
1172      * @param luteceUserConnected the lutece UserConnected
1173      * @return the html list of digg submit
1174      * @throws SiteMessageException SiteMessageException
1175      *             {@link SiteMessageException}
1176      */
1177     private String getHtmlListDiggSubmit( Locale locale, Plugin plugin, Digg digg, SearchFields searchFields,
1178         UrlItem urlDiggXPage, LuteceUser luteceUserConnected )
1179         throws SiteMessageException
1180     {
1181         Map<String, Object> model = new HashMap<String, Object>(  );
1182 
1183         List<Integer> listIdDiggSubmit;
1184 
1185         SubmitFilter submitFilter = new SubmitFilter(  );
1186 
1187         // Filter the list
1188         DiggUtils.initSubmitFilterByPeriod( submitFilter, searchFields.getIdFilterPeriod(  ) );
1189         DiggUtils.initSubmitFilterBySort( submitFilter,
1190             ( searchFields.getIdDiggSubmitSort(  ) != DiggUtils.CONSTANT_ID_NULL )
1191             ? searchFields.getIdDiggSubmitSort(  ) : digg.getIdDefaultSort(  ) );
1192         //add sort by pinned first
1193         DiggUtils.initSubmitFilterBySort( submitFilter, SubmitFilter.SORT_BY_PINNED_FIRST );
1194 
1195         submitFilter.setIdDigg( digg.getIdDigg(  ) );
1196 
1197         submitFilter.setIdDiggSubmitState( _nIdDiggSubmitStatePublish );
1198         submitFilter.setIdCategory( searchFields.getIdFilterCategory(  ) );
1199         submitFilter.setIdType( searchFields.getIdFilterDiggSubmitType(  ) );
1200         submitFilter.setLuteceUserKey(searchFields.getLuteceUserName());
1201         
1202         listIdDiggSubmit = DigglikeSearchService.getInstance(  )
1203                                                 .getSearchResults( searchFields.getQuery(  ), submitFilter, plugin );
1204 
1205         if ( digg.isActiveDiggSubmitPaginator(  ) && ( digg.getNumberDiggSubmitPerPage(  ) > 0 ) )
1206         {
1207             Paginator<Integer> paginator = new Paginator<Integer>( listIdDiggSubmit,
1208                     digg.getNumberDiggSubmitPerPage(  ), urlDiggXPage.getUrl(  ), PARAMETER_FILTER_PAGE_INDEX,
1209                     searchFields.getPageIndex(  ) );
1210             listIdDiggSubmit = paginator.getPageItems(  );
1211             model.put( MARK_PAGINATOR, paginator );
1212         }
1213 
1214         model.put( MARK_DIGG, digg );
1215         model.put( MARK_LIST_DIGG_SUBMIT, getDiggSubmitDisplayList( listIdDiggSubmit, digg, locale, plugin ) );
1216 
1217         model.put( MARK_AUTHORIZED_COMMENT, digg.isAuthorizedComment(  ) );
1218         model.put( MARK_AUTHORIZED_VOTE, !digg.isDisableVote(  ) );
1219         model.put( MARK_DISPLAY_COMMENT_IN_LIST, digg.isDisplayCommentInDiggSubmitList(  ) );
1220         model.put( MARK_ENABLE_DIGG_REPORTS, digg.isEnableReports(  ) );
1221         model.put( MARK_ID_DIGG, digg.getIdDigg(  ) );
1222 
1223         if ( digg.isAuthorizedComment(  ) )
1224         {
1225             model.put( MARK_MAX_AMOUNT_COMMENTS, digg.getNumberCommentDisplayInDiggSubmitList(  ) );
1226             model.put( MARK_MAX_AMOUNT_COMMENTS_CHAR, digg.getNumberCharCommentDisplayInDiggSubmitList(  ) );
1227         }
1228 
1229         model.put( MARK_LUTECE_USER_CONNECTED, luteceUserConnected );
1230         model.put( MARK_IS_EXTEND_INSTALLED, PortalService.isExtendActivated(  ) );
1231 
1232         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_XPAGE_LIST_SUBMIT_DIGG, locale, model );
1233 
1234         return template.getHtml(  );
1235     }
1236 
1237     /**
1238      * return the html list of digg
1239      *
1240      * @param locale
1241      *            the locale
1242      * @param plugin
1243      *            the plugin
1244      * @param strCurrentPageIndexDigg
1245      *            the current page index
1246      * @param nItemsPerPageDigg
1247      *            the number of items per page
1248      * @param urlDiggXPage
1249      *            the url of the digg xpage
1250      * @param luteceUserConnected
1251      *            luteceUser
1252      * @throws SiteMessageException
1253      *             SiteMessageException
1254      * @return the html list of digg
1255      */
1256     private String getHtmlListDigg( Locale locale, Plugin plugin, String strCurrentPageIndexDigg,
1257         int nItemsPerPageDigg, UrlItem urlDiggXPage, LuteceUser luteceUserConnected )
1258         throws SiteMessageException
1259     {
1260         DiggFilter filter = new DiggFilter(  );
1261         filter.setIdState( Digg.STATE_ENABLE );
1262 
1263         List<Digg> listDigg = DiggHome.getDiggList( filter, plugin );
1264         HashMap<String, Object> model = new HashMap<String, Object>(  );
1265         Paginator<Digg> paginator = new Paginator<Digg>( listDigg, nItemsPerPageDigg, urlDiggXPage.getUrl(  ),
1266                 PARAMETER_PAGE_INDEX, strCurrentPageIndexDigg );
1267 
1268         model.put( MARK_PAGINATOR, paginator );
1269         model.put( MARK_NB_ITEMS_PER_PAGE, EMPTY_STRING + nItemsPerPageDigg );
1270 
1271         model.put( MARK_DIGG_LIST, paginator.getPageItems(  ) );
1272         model.put( MARK_LUTECE_USER_CONNECTED, luteceUserConnected );
1273 
1274         HtmlTemplate templateList = AppTemplateService.getTemplate( TEMPLATE_XPAGE_LIST_DIGG, locale, model );
1275 
1276         return templateList.getHtml(  );
1277     }
1278 
1279     /**
1280      * return a collection which contains digg submit and lutece user associate
1281      *
1282      * @param listDiggSubmit
1283      *            the list of digg submit
1284      * @param digg
1285      *            the digg possessing submits
1286      * @param strDiggDetail
1287      *            the digg detail
1288      * @param locale
1289      *            the locale
1290      * @throws SiteMessageException
1291      *             SiteMessageException
1292      * @return a collection which contains digg submit and lutece user associate
1293      */
1294     private Collection<HashMap> getDiggSubmitDisplayList( Collection<Integer> listDiggSubmit, Digg digg, Locale locale,
1295         Plugin plugin ) throws SiteMessageException
1296     {
1297         DiggUserInfo luteceUserInfo;
1298         DiggSubmit diggSubmit;
1299         Collection<HashMap> listHashDigg = new ArrayList<HashMap>(  );
1300 
1301         for ( Integer idDiggSubmit : listDiggSubmit )
1302         {
1303             HashMap<String, Object> modelDigg = new HashMap<String, Object>(  );
1304 
1305             luteceUserInfo = null;
1306             diggSubmit = _diggSubmitService.findByPrimaryKey( idDiggSubmit,
1307                     ( digg.isAuthorizedComment(  ) && digg.isDisplayCommentInDiggSubmitList(  ) ),
1308                     digg.getNumberCommentDisplayInDiggSubmitList(  ), plugin );
1309             modelDigg.put( MARK_DIGG_SUBMIT, diggSubmit );
1310 
1311             if ( SecurityService.isAuthenticationEnable(  ) && ( diggSubmit.getLuteceUserKey(  ) != null ) )
1312             {
1313                 luteceUserInfo = DiggUserInfoService.getService(  )
1314                                                     .findDiggUserInfoByKey( diggSubmit.getLuteceUserKey(  ), plugin );
1315             }
1316 
1317             modelDigg.put( MARK_LUTECE_USER, luteceUserInfo );
1318             DiggUtils.addAvatarToModel(modelDigg, luteceUserInfo);
1319             
1320             
1321             if ( !digg.isDisableVote(  ) )
1322             {
1323                 modelDigg.put( MARK_DIGG_SUBMIT_VOTE_TYPE,
1324                     getHtmlDiggSubmitVoteType( digg, diggSubmit, CONSTANT_VIEW_LIST_DIGG_SUBMIT, locale ) );
1325             }
1326 
1327             listHashDigg.add( modelDigg );
1328         }
1329 
1330         return listHashDigg;
1331     }
1332 
1333     /**
1334      * return a collection which contains comment and lutece user associate
1335      *
1336      * @param listCommentSubmit
1337      *            the list of comment submit
1338      * @return a collection which contains comment and lutece user associate
1339      */
1340     private Collection<HashMap> getCommentSubmitDisplayList( Collection<CommentSubmit> listCommentSubmit, Plugin plugin )
1341     {
1342         Collection<HashMap> listHashComment = new ArrayList<HashMap>(  );
1343         DiggUserInfo luteceUserInfo;
1344 
1345         for ( CommentSubmit commentSubmit : listCommentSubmit )
1346         {
1347             HashMap<String, Object> modelComment = new HashMap<String, Object>(  );
1348 
1349             luteceUserInfo = null;
1350 
1351             modelComment.put( MARK_COMMENT_SUBMIT, commentSubmit );
1352 
1353             if ( SecurityService.isAuthenticationEnable(  ) && ( commentSubmit.getLuteceUserKey(  ) != null ) )
1354             {
1355                 luteceUserInfo = DiggUserInfoService.getService(  )
1356                                                     .findDiggUserInfoByKey( commentSubmit.getLuteceUserKey(  ), plugin );
1357             }
1358 
1359             modelComment.put( MARK_LUTECE_USER, luteceUserInfo );
1360             DiggUtils.addAvatarToModel(modelComment, luteceUserInfo);
1361             
1362             
1363             modelComment.put( MARK_LIST_SUB_COMMENT_SUBMIT_DIGG,
1364                 ( ( commentSubmit.getComments(  ) != null ) && !commentSubmit.getComments(  ).isEmpty(  ) )
1365                 ? getCommentSubmitDisplayList( commentSubmit.getComments(  ), plugin ) : null );
1366 
1367             listHashComment.add( modelComment );
1368         }
1369 
1370         return listHashComment;
1371     }
1372 
1373     /**
1374      * the html digg submit detail
1375      *
1376      * @param request
1377      *            the request
1378      * @param nMode
1379      *            The current mode.
1380      * @param plugin
1381      *            the plugin
1382      * @param diggSubmit
1383      *            the {@link DiggSubmit}
1384      *
1385      *
1386      * @param luteceUserConnected
1387      *            the lutece user
1388      * @return the html digg submit detail
1389      * @throws SiteMessageException
1390      *             SiteMessageException
1391      */
1392     private String getHtmlDiggSubmitDetail( HttpServletRequest request, int nMode, Plugin plugin,
1393         DiggSubmit diggSubmit, LuteceUser luteceUserConnected )
1394         throws SiteMessageException
1395     {
1396         DiggUserInfo luteceUserInfo = null;
1397         HashMap<String, Object> model = new HashMap<String, Object>(  );
1398 
1399         if ( ( diggSubmit == null ) || ( diggSubmit.getDiggSubmitState(  ).getNumber(  ) == DiggSubmit.STATE_DISABLE ) )
1400         {
1401             SiteMessageService.setMessage( request, MESSAGE_ERROR, SiteMessage.TYPE_STOP );
1402 
1403             return null;
1404         }
1405 
1406         // update number view
1407         diggSubmit.setNumberView( diggSubmit.getNumberView(  ) + 1 );
1408         _diggSubmitService.update( diggSubmit, false, plugin );
1409 
1410         if ( SecurityService.isAuthenticationEnable(  ) && ( diggSubmit.getLuteceUserKey(  ) != null ) )
1411         {
1412             luteceUserInfo = DiggUserInfoService.getService(  )
1413                                                 .findDiggUserInfoByKey( diggSubmit.getLuteceUserKey(  ), plugin );
1414         }
1415 
1416         if ( luteceUserConnected != null )
1417         {
1418             model.put( MARK_USER_SUBSCRIBED,
1419                 DigglikeSubscriptionProviderService.getService(  )
1420                                                    .hasUserSubscribedToDiggSubmit( luteceUserConnected,
1421                     diggSubmit.getIdDiggSubmit(  ) ) );
1422         }
1423         
1424 
1425         model.put( MARK_ID_DIGG, diggSubmit.getDigg(  ).getIdDigg(  ) );
1426         model.put( MARK_DIGG_SUBMIT, diggSubmit );
1427         model.put( MARK_LUTECE_USER, luteceUserInfo );
1428         DiggUtils.addAvatarToModel(model, luteceUserInfo);
1429         
1430         model.put( MARK_LUTECE_USER_CONNECTED, luteceUserConnected );
1431         model.put( MARK_DIGG_SUBMIT_VOTE_TYPE,
1432             getHtmlDiggSubmitVoteType( diggSubmit.getDigg(  ), diggSubmit, CONSTANT_VIEW_DIGG_SUBMIT,
1433                 request.getLocale(  ) ) );
1434         
1435        
1436         
1437         
1438         model.put( MARK_AUTHORIZED_COMMENT, diggSubmit.getDigg(  ).isAuthorizedComment(  ) );
1439         model.put( MARK_AUTHORIZED_VOTE, !diggSubmit.getDigg(  ).isDisableVote(  ) );
1440         model.put( MARK_ENABLE_DIGG_REPORTS, diggSubmit.getDigg(  ).isEnableReports(  ) );
1441         model.put( MARK_IS_EXTEND_INSTALLED, PortalService.isExtendActivated(  ) );
1442 
1443         if ( diggSubmit.getDigg(  ).isAuthorizedComment(  ) && !diggSubmit.isDisableComment(  ) )
1444         {
1445             model.put( MARK_LIST_COMMENT_SUBMIT_DIGG,
1446                 getHtmlCommentSubmitList( request, diggSubmit.getComments(  ), diggSubmit.getDigg(  ),
1447                     diggSubmit.getIdDiggSubmit(  ), luteceUserConnected, plugin ) );
1448         }
1449         CaptchaSecurityService captchaSecurityService = new CaptchaSecurityService(  );
1450 
1451         if ( diggSubmit.getDigg(  ).isActiveCaptcha(  ) && PluginService.isPluginEnable( JCAPTCHA_PLUGIN ) )
1452         {
1453             model.put( MARK_JCAPTCHA, captchaSecurityService.getHtmlCode(  ) );
1454         }
1455 
1456 
1457         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_XPAGE_DETAIL_SUBMIT_DIGG,
1458                 request.getLocale(  ), model );
1459 
1460         return template.getHtml(  );
1461     }
1462 
1463     /**
1464      * return the Html type of vote
1465      *
1466      * @param strVoteTypeTemplateName
1467      *            the template use
1468      * @param digg
1469      *            the digg
1470      * @param nIdDiggSubmit
1471      *            the id of the diggSubmit
1472      * @param strView the view which is display the vote type
1473      * @param locale
1474      *            the locale
1475      * @return the Html type of vote
1476      * @throws SiteMessageException
1477      *             SiteMessageException
1478      */
1479     private String getHtmlDiggSubmitVoteType( Digg digg, DiggSubmit diggSubmit, String strView, Locale locale )
1480         throws SiteMessageException
1481     {
1482         if ( !digg.isDisableVote(  ) && !diggSubmit.isDisableVote(  ) )
1483         {
1484             VoteType voteType = VoteTypeHome.findByPrimaryKey( digg.getVoteType(  ).getIdVoteType(  ), _plugin );
1485 
1486             String strFilePath = PATH_TYPE_VOTE_FOLDER + voteType.getTemplateFileName(  );
1487             HashMap<String, Object> model = new HashMap<String, Object>(  );
1488             model.put( MARK_ID_DIGG, digg.getIdDigg(  ) );
1489             model.put( MARK_ID_DIGG_SUBMIT, diggSubmit.getIdDiggSubmit(  ) );
1490             model.put( MARK_VIEW, strView );
1491 
1492             HtmlTemplate template = AppTemplateService.getTemplate( strFilePath, locale, model );
1493 
1494             return template.getHtml(  );
1495         }
1496 
1497         return null;
1498     }
1499 
1500     /**
1501      * return the html form reported
1502      *
1503      * @param request
1504      *            the request
1505      * @param nMode
1506      *            The current mode.
1507      * @param plugin
1508      *            plugin
1509      * @param diggSubmit
1510      *            the diggSubmit
1511      *
1512      * @return the html form reported
1513      * @throws SiteMessageException
1514      *             SiteMessageException
1515      */
1516     private String getHtmlReported( HttpServletRequest request, int nMode, Plugin plugin, DiggSubmit diggSubmit )
1517         throws SiteMessageException
1518     {
1519         HashMap<String, Object> model = new HashMap<String, Object>(  );
1520 
1521         if ( ( diggSubmit == null ) || ( diggSubmit.getDiggSubmitState(  ).getNumber(  ) == DiggSubmit.STATE_DISABLE ) )
1522         {
1523             SiteMessageService.setMessage( request, MESSAGE_ERROR, SiteMessage.TYPE_STOP );
1524 
1525             return null;
1526         }
1527 
1528         model.put( MARK_ID_DIGG, diggSubmit.getDigg(  ).getIdDigg(  ) );
1529         model.put( MARK_DIGG_SUBMIT, diggSubmit );
1530 
1531         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_XPAGE_DIGG_REPORTED, request.getLocale(  ),
1532                 model );
1533 
1534         return template.getHtml(  );
1535     }
1536 
1537     /**
1538      * return the html list of comment submit for a digg submit
1539      *
1540      * @param request
1541      *            the request
1542      * @param listCommentSubmit
1543      *            the list of comment submit
1544      * @param digg
1545      *            the digg
1546      * @param plugin
1547      *            plugin
1548      * @param nIdSubmitDigg
1549      *            the id of the digg submit
1550      * @param luteceUserConnected
1551      *            lutece user connected
1552      * @return the html list of comment submit for a digg submit
1553      */
1554     private String getHtmlCommentSubmitList( HttpServletRequest request, List<CommentSubmit> listCommentSubmit,
1555         Digg digg, int nIdSubmitDigg, LuteceUser luteceUserConnected, Plugin plugin )
1556     {
1557         HashMap<String, Object> model = new HashMap<String, Object>(  );
1558 
1559         model.put( MARK_DIGG, digg );
1560         model.put( MARK_ID_DIGG, digg.getIdDigg(  ) );
1561         model.put( MARK_ID_DIGG_SUBMIT, nIdSubmitDigg );
1562         model.put( MARK_DIGG_COMMENT, CONSTANTE_PARAMETER_TRUE_VALUE );
1563         model.put( MARK_LIST_COMMENT_SUBMIT_DIGG, getCommentSubmitDisplayList( listCommentSubmit, plugin ) );
1564         model.put( MARK_DISABLE_NEW_COMMENT_SUBMIT, digg.isDisableNewComment(  ) );
1565         model.put( MARK_ACTIVE_EDITOR_BBCODE, digg.isActiveEditorBbcode(  ) );
1566         model.put( MARK_LUTECE_USER_CONNECTED, luteceUserConnected );
1567 
1568         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_XPAGE_COMMENT_SUBMIT_DIGG,
1569                 request.getLocale(  ), model );
1570 
1571         return template.getHtml(  );
1572     }
1573 
1574     /**
1575      * Return the html form for creating digg submit
1576      *
1577      * @param request
1578      *            The HTTP request
1579      * @param nMode
1580      *            The current mode.
1581      * @param plugin
1582      *            The Plugin
1583      * @param digg
1584      *            the digg
1585      * @param nIdDefaultCategory the id of the default category
1586      * @return the html form
1587      * @throws SiteMessageException
1588      *             SiteMessageException
1589      */
1590     private String getHtmlForm( HttpServletRequest request, int nMode, Plugin plugin, Digg digg, int nIdDefaultCategory )
1591         throws SiteMessageException
1592     {
1593         Map<String, Object> model = DiggUtils.getModelHtmlForm( digg, plugin, request.getLocale(  ),
1594                 nIdDefaultCategory, false );
1595 
1596         // get form Recap
1597         model.put( MARK_DISABLE_NEW_DIGG_SUBMIT, digg.isDisableNewDiggSubmit(  ) );
1598 
1599         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_XPAGE_FORM_DIGG, request.getLocale(  ), model );
1600 
1601         return template.getHtml(  );
1602     }
1603 
1604     /**
1605      * Return the new digg submit object
1606      *
1607      * @param request
1608      *            The HTTP request
1609      * @param nMode
1610      *            The current mode.
1611      * @param plugin
1612      *            The Plugin
1613      * @param digg
1614      *            the digg
1615      * @param nIdCategory
1616      *            the id of the category
1617      * @param nIdType
1618      *            the id of the type
1619      * @param user
1620      *            the lutece user
1621      * @return the new digg submit object
1622      * @throws SiteMessageException
1623      *             SiteMessageException
1624      */
1625     private DiggSubmit doInsertDiggSubmit( HttpServletRequest request, int nMode, Plugin plugin, Digg digg,
1626         int nIdCategory, int nIdType, LuteceUser user )
1627         throws SiteMessageException
1628     {
1629         Locale locale = request.getLocale(  );
1630         List<Response> listResponse = new ArrayList<Response>(  );
1631 
1632         if ( digg.isActiveCaptcha(  ) && PluginService.isPluginEnable( JCAPTCHA_PLUGIN ) )
1633         {
1634             CaptchaSecurityService captchaSecurityService = new CaptchaSecurityService(  );
1635 
1636             if ( !captchaSecurityService.validate( request ) )
1637             {
1638                 SiteMessageService.setMessage( request, MESSAGE_CAPTCHA_ERROR, SiteMessage.TYPE_STOP );
1639             }
1640         }
1641 
1642         DiggSubmit diggSubmit = new DiggSubmit(  );
1643         diggSubmit.setDigg( digg );
1644         diggSubmit.setResponses( listResponse );
1645 
1646         FormError formError = DiggUtils.getAllResponsesData( request, diggSubmit, plugin, locale );
1647 
1648         if ( formError != null )
1649         {
1650             if ( formError.isMandatoryError(  ) )
1651             {
1652                 Object[] tabRequiredFields = { formError.getTitleQuestion(  ) };
1653                 SiteMessageService.setMessage( request, MESSAGE_MANDATORY_QUESTION, tabRequiredFields,
1654                     SiteMessage.TYPE_STOP );
1655             }
1656             else
1657             {
1658                 Object[] tabFormError = { formError.getTitleQuestion(  ), formError.getErrorMessage(  ) };
1659                 SiteMessageService.setMessage( request, MESSAGE_FORM_ERROR, tabFormError, SiteMessage.TYPE_STOP );
1660             }
1661         }
1662 
1663         // perform digg submit
1664         if ( nIdCategory != DiggUtils.CONSTANT_ID_NULL )
1665         {
1666             Category category = CategoryHome.findByPrimaryKey( nIdCategory, plugin );
1667             diggSubmit.setCategory( category );
1668         }
1669 
1670         if ( nIdType != DiggUtils.CONSTANT_ID_NULL )
1671         {
1672             DiggSubmitType type = DiggSubmitTypeHome.findByPrimaryKey( nIdType, plugin );
1673             diggSubmit.setDiggSubmitType( type );
1674         }
1675 
1676         if ( user != null )
1677         {
1678             diggSubmit.setLuteceUserKey( user.getName(  ) );
1679             //insert DiggSubmitInfi=ormation if not exists
1680             DiggUserInfoService.getService(  ).updateDiggUserInfoByLuteceUser( user, plugin );
1681         }
1682 
1683         try
1684         {
1685             _diggSubmitService.create( diggSubmit, plugin, locale );
1686         }
1687         catch ( Exception ex )
1688         {
1689             // something very wrong happened... a database check might be needed
1690             AppLogService.error( ex.getMessage(  ) + " for DiggSubmit " + diggSubmit.getIdDiggSubmit(  ), ex );
1691             // revert
1692             // we clear the DB form the given formsubmit (FormSubmitHome also
1693             // removes the reponses)
1694             _diggSubmitService.remove( diggSubmit.getIdDiggSubmit(  ), plugin );
1695             // throw a message to the user
1696             SiteMessageService.setMessage( request, MESSAGE_MESSAGE_SUBMIT_SAVE_ERROR, SiteMessage.TYPE_ERROR );
1697         }
1698 
1699         return diggSubmit;
1700     }
1701 
1702     /**
1703      * return the new comment submit create
1704      *
1705      * @param request
1706      *            the http request
1707      * @param diggSubmit
1708      *            the DiggSubmit
1709      *
1710      * @param strCommentValueDigg
1711      *            the comment value
1712      * @param plugin
1713      *            the plugin
1714      * @param nIdParentComment
1715      *            the id of the parent of this comment
1716      * @param user
1717      *            the Lutece user associate to the comment
1718      * @return the new comment submit create
1719      * @throws SiteMessageException
1720      *             SiteMessageException
1721      */
1722     public CommentSubmit doInsertComment( HttpServletRequest request, DiggSubmit diggSubmit,
1723         String strCommentValueDigg, Plugin plugin, LuteceUser user, int nIdParentComment )
1724         throws SiteMessageException
1725     {
1726         CommentSubmit commentSubmit = new CommentSubmit(  );
1727 
1728         if ( ( diggSubmit == null ) || ( diggSubmit.getDiggSubmitState(  ).getNumber(  ) == DiggSubmit.STATE_DISABLE ) )
1729         {
1730             SiteMessageService.setMessage( request, MESSAGE_ERROR, SiteMessage.TYPE_STOP );
1731 
1732             return null;
1733         }
1734 
1735         diggSubmit.setNumberComment( diggSubmit.getNumberComment(  ) + 1 );
1736 
1737         if ( !diggSubmit.getDigg(  ).isDisableNewComment(  ) )
1738         {
1739             commentSubmit.setActive( true );
1740             diggSubmit.setNumberCommentEnable( diggSubmit.getNumberCommentEnable(  ) + 1 );
1741         }
1742 
1743         _diggSubmitService.update( diggSubmit, plugin );
1744 
1745         commentSubmit.setDateComment( DiggUtils.getCurrentDate(  ) );
1746         commentSubmit.setDiggSubmit( diggSubmit );
1747         commentSubmit.setValue( strCommentValueDigg );
1748         commentSubmit.setOfficialAnswer( false );
1749         commentSubmit.setIdParent( nIdParentComment );
1750 
1751         if ( user != null )
1752         {
1753             commentSubmit.setLuteceUserKey( user.getName(  ) );
1754             //insert DiggSubmitInfiormation if not exists
1755             DiggUserInfoService.getService(  ).updateDiggUserInfoByLuteceUser( user, plugin );
1756         }
1757 
1758         _commentSubmitService.create( commentSubmit, plugin );
1759 
1760         return commentSubmit;
1761     }
1762 
1763     /**
1764      * Clear params stores in session
1765      *
1766      * @param session
1767      *            the Http session
1768      */
1769     private void clearSessionFilter( HttpSession session )
1770     {
1771         session.setAttribute( SESSION_SEARCH_FIELDS, null );
1772     }
1773 
1774     /**
1775      *
1776      * method init
1777      * @param request
1778      *            The HTTP request
1779      * @param plugin
1780      *            The plugin
1781      */
1782     public void init( HttpServletRequest request, Plugin plugin )
1783     {
1784         _plugin = plugin;
1785 
1786         if ( _nIdDiggSubmitStatePublish == DiggUtils.CONSTANT_ID_NULL )
1787         {
1788             DiggSubmitState diggSubmitStatePublish = DiggSubmitStateHome.findByNumero( DiggSubmit.STATE_PUBLISH, plugin );
1789 
1790             if ( diggSubmitStatePublish != null )
1791             {
1792                 _nIdDiggSubmitStatePublish = diggSubmitStatePublish.getIdDiggSubmitState(  );
1793             }
1794         }
1795 
1796         String strPortalUrl = AppPathService.getPortalUrl(  );
1797 
1798         if ( _urlDiggXpageHome == null )
1799         {
1800             _urlDiggXpageHome = new UrlItem( strPortalUrl );
1801             _urlDiggXpageHome.addParameter( XPageAppService.PARAM_XPAGE_APP,
1802                 AppPropertiesService.getProperty( PROPERTY_PAGE_APPLICATION_ID ) );
1803         }
1804 
1805         if ( _nNumberShownCharacters == DiggUtils.CONSTANT_ID_NULL )
1806         {
1807             _nNumberShownCharacters = AppPropertiesService.getPropertyInt( PROPERTY_NUMBER_DIGG_SUBMIT_VALUE_SHOWN_CHARACTERS,
1808                     100 );
1809         }
1810     }
1811 
1812     /**
1813      *
1814      * Return the searcheField contains in the request or store in session
1815      * @param request {@link HttpServletRequest}
1816      * @return the SearchField
1817      */
1818     private SearchFields getSearchFields( HttpServletRequest request )
1819     {
1820         HttpSession session = request.getSession(  );
1821         String strQuery = request.getParameter( PARAMETER_QUERY );
1822         String strIdFilterPeriod = request.getParameter( PARAMETER_ID_FILTER_PERIOD );
1823         String strIdDiggSubmitSort = request.getParameter( PARAMETER_ID_DIGG_SUBMIT_SORT );
1824         String strIdFilterCategory = request.getParameter( PARAMETER_ID_FILTER_CATEGORY_DIGG );
1825         String strFilterPageIndex = request.getParameter( PARAMETER_FILTER_PAGE_INDEX );
1826         String strIdFilterDiggSubmitType = request.getParameter( PARAMETER_ID_FILTER_DIGG_SUBMIT_TYPE );
1827         String strLuteceUserName = request.getParameter( PARAMETER_LUTECE_USER_NAME_FILTER );
1828 
1829         int nIdFilterPeriod = DiggUtils.getIntegerParameter( strIdFilterPeriod );
1830         int nIdDiggSubmitSort = DiggUtils.getIntegerParameter( strIdDiggSubmitSort );
1831         int nIdFilterCategory = DiggUtils.getIntegerParameter( strIdFilterCategory );
1832         int nIdFilterDiggSubmitType = DiggUtils.getIntegerParameter( strIdFilterDiggSubmitType );
1833 
1834         SearchFields searchFields = ( session.getAttribute( SESSION_SEARCH_FIELDS ) != null )
1835             ? (SearchFields) session.getAttribute( SESSION_SEARCH_FIELDS ) : new SearchFields(  );
1836         searchFields.setQuery( ( strQuery != null ) ? strQuery : searchFields.getQuery(  ) );
1837         
1838         
1839         searchFields.setIdFilterPeriod( ( strIdFilterPeriod != null ) ? nIdFilterPeriod
1840                                                                       : searchFields.getIdFilterPeriod(  ) );
1841         searchFields.setIdDiggSubmitSort( ( strIdDiggSubmitSort != null ) ? nIdDiggSubmitSort
1842                                                                           : searchFields.getIdDiggSubmitSort(  ) );
1843         searchFields.setIdFilterCategory( ( strIdFilterCategory != null ) ? nIdFilterCategory
1844                                                                           : searchFields.getIdFilterCategory(  ) );
1845         searchFields.setIdFilterDiggSubmitType( ( strIdFilterDiggSubmitType != null ) ? nIdFilterDiggSubmitType
1846                                                                                       : searchFields.getIdFilterDiggSubmitType(  ) );
1847         searchFields.setPageIndex( ( strFilterPageIndex != null ) ? strFilterPageIndex : searchFields.getPageIndex(  ) );
1848 
1849         searchFields.setLuteceUserName( ( strLuteceUserName != null ) ? strLuteceUserName : searchFields.getLuteceUserName(  ) );
1850         
1851         // update search Fields in session
1852         session.setAttribute( SESSION_SEARCH_FIELDS, searchFields );
1853         
1854         
1855 
1856         return searchFields;
1857     }
1858 
1859 
1860 
1861     /**
1862      * Add the digg page frameset
1863      * @param strContentDigg
1864      * @param request the {@link HttpServletRequest}
1865      * @param page {@link XPage}
1866      * @param digg {@link Digg}
1867      * @param model the model
1868      * @param searchFields the searchField
1869      * @param luteceUserConnected the luteceUserConnected
1870      */
1871     private void addDiggPageFrameset( String strContentDigg, HttpServletRequest request, XPage page, Digg digg,
1872         Map<String, Object> model, SearchFields searchFields, LuteceUser luteceUserConnected )
1873     {
1874         page.setTitle( I18nService.getLocalizedString( PROPERTY_XPAGE_PAGETITLE, request.getLocale(  ) ) );
1875         page.setPathLabel( I18nService.getLocalizedString( PROPERTY_XPAGE_PATHLABEL, request.getLocale(  ) ) );
1876 
1877         if ( digg.isActive(  ) )
1878         {
1879             //Filter by comment
1880             if ( digg.isAuthorizedComment(  ) && digg.isShowTopCommentBlock(  ) )
1881             {
1882                 SubmitFilter submmitFilterTopComment = new SubmitFilter(  );
1883                 submmitFilterTopComment.setIdDigg( digg.getIdDigg(  ) );
1884                 submmitFilterTopComment.setIdDiggSubmitState( _nIdDiggSubmitStatePublish );
1885                 submmitFilterTopComment.setIdCategory( searchFields.getIdFilterCategory(  ) );
1886 
1887                 DiggUtils.initSubmitFilterBySort( submmitFilterTopComment, SubmitFilter.SORT_BY_NUMBER_COMMENT_DESC );
1888 
1889                 List<DiggSubmit> listDiggSubmitTopComment = _diggSubmitService.getDiggSubmitList( submmitFilterTopComment,
1890                         _plugin, digg.getNumberDiggSubmitInTopComment(  ) );
1891                 model.put( MARK_LIST_SUBMIT_TOP_COMMENT, listDiggSubmitTopComment );
1892             }
1893 
1894             //Filter by popularity
1895             if ( digg.isShowTopScoreBlock(  ) )
1896             {
1897                 SubmitFilter submmitFilterTopPopularity = new SubmitFilter(  );
1898                 submmitFilterTopPopularity.setIdDigg( digg.getIdDigg(  ) );
1899 
1900                 DiggUtils.initSubmitFilterBySort( submmitFilterTopPopularity, SubmitFilter.SORT_BY_SCORE_DESC );
1901 
1902                 submmitFilterTopPopularity.setIdDiggSubmitState( _nIdDiggSubmitStatePublish );
1903                 submmitFilterTopPopularity.setIdCategory( searchFields.getIdFilterCategory(  ) );
1904 
1905                 List<DiggSubmit> listDiggSubmitTopPopularity = _diggSubmitService.getDiggSubmitList( submmitFilterTopPopularity,
1906                         _plugin, digg.getNumberDiggSubmitInTopScore(  ) );
1907                 model.put( MARK_LIST_SUBMIT_TOP_POPULARITY_DIGG, listDiggSubmitTopPopularity );
1908             }
1909 
1910             //category Block
1911             if ( digg.isShowCategoryBlock(  ) )
1912             {
1913                 model.put( MARK_LIST_CATEGORIES_DIGG, digg.getCategories(  ) );
1914             }
1915 
1916             ReferenceList refListDiggSort = DiggUtils.getRefListDiggSort( request.getLocale(  ), true );
1917             ReferenceList refListFilterByPeriod = DiggUtils.getRefListFilterByPeriod( request.getLocale(  ) );
1918 
1919             //model
1920             model.put( MARK_ID_DIGG, digg.getIdDigg(  ) );
1921             model.put( MARK_QUERY, searchFields.getQuery(  ) );
1922             model.put( MARK_ID_DIGG_SUBMIT_SORT, searchFields.getIdDiggSubmitSort(  ) );
1923             model.put( MARK_ID_FILTER_PERIOD, searchFields.getIdFilterPeriod(  ) );
1924             model.put( MARK_ID_FILTER_CATEGORY_DIGG, searchFields.getIdFilterCategory(  ) );
1925             model.put( MARK_ID_FILTER_TYPE, searchFields.getIdFilterDiggSubmitType(  ) );
1926 
1927             if ( searchFields.getIdFilterDiggSubmitType(  ) != DiggUtils.CONSTANT_ID_NULL )
1928             {
1929                 model.put( MARK_TYPE_SELECTED,
1930                     DiggSubmitTypeHome.findByPrimaryKey( searchFields.getIdFilterDiggSubmitType(  ), _plugin ) );
1931             }
1932 
1933             model.put( MARK_CONTENT_DIGG, strContentDigg );
1934             model.put( MARK_LABEL_DIGG, digg.getLibelleContribution(  ) );
1935             model.put( MARK_HEADER_DIGG, digg.getHeader(  ) );
1936 
1937             model.put( MARK_AUTHORIZED_COMMENT, digg.isAuthorizedComment(  ) );
1938             model.put( MARK_AUTHORIZED_VOTE, !digg.isDisableVote(  ) );
1939             model.put( MARK_NUMBER_SHOWN_CHARACTERS, _nNumberShownCharacters );
1940 
1941             model.put( MARK_LIST_DIGG_SUBMIT_SORT, refListDiggSort );
1942             model.put( MARK_LIST_FILTER_BY_PERIOD, refListFilterByPeriod );
1943 
1944             model.put( MARK_SHOW_CATEGORY_BLOCK, digg.isShowCategoryBlock(  ) );
1945             model.put( MARK_SHOW_TOP_SCORE_BLOCK, digg.isShowTopScoreBlock(  ) );
1946             model.put( MARK_SHOW_TOP_COMMENT_BLOCK, digg.isShowTopCommentBlock(  ) );
1947             model.put( MARK_IS_EXTEND_INSTALLED, PortalService.isExtendActivated(  ) );
1948         }
1949         else
1950         {
1951             model.put( MARK_UNAVAILABILITY_MESSAGE, digg.getUnavailabilityMessage(  ) );
1952         }
1953 
1954         model.put( MARK_LUTECE_USER_CONNECTED, luteceUserConnected );
1955 
1956         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_XPAGE_FRAME_DIGG, request.getLocale(  ), model );
1957         page.setContent( template.getHtml(  ) );
1958     }
1959 
1960     /**
1961      * return a new UrlItem Xpage
1962      * @return a new UrlItem Xpage
1963      */
1964     private UrlItem getNewUrlItemPage(  )
1965     {
1966         return new UrlItem( _urlDiggXpageHome.getUrl(  ) );
1967     }
1968 
1969     /**
1970      * Test if a user can process action to a digg
1971      * @param digg the digg
1972      * @param request the {@link HttpServletRequest}
1973      * @param user The LuteceUser
1974      * @throws UserNotSignedException {@link UserNotSignedException}
1975      * @throws SiteMessageException {@link SiteMessageException}
1976      */
1977     private void testUserAuthorizationAccess( Digg digg, HttpServletRequest request, LuteceUser user )
1978         throws UserNotSignedException, SiteMessageException
1979     {
1980         if ( ( digg.getRole(  ) != null ) && !Digg.ROLE_NONE.equals( digg.getRole(  ) ) )
1981         {
1982             if ( user == null )
1983             {
1984                 throw new UserNotSignedException(  );
1985             }
1986 
1987             else if ( !SecurityService.getInstance(  ).isUserInRole( request, digg.getRole(  ) ) )
1988             {
1989                 SiteMessageService.setMessage( request, MESSAGE_ACCESS_DENIED, SiteMessage.TYPE_STOP );
1990             }
1991         }
1992     }
1993 }