View Javadoc
1   /*
2    * Copyright (c) 2002-2021, City of 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.extend.modules.comment.web.component;
35  
36  import java.util.HashMap;
37  import java.util.List;
38  import java.util.Locale;
39  import java.util.Map;
40  import java.util.Map.Entry;
41  
42  import javax.inject.Inject;
43  import javax.inject.Named;
44  import javax.servlet.http.HttpServletRequest;
45  import javax.servlet.http.HttpSession;
46  
47  import org.apache.commons.lang3.StringUtils;
48  
49  import fr.paris.lutece.plugins.extend.business.extender.ResourceExtenderDTO;
50  import fr.paris.lutece.plugins.extend.business.extender.config.IExtenderConfig;
51  import fr.paris.lutece.plugins.extend.modules.comment.business.AddCommentPosition;
52  import fr.paris.lutece.plugins.extend.modules.comment.business.Comment;
53  import fr.paris.lutece.plugins.extend.modules.comment.business.CommentFilter;
54  import fr.paris.lutece.plugins.extend.modules.comment.business.config.CommentExtenderConfig;
55  import fr.paris.lutece.plugins.extend.modules.comment.service.CommentListenerService;
56  import fr.paris.lutece.plugins.extend.modules.comment.service.CommentPlugin;
57  import fr.paris.lutece.plugins.extend.modules.comment.service.ICommentService;
58  import fr.paris.lutece.plugins.extend.modules.comment.service.extender.CommentResourceExtender;
59  import fr.paris.lutece.plugins.extend.modules.comment.util.constants.CommentConstants;
60  import fr.paris.lutece.plugins.extend.service.ExtendPlugin;
61  import fr.paris.lutece.plugins.extend.service.content.ExtendableContentPostProcessor;
62  import fr.paris.lutece.plugins.extend.service.extender.IResourceExtenderService;
63  import fr.paris.lutece.plugins.extend.service.extender.ResourceExtenderService;
64  import fr.paris.lutece.plugins.extend.service.extender.config.IResourceExtenderConfigService;
65  import fr.paris.lutece.plugins.extend.util.ExtendErrorException;
66  import fr.paris.lutece.plugins.extend.web.component.AbstractResourceExtenderComponent;
67  import fr.paris.lutece.portal.business.user.AdminUser;
68  import fr.paris.lutece.portal.service.admin.AdminUserService;
69  import fr.paris.lutece.portal.service.captcha.CaptchaSecurityService;
70  import fr.paris.lutece.portal.service.content.ContentPostProcessor;
71  import fr.paris.lutece.portal.service.i18n.I18nService;
72  import fr.paris.lutece.portal.service.mailinglist.AdminMailingListService;
73  import fr.paris.lutece.portal.service.plugin.PluginService;
74  import fr.paris.lutece.portal.service.prefs.UserPreferencesService;
75  import fr.paris.lutece.portal.service.resource.IExtendableResource;
76  import fr.paris.lutece.portal.service.security.LuteceUser;
77  import fr.paris.lutece.portal.service.security.SecurityService;
78  import fr.paris.lutece.portal.service.spring.SpringContextService;
79  import fr.paris.lutece.portal.service.template.AppTemplateService;
80  import fr.paris.lutece.portal.service.util.AppPathService;
81  import fr.paris.lutece.portal.service.util.AppPropertiesService;
82  import fr.paris.lutece.portal.service.workflow.WorkflowService;
83  import fr.paris.lutece.portal.web.constants.Parameters;
84  import fr.paris.lutece.portal.web.util.LocalizedDelegatePaginator;
85  import fr.paris.lutece.util.ReferenceList;
86  import fr.paris.lutece.util.html.HtmlTemplate;
87  import fr.paris.lutece.util.html.IPaginator;
88  import fr.paris.lutece.util.html.Paginator;
89  import fr.paris.lutece.util.url.UrlItem;
90  
91  /**
92   * 
93   * CommentResourceExtenderComponent
94   * 
95   */
96  public class CommentResourceExtenderComponent extends AbstractResourceExtenderComponent
97  {
98      // TEMPLATES
99      private static final String TEMPLATE_COMMENT = "skin/plugins/extend/modules/comment/comment.html";
100     private static final String TEMPLATE_COMMENT_CONFIG = "admin/plugins/extend/modules/comment/comment_config.html";
101     private static final String TEMPLATE_MANAGE_COMMENTS = "admin/plugins/extend/modules/comment/comment_info.html";
102 
103     private static final String JSP_URL_MANAGE_COMMENTS = "jsp/admin/plugins/extend/ViewExtenderInfo.jsp";
104 
105     @Inject
106     private ICommentService _commentService;
107     @Inject
108     @Named( CommentConstants.BEAN_CONFIG_SERVICE )
109     private IResourceExtenderConfigService _configService;
110     @Inject
111     @Named( ResourceExtenderService.BEAN_SERVICE )
112     private IResourceExtenderService _resourceExtenderService;
113 
114     private int _nDefaultItemsPerPage = AppPropertiesService.getPropertyInt( CommentConstants.PROPERTY_DEFAULT_LIST_COMMENTS_PER_PAGE, 50 );
115 
116     private volatile ContentPostProcessor _contentPostProcessor;
117 
118     /**
119      * {@inheritDoc}
120      */
121     @Override
122     public void buildXmlAddOn( String strIdExtendableResource, String strExtendableResourceType, String strParameters, StringBuffer strXml )
123     {
124         // Nothing yet
125     }
126 
127     /**
128      * {@inheritDoc}
129      */
130     @Override
131     public String getPageAddOn( String strIdExtendableResource, String strExtendableResourceType, String strParameters, HttpServletRequest request )
132     {
133         CommentExtenderConfig config = _configService.find( getResourceExtender( ).getKey( ), strIdExtendableResource, strExtendableResourceType );
134 
135         int nNbComments = 1;
136         boolean bAuthorizedsubComments = true;
137         boolean bUseBBCodeEditor = false;
138         boolean bDisplaySubComments = true;
139         boolean bTriCommentsByDateCreation = false;
140         int nAddCommentPosition = 0;
141         String strAdminBadge = StringUtils.EMPTY;
142 
143         if ( config != null )
144         {
145             nNbComments = config.getNbComments( );
146             bAuthorizedsubComments = config.getAuthorizeSubComments( );
147             nAddCommentPosition = config.getAddCommentPosition( );
148             bUseBBCodeEditor = config.getUseBBCodeEditor( );
149             strAdminBadge = config.getAdminBadge( );
150             bDisplaySubComments = config.isDisplaySubComments( );
151             bTriCommentsByDateCreation = config.isTriCommentsByCreation( );
152         }
153 
154         List<Comment> listComments = _commentService.findLastComments( strIdExtendableResource, strExtendableResourceType, nNbComments, true, true,
155                 bAuthorizedsubComments, bDisplaySubComments, config.isTriCommentsByCreation( ) );
156 
157         int nNbPublishedComments = _commentService.getCommentNb( strIdExtendableResource, strExtendableResourceType, !bDisplaySubComments, true );
158         Map<String, Object> model = new HashMap<String, Object>( );
159         model.put( CommentConstants.MARK_COMMENT_CONFIG,
160                 _configService.find( CommentResourceExtender.EXTENDER_TYPE_COMMENT, strIdExtendableResource, strExtendableResourceType ) );
161         model.put( CommentConstants.MARK_LIST_COMMENTS, listComments );
162         model.put( CommentConstants.MARK_ID_EXTENDABLE_RESOURCE, strIdExtendableResource );
163         model.put( CommentConstants.MARK_EXTENDABLE_RESOURCE_TYPE, strExtendableResourceType );
164         model.put( CommentConstants.MARK_ADD_COMMENT_POSITION, nAddCommentPosition );
165         model.put( CommentConstants.MARK_USE_BBCODE, bUseBBCodeEditor );
166         model.put( CommentConstants.MARK_ADMIN_BADGE, strAdminBadge );
167         model.put( CommentConstants.MARK_ALLOW_SUB_COMMENTS, bAuthorizedsubComments );
168         model.put( CommentConstants.MARK_DISPLAY_SUB_COMMENTS, bDisplaySubComments );
169         model.put( CommentConstants.MARK_NB_PUBLISHED_COMMENTS, nNbPublishedComments );
170         model.put( CommentConstants.MARK_TRI_COMMENTS_BY_DATE_CREATION, bTriCommentsByDateCreation );
171 
172         if ( nAddCommentPosition != AddCommentPosition.NEW_PAGE )
173         {
174             // Add Captcha
175             boolean bIsCaptchaEnabled = PluginService.isPluginEnable( CommentConstants.JCAPTCHA_PLUGIN )
176                     && Boolean.parseBoolean( AppPropertiesService.getProperty( CommentConstants.PROPERTY_USE_CAPTCHA, Boolean.TRUE.toString( ) ) );
177             model.put( CommentConstants.MARK_IS_ACTIVE_CAPTCHA, bIsCaptchaEnabled );
178 
179             if ( bIsCaptchaEnabled )
180             {
181                 CaptchaSecurityService captchaService = new CaptchaSecurityService( );
182                 model.put( CommentConstants.MARK_CAPTCHA, captchaService.getHtmlCode( ) );
183             }
184             // Add NickName if auth mod enable
185             if ( config != null && config.isEnabledAuthMode( ) )
186             {
187                 LuteceUser user = SecurityService.getInstance( ).getRegisteredUser( request );
188                 if ( user != null )
189                 {
190                     model.put( CommentConstants.MARK_NICKNAME, UserPreferencesService.instance( ).getNickname( user ) );
191                 }
192 
193                 if ( CommentListenerService.canComment( user, strIdExtendableResource, strExtendableResourceType ) )
194                 {
195                     model.put( CommentConstants.MARK_CAN_DELETE_COMMENTS, config.getDeleteComments( ) );
196                 }
197                 else
198                 {
199                     model.put( CommentConstants.MARK_COMMENT_CLOSED, true );
200                 }
201             }
202 
203             if ( SecurityService.isAuthenticationEnable( ) )
204             {
205                 LuteceUser user = SecurityService.getInstance( ).getRegisteredUser( request );
206 
207                 if ( user != null )
208                 {
209                     model.put( CommentConstants.MARK_MYLUTECE_USER, user );
210                 }
211             }
212 
213             // display message when form was submitted
214             if ( request.getSession( ).getAttribute( CommentConstants.SESSION_COMMENT_ADD_MESSAGE_RESULT + strIdExtendableResource ) != null )
215             {
216                 model.put( CommentConstants.MARK_ADD_COMMENT_MESSAGE_RESULT,
217                         (String) request.getSession( ).getAttribute( CommentConstants.SESSION_COMMENT_ADD_MESSAGE_RESULT + strIdExtendableResource ) );
218                 request.getSession( ).removeAttribute( CommentConstants.SESSION_COMMENT_ADD_MESSAGE_RESULT + strIdExtendableResource );
219             }
220             // get redirect URL
221             request.getSession( ).setAttribute( ExtendPlugin.PLUGIN_NAME + CommentConstants.PARAMETER_FROM_URL,
222                     request.getRequestURI( ) + "?" + request.getQueryString( ) );
223             model.put( CommentConstants.PARAMETER_FROM_URL, CommentConstants.FROM_SESSION );
224         }
225 
226         LuteceUser user = SecurityService.getInstance( ).getRegisteredUser( request );
227 
228         if ( user != null )
229         {
230             model.put( CommentConstants.MARK_REGISTERED_USER_EMAIL, user.getEmail( ) );
231         }
232 
233         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_COMMENT, request.getLocale( ), model );
234         String strContent = template.getHtml( );
235 
236         ContentPostProcessor postProcessor = getExtendPostProcessor( );
237         if ( postProcessor != null )
238         {
239             strContent = postProcessor.process( request, strContent );
240         }
241 
242         return strContent;
243     }
244 
245     /**
246      * {@inheritDoc}
247      */
248     @Override
249     public String getConfigHtml( ResourceExtenderDTO resourceExtender, Locale locale, HttpServletRequest request )
250     {
251         ReferenceList listIdsMailingList = new ReferenceList( );
252         listIdsMailingList.addItem( -1, I18nService.getLocalizedString( CommentConstants.PROPERTY_COMMENT_CONFIG_LABEL_NO_MAILING_LIST, locale ) );
253         listIdsMailingList.addAll( AdminMailingListService.getMailingLists( AdminUserService.getAdminUser( request ) ) );
254 
255         Map<String, Object> model = new HashMap<String, Object>( );
256         model.put( CommentConstants.MARK_COMMENT_CONFIG, _configService.find( resourceExtender.getIdExtender( ) ) );
257         model.put( CommentConstants.MARK_LIST_IDS_MAILING_LIST, listIdsMailingList );
258         model.put( CommentConstants.MARK_ADD_COMMENT_POSITIONS, AddCommentPosition.getAllPositions( ) );
259         model.put( CommentConstants.MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
260         model.put( CommentConstants.MARK_LOCALE, AdminUserService.getLocale( request ) );
261         if ( WorkflowService.getInstance( ).isAvailable( ) )
262         {
263             AdminUser adminUser = AdminUserService.getAdminUser( request );
264             ReferenceList referenceList = WorkflowService.getInstance( ).getWorkflowsEnabled( adminUser, locale );
265             model.put( CommentConstants.MARK_WORKFLOW_REF_LIST, referenceList );
266         }
267 
268         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_COMMENT_CONFIG, request.getLocale( ), model );
269 
270         return template.getHtml( );
271     }
272 
273     /**
274      * {@inheritDoc}
275      */
276     @Override
277     public IExtenderConfig getConfig( int nIdExtender )
278     {
279         return _configService.find( nIdExtender );
280     }
281 
282     /**
283      * {@inheritDoc}
284      */
285     @Override
286     public String getInfoHtml( ResourceExtenderDTO resourceExtender, Locale locale, HttpServletRequest request )
287     {
288         if ( resourceExtender != null )
289         {
290             CommentExtenderConfig config = _configService.find( getResourceExtender( ).getKey( ), resourceExtender.getIdExtendableResource( ),
291                     resourceExtender.getExtendableResourceType( ) );
292             if ( config != null )
293             {
294 
295             // We save in session the post back URL
296             String strPostBackUrl = getPostBackUrl( request );
297             request.getSession( ).setAttribute( CommentPlugin.PLUGIN_NAME + CommentConstants.SESSION_COMMENT_ADMIN_POST_BACK_URL, strPostBackUrl );
298 
299             // We get the pagination info from the session
300             Integer nItemsPerPage = _nDefaultItemsPerPage;
301             String strCurrentPageIndex = CommentConstants.CONSTANT_FIRST_PAGE_NUMBER;
302             Boolean bIsAscSort = false;
303             String strSortedAttributeName = null;
304             String strFilterState = null;
305             String strFilterMarkAsImportant = null;
306             String strFilterPinned = null;
307             Object object = request.getSession( ).getAttribute( CommentConstants.SESSION_COMMENT_ADMIN_ITEMS_PER_PAGE );
308             if ( object != null )
309             {
310                 nItemsPerPage = (Integer) object;
311             }
312             object = request.getSession( ).getAttribute( CommentConstants.SESSION_COMMENT_ADMIN_CURRENT_PAGE_INDEX );
313             if ( object != null )
314             {
315                 strCurrentPageIndex = (String) object;
316             }
317             object = request.getSession( ).getAttribute( CommentConstants.SESSION_COMMENT_ADMIN_IS_ASC_SORT );
318             if ( object != null )
319             {
320                 bIsAscSort = (Boolean) object;
321             }
322             object = request.getSession( ).getAttribute( CommentConstants.SESSION_COMMENT_ADMIN_SORTED_ATTRIBUTE_NAME );
323             if ( object != null )
324             {
325                 strSortedAttributeName = (String) object;
326             }
327 
328             object = request.getSession( ).getAttribute( CommentConstants.SESSION_COMMENT_ADMIN_FILTER_STATE );
329             if ( object != null )
330             {
331                 strFilterState = (String) object;
332             }
333 
334             object = request.getSession( ).getAttribute( CommentConstants.SESSION_COMMENT_ADMIN_FILTER_PINNED );
335             if ( object != null )
336             {
337                 strFilterPinned = (String) object;
338             }
339 
340             object = request.getSession( ).getAttribute( CommentConstants.SESSION_COMMENT_ADMIN_FILTER_MARK_AS_IMPORTANT );
341             if ( object != null )
342             {
343                 strFilterMarkAsImportant = (String) object;
344             }
345 
346             int nItemsCount = _commentService.getCommentNb( resourceExtender.getIdExtendableResource( ), resourceExtender.getExtendableResourceType( ),
347                     config.getAuthorizeSubComments( ), false );
348             String strFromUrl = StringUtils.replace( request.getParameter( CommentConstants.PARAMETER_FROM_URL ), CommentConstants.CONSTANT_AND,
349                     CommentConstants.CONSTANT_AND_HTML );
350             strCurrentPageIndex = Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX, strCurrentPageIndex );
351             int nOldITemsPerPage = nItemsPerPage;
352             nItemsPerPage = Paginator.getItemsPerPage( request, Paginator.PARAMETER_ITEMS_PER_PAGE, nItemsPerPage, _nDefaultItemsPerPage );
353             if ( nItemsPerPage <= 0 )
354             {
355                 nItemsPerPage = _nDefaultItemsPerPage;
356             }
357             // If we changed the number of items per page, we go back to the first page
358             if ( nItemsPerPage != nOldITemsPerPage )
359             {
360                 strCurrentPageIndex = CommentConstants.CONSTANT_FIRST_PAGE_NUMBER;
361             }
362             String strNewSortedAttributeName = request.getParameter( Parameters.SORTED_ATTRIBUTE_NAME );
363             if ( strNewSortedAttributeName != null )
364             {
365                 // We update sort properties
366                 strSortedAttributeName = strNewSortedAttributeName;
367                 bIsAscSort = Boolean.parseBoolean( request.getParameter( Parameters.SORTED_ASC ) );
368             }
369 
370             if ( request.getParameter( CommentConstants.PARAMETER_FILTER_STATE ) != null )
371             {
372                 strFilterState = request.getParameter( CommentConstants.PARAMETER_FILTER_STATE );
373             }
374 
375             if ( request.getParameter( CommentConstants.PARAMETER_FILTER_PINNED ) != null )
376             {
377                 strFilterPinned = request.getParameter( CommentConstants.PARAMETER_FILTER_PINNED );
378             }
379 
380             if ( request.getParameter( CommentConstants.PARAMETER_FILTER_MARK_AS_IMPORTANT ) != null )
381             {
382                 strFilterMarkAsImportant = request.getParameter( CommentConstants.PARAMETER_FILTER_MARK_AS_IMPORTANT );
383             }
384 
385             int nItemsOffset = nItemsPerPage * ( Integer.parseInt( strCurrentPageIndex ) - 1 );
386 
387             CommentFilterend/modules/comment/business/CommentFilter.html#CommentFilter">CommentFilter commentFilter = new CommentFilter( );
388             if ( StringUtils.isNotBlank( strFilterState ) && StringUtils.isNumeric( strFilterState ) )
389             {
390                 commentFilter.setCommentState( Integer.parseInt( strFilterState ) );
391             }
392             if ( StringUtils.isNotBlank( strFilterPinned ) )
393             {
394                 commentFilter.setPinned( new Boolean( strFilterPinned ) );
395             }
396             if ( StringUtils.isNotBlank( strFilterMarkAsImportant ) )
397             {
398                 commentFilter.setImportant( new Boolean( strFilterMarkAsImportant ) );
399             }
400             commentFilter.setSortedAttributeName( strSortedAttributeName );
401             commentFilter.setAscSort( bIsAscSort );
402 
403             List<Comment> listComments = _commentService.findByResource( resourceExtender.getIdExtendableResource( ),
404                     resourceExtender.getExtendableResourceType( ), commentFilter, nItemsOffset, nItemsPerPage, config.getAuthorizeSubComments( ) );
405 
406             // We generate the base URL for the paginator
407             UrlItem url = new UrlItem( strPostBackUrl );
408             url.addParameter( CommentConstants.PARAMETER_EXTENDER_TYPE, CommentResourceExtender.EXTENDER_TYPE_COMMENT );
409             url.addParameter( CommentConstants.PARAMETER_ID_EXTENDABLE_RESOURCE, resourceExtender.getIdExtendableResource( ) );
410             url.addParameter( CommentConstants.PARAMETER_EXTENDABLE_RESOURCE_TYPE, resourceExtender.getExtendableResourceType( ) );
411             url.addParameter( CommentConstants.PARAMETER_FROM_URL, strFromUrl );
412 
413             // We get the paginator
414             IPaginator<Comment> paginator = new LocalizedDelegatePaginator<Comment>( listComments, nItemsPerPage, url.getUrl( ), Paginator.PARAMETER_PAGE_INDEX,
415                     strCurrentPageIndex, nItemsCount, AdminUserService.getLocale( request ) );
416 
417             Map<String, Object> model = new HashMap<String, Object>( );
418             List<Comment> listCommentDisplay = paginator.getPageItems( );
419             AdminUser adminUser = AdminUserService.getAdminUser( request );
420             if ( adminUser != null && WorkflowService.getInstance( ).isAvailable( ) )
421             {
422                 for ( Comment comment : listCommentDisplay )
423                 {
424 
425                     comment.setListWorkflowActions( WorkflowService.getInstance( ).getActions( comment.getIdComment( ),
426                             _commentService.getResourceType( comment.getExtendableResourceType( ) ), config.getIdWorkflow( ), adminUser ) );
427 
428                 }
429             }
430             if ( !CommentConstants.CONSTANT_ALL_RESSOURCE_ID.equals( resourceExtender.getIdExtendableResource( ) ) )
431             {
432 
433                 IExtendableResource resourceExtenderInfo = _resourceExtenderService.getExtendableResource( resourceExtender );
434                 model.put( CommentConstants.MARK_RESOURCE_EXTENDER, resourceExtenderInfo );
435                 model.put( CommentConstants.MARK_ALL_RESOURCES, false );
436             }
437             else
438             {
439                 HashMap<String, IExtendableResource> mapResourceExtender = new HashMap<>( );
440                 for ( Comment comment : listCommentDisplay )
441                 {
442                     if ( !mapResourceExtender.containsKey( comment.getIdExtendableResource( ) ) )
443                     {
444 
445                         mapResourceExtender.put( comment.getIdExtendableResource( ), _resourceExtenderService
446                                 .getExtendableResource( comment.getIdExtendableResource( ), resourceExtender.getExtendableResourceType( ) ) );
447                     }
448 
449                 }
450                 model.put( CommentConstants.MARK_ALL_RESOURCES, true );
451                 model.put( CommentConstants.MARK_RESOURCE_EXTENDER_MAP, mapResourceExtender );
452             }
453 
454             model.put( CommentConstants.MARK_ID_EXTENDABLE_RESOURCE, resourceExtender.getIdExtendableResource( ) );
455             model.put( CommentConstants.MARK_EXTENDABLE_RESOURCE_TYPE, resourceExtender.getExtendableResourceType( ) );
456 
457             model.put( CommentConstants.MARK_LIST_COMMENTS, listCommentDisplay );
458             model.put( CommentConstants.PARAMETER_FROM_URL, strFromUrl );
459             model.put( CommentConstants.MARK_PAGINATOR, paginator );
460             model.put( CommentConstants.MARK_NB_ITEMS_PER_PAGE, Integer.toString( paginator.getItemsPerPage( ) ) );
461             model.put( CommentConstants.MARK_ASC_SORT, bIsAscSort );
462             model.put( Parameters.SORTED_ATTRIBUTE_NAME, strSortedAttributeName );
463             model.put( CommentConstants.PARAMETER_ID_COMMENT, request.getParameter( CommentConstants.PARAMETER_ID_COMMENT ) );
464             model.put( CommentConstants.MARK_USE_BBCODE, config.getUseBBCodeEditor( ) );
465             model.put( CommentConstants.MARK_ADMIN_BADGE, config.getAdminBadge( ) );
466             model.put( CommentConstants.MARK_ALLOW_SUB_COMMENTS, config.getAuthorizeSubComments( ) );
467             model.put( CommentConstants.MARK_FILTER_STATE, strFilterState );
468             model.put( CommentConstants.MARK_FILTER_MARK_AS_IMPORTANT, strFilterMarkAsImportant );
469             model.put( CommentConstants.MARK_FILTER_PINNED, strFilterPinned );
470             model.put( CommentConstants.MARK_LIST_COMMENT_STATES, _commentService.getRefListCommentStates( locale ) );
471             model.put( CommentConstants.MARK_LIST_MARK_AS_IMPORTANT_FILTER, _commentService.getRefListFilterAsImportant( locale ) );
472             model.put( CommentConstants.MARK_LIST_PINNED_FILTER, _commentService.getRefListFilterAsPinned( locale ) );
473 
474             model.put( CommentConstants.PARAMETER_POST_BACK_URL, strPostBackUrl );
475 
476             HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MANAGE_COMMENTS, request.getLocale( ), model );
477 
478             // We save the pagination info in the session
479             HttpSession session = request.getSession( );
480             session.setAttribute( CommentConstants.SESSION_COMMENT_ADMIN_ITEMS_PER_PAGE, nItemsPerPage );
481             session.setAttribute( CommentConstants.SESSION_COMMENT_ADMIN_CURRENT_PAGE_INDEX, strCurrentPageIndex );
482             session.setAttribute( CommentConstants.SESSION_COMMENT_ADMIN_IS_ASC_SORT, bIsAscSort );
483             session.setAttribute( CommentConstants.SESSION_COMMENT_ADMIN_SORTED_ATTRIBUTE_NAME, strSortedAttributeName );
484             session.setAttribute( CommentConstants.SESSION_COMMENT_ADMIN_FILTER_STATE, strFilterState );
485 
486             String strContent = template.getHtml( );
487 
488             ContentPostProcessor postProcessor = getExtendPostProcessor( );
489             if ( postProcessor != null )
490             {
491                 strContent = postProcessor.process( request, strContent );
492             }
493 
494             return strContent;
495             }
496         }
497 
498         return StringUtils.EMPTY;
499     }
500 
501     /**
502      * {@inheritDoc}
503      */
504     @Override
505     public void doSaveConfig( HttpServletRequest request, IExtenderConfig config ) throws ExtendErrorException
506     {
507         _configService.update( config );
508     }
509 
510     /**
511      * {@inheritDoc}
512      */
513     @Override
514     public String getPostBackUrl( HttpServletRequest request )
515     {
516         UrlItem urlItem = new UrlItem( request.getRequestURI( ) );
517         Map<String, String [ ]> mapParameters = new HashMap<String, String [ ]>( request.getParameterMap( ) );
518         // We ignore some parameters : those parameter will be set regardlessly of the post pack URL
519         mapParameters.remove( CommentConstants.MARK_ID_EXTENDABLE_RESOURCE );
520         mapParameters.remove( CommentConstants.MARK_EXTENDABLE_RESOURCE_TYPE );
521         mapParameters.remove( CommentConstants.PARAMETER_EXTENDER_TYPE );
522         mapParameters.remove( CommentConstants.PARAMETER_FROM_URL );
523         mapParameters.remove( CommentConstants.PARAMETER_ID_COMMENT );
524         mapParameters.remove( Paginator.PARAMETER_PAGE_INDEX );
525         mapParameters.remove( Paginator.PARAMETER_ITEMS_PER_PAGE );
526         mapParameters.remove( Parameters.SORTED_ATTRIBUTE_NAME );
527         mapParameters.remove( Parameters.SORTED_ASC );
528         for ( Entry<String, String [ ]> entry : mapParameters.entrySet( ) )
529         {
530             urlItem.addParameter( entry.getKey( ), entry.getValue( ) [0] );
531         }
532         return urlItem.getUrl( );
533     }
534 
535     /**
536      * Get the content post processor of plugin extend
537      * 
538      * @return the content post processor of plugin extend
539      */
540     private ContentPostProcessor getExtendPostProcessor( )
541     {
542         if ( _contentPostProcessor == null )
543         {
544             synchronized( this )
545             {
546                 if ( _contentPostProcessor == null )
547                 {
548                     _contentPostProcessor = SpringContextService.getBean( ExtendableContentPostProcessor.BEAN_NAME );
549                 }
550             }
551         }
552         return _contentPostProcessor;
553     }
554 
555 }