View Javadoc
1   /*
2    * Copyright (c) 2002-2020, 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.document.web.publishing;
35  
36  import fr.paris.lutece.plugins.document.business.Document;
37  import fr.paris.lutece.plugins.document.business.DocumentHome;
38  import fr.paris.lutece.plugins.document.business.DocumentPageTemplate;
39  import fr.paris.lutece.plugins.document.business.DocumentPageTemplateHome;
40  import fr.paris.lutece.plugins.document.business.autopublication.DocumentAutoPublication;
41  import fr.paris.lutece.plugins.document.business.autopublication.DocumentAutoPublicationHome;
42  import fr.paris.lutece.plugins.document.business.portlet.DocumentListPortlet;
43  import fr.paris.lutece.plugins.document.business.portlet.DocumentListPortletHome;
44  import fr.paris.lutece.plugins.document.business.portlet.DocumentPortlet;
45  import fr.paris.lutece.plugins.document.business.portlet.DocumentPortletHome;
46  import fr.paris.lutece.plugins.document.business.portlet.PortletFilter;
47  import fr.paris.lutece.plugins.document.business.portlet.PortletOrder;
48  import fr.paris.lutece.plugins.document.business.publication.DocumentPublication;
49  import fr.paris.lutece.plugins.document.business.spaces.DocumentSpace;
50  import fr.paris.lutece.plugins.document.business.spaces.DocumentSpaceHome;
51  import fr.paris.lutece.plugins.document.business.workflow.DocumentAction;
52  import fr.paris.lutece.plugins.document.service.DocumentService;
53  import fr.paris.lutece.plugins.document.service.DocumentTypeResourceIdService;
54  import fr.paris.lutece.plugins.document.service.autopublication.AutoPublicationService;
55  import fr.paris.lutece.plugins.document.service.publishing.PublishingService;
56  import fr.paris.lutece.plugins.document.service.spaces.DocumentSpacesService;
57  import fr.paris.lutece.plugins.document.utils.IntegerUtils;
58  import fr.paris.lutece.portal.business.page.Page;
59  import fr.paris.lutece.portal.business.page.PageHome;
60  import fr.paris.lutece.portal.business.portlet.Portlet;
61  import fr.paris.lutece.portal.business.portlet.PortletHome;
62  import fr.paris.lutece.portal.business.portlet.PortletType;
63  import fr.paris.lutece.portal.business.user.AdminUser;
64  import fr.paris.lutece.portal.service.i18n.I18nService;
65  import fr.paris.lutece.portal.service.message.AdminMessage;
66  import fr.paris.lutece.portal.service.message.AdminMessageService;
67  import fr.paris.lutece.portal.service.portal.PortalService;
68  import fr.paris.lutece.portal.service.portlet.PortletResourceIdService;
69  import fr.paris.lutece.portal.service.portlet.PortletService;
70  import fr.paris.lutece.portal.service.rbac.RBACService;
71  import fr.paris.lutece.portal.service.template.AppTemplateService;
72  import fr.paris.lutece.portal.web.admin.PluginAdminPageJspBean;
73  import fr.paris.lutece.util.ReferenceItem;
74  import fr.paris.lutece.util.ReferenceList;
75  import fr.paris.lutece.util.html.HtmlTemplate;
76  import fr.paris.lutece.util.url.UrlItem;
77  
78  import org.apache.commons.lang3.StringUtils;
79  
80  import java.util.ArrayList;
81  import java.util.Collection;
82  import java.util.HashMap;
83  import java.util.Iterator;
84  import java.util.List;
85  import java.util.Map;
86  
87  import javax.servlet.http.HttpServletRequest;
88  
89  
90  /**
91   * DocumentPublishingJspBean
92   */
93  public class DocumentPublishingJspBean extends PluginAdminPageJspBean
94  {
95      public static final String RIGHT_DOCUMENT_MANAGEMENT = "DOCUMENT_MANAGEMENT";
96      public static final String RIGHT_MANAGE_ADMIN_SITE = "CORE_ADMIN_SITE";
97  
98      /**
99       * Generated serial version UID
100      */
101     private static final long serialVersionUID = -7693499948082725314L;
102     private static final String REGEX_ID = "^[\\d]+$";
103     private static final int MODE_PUBLICATION_STANDARD = 0;
104     private static final int MODE_PUBLICATION_AUTO_PUBLICATION = 1;
105     private static final String PARAMETER_DOCUMENT_ID = "id_document";
106     private static final String PARAMETER_PORTLET_ID = "id_portlet";
107     private static final String PARAMETER_SPACE_ID = "id_space";
108     private static final String PARAMETER_MODE_PUBLICATION = "mode_publication";
109     private static final String PARAMETER_OLD_MODE_PUBLICATION = "old_mode_publication";
110     private static final String PARAMETER_DOCUMENT_ORDER = "document_order";
111     private static final String PARAMETER_DOCUMENT_LIST_PORTLET_IDS = "document_list_portlet_ids";
112     private static final String PARAMETER_DOCUMENT_PORTLET_IDS = "document_portlet_ids";
113     private static final String PARAMETER_DOCUMENT_PUBLISHED_STATUS = "status";
114     private static final String PARAMETER_ORDER_PORTLET = "order_portlet";
115     private static final String PARAMETER_ORDER_PORTLET_ASC = "order_portlet_asc";
116     private static final String PARAMETER_PORTLET_FILTER_TYPE = "portlet_filter_type";
117     private static final String PARAMETER_PORTLET_FILTER_VALUE = "portlet_filter_value";
118     private static final String MARK_DOCUMENT = "document";
119     private static final String MARK_DOCUMENT_PUBLISHED = "document_published";
120     private static final String MARK_DOCUMENT_PUBLISHED_STATUS = "status";
121     private static final String MARK_PUBLISHED_STATUS_VALUE = "status_published";
122     private static final String MARK_UNPUBLISHED_STATUS_VALUE = "status_unpublished";
123     private static final String MARK_ASSIGNED_PORTLET = "assigned_portlet_list";
124     private static final String MARK_ASSIGNED_PUBLICATION = "publication";
125     private static final String MARK_PORTLET = "portlet";
126     private static final String MARK_LIST_PAGE = "page_list";
127     private static final String MARK_MODE_PUBLICATION = "mode_publication";
128     private static final String MARK_ASSIGNED_DOCUMENT_LIST = "assigned_document_list";
129     private static final String MARK_SPACES_BROWSER = "spaces_browser";
130     private static final String MARK_DOCUMENT_AUTO_PUBLICATION = "document_auto_publication";
131     private static final String MARK_SPACE_NAME = "space_name";
132     private static final String MARK_NUMBER_AUTO_PUBLISHED_DOCUMENTS = "number_auto_published_documents";
133     private static final String MARK_LIST_AUTO_PUBLICATION = "list_auto_publication";
134     private static final String MARK_DOCUMENT_ORDER = "document_order";
135     private static final String MARK_DOCUMENT_ORDER_LIST = "document_order_list";
136     private static final String MARK_PUBLISHED_DOCUMENT_LIST = "published_document_list";
137     private static final String MARK_PORTLET_ID = "portlet_id";
138     private static final String MARK_PAGE_NAME = "page_name";
139     private static final String MARK_SUBMIT_BUTTON_DISABLED = "submit_button_disabled";
140     private static final String MARK_DOCUMENT_PAGE_TEMPLATE_PICTURE = "page_template_picture";
141     private static final String MARK_PERMISSION_PUBLISH = "permission_publish";
142     private static final String MARK_PERMISSION_ASSIGN = "permission_assign";
143     private static final String PARAMETER_IS_DISPLAY_LATEST_PORTLETS = "is_display_latest_portlets";
144     private static final String MARK_ORDER_PORTLET = "order_portlet";
145     private static final String MARK_ORDER_PORTLET_ASC = "order_portlet_asc";
146     private static final String MARK_DOCUMENT_PORTLET_LIST = "document_portlet_list";
147     private static final String MARk_DOCUMENT_LIST_PORTLET_LIST = "document_list_portlet_list";
148     private static final String MARK_PORTLET_FILTER_ERROR = "portlet_filter_error";
149     private static final String MARK_PORTLET_FILTER = "portlet_filter";
150     private static final String MARK_LABEL_DISPLAY_LATEST_PORTLETS = "label_display_latest_portlets";
151     private static final String PROPERTY_PUBLISHING_SPACE_PAGE_TITLE = "document.assign.pageTitle";
152     private static final String PROPERTY_MANAGE_PUBLISHING = "document.portlet.publishing.pageTitle";
153     private static final String PROPERTY_CREATE_AUTO_PUBLICATION = "document.portlet.publishing.pageTitle";
154     private static final String PROPERTY_DISPLAY_LATEST_PORTLETS = "document.manage_document_publishing.labelDisplayLatestPortlets";
155     private static final String TEMPLATE_DOCUMENT_PUBLISHING = "/admin/plugins/document/publishing/manage_document_publishing.html";
156     private static final String TEMPLATE_PORTLET_PAGE_PATH = "/admin/plugins/document/publishing/portlet_page_path.html";
157     private static final String TEMPLATE_PORTLET_PUBLISHING = "/admin/plugins/document/publishing/manage_portlet_publishing.html";
158     private static final String TEMPLATE_CREATE_AUTO_PUBLICATION = "/admin/plugins/document/publishing/create_auto_publication.html";
159     private static final String TEMPLATE_PUBLISHED_DOCUMENT_LIST = "/admin/plugins/document/publishing/published_document_list.html";
160     private static final String TEMPLATE_PUBLISHED_DOCUMENT_LIST_CONTAINER = "/admin/plugins/document/publishing/published_document_list_container.html";
161     private static final String TEMPLATE_ASSIGNED_DOCUMENT_LIST = "/admin/plugins/document/publishing/assigned_document_list.html";
162     private static final String TEMPLATE_ASSIGNED_DOCUMENT_LIST_CONTAINER = "/admin/plugins/document/publishing/assigned_document_list_container.html";
163     private static final String JSP_DOCUMENTS_ASSIGN = "ManageDocumentPublishing.jsp";
164     private static final String JSP_DOCUMENTS_PUBLISHING = "ManagePublishing.jsp";
165     private static final String JSP_DELETE_AUTO_PUBLICATION = "jsp/admin/plugins/document/DoDeleteAutoPublication.jsp";
166     private static final String JSP_CHANGE_MODE_PUBLICATION = "jsp/admin/plugins/document/DoChangeModePublication.jsp";
167     private static final String MESSAGE_AUTO_PUBLICATION_ALREADY_EXISTS = "document.message.autoPublication.alreadyExists";
168     private static final String MESSAGE_CONFIRM_DELETE_AUTO_PUBLICATION = "document.message.autoPublication.confirmDeleteAutoPublication";
169     private static final String MESSAGE_CONFIRM_CHANGE_MODE_PUBLICATION_STANDARD = "document.message.modePublication.confirmChangeModePublication.standard";
170     private static final String MESSAGE_CONFIRM_CHANGE_MODE_PUBLICATION_AUTO_PUBLICATION = "document.message.modePublication.confirmChangeModePublication.autoPublication";
171     private static final String ERROR_MESSAGE_NOT_NUMERIC_FIELD = "document.message.notNumericField";
172     private static final String ERROR_MESSAGE_MESSAGE_MANDATORY_SEARCH_FIELD = "document.message.mandatory.searchField";
173 
174     /**
175      * Returns the publish template management
176      *
177      * @param request
178      *            The Http request
179      * @return the html code for display the modes list
180      */
181     public String getManageDocumentPublishing( HttpServletRequest request )
182     {
183         setPageTitleProperty( PROPERTY_PUBLISHING_SPACE_PAGE_TITLE );
184 
185         Object[] messageNumberOfMaxLatestPortletsDisplay = 
186             {
187                 String.valueOf( PortletFilter.PROPERTY_NUMBER_OF_MAX_LATEST_PORTLETS_DISPLAY )
188             };
189 
190         String strErrorFilter = null;
191         String strDocumentId = request.getParameter( PARAMETER_DOCUMENT_ID );
192         Portlet portlet;
193         Document document = DocumentHome.findByPrimaryKeyWithoutBinaries( IntegerUtils.convert( strDocumentId ) );
194         Map<String, Object> model = new HashMap<String, Object>(  );
195 
196         if ( ( document != null ) &&
197                 DocumentService.getInstance(  )
198                                    .isAuthorizedAdminDocument( document.getSpaceId(  ),
199                     document.getCodeDocumentType(  ), DocumentTypeResourceIdService.PERMISSION_VIEW, getUser(  ) ) )
200         {
201             PortletOrderocument/business/portlet/PortletOrder.html#PortletOrder">PortletOrder pOrder = new PortletOrder(  );
202             String strOrderPortlet = request.getParameter( PARAMETER_ORDER_PORTLET );
203 
204             boolean bIsDisplayPortlets = ( ( request.getParameter( PARAMETER_IS_DISPLAY_LATEST_PORTLETS ) != null ) &&
205                 !Boolean.valueOf( request.getParameter( PARAMETER_IS_DISPLAY_LATEST_PORTLETS ) ) ) ? false : true;
206 
207             String strOrderPortletAsc = request.getParameter( PARAMETER_ORDER_PORTLET_ASC );
208             int nOrderPortlet = -1;
209             int nOrderPortletAsc = -1;
210 
211             PortletFilter portletFilter = null;
212 
213             if ( !bIsDisplayPortlets )
214             {
215                 portletFilter = new PortletFilter(  );
216                 portletFilter.setPortletFilterType( request.getParameter( PARAMETER_PORTLET_FILTER_TYPE ) );
217                 portletFilter.setDisplayLatestPortlets( bIsDisplayPortlets );
218                 portletFilter.setSearchValue( request.getParameter( PARAMETER_PORTLET_FILTER_VALUE ) );
219                 strErrorFilter = setFillFilter( portletFilter );
220 
221                 if ( strErrorFilter != null )
222                 {
223                     model.put( MARK_PORTLET_FILTER_ERROR, strErrorFilter );
224                 }
225             }
226 
227             if ( StringUtils.isNotBlank( strOrderPortlet ) && StringUtils.isNumeric( strOrderPortlet ) &&
228                     StringUtils.isNotBlank( strOrderPortletAsc ) && StringUtils.isNumeric( strOrderPortletAsc ) )
229             {
230                 nOrderPortlet = IntegerUtils.convert( strOrderPortlet );
231                 nOrderPortletAsc = IntegerUtils.convert( strOrderPortletAsc );
232                 pOrder.setTypeOrder( nOrderPortlet );
233                 pOrder.setSortAsc( nOrderPortletAsc == PortletOrder.SORT_ASC );
234             }
235 
236             Collection<ReferenceItem> listDocumentListPortlets = getListAuthorizedDocumentListPortlets( document.getId(  ),
237                     document.getCodeDocumentType(  ), pOrder, ( strErrorFilter == null ) ? portletFilter : null );
238             Collection<ReferenceItem> listDocumentPortlets = getListAuthorizedDocumentPortlets( document.getId(  ),
239                     document.getCodeDocumentType(  ), pOrder, ( strErrorFilter == null ) ? portletFilter : null );
240 
241             Collection<Portlet> listAssignedPortlet = PublishingService.getInstance(  )
242                                                                        .getPortletsByDocumentId( strDocumentId );
243 
244             Collection<HashMap<String, Object>> listAssignedPortlets = new ArrayList<HashMap<String, Object>>(  );
245 
246             for ( Iterator<Portlet> iterator = listAssignedPortlet.iterator(  ); iterator.hasNext(  ); )
247             {
248                 portlet = iterator.next(  );
249 
250                 // Check if portlet is in Auto publication mode, if yes, delete
251                 // it from iterator
252                 if ( !DocumentAutoPublicationHome.isPortletAutoPublished( portlet.getId(  ) ) &&
253                         PortletService.getInstance(  ).isAuthorized( portlet, getUser(  ) ) )
254                 {
255                     HashMap<String, Object> portletPublication = new HashMap<String, Object>(  );
256                     portletPublication.put( MARK_PORTLET, portlet );
257                     portletPublication.put( MARK_ASSIGNED_PUBLICATION,
258                         PublishingService.getInstance(  ).getDocumentPublication( portlet.getId(  ), document.getId(  ) ) );
259 
260                     listAssignedPortlets.add( portletPublication );
261                 }
262             }
263 
264             DocumentService.getInstance(  ).getActions( document, getLocale(  ), getUser(  ) );
265 
266             for ( Object action : document.getActions(  ) )
267             {
268                 DocumentAction/../../../fr/paris/lutece/plugins/document/business/workflow/DocumentAction.html#DocumentAction">DocumentAction docAction = (DocumentAction) action;
269 
270                 if ( ( docAction.getPermission(  ) != null ) &&
271                         DocumentTypeResourceIdService.PERMISSION_ASSIGN.equals( docAction.getPermission(  ) ) )
272                 {
273                     model.put( MARK_PERMISSION_ASSIGN, 1 );
274                 }
275                 else if ( ( docAction.getPermission(  ) != null ) &&
276                         DocumentTypeResourceIdService.PERMISSION_PUBLISH.equals( docAction.getPermission(  ) ) )
277                 {
278                     model.put( MARK_PERMISSION_PUBLISH, 1 );
279                 }
280             }
281 
282             model.put( MARK_ORDER_PORTLET, nOrderPortlet );
283             model.put( MARK_ORDER_PORTLET_ASC, nOrderPortletAsc );
284             model.put( MARk_DOCUMENT_LIST_PORTLET_LIST, listDocumentListPortlets );
285             model.put( MARK_DOCUMENT_PORTLET_LIST, listDocumentPortlets );
286             model.put( MARK_ASSIGNED_PORTLET, listAssignedPortlets );
287             model.put( MARK_PUBLISHED_STATUS_VALUE, DocumentPublication.STATUS_PUBLISHED );
288             model.put( MARK_DOCUMENT, document );
289             model.put( MARK_UNPUBLISHED_STATUS_VALUE, DocumentPublication.STATUS_UNPUBLISHED );
290             model.put( MARK_PORTLET_FILTER, portletFilter );
291             model.put( MARK_LABEL_DISPLAY_LATEST_PORTLETS,
292                 I18nService.getLocalizedString( PROPERTY_DISPLAY_LATEST_PORTLETS,
293                     messageNumberOfMaxLatestPortletsDisplay, getLocale(  ) ) );
294         }
295 
296         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_DOCUMENT_PUBLISHING, getLocale(  ), model );
297 
298         return getAdminPage( template.getHtml(  ) );
299     }
300 
301     /**
302      * Get the list of authorized portlets.
303      *
304      * Check :
305      * <ul>
306      * <li>if user is authorized to manage DocumentListPortlet</li>
307      * <li>if user is authorized to manage DocumentPortlet</li>
308      * <li>For each portlet :
309      * <ul>
310      * <li>if user is authorized to manage the linked page</li>
311      * <li>if portlet isn't in autopublication mode</li>
312      * </ul>
313      * </li>
314      * </ul>
315      *
316      * @param nDocumentId
317      *            The document id
318      * @param strCodeDocumentType
319      *            The code document type
320      * @param pOrder The portlet order
321      * @param pFilter The portlet filter
322      * @return A collection of {@link ReferenceItem}
323      */
324     private Collection<ReferenceItem> getListAuthorizedDocumentListPortlets( int nDocumentId,
325         String strCodeDocumentType, PortletOrder pOrder, PortletFilter pFilter )
326     {
327         Collection<ReferenceItem> listPortlets = new ArrayList<ReferenceItem>(  );
328 
329         // Check role PERMISSION_MANAGE for DocumentListPortlet
330         if ( RBACService.isAuthorized( PortletType.RESOURCE_TYPE, DocumentListPortlet.RESOURCE_ID,
331                     PortletResourceIdService.PERMISSION_MANAGE, getUser(  ) ) )
332         {
333             listPortlets.addAll( DocumentListPortletHome.findByCodeDocumentTypeAndCategory( nDocumentId,
334                     strCodeDocumentType, pOrder, pFilter ) );
335         }
336 
337         // check ROLE PERMISSION_MANAGE for PAGE and WORKGROUP
338         Collection<ReferenceItem> listFilteredPortlets = filterByWorkgroup( listPortlets, pFilter );
339 
340         return listFilteredPortlets;
341     }
342 
343     /**
344      * Get the list of authorized portlets.
345      *
346      * Check :
347      * <ul>
348      * <li>if user is authorized to manage DocumentListPortlet</li>
349      * <li>if user is authorized to manage DocumentPortlet</li>
350      * <li>For each portlet :
351      * <ul>
352      * <li>if user is authorized to manage the linked page</li>
353      * <li>if portlet isn't in autopublication mode</li>
354      * </ul>
355      * </li>
356      * </ul>
357      *
358      * @param nDocumentId
359      *            The document id
360      * @param strCodeDocumentType
361      *            The code document type
362      * @param pOrder The portlet order
363      * @param pFilter The portlet filter
364      * @return A collection of {@link ReferenceItem}
365      */
366     private Collection<ReferenceItem> getListAuthorizedDocumentPortlets( int nDocumentId, String strCodeDocumentType,
367         PortletOrder pOrder, PortletFilter pFilter )
368     {
369         Collection<ReferenceItem> listPortlets = new ArrayList<ReferenceItem>(  );
370 
371         // Check role PERMISSION_MANAGE for DocumentPortlet
372         if ( RBACService.isAuthorized( PortletType.RESOURCE_TYPE, DocumentPortlet.RESOURCE_ID,
373                     PortletResourceIdService.PERMISSION_MANAGE, getUser(  ) ) )
374         {
375             listPortlets.addAll( DocumentPortletHome.findByCodeDocumentTypeAndCategory( nDocumentId,
376                     strCodeDocumentType, pOrder, pFilter ) );
377         }
378 
379         Collection<ReferenceItem> listFilteredPortlets = filterByWorkgroup( listPortlets, pFilter );
380 
381         return listFilteredPortlets;
382     }
383 
384     /**
385      * Filter the given portlets list by its workgroup
386      *
387      * @param listPortlets
388      *            a collection of {@link ReferenceItem}
389      * @param pFilter The portlet filter
390      * @return a collection of {@link ReferenceItem}
391      */
392     private Collection<ReferenceItem> filterByWorkgroup( Collection<ReferenceItem> listPortlets, PortletFilter pFilter )
393     {
394         // check ROLE PERMISSION_MANAGE for PAGE and WORKGROUP
395         Collection<ReferenceItem> listFilteredPortlets = new ArrayList<ReferenceItem>(  );
396 
397         // Check role PERMISSION_MANAGE for workgroup and page and check if
398         // portlet isn't autopublished
399         for ( ReferenceItem item : listPortlets )
400         {
401             Portlet portlet = PortletHome.findByPrimaryKey( IntegerUtils.convert( item.getCode(  ) ) );
402 
403             if ( ( portlet != null ) && !DocumentAutoPublicationHome.isPortletAutoPublished( portlet.getId(  ) ) &&
404                     PortletService.getInstance(  ).isAuthorized( portlet, getUser(  ) ) )
405             {
406                 Map<String, Object> subModel = new HashMap<String, Object>(  );
407                 subModel.put( MARK_LIST_PAGE,
408                     PortalService.getPagePath( PortletHome.findByPrimaryKey( IntegerUtils.convert( item.getCode(  ) ) )
409                                                           .getPageId(  ) ) );
410                 subModel.put( MARK_PORTLET, item );
411 
412                 HtmlTemplate subTemplate = AppTemplateService.getTemplate( TEMPLATE_PORTLET_PAGE_PATH, getLocale(  ),
413                         subModel );
414                 item.setName( subTemplate.getHtml(  ) );
415 
416                 listFilteredPortlets.add( item );
417 
418                 if ( ( ( pFilter == null ) || pFilter.isDisplayLatestPortlets(  ) ) &&
419                         ( listFilteredPortlets.size(  ) >= PortletFilter.PROPERTY_NUMBER_OF_MAX_LATEST_PORTLETS_DISPLAY ) )
420                 {
421                     break;
422                 }
423             }
424         }
425 
426         return listFilteredPortlets;
427     }
428 
429     /**
430      * Process the publishing article
431      *
432      * @param request
433      *            requete Http
434      * @return The Jsp URL of the process result
435      */
436     public String doAssignedDocument( HttpServletRequest request )
437     {
438         // Recovery of parameters processing
439         int nDocumentId = IntegerUtils.convert( request.getParameter( PARAMETER_DOCUMENT_ID ) );
440         String strPortletId = request.getParameter( PARAMETER_PORTLET_ID );
441 
442         // retrieve the selected portlets ids
443         String[] arrayDocumentListPortletIds = request.getParameterValues( PARAMETER_DOCUMENT_LIST_PORTLET_IDS );
444         String[] arrayDocumentPortletIds = request.getParameterValues( PARAMETER_DOCUMENT_PORTLET_IDS );
445         List<String> listPortletIds = new ArrayList<String>(  );
446 
447         if ( arrayDocumentListPortletIds != null )
448         {
449             for ( String strId : arrayDocumentListPortletIds )
450             {
451                 listPortletIds.add( strId );
452             }
453         }
454 
455         if ( arrayDocumentPortletIds != null )
456         {
457             for ( String strId : arrayDocumentPortletIds )
458             {
459                 listPortletIds.add( strId );
460             }
461         }
462 
463         if ( ( listPortletIds.size(  ) > 0 ) || ( strPortletId != null ) )
464         {
465             if ( strPortletId == null )
466             {
467                 for ( String strId : listPortletIds )
468                 {
469                     int nPortletId = IntegerUtils.convert( strId );
470                     int nStatus = IntegerUtils.convert( request.getParameter( PARAMETER_DOCUMENT_PUBLISHED_STATUS ) );
471 
472                     if ( !PublishingService.getInstance(  ).isAssigned( nDocumentId, nPortletId ) )
473                     {
474                         // Publishing of document : if status =
475                         // DocumentListPortlet.STATUS_UNPUBLISHED (=1), the
476                         // document is assigned, otherwize is assigned AND
477                         // published
478                         PublishingService.getInstance(  ).assign( nDocumentId, nPortletId );
479 
480                         if ( nStatus == DocumentPublication.STATUS_PUBLISHED )
481                         {
482                             PublishingService.getInstance(  ).publish( nDocumentId, nPortletId );
483                         }
484                     }
485                 }
486             }
487             else
488             {
489                 int nIdPortlet = IntegerUtils.convert( strPortletId );
490                 PublishingService.getInstance(  ).publish( nDocumentId, nIdPortlet );
491             }
492         }
493 
494         // Display the page of publishing
495         return getUrlAssignedPage( nDocumentId );
496     }
497 
498     /**
499      * Process of unselecting the article of publishing
500      *
501      * @param request
502      *            requete Http
503      * @return The Jsp URL of the process result
504      */
505     public String doUnAssignedDocument( HttpServletRequest request )
506     {
507         // Recovery of parameters processing
508         int nDocumentId = IntegerUtils.convert( request.getParameter( PARAMETER_DOCUMENT_ID ) );
509         int nPortletId = IntegerUtils.convert( request.getParameter( PARAMETER_PORTLET_ID ) );
510         int nStatus = IntegerUtils.convert( request.getParameter( PARAMETER_DOCUMENT_PUBLISHED_STATUS ) );
511 
512         // Remove the document assigned
513         if ( nStatus != DocumentPublication.STATUS_PUBLISHED )
514         {
515             PublishingService.getInstance(  ).unAssign( nDocumentId, nPortletId );
516         }
517         else
518         {
519             PublishingService.getInstance(  ).unPublish( nDocumentId, nPortletId );
520         }
521 
522         // Display the page of publishing
523         return getUrlAssignedPage( nDocumentId );
524     }
525 
526     /**
527      * Returns the portlet document template management
528      *
529      * @param request
530      *            The Http request
531      * @return the html code
532      */
533     public String getPublishingManagement( HttpServletRequest request )
534     {
535         String strModePublication = request.getParameter( PARAMETER_MODE_PUBLICATION );
536         int nModePublication = MODE_PUBLICATION_STANDARD;
537 
538         // Set commons elements
539         setPageTitleProperty( PROPERTY_MANAGE_PUBLISHING );
540 
541         String strPortletId = request.getParameter( PARAMETER_PORTLET_ID );
542         int nPortletId = IntegerUtils.convert( strPortletId );
543 
544         Portlet portlet = PortletHome.findByPrimaryKey( nPortletId );
545 
546         Map<String, Object> model = new HashMap<String, Object>(  );
547         model.put( MARK_PORTLET, portlet );
548 
549         Page page = PageHome.findByPrimaryKey( portlet.getPageId(  ) );
550         String strPageName = page.getName(  );
551         model.put( MARK_PAGE_NAME, strPageName );
552 
553         // get publication mode
554         if ( DocumentAutoPublicationHome.isPortletAutoPublished( nPortletId ) )
555         {
556             model.put( MARK_MODE_PUBLICATION, MODE_PUBLICATION_AUTO_PUBLICATION );
557 
558             return getAutoPublicationManagement( request, model, nPortletId );
559         }
560 
561         if ( ( strModePublication == null ) || !strModePublication.matches( REGEX_ID ) )
562         {
563             model.put( MARK_MODE_PUBLICATION, MODE_PUBLICATION_STANDARD );
564 
565             return getStandardPublication( request, model, nPortletId );
566         }
567 
568         nModePublication = IntegerUtils.convert( strModePublication );
569 
570         model.put( MARK_MODE_PUBLICATION, nModePublication );
571 
572         switch ( nModePublication )
573         {
574             case MODE_PUBLICATION_AUTO_PUBLICATION:
575                 return getAutoPublicationManagement( request, model, nPortletId );
576 
577             default:
578                 return getStandardPublication( request, model, nPortletId );
579         }
580     }
581 
582     /**
583      * Returns the portlet document template management
584      *
585      * @param request
586      *            The Http request
587      * @return the html code
588      */
589     public String doConfirmChangeModePublication( HttpServletRequest request )
590     {
591         String strOldModePublication = request.getParameter( PARAMETER_OLD_MODE_PUBLICATION );
592         String strModePublication = request.getParameter( PARAMETER_MODE_PUBLICATION );
593         String strPortletId = request.getParameter( PARAMETER_PORTLET_ID );
594         int nPortletId = IntegerUtils.convert( strPortletId );
595         UrlItem url = new UrlItem( JSP_CHANGE_MODE_PUBLICATION );
596         url.addParameter( PARAMETER_PORTLET_ID, strPortletId );
597         url.addParameter( PARAMETER_MODE_PUBLICATION, strModePublication );
598         url.addParameter( PARAMETER_OLD_MODE_PUBLICATION, strOldModePublication );
599 
600         String strMessage = null;
601 
602         if ( !strOldModePublication.equals( strModePublication ) )
603         {
604             switch ( IntegerUtils.convert( strOldModePublication ) )
605             {
606                 case MODE_PUBLICATION_AUTO_PUBLICATION:
607 
608                     if ( DocumentAutoPublicationHome.findByPortletId( nPortletId ).size(  ) > 0 )
609                     {
610                         strMessage = MESSAGE_CONFIRM_CHANGE_MODE_PUBLICATION_AUTO_PUBLICATION;
611                     }
612 
613                     break;
614 
615                 default:
616 
617                     if ( PublishingService.getInstance(  ).getAssignedDocumentsByPortletId( nPortletId ).size(  ) > 0 )
618                     {
619                         strMessage = MESSAGE_CONFIRM_CHANGE_MODE_PUBLICATION_STANDARD;
620                     }
621             }
622         }
623 
624         if ( strMessage != null )
625         {
626             return AdminMessageService.getMessageUrl( request, strMessage, url.getUrl(  ),
627                 AdminMessage.TYPE_CONFIRMATION );
628         }
629         else
630         {
631             return doChangeModePublication( request );
632         }
633     }
634 
635     /**
636      * Returns the portlet document template management
637      *
638      * @param request
639      *            The Http request
640      * @return the html code
641      */
642     public String doChangeModePublication( HttpServletRequest request )
643     {
644         String strModePublication = request.getParameter( PARAMETER_MODE_PUBLICATION );
645         String strOldModePublication = request.getParameter( PARAMETER_OLD_MODE_PUBLICATION );
646         String strPortletId = request.getParameter( PARAMETER_PORTLET_ID );
647         int nPortletId = IntegerUtils.convert( strPortletId );
648         int nModePublication = MODE_PUBLICATION_STANDARD;
649         int nOldModePublication = MODE_PUBLICATION_STANDARD;
650 
651         if ( ( strModePublication != null ) && strModePublication.matches( REGEX_ID ) )
652         {
653             nModePublication = IntegerUtils.convert( strModePublication );
654         }
655 
656         if ( ( strOldModePublication != null ) && strOldModePublication.matches( REGEX_ID ) )
657         {
658             nOldModePublication = IntegerUtils.convert( strOldModePublication );
659         }
660 
661         if ( nOldModePublication != nModePublication )
662         {
663             // Process to old publication mode configuration cleaning and
664             // document unpublication
665             switch ( nOldModePublication )
666             {
667                 case MODE_PUBLICATION_AUTO_PUBLICATION:
668                     DocumentAutoPublicationHome.removeAllSpaces( nPortletId );
669 
670                 default:
671 
672                     for ( Document document : PublishingService.getInstance(  )
673                                                                .getPublishedDocumentsByPortletId( nPortletId ) )
674                     {
675                         PublishingService.getInstance(  ).unPublish( document.getId(  ), nPortletId );
676                     }
677 
678                     for ( Document document : PublishingService.getInstance(  )
679                                                                .getAssignedDocumentsByPortletId( nPortletId ) )
680                     {
681                         PublishingService.getInstance(  ).unAssign( document.getId(  ), nPortletId );
682                     }
683             }
684         }
685 
686         UrlItem url = new UrlItem( JSP_DOCUMENTS_PUBLISHING );
687         url.addParameter( PARAMETER_PORTLET_ID, nPortletId );
688         url.addParameter( PARAMETER_MODE_PUBLICATION, nModePublication );
689 
690         return url.getUrl(  );
691     }
692 
693     /**
694      * Process the publishing article
695      *
696      * @param request
697      *            requete Http
698      * @return The Jsp URL of the process result
699      */
700     public String doPublishingDocument( HttpServletRequest request )
701     {
702         // Recovery of parameters processing
703         int nDocumentId = IntegerUtils.convert( request.getParameter( PARAMETER_DOCUMENT_ID ) );
704         int nPortletId = IntegerUtils.convert( request.getParameter( PARAMETER_PORTLET_ID ) );
705 
706         PublishingService.getInstance(  ).publish( nDocumentId, nPortletId );
707 
708         // Display the page of publishing
709         return getUrlPublishedPage( nPortletId, nDocumentId );
710     }
711 
712     /**
713      * Process of unselecting the article of publishing
714      *
715      * @param request
716      *            requete Http
717      * @return The Jsp URL of the process result
718      */
719     public String doUnPublishingDocument( HttpServletRequest request )
720     {
721         // Recovery of parameters processing
722         int nDocumentId = IntegerUtils.convert( request.getParameter( PARAMETER_DOCUMENT_ID ) );
723         int nPortletId = IntegerUtils.convert( request.getParameter( PARAMETER_PORTLET_ID ) );
724         PublishingService.getInstance(  ).unPublish( nDocumentId, nPortletId );
725 
726         // Display the page of publishing
727         return getUrlPublishedPage( nPortletId, nDocumentId );
728     }
729 
730     /**
731      * Modifies the order in the list of contacts
732      *
733      * @param request
734      *            The Http request
735      * @return The Jsp URL of the process result
736      */
737     public String doModifyDocumentOrder( HttpServletRequest request )
738     {
739         int nDocumentId = IntegerUtils.convert( request.getParameter( PARAMETER_DOCUMENT_ID ) );
740         int nPortletId = IntegerUtils.convert( request.getParameter( PARAMETER_PORTLET_ID ) );
741         int nNewOrder = IntegerUtils.convert( request.getParameter( PARAMETER_DOCUMENT_ORDER ) );
742 
743         PublishingService.getInstance(  ).changeDocumentOrder( nDocumentId, nPortletId, nNewOrder );
744 
745         // Display the page of publishing
746         return getUrlPublishedPage( nPortletId, nDocumentId );
747     }
748 
749     // ////////////////////////////////////////////////////////////////////////////////
750     // Auto publication
751 
752     /**
753      * Generate the html code for auto publication creation page
754      *
755      * @param request
756      *            The {@link HttpServletRequest} request
757      * @return The Html code
758      */
759     public String getCreateAutoPublication( HttpServletRequest request )
760     {
761         String strSpaceId = request.getParameter( DocumentSpacesService.PARAMETER_BROWSER_SELECTED_SPACE_ID );
762         boolean bSubmitButtonDisabled = Boolean.TRUE;
763 
764         setPageTitleProperty( PROPERTY_CREATE_AUTO_PUBLICATION );
765 
766         String strPortletId = request.getParameter( PARAMETER_PORTLET_ID );
767 
768         Map<String, Object> model = new HashMap<String, Object>(  );
769         model.put( MARK_PORTLET_ID, strPortletId );
770 
771         if ( ( strSpaceId != null ) && !strSpaceId.equals( "" ) )
772         {
773             bSubmitButtonDisabled = Boolean.FALSE;
774         }
775 
776         model.put( MARK_SUBMIT_BUTTON_DISABLED, bSubmitButtonDisabled );
777         model.put( MARK_SPACES_BROWSER,
778             DocumentSpacesService.getInstance(  ).getSpacesBrowser( request, getUser(  ), getLocale(  ), true, true ) );
779 
780         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CREATE_AUTO_PUBLICATION, getLocale(  ), model );
781 
782         return getAdminPage( template.getHtml(  ) );
783     }
784 
785     /**
786      * Process to the creation of auto publication object
787      *
788      * @param request
789      *            The {@link HttpServletRequest} request
790      * @return The Jsp URL of the process result
791      */
792     public String doCreateAutoPublication( HttpServletRequest request )
793     {
794         String strPortletId = request.getParameter( PARAMETER_PORTLET_ID );
795         String strSpaceId = request.getParameter( DocumentSpacesService.PARAMETER_BROWSER_SELECTED_SPACE_ID );
796         int nPortletId = IntegerUtils.convert( strPortletId );
797         int nSpaceId = IntegerUtils.convert( strSpaceId );
798         DocumentAutoPublication documentAutoPublication = DocumentAutoPublicationHome.findByPrimaryKey( nPortletId,
799                 nSpaceId );
800 
801         if ( documentAutoPublication == null )
802         {
803             // Create Auto publication
804             documentAutoPublication = new DocumentAutoPublication(  );
805             documentAutoPublication.setIdPortlet( nPortletId );
806             documentAutoPublication.setIdSpace( nSpaceId );
807             DocumentAutoPublicationHome.add( documentAutoPublication );
808         }
809         else
810         {
811             return AdminMessageService.getMessageUrl( request, MESSAGE_AUTO_PUBLICATION_ALREADY_EXISTS,
812                 AdminMessage.TYPE_STOP );
813         }
814 
815         return getUrlPublishingModeAutoPublication( nPortletId );
816     }
817 
818     /**
819      * Set the confirmation message for deletion of auto publication object
820      *
821      * @param request
822      *            The {@link HttpServletRequest} request
823      * @return The Jsp URL of the process result
824      */
825     public String getConfirmDeleteAutoPublication( HttpServletRequest request )
826     {
827         String strPortletId = request.getParameter( PARAMETER_PORTLET_ID );
828         String strSpaceId = request.getParameter( PARAMETER_SPACE_ID );
829         int nPortletId = IntegerUtils.convert( strPortletId );
830         int nSpaceId = IntegerUtils.convert( strSpaceId );
831         UrlItem url = new UrlItem( JSP_DELETE_AUTO_PUBLICATION );
832         url.addParameter( PARAMETER_PORTLET_ID, nPortletId );
833         url.addParameter( PARAMETER_MODE_PUBLICATION, MODE_PUBLICATION_AUTO_PUBLICATION );
834         url.addParameter( PARAMETER_SPACE_ID, nSpaceId );
835 
836         return AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_DELETE_AUTO_PUBLICATION, url.getUrl(  ),
837             AdminMessage.TYPE_CONFIRMATION );
838     }
839 
840     /**
841      * Process to the deletion of auto publication object
842      *
843      * @param request
844      *            The {@link HttpServletRequest} request
845      * @return The Jsp URL of the process result
846      */
847     public String doDeleteAutoPublication( HttpServletRequest request )
848     {
849         String strPortletId = request.getParameter( PARAMETER_PORTLET_ID );
850         String strSpaceId = request.getParameter( PARAMETER_SPACE_ID );
851         int nPortletId = IntegerUtils.convert( strPortletId );
852         int nSpaceId = IntegerUtils.convert( strSpaceId );
853 
854         // delete auto publication
855         DocumentAutoPublicationHome.remove( nPortletId, nSpaceId );
856 
857         for ( Document document : PublishingService.getInstance(  ).getPublishedDocumentsByPortletId( nPortletId ) )
858         {
859             if ( PublishingService.getInstance(  ).isPublished( document.getId(  ), nPortletId ) )
860             {
861                 PublishingService.getInstance(  ).unPublish( document.getId(  ), nPortletId );
862                 PublishingService.getInstance(  ).unAssign( document.getId(  ), nPortletId );
863             }
864         }
865 
866         return getUrlPublishingModeAutoPublication( nPortletId );
867     }
868 
869     // ////////////////////////////////////////////////////////////////////////////////
870     // Private implementation
871 
872     /**
873      * Returns an html template containing the list of the portlet types
874      *
875      * @param document
876      *            The document object
877      * @param nPortletId
878      *            The Portet Identifier
879      * @return The html code
880      */
881     private String getPublishedDocumentsList( Document document, int nPortletId )
882     {
883         Map<String, Object> model = new HashMap<String, Object>(  );
884 
885         DocumentService.getInstance(  ).getActions( document, getLocale(  ), getUser(  ) );
886 
887         for ( Object action : document.getActions(  ) )
888         {
889             DocumentAction/../../../fr/paris/lutece/plugins/document/business/workflow/DocumentAction.html#DocumentAction">DocumentAction docAction = (DocumentAction) action;
890 
891             if ( ( docAction != null ) && ( docAction.getPermission(  ) != null ) &&
892                     docAction.getPermission(  ).equals( DocumentTypeResourceIdService.PERMISSION_PUBLISH ) )
893             {
894                 model.put( MARK_PERMISSION_PUBLISH, 1 );
895             }
896         }
897 
898         DocumentPublication documentPublication = PublishingService.getInstance(  )
899                                                                    .getDocumentPublication( nPortletId,
900                 document.getId(  ) );
901         model.put( MARK_PORTLET_ID, Integer.toString( nPortletId ) );
902         model.put( MARK_DOCUMENT_PUBLISHED_STATUS, Integer.toString( documentPublication.getStatus(  ) ) );
903         model.put( MARK_PUBLISHED_STATUS_VALUE, Integer.toString( DocumentPublication.STATUS_PUBLISHED ) );
904         model.put( MARK_DOCUMENT_PUBLISHED, document );
905         model.put( MARK_DOCUMENT_ORDER_LIST, getOrdersList( nPortletId ) );
906         model.put( MARK_DOCUMENT_ORDER, Integer.toString( documentPublication.getDocumentOrder(  ) ) );
907 
908         // Page Template display
909         DocumentPageTemplate documentPageTemplate = DocumentPageTemplateHome.findByPrimaryKey( document.getPageTemplateDocumentId(  ) );
910         model.put( MARK_DOCUMENT_PAGE_TEMPLATE_PICTURE, documentPageTemplate.getPicture(  ) );
911 
912         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_PUBLISHED_DOCUMENT_LIST, getLocale(  ), model );
913 
914         return template.getHtml(  );
915     }
916 
917     /**
918      * Returns an html template containing the list of the portlet types
919      *
920      * @param document
921      *            The document object
922      * @param nPortletId
923      *            The Portet Identifier
924      * @return The html code
925      */
926     private String getAssignedDocumentsList( Document document, int nPortletId )
927     {
928         Map<String, Object> model = new HashMap<String, Object>(  );
929 
930         DocumentService.getInstance(  ).getActions( document, getLocale(  ), getUser(  ) );
931 
932         for ( Object action : document.getActions(  ) )
933         {
934             DocumentAction/../../../fr/paris/lutece/plugins/document/business/workflow/DocumentAction.html#DocumentAction">DocumentAction docAction = (DocumentAction) action;
935 
936             if ( ( docAction.getPermission(  ) != null ) &&
937                     docAction.getPermission(  ).equals( DocumentTypeResourceIdService.PERMISSION_ASSIGN ) )
938             {
939                 model.put( MARK_PERMISSION_ASSIGN, 1 );
940             }
941             else if ( ( docAction.getPermission(  ) != null ) &&
942                     docAction.getPermission(  ).equals( DocumentTypeResourceIdService.PERMISSION_PUBLISH ) )
943             {
944                 model.put( MARK_PERMISSION_PUBLISH, 1 );
945             }
946         }
947 
948         DocumentPublication documentPublication = PublishingService.getInstance(  )
949                                                                    .getDocumentPublication( nPortletId,
950                 document.getId(  ) );
951         model.put( MARK_PORTLET_ID, Integer.toString( nPortletId ) );
952         model.put( MARK_DOCUMENT_PUBLISHED_STATUS, Integer.toString( documentPublication.getStatus(  ) ) );
953         model.put( MARK_UNPUBLISHED_STATUS_VALUE, Integer.toString( DocumentPublication.STATUS_UNPUBLISHED ) );
954         model.put( MARK_DOCUMENT_PUBLISHED, document );
955 
956         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_ASSIGNED_DOCUMENT_LIST, getLocale(  ), model );
957 
958         return template.getHtml(  );
959     }
960 
961     /**
962      * Builts a list of sequence numbers
963      *
964      * @param nPortletId
965      *            the portlet identifier
966      * @return the list of sequence numbers
967      */
968     private ReferenceList getOrdersList( int nPortletId )
969     {
970         int nMax = PublishingService.getInstance(  ).getMaxDocumentOrderByPortletId( nPortletId );
971         ReferenceList list = new ReferenceList(  );
972 
973         for ( int i = 1; i < ( nMax + 1 ); i++ )
974         {
975             list.addItem( i, Integer.toString( ( i ) ) );
976         }
977 
978         return list;
979     }
980 
981     /**
982      * Return AdminSite Url
983      *
984      * @param nId
985      *            The PageId
986      * @return url
987      */
988     private String getUrlAssignedPage( int nId )
989     {
990         UrlItem url = new UrlItem( JSP_DOCUMENTS_ASSIGN );
991         url.addParameter( PARAMETER_DOCUMENT_ID, nId );
992 
993         return url.getUrl(  );
994     }
995 
996     /**
997      * Return AdminSite Url
998      *
999      * @param nPortletId The portlet id
1000      * @param nDocumentId The document id
1001      * @return url
1002      */
1003     private String getUrlPublishedPage( int nPortletId, int nDocumentId )
1004     {
1005         UrlItem url = new UrlItem( JSP_DOCUMENTS_PUBLISHING );
1006         url.addParameter( PARAMETER_PORTLET_ID, nPortletId );
1007         url.addParameter( PARAMETER_DOCUMENT_ID, nDocumentId );
1008 
1009         return url.getUrl(  );
1010     }
1011 
1012     /**
1013      * Return AdminSite Url
1014      *
1015      * @param nPortletId
1016      *            The portlet Id
1017      * @return url
1018      */
1019     private String getUrlPublishingModeAutoPublication( int nPortletId )
1020     {
1021         UrlItem url = new UrlItem( JSP_DOCUMENTS_PUBLISHING );
1022         url.addParameter( PARAMETER_PORTLET_ID, nPortletId );
1023         url.addParameter( PARAMETER_MODE_PUBLICATION, MODE_PUBLICATION_AUTO_PUBLICATION );
1024 
1025         return url.getUrl(  );
1026     }
1027 
1028     /**
1029      * Generate html for standard publication management page
1030      *
1031      * @param request
1032      *            The {@link HttpServletRequest} request
1033      * @param model
1034      *            The {@link HashMap} for the template
1035      * @param nPortletId
1036      *            The portlet Id
1037      * @return The HTML code
1038      */
1039     private String getStandardPublication( HttpServletRequest request, Map<String, Object> model, int nPortletId )
1040     {
1041         StringBuffer strPublishedDocumentsRow = new StringBuffer(  );
1042 
1043         // Scan of the list
1044         for ( Document document : PublishingService.getInstance(  ).getAssignedDocumentsByPortletId( nPortletId ) )
1045         {
1046             strPublishedDocumentsRow.append( getPublishedDocumentsList( document, nPortletId ) );
1047         }
1048 
1049         Map<String, Object> publishedDocumentListModel = new HashMap<String, Object>(  );
1050         publishedDocumentListModel.put( MARK_PUBLISHED_DOCUMENT_LIST, strPublishedDocumentsRow );
1051 
1052         HtmlTemplate publishedDocumentListTemplate = AppTemplateService.getTemplate( TEMPLATE_PUBLISHED_DOCUMENT_LIST_CONTAINER,
1053                 getLocale(  ), publishedDocumentListModel );
1054 
1055         model.put( MARK_PUBLISHED_DOCUMENT_LIST, publishedDocumentListTemplate.getHtml(  ) );
1056 
1057         StringBuffer strAssignedDocumentsRow = new StringBuffer(  );
1058 
1059         // Scan of the list
1060         for ( Document document : PublishingService.getInstance(  ).getAssignedDocumentsByPortletId( nPortletId ) )
1061         {
1062             strAssignedDocumentsRow.append( getAssignedDocumentsList( document, nPortletId ) );
1063         }
1064 
1065         Map<String, Object> assignedDocumentListModel = new HashMap<String, Object>(  );
1066         assignedDocumentListModel.put( MARK_ASSIGNED_DOCUMENT_LIST, strAssignedDocumentsRow );
1067 
1068         HtmlTemplate assignedDocumentListTemplate = AppTemplateService.getTemplate( TEMPLATE_ASSIGNED_DOCUMENT_LIST_CONTAINER,
1069                 getLocale(  ), assignedDocumentListModel );
1070 
1071         model.put( MARK_ASSIGNED_DOCUMENT_LIST, assignedDocumentListTemplate.getHtml(  ) );
1072 
1073         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_PORTLET_PUBLISHING, getLocale(  ), model );
1074 
1075         return getAdminPage( template.getHtml(  ) );
1076     }
1077 
1078     /**
1079      * Generate html for auto publication management page
1080      *
1081      * @param request
1082      *            The {@link HttpServletRequest} request
1083      * @param model
1084      *            The {@link HashMap} for the template
1085      * @param nPortletId
1086      *            The portlet Id
1087      * @return The HTML code
1088      */
1089     private String getAutoPublicationManagement( HttpServletRequest request, Map<String, Object> model, int nPortletId )
1090     {
1091         Collection<DocumentAutoPublication> listDocumentAutoPublication = DocumentAutoPublicationHome.findByPortletId( nPortletId );
1092         Collection<Map<String, Object>> listModels = new ArrayList<Map<String, Object>>(  );
1093         DocumentSpace documentSpace;
1094         AdminUser user = getUser(  );
1095 
1096         for ( DocumentAutoPublication documentAutoPublication : listDocumentAutoPublication )
1097         {
1098             // Check if user is authorized to view space
1099             if ( DocumentSpacesService.getInstance(  )
1100                                           .isAuthorizedViewByRole( documentAutoPublication.getIdSpace(  ), getUser(  ) ) )
1101             {
1102                 Map<String, Object> subModel = new HashMap<String, Object>(  );
1103 
1104                 if ( DocumentSpacesService.getInstance(  )
1105                                               .isAuthorizedViewByWorkgroup( documentAutoPublication.getIdSpace(  ), user ) )
1106                 {
1107                     documentSpace = DocumentSpaceHome.findByPrimaryKey( documentAutoPublication.getIdSpace(  ) );
1108                     subModel.put( MARK_SPACE_NAME,
1109                         ( documentSpace != null ) ? documentSpace.getName(  ) : StringUtils.EMPTY );
1110 
1111                     int nCountDocuments = AutoPublicationService.findCountByPortletAndSpace( documentAutoPublication.getIdPortlet(  ),
1112                             documentAutoPublication.getIdSpace(  ) );
1113                     subModel.put( MARK_NUMBER_AUTO_PUBLISHED_DOCUMENTS, nCountDocuments );
1114                     subModel.put( MARK_DOCUMENT_AUTO_PUBLICATION, documentAutoPublication );
1115                     listModels.add( subModel );
1116                 }
1117             }
1118         }
1119 
1120         model.put( MARK_LIST_AUTO_PUBLICATION, listModels );
1121 
1122         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_PORTLET_PUBLISHING, getLocale(  ), model );
1123 
1124         return getAdminPage( template.getHtml(  ) );
1125     }
1126 
1127     /**
1128      * Fill the searchFilter
1129      * @param portletFilter {@link PortletFilter}
1130      * @return return error message if an error appear
1131      */
1132     public String setFillFilter( PortletFilter portletFilter )
1133     {
1134         String strErrorMessage = null;
1135         String strValue = null;
1136 
1137         if ( ( portletFilter.getSearchValue(  ) != null ) && !portletFilter.getSearchValue(  ).trim(  ).equals( "" ) &&
1138                 ( portletFilter.getPortletFilterType(  ) != null ) )
1139         {
1140             strValue = portletFilter.getSearchValue(  ).trim(  );
1141 
1142             if ( portletFilter.getPortletFilterType(  ).equals( PortletFilter.PAGE_NAME ) )
1143             {
1144                 portletFilter.setPageName( strValue.split( PortletFilter.CONSTANTE_SPACE_STRING ) );
1145             }
1146             else if ( portletFilter.getPortletFilterType(  ).equals( PortletFilter.PORTLET_NAME ) )
1147             {
1148                 portletFilter.setPortletName( strValue.split( PortletFilter.CONSTANTE_SPACE_STRING ) );
1149             }
1150             else if ( portletFilter.getPortletFilterType(  ).equals( PortletFilter.PAGE_ID ) )
1151             {
1152                 if ( StringUtils.isNumeric( strValue ) )
1153                 {
1154                     portletFilter.setIdPage( IntegerUtils.convert( strValue ) );
1155                 }
1156                 else
1157                 {
1158                     strErrorMessage = I18nService.getLocalizedString( ERROR_MESSAGE_NOT_NUMERIC_FIELD, getLocale(  ) );
1159                 }
1160             }
1161         }
1162 
1163         else
1164         {
1165             strErrorMessage = I18nService.getLocalizedString( ERROR_MESSAGE_MESSAGE_MANDATORY_SEARCH_FIELD,
1166                     getLocale(  ) );
1167         }
1168 
1169         return strErrorMessage;
1170     }
1171 }