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.blog.web;
35  
36  import java.io.ByteArrayInputStream;
37  import java.io.IOException;
38  import java.io.InputStream;
39  import java.io.StringWriter;
40  import java.net.URLConnection;
41  import java.nio.charset.StandardCharsets;
42  import java.sql.Timestamp;
43  import java.text.ParseException;
44  import java.text.SimpleDateFormat;
45  import java.util.ArrayList;
46  import java.util.Base64;
47  import java.util.Collections;
48  import java.util.HashMap;
49  import java.util.List;
50  import java.util.Locale;
51  import java.util.Map;
52  import java.util.stream.Collectors;
53  
54  import javax.servlet.http.HttpServletRequest;
55  import javax.servlet.http.HttpSession;
56  import javax.xml.transform.OutputKeys;
57  import javax.xml.transform.TransformerFactory;
58  import javax.xml.transform.sax.SAXTransformerFactory;
59  import javax.xml.transform.sax.TransformerHandler;
60  import javax.xml.transform.stream.StreamResult;
61  
62  import fr.paris.lutece.plugins.blog.utils.BlogUtils;
63  import org.apache.commons.collections.CollectionUtils;
64  import org.apache.commons.fileupload.FileItem;
65  import org.apache.commons.lang3.ArrayUtils;
66  import org.apache.commons.lang3.StringUtils;
67  import org.outerj.daisy.diff.HtmlCleaner;
68  import org.outerj.daisy.diff.html.HTMLDiffer;
69  import org.outerj.daisy.diff.html.HtmlSaxDiffOutput;
70  import org.outerj.daisy.diff.html.TextNodeComparator;
71  import org.outerj.daisy.diff.html.dom.DomTreeBuilder;
72  import org.xml.sax.InputSource;
73  
74  import fr.paris.lutece.api.user.User;
75  import fr.paris.lutece.plugins.blog.business.Blog;
76  import fr.paris.lutece.plugins.blog.business.BlogHome;
77  import fr.paris.lutece.plugins.blog.business.BlogSearchFilter;
78  import fr.paris.lutece.plugins.blog.business.ContentType;
79  import fr.paris.lutece.plugins.blog.business.DocContent;
80  import fr.paris.lutece.plugins.blog.business.DocContentHome;
81  import fr.paris.lutece.plugins.blog.business.Tag;
82  import fr.paris.lutece.plugins.blog.business.TagHome;
83  import fr.paris.lutece.plugins.blog.business.portlet.BlogPublication;
84  import fr.paris.lutece.plugins.blog.business.portlet.BlogPublicationHome;
85  import fr.paris.lutece.plugins.blog.service.BlogService;
86  import fr.paris.lutece.plugins.blog.service.BlogServiceSession;
87  import fr.paris.lutece.plugins.blog.service.BlogSessionListner;
88  import fr.paris.lutece.plugins.blog.service.docsearch.BlogSearchService;
89  import fr.paris.lutece.plugins.blog.utils.BlogLock;
90  import fr.paris.lutece.portal.business.rbac.RBAC;
91  import fr.paris.lutece.portal.business.user.AdminUser;
92  import fr.paris.lutece.portal.service.admin.AccessDeniedException;
93  import fr.paris.lutece.portal.service.admin.AdminUserService;
94  import fr.paris.lutece.portal.service.datastore.DatastoreService;
95  import fr.paris.lutece.portal.service.message.AdminMessage;
96  import fr.paris.lutece.portal.service.message.AdminMessageService;
97  import fr.paris.lutece.portal.service.rbac.RBACService;
98  import fr.paris.lutece.portal.service.resource.ExtendableResourceRemovalListenerService;
99  import fr.paris.lutece.portal.service.util.AppLogService;
100 import fr.paris.lutece.portal.service.util.AppPathService;
101 import fr.paris.lutece.portal.service.util.AppPropertiesService;
102 import fr.paris.lutece.portal.util.mvc.admin.annotations.Controller;
103 import fr.paris.lutece.portal.util.mvc.commons.annotations.Action;
104 import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
105 import fr.paris.lutece.portal.web.resource.ExtendableResourcePluginActionManager;
106 import fr.paris.lutece.portal.web.upload.MultipartHttpServletRequest;
107 import fr.paris.lutece.portal.web.util.LocalizedPaginator;
108 import fr.paris.lutece.util.ReferenceList;
109 import fr.paris.lutece.util.date.DateUtil;
110 import fr.paris.lutece.util.html.AbstractPaginator;
111 import fr.paris.lutece.util.json.JsonResponse;
112 import fr.paris.lutece.util.json.JsonUtil;
113 import fr.paris.lutece.util.sort.AttributeComparator;
114 import fr.paris.lutece.util.url.UrlItem;
115 
116 /**
117  * This class provides the user interface to manage Blog features ( manage, create, modify, remove )
118  */
119 @Controller( controllerJsp = "ManageBlogs.jsp", controllerPath = "jsp/admin/plugins/blog/", right = "BLOG_MANAGEMENT" )
120 public class BlogJspBean extends ManageBlogJspBean
121 {
122     private static final long serialVersionUID = 9149742923528515045L;
123 
124     // Templates
125     private static final String TEMPLATE_MANAGE_BLOGS = "/admin/plugins/blog/manage_blogs.html";
126     private static final String TEMPLATE_CREATE_BLOG = "/admin/plugins/blog/create_blog.html";
127     private static final String TEMPLATE_MODIFY_BLOG = "/admin/plugins/blog/modify_blog.html";
128     private static final String TEMPLATE_HISTORY_BLOG = "admin/plugins/blog/history_blog.html";
129     private static final String TEMPLATE_PREVIEW_BLOG = "admin/plugins/blog/preview_blog.html";
130     private static final String TEMPLATE_DIFF_BLOG = "admin/plugins/blog/diff_blog.html";
131 
132     // Parameters
133     protected static final String PARAMETER_ID_BLOG = "id";
134     protected static final String PARAMETER_VERSION_BLOG = "blog_version";
135     protected static final String PARAMETER_VERSION_BLOG2 = "blog_version2";
136     protected static final String PARAMETER_CONTENT_LABEL = "content_label";
137     protected static final String PARAMETER_HTML_CONTENT = "html_content";
138     protected static final String PARAMETER_EDIT_COMMENT = "edit_comment";
139     protected static final String PARAMETER_DESCRIPTION = "description";
140     protected static final String PARAMETER_FILE_NAME = "fileName";
141     protected static final String PARAMETER_VIEW = "view";
142     protected static final String PARAMETER_BUTTON_SEARCH = "button_search";
143     protected static final String PARAMETER_BUTTON_RESET = "button_reset";
144 
145     protected static final String PARAMETER_SEARCH_TEXT = "search_text";
146     protected static final String PARAMETER_UPDATE_ATTACHMENT = "update_attachment";
147     protected static final String PARAMETER_TAG = "tag_doc";
148     protected static final String PARAMETER_TAG_NAME = "tag_name";
149     protected static final String PARAMETER_URL = "url";
150     protected static final String PARAMETER_UNPUBLISHED = "unpublished";
151     protected static final String PARAMETER_DATE_UPDATE_BLOG_AFTER = "dateUpdateBlogAfter";
152     protected static final String PARAMETER_DATE_UPDATE_BLOG_BEFOR = "dateUpdateBlogBefor";
153 
154     protected static final String PARAMETER_TAG_TO_REMOVE = "tag_remove";
155     protected static final String PARAMETER_SHAREABLE = "shareable";
156     protected static final String PARAMETER_PRIORITY = "tag_priority";
157     protected static final String PARAMETER_TAG_ACTION = "tagAction";
158     protected static final String PARAMETER_ACTION_BUTTON = "button";
159     protected static final String PARAMETER_APPLY = "apply";
160     protected static final String PARAMETER_TYPE_ID = "idType";
161     protected static final String PARAMETER_CONTENT_ID = "idContent";
162     protected static final String PARAMETER_CONTENT_ACTION = "contentAction";
163 
164     // Properties for page titles
165     private static final String PROPERTY_PAGE_TITLE_MANAGE_BLOG = "blog.manage_blog.pageTitle";
166     private static final String PROPERTY_PAGE_TITLE_MODIFY_BLOG = "blog.modify_blog.pageTitle";
167     private static final String PROPERTY_PAGE_TITLE_CREATE_BLOG = "blog.create_blog.pageTitle";
168     private static final String PROPERTY_PAGE_TITLE_HISTORY_BLOG = "blog.history_blog.pageTitle";
169     private static final String PROPERTY_PAGE_TITLE_PREVIEW_BLOG = "blog.preview_blog.pageTitle";
170     private static final String PROPERTY_PAGE_TITLE_DIFF_BLOG = "blog.diff_blog.pageTitle";
171     protected static final String PROPERTY_USE_UPLOAD_IMAGE_PLUGIN = "use_upload_image_plugin";
172 
173     // Properties
174     private static final String PROPERTY_DEFAULT_LIST_ITEM_PER_PAGE = "blog.listItems.itemsPerPage";
175 
176     // Markers
177     protected static final String MARK_BLOG_LIST = "blog_list";
178     protected static final String MARK_BLOG_VERSION_LIST = "blog_version_list";
179     protected static final String MARK_BLOG = "blog";
180     protected static final String MARK_WEBAPP_URL = "webapp_url";
181     protected static final String MARK_IS_CHECKED = "is_checked";
182     protected static final String MARK_CURRENT_USER = "current_user";
183     protected static final String MARK_ID_BLOG = "id";
184     protected static final String MARK_SEARCH_TEXT = "search_text";
185     protected static final String MARK_DIFF = "blog_diff";
186     protected static final String MARK_BLOG2 = "blog2";
187     protected static final String MARK_LIST_TAG = "list_tag";
188     protected static final String MARK_LIST_IMAGE_TYPE = "image_type";
189     protected static final String MARK_SORTED_ATTRIBUTE = "sorted_attribute_name";
190     protected static final String MARK_TAG = "tags";
191     protected static final String MARK_USE_UPLOAD_IMAGE_PLUGIN = "is_crop_image";
192     protected static final String MARK_PERMISSION_CREATE_BLOG = "permission_manage_create_blog";
193     protected static final String MARK_PERMISSION_MODIFY_BLOG = "permission_manage_modify_blog";
194     protected static final String MARK_PERMISSION_PUBLISH_BLOG = "permission_manage_publish_blog";
195     protected static final String MARK_PERMISSION_DELETE_BLOG = "permission_manage_delete_blog";
196 
197     private static final String JSP_MANAGE_BLOGS = "jsp/admin/plugins/blog/ManageBlogs.jsp";
198 
199     // Properties
200     private static final String MESSAGE_CONFIRM_REMOVE_BLOG = "blog.message.confirmRemoveBlog";
201     private static final String MESSAGE_ERROR_DOCUMENT_IS_PUBLISHED = "blog.message.errorDocumentIsPublished";
202     private static final String MESSAGE_CONFIRM_REMOVE_HISTORY_BLOG = "blog.message.confirmRemoveHistoryBlog";
203 
204     // Validations
205     private static final String VALIDATION_ATTRIBUTES_PREFIX = "blog.model.entity.blog.attribute.";
206 
207     // Views
208     protected static final String VIEW_MANAGE_BLOGS = "manageBlogs";
209     private static final String VIEW_CREATE_BLOG = "createBlog";
210     private static final String VIEW_MODIFY_BLOG = "modifyBlog";
211     private static final String VIEW_HISTORY_BLOG = "historyBlog";
212     private static final String VIEW_PREVIEW_BLOG = "previewBlog";
213     private static final String VIEW_DIFF_BLOG = "diffBlog";
214 
215     // Actions
216     private static final String ACTION_CREATE_BLOG = "createBlog";
217     private static final String ACTION_MODIFY_BLOG = "modifyBlog";
218     private static final String ACTION_REMOVE_BLOG = "removeBlog";
219     private static final String ACTION_CONFIRM_REMOVE_BLOG = "confirmRemoveBlog";
220     private static final String ACTION_ADD_TAG = "addTag";
221     private static final String ACTION_REMOVE_TAG = "removeTag";
222     private static final String ACTION_UPDATE_PRIORITY_TAG = "updatePriorityTag";
223     private static final String ACTION_ADD_FILE_CONTENT = "addContent";
224     private static final String ACTION_REMOVE_FILE_CONTENT = "deleteContent";
225     private static final String ACTION_UPDATE_PRIORITY_FILE_CONTENT = "updatePriorityContent";
226     private static final String ACTION_UPDATE_CONTENT_TYPE = "updateContentType";
227     private static final String ACTION_DUPLICATE_BLOG = "duplicateBlog";
228     private static final String ACTION_REMOVE_HISTORY_BLOG = "removeHistoryBlog";
229     private static final String ACTION_CONFIRM_REMOVE_HISTORY_BLOG = "confirmRemoveHistoryBlog";
230 
231     // Infos
232     private static final String INFO_BLOG_CREATED = "blog.info.blog.created";
233     private static final String INFO_BLOG_UPDATED = "blog.info.blog.updated";
234     private static final String INFO_BLOG_REMOVED = "blog.info.blog.removed";
235     private static final String BLOG_LOCKED = "blog.message.blogLocked";
236     private static final String INFO_HISTORY_BLOG_REMOVED = "blog.info.history.blog.removed";
237 
238     // Errors
239     private static final String ERROR_HISTORY_BLOG_CANT_REMOVE_ORIGINAL = "blog.error.history.blog.cantRemoveOriginal";
240     private static final String ERROR_HISTORY_BLOG_NOT_REMOVED = "blog.error.history.blog.notRemoved";
241 
242     // Filter Marks
243     protected static final String MARK_BLOG_FILTER_LIST = "blog_filter_list";
244     protected static final String MARK_BLOG_FILTER_NAME = "Nom";
245     protected static final String MARK_BLOG_FILTER_DATE = "Date";
246     protected static final String MARK_BLOG_FILTER_USER = "Utilisateur";
247     protected static final String MARK_PAGINATOR = "paginator";
248     protected static final String MARK_NB_ITEMS_PER_PAGE = "nb_items_per_page";
249     protected static final String MARK_ASC_SORT = "asc_sort";
250     protected static final String MARK_DATE_UPDATE_BLOG_AFTER = "dateUpdateBlogAfter";
251     protected static final String MARK_DATE_UPDATE_BLOG_BEFOR = "dateUpdateBlogBefor";
252     protected static final String MARK_UNPUBLISHED = "unpublished";
253     protected static final String MARK_LIST_BLOG_CONTRIBUTORS = "list_blog_contributors";
254 
255     public static final String CONSTANT_DUPLICATE_BLOG_NAME = "Copie de ";
256 
257     private static final String RESPONSE_BLOG_LOCKED = "BLOG_LOCKED";
258     private static final String RESPONSE_SUCCESS = "SUCCESS";
259     private static final String RESPONSE_FAILURE = "FAILURE";
260 
261     // Session variable to store working values
262     private static Map<Integer, BlogLock> _mapLockBlog = new HashMap<>( );
263     protected Blog _blog;
264     protected boolean _bIsChecked = false;
265     protected String _strSearchText;
266     protected boolean _bIsUnpulished = false;
267     protected String _dateUpdateBlogAfter;
268     protected String _dateUpdateBlogBefor;
269     protected String _strCurrentPageIndex;
270     protected int _nItemsPerPage;
271     protected int _nDefaultItemsPerPage;
272     protected boolean _bIsSorted = false;
273     protected String _strSortedAttributeName;
274     protected Boolean _bIsAscSort;
275     protected String [ ] _strTag;
276 
277     // Session variable to store working values
278     private final BlogServiceSession _blogServiceSession = BlogServiceSession.getInstance( );
279 
280     /**
281      * Build the Manage View
282      *
283      * @param request
284      *            The HTTP request
285      * @return The page
286      */
287     @View( value = VIEW_MANAGE_BLOGS, defaultView = true )
288     public String getManageBlogs( HttpServletRequest request )
289     {
290         _blog = null;
291         _strCurrentPageIndex = AbstractPaginator.getPageIndex( request, AbstractPaginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex );
292         _nDefaultItemsPerPage = AppPropertiesService.getPropertyInt( PROPERTY_DEFAULT_LIST_ITEM_PER_PAGE, 50 );
293         _nItemsPerPage = AbstractPaginator.getItemsPerPage( request, AbstractPaginator.PARAMETER_ITEMS_PER_PAGE, _nItemsPerPage, _nDefaultItemsPerPage );
294         // SORT
295         String strSortedAttributeName = request.getParameter( MARK_SORTED_ATTRIBUTE );
296         String strAscSort;
297         SimpleDateFormat isoDateFormat = new SimpleDateFormat("yyyy-MM-dd");
298         AdminUser user = AdminUserService.getAdminUser( request );
299         List<Integer> listBlogsId = new ArrayList<>( );
300         String strButtonSearch = request.getParameter( PARAMETER_BUTTON_SEARCH );
301         String strButtonReset = request.getParameter( PARAMETER_BUTTON_RESET );
302         _bIsUnpulished = request.getParameter( PARAMETER_UNPUBLISHED ) != null;
303 
304         if ( strButtonSearch != null )
305         {
306             // CURRENT USER
307             _bIsChecked = request.getParameter( MARK_CURRENT_USER ) != null;
308             _strSearchText = request.getParameter( PARAMETER_SEARCH_TEXT );
309             _strTag = request.getParameterValues( PARAMETER_TAG );
310             _dateUpdateBlogAfter = request.getParameter( PARAMETER_DATE_UPDATE_BLOG_AFTER );
311             _dateUpdateBlogBefor = request.getParameter( PARAMETER_DATE_UPDATE_BLOG_BEFOR );
312 
313         }
314         else
315             if ( strButtonReset != null )
316             {
317                 _bIsChecked = false;
318                 _strSearchText = null;
319                 _strTag = null;
320                 _bIsUnpulished = false;
321                 _dateUpdateBlogAfter = null;
322                 _dateUpdateBlogBefor = null;
323 
324             }
325 
326         if ( StringUtils.isNotBlank( _strSearchText ) || ( _strTag != null && _strTag.length > 0 ) || _bIsChecked || _bIsUnpulished
327                 || _dateUpdateBlogAfter != null || _dateUpdateBlogBefor != null )
328         {
329             BlogSearchFilteriness/BlogSearchFilter.html#BlogSearchFilter">BlogSearchFilter filter = new BlogSearchFilter( );
330             if ( StringUtils.isNotBlank( _strSearchText ) )
331             {
332                 filter.setKeywords( BlogUtils.removeAccents( _strSearchText ) );
333             }
334             if ( !ArrayUtils.isEmpty( _strTag ) )
335             {
336                 filter.setTag( _strTag );
337             }
338             if ( _bIsChecked )
339             {
340                 filter.setUser( user.getAccessCode( ) );
341             }
342             if ( _bIsUnpulished )
343             {
344                 filter.setIsUnpulished( _bIsUnpulished );
345             }
346             if ( _dateUpdateBlogAfter != null )
347             {
348                 try {
349                     filter.setUpdateDateAfter( isoDateFormat.parse(_dateUpdateBlogAfter)) ;
350                 } catch (ParseException e) {
351                     AppLogService.error( "Bad Date Format for indexed item: " + e.getMessage( ) );
352                 }
353             }
354             if ( _dateUpdateBlogBefor != null )
355             {
356                 try {
357                     filter.setUpdateDateBefor( isoDateFormat.parse( _dateUpdateBlogBefor ) ) ;
358                 } catch ( ParseException e ) {
359                     AppLogService.error( "Bad Date Format for indexed item: " + e.getMessage( ) );
360                 }
361             }
362 
363             BlogSearchService.getInstance( ).getSearchResults( filter, listBlogsId );
364 
365         }
366         else
367         {
368             listBlogsId = BlogHome.getIdBlogsList( );
369         }
370 
371         LocalizedPaginator<Integer> paginator = new LocalizedPaginator<>( (List<Integer>) listBlogsId, _nItemsPerPage, getHomeUrl( request ),
372                 AbstractPaginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex, getLocale( ) );
373 
374         List<Blog> listDocuments = new ArrayList<>( );
375         HashMap<Integer, List<String>> mapContributors = new HashMap<>( );
376         for ( Integer documentId : paginator.getPageItems( ) )
377         {
378             Blog document = BlogService.getInstance( ).findByPrimaryKeyWithoutBinaries( documentId );
379 
380             if ( document != null )
381             {
382                 if ( _mapLockBlog.containsKey( document.getId( ) ) && !_mapLockBlog.get( document.getId( ) ).getSessionId( )
383                         .equals( request.getSession( ).getId( ) ) )
384                 {
385 
386                     document.setLocked( true );
387                 }
388                 listDocuments.add( document );
389                 List<String> listContributors = BlogHome.getUsersEditedBlogVersions( document.getId( ) );
390                 mapContributors.put( document.getId( ), listContributors );
391             }
392         }
393 
394         if ( strSortedAttributeName != null || _bIsSorted )
395         {
396             if ( strSortedAttributeName == null )
397             {
398                 strSortedAttributeName = _strSortedAttributeName;
399             }
400             strAscSort = request.getParameter( MARK_ASC_SORT );
401 
402             boolean bIsAscSort = Boolean.parseBoolean( strAscSort );
403             if ( strAscSort == null )
404             {
405                 bIsAscSort = _bIsAscSort;
406             }
407 
408             Collections.sort( listDocuments, new AttributeComparator( strSortedAttributeName, bIsAscSort ) );
409 
410             _bIsSorted = true;
411 
412             _strSortedAttributeName = strSortedAttributeName;
413             _bIsAscSort = bIsAscSort;
414         }
415         boolean bPermissionCreate = RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, Blog.PERMISSION_CREATE,
416                 (User) getUser( ) );
417         boolean bPermissionModify = RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, Blog.PERMISSION_MODIFY,
418                 (User) getUser( ) );
419         boolean bPermissionDelete = RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, Blog.PERMISSION_DELETE,
420                 (User) getUser( ) );
421         boolean bPermissionPublish = RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, Blog.PERMISSION_PUBLISH,
422                 (User) getUser( ) );
423 
424         Map<String, Object> model = new HashMap<>( );
425         model.put( MARK_BLOG_LIST, listDocuments );
426         model.put( MARK_PAGINATOR, paginator );
427         model.put( MARK_BLOG_FILTER_LIST, getBlogFilterList( ) );
428         model.put( MARK_LIST_TAG, TagHome.getTagsReferenceList( ) );
429         model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
430         model.put( MARK_IS_CHECKED, _bIsChecked );
431         model.put( MARK_SEARCH_TEXT, _strSearchText );
432         model.put( MARK_NB_ITEMS_PER_PAGE, "" + _nItemsPerPage );
433         model.put( MARK_TAG, _strTag );
434         model.put( MARK_DATE_UPDATE_BLOG_AFTER, _dateUpdateBlogAfter );
435         model.put( MARK_DATE_UPDATE_BLOG_BEFOR, _dateUpdateBlogBefor );
436         model.put( MARK_UNPUBLISHED, _bIsUnpulished );
437         model.put( MARK_LIST_BLOG_CONTRIBUTORS, mapContributors );
438         model.put( MARK_PERMISSION_CREATE_BLOG, bPermissionCreate );
439         model.put( MARK_PERMISSION_MODIFY_BLOG, bPermissionModify );
440         model.put( MARK_PERMISSION_DELETE_BLOG, bPermissionDelete );
441         model.put( MARK_PERMISSION_PUBLISH_BLOG, bPermissionPublish );
442 
443         return getPage( PROPERTY_PAGE_TITLE_MANAGE_BLOG, TEMPLATE_MANAGE_BLOGS, model );
444     }
445 
446     /**
447      * Return View history page
448      *
449      * @param request
450      *            The request
451      * @return the hostory page
452      */
453     @View( value = VIEW_HISTORY_BLOG )
454     public String getHistoryBlog( HttpServletRequest request )
455     {
456         _blog = null;
457         int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_BLOG ) );
458         List<Blog> listBlogsVersions = BlogHome.getBlogsVersionsList( nId );
459 
460         UrlItem urlHistory = new UrlItem( JSP_MANAGE_BLOGS );
461         urlHistory.addParameter( PARAMETER_VIEW, VIEW_HISTORY_BLOG );
462         urlHistory.addParameter( PARAMETER_ID_BLOG, nId );
463 
464         Map<String, Object> model = getPaginatedListModel( request, MARK_BLOG_LIST, listBlogsVersions, urlHistory.getUrl( ) );
465 
466         model.put( MARK_ID_BLOG, nId );
467 
468         return getPage( PROPERTY_PAGE_TITLE_HISTORY_BLOG, TEMPLATE_HISTORY_BLOG, model );
469     }
470 
471     /**
472      * Manages the removal of a blog's version from its history
473      *
474      * @param request
475      *            The Http request
476      * @return the html code for the removal's confirmation page
477      * @throws AccessDeniedException
478      */
479     @Action( ACTION_CONFIRM_REMOVE_HISTORY_BLOG )
480     public String getconfirmRemoveHistoryBlog( HttpServletRequest request ) throws AccessDeniedException
481     {
482         String strId = request.getParameter( PARAMETER_ID_BLOG );
483         int nId = Integer.parseInt( strId );
484         String strVersion = request.getParameter( PARAMETER_VERSION_BLOG );
485 
486         if ( !RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, strId, Blog.PERMISSION_DELETE, (User) getUser( ) ) )
487         {
488             throw new AccessDeniedException( UNAUTHORIZED );
489         }
490 
491         UrlItem url = new UrlItem( getActionUrl( ACTION_REMOVE_HISTORY_BLOG ) );
492         url.addParameter( PARAMETER_ID_BLOG, nId );
493         url.addParameter( PARAMETER_VERSION_BLOG, strVersion );
494 
495         String strMessageUrl = AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_REMOVE_HISTORY_BLOG, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION );
496 
497         return redirect( request, strMessageUrl );
498     }
499 
500     /**
501      * Handles the removal of a blog's version
502      *
503      * @param request
504      *            The Http request
505      * @return the jsp URL to display the page to manage the blog's versions
506      */
507     @Action( ACTION_REMOVE_HISTORY_BLOG )
508     public String doRemoveHistoryBlog( HttpServletRequest request )
509     {
510         String strBlogId = request.getParameter( PARAMETER_ID_BLOG );
511         int nBlogId = Integer.parseInt( strBlogId );
512         String strVersion = request.getParameter( PARAMETER_VERSION_BLOG );
513         int nVersion = -1;
514 
515         // Make sure the version number is valid, and that the original version ( 1 ) is not being removed somehow
516         if ( StringUtils.isNumeric( strVersion ) )
517         {
518             nVersion = Integer.parseInt( strVersion );
519             if ( nVersion == 1 )
520             {
521                 // If a request to delete the original version was made, redirect the user and display an error message
522                 addError( ERROR_HISTORY_BLOG_CANT_REMOVE_ORIGINAL, getLocale( ) );
523                 return redirect( request, VIEW_HISTORY_BLOG, PARAMETER_ID_BLOG, nBlogId );
524             }
525         }
526         else
527         {
528             // In case the version number is not valid
529             addError( ERROR_HISTORY_BLOG_NOT_REMOVED, getLocale( ) );
530             AppLogService.error( "Plugin Blog: Can't delete invalid version {} for blog ID {}", strVersion, strBlogId );
531             return redirect( request, VIEW_HISTORY_BLOG, PARAMETER_ID_BLOG, nBlogId );
532         }
533 
534         if ( RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, strBlogId, Blog.PERMISSION_DELETE, (User) getUser( ) ) )
535         {
536             Blog blog = BlogService.getInstance( ).loadBlog( nBlogId );
537 
538             // Check if the blog's current version is the one being removed
539             if ( blog.getVersion( ) == nVersion )
540             {
541                 // Check if this blog is being modified by another user
542                 if ( checkLockBlog( nBlogId, request.getSession( ).getId( ) ) )
543                 {
544                     // Inform the user that the blog is locked by another user and redirect to the blog's history view
545                     UrlItem url = new UrlItem( getViewFullUrl( VIEW_HISTORY_BLOG ) );
546                     url.addParameter( PARAMETER_ID_BLOG, nBlogId );
547                     String strMessageUrl = AdminMessageService.getMessageUrl( request, BLOG_LOCKED, url.getUrl( ), AdminMessage.TYPE_STOP );
548                     return redirect( request, strMessageUrl );
549                 }
550                 // Check if this blog is currently published
551                 List<BlogPublication> docPublication = BlogPublicationHome.getDocPublicationByIdDoc( nBlogId );
552                 if ( CollectionUtils.isNotEmpty( docPublication ) )
553                 {
554                     // Inform the user that the blog is currently published and redirect to the blog's history view
555                     UrlItem url = new UrlItem( getViewFullUrl( VIEW_HISTORY_BLOG ) );
556                     url.addParameter( PARAMETER_ID_BLOG, nBlogId );
557                     String strMessageUrl = AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_DOCUMENT_IS_PUBLISHED, url.getUrl( ),
558                             AdminMessage.TYPE_STOP );
559                     return redirect( request, strMessageUrl );
560                 }
561                 // Delete the current version of the blog and revert to its previous version
562                 BlogService.getInstance( ).revertBlogToPreviousVersion( blog );
563             }
564             else
565             {
566                 // Delete an older version of the blog
567                 BlogService.getInstance( ).deleteBlogVersion( nBlogId, nVersion );
568             }
569             addInfo( INFO_HISTORY_BLOG_REMOVED, getLocale( ) );
570         }
571         return redirect( request, VIEW_HISTORY_BLOG, PARAMETER_ID_BLOG, nBlogId );
572     }
573 
574     /**
575      * Returns the form to create a blog
576      *
577      * @param request
578      *            The Http request
579      * @return the html code of the blog form
580      * @throws AccessDeniedException
581      */
582     @View( VIEW_CREATE_BLOG )
583     public String getCreateBlog( HttpServletRequest request ) throws AccessDeniedException
584     {
585 
586         if ( !RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, Blog.PERMISSION_CREATE, (User) getUser( ) ) )
587         {
588             throw new AccessDeniedException( UNAUTHORIZED );
589         }
590 
591         _blog = ( _blog != null && _blog.getId( ) == 0 ) ? _blog : new Blog( );
592         _blogServiceSession.saveBlogInSession( request.getSession( ), _blog );
593         _blog.getTag( ).sort( ( tg1, tg2 ) -> tg1.getPriority( ) - tg2.getPriority( ) );
594 
595         String useCropImage = DatastoreService.getDataValue( PROPERTY_USE_UPLOAD_IMAGE_PLUGIN, "false" );
596         Map<String, Object> model = getModel( );
597 
598         boolean bPermissionCreate = RBACService.isAuthorized( Tag.PROPERTY_RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, Tag.PERMISSION_CREATE,
599                 (User) getUser( ) );
600 
601         model.put( MARK_LIST_IMAGE_TYPE, DocContentHome.getListContentType( ) );
602         model.put( MARK_PERMISSION_CREATE_TAG, bPermissionCreate );
603         model.put( MARK_BLOG, _blog );
604         model.put( MARK_LIST_TAG, getTageList( ) );
605         model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
606         model.put( MARK_USE_UPLOAD_IMAGE_PLUGIN, Boolean.parseBoolean( useCropImage ) );
607 
608         return getPage( PROPERTY_PAGE_TITLE_CREATE_BLOG, TEMPLATE_CREATE_BLOG, model );
609     }
610 
611     /**
612      * Process the data capture form of a new blog
613      *
614      * @param request
615      *            The Http Request
616      * @return The Jsp URL of the process result
617      */
618     @Action( ACTION_CREATE_BLOG )
619     public String doCreateBlog( HttpServletRequest request )
620     {
621 
622         if ( RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, Blog.PERMISSION_CREATE, (User) getUser( ) ) )
623         {
624             String strAction = request.getParameter( PARAMETER_ACTION_BUTTON );
625             _blog.setCreationDate( getSqlDate( ) );
626             _blog.setUpdateDate( getSqlDate( ) );
627             _blog.setUser( AdminUserService.getAdminUser( request ).getAccessCode( ) );
628             _blog.setUserCreator( AdminUserService.getAdminUser( request ).getAccessCode( ) );
629             _blog.setVersion( 1 );
630             _blog.setAttachedPortletId( 0 );
631             populate( _blog, request );
632 
633             // Check constraints
634             if ( !validateBean( _blog, VALIDATION_ATTRIBUTES_PREFIX ) )
635             {
636                 return redirectView( request, VIEW_CREATE_BLOG );
637             }
638 
639             BlogService.getInstance( ).createBlog( _blog, _blog.getDocContent( ) );
640             _blogServiceSession.removeBlogFromSession( request.getSession( ), _blog.getId( ) );
641 
642             if ( strAction != null && strAction.equals( PARAMETER_APPLY ) )
643             {
644 
645                 return redirect( request, VIEW_MODIFY_BLOG, PARAMETER_ID_BLOG, _blog.getId( ) );
646             }
647 
648             addInfo( INFO_BLOG_CREATED, getLocale( ) );
649         }
650         return redirectView( request, VIEW_MANAGE_BLOGS );
651     }
652 
653     /**
654      * Return Json if the tag is added
655      *
656      * @param request
657      *            The request
658      * @return Json The Json success or echec
659      */
660     @Action( ACTION_ADD_TAG )
661     public String doAddTag( HttpServletRequest request )
662     {
663         String strIdTag = request.getParameter( PARAMETER_TAG );
664         int nIdBlog = Integer.parseInt( request.getParameter( PARAMETER_ID_BLOG ) );
665         String nIdSession = request.getSession( ).getId( );
666         _blog = _blogServiceSession.getBlogFromSession( request.getSession( ), nIdBlog );
667         if ( _mapLockBlog.get( nIdBlog ) != null && _mapLockBlog.get( nIdBlog ).getSessionId( ).equals( nIdSession ) )
668         {
669 
670             lockBlog( nIdBlog, request.getSession( ).getId( ) );
671         }
672         else
673             if ( _blog.getId( ) != 0 )
674             {
675 
676                 return JsonUtil.buildJsonResponse( new JsonResponse( RESPONSE_BLOG_LOCKED ) );
677             }
678 
679         if ( RBACService.isAuthorized( Tag.PROPERTY_RESOURCE_TYPE, strIdTag, Tag.PERMISSION_CREATE, (User) getUser( ) ) )
680         {
681 
682             String strTagName = request.getParameter( PARAMETER_TAG_NAME );
683 
684             Tagplugins/blog/business/Tag.html#Tag">Tag tag = new Tag( Integer.parseInt( strIdTag ), _blog.getTag( ).size( ) + 1 );
685             tag.setName( strTagName );
686 
687             _blog.addTag( tag );
688 
689             return JsonUtil.buildJsonResponse( new JsonResponse( RESPONSE_SUCCESS ) );
690         }
691         return JsonUtil.buildJsonResponse( new JsonResponse( RESPONSE_FAILURE ) );
692 
693     }
694 
695     /**
696      * Return Json if the tag is removed
697      *
698      * @param request
699      * @return Json The Json success or echec
700      */
701     @Action( ACTION_REMOVE_TAG )
702     public String doRemoveTag( HttpServletRequest request )
703     {
704         String strIdTag = request.getParameter( PARAMETER_TAG );
705         int nIdBlog = Integer.parseInt( request.getParameter( PARAMETER_ID_BLOG ) );
706         String nIdSession = request.getSession( ).getId( );
707         _blog = _blogServiceSession.getBlogFromSession( request.getSession( ), nIdBlog );
708         if ( _mapLockBlog.get( nIdBlog ) != null && _mapLockBlog.get( nIdBlog ).getSessionId( ).equals( nIdSession ) )
709         {
710 
711             lockBlog( nIdBlog, request.getSession( ).getId( ) );
712         }
713         else
714             if ( _blog.getId( ) != 0 )
715             {
716 
717                 return JsonUtil.buildJsonResponse( new JsonResponse( RESPONSE_BLOG_LOCKED ) );
718             }
719 
720         if ( RBACService.isAuthorized( Tag.PROPERTY_RESOURCE_TYPE, strIdTag, Tag.PERMISSION_DELETE, (User) getUser( ) ) )
721         {
722             Tag tag = _blog.getTag( ).stream( ).filter( tg -> tg.getIdTag( ) == Integer.parseInt( strIdTag ) ).collect( Collectors.toList( ) ).get( 0 );
723             _blog.deleteTag( tag );
724 
725             List<Tag> listTag = _blog.getTag( ).stream( ).map( ( Tag tg ) -> {
726                 if ( ( tg.getPriority( ) > tag.getPriority( ) ) )
727                 {
728                     tg.setPriority( tg.getPriority( ) - 1 );
729                 }
730                 return tg;
731             } ).collect( Collectors.toList( ) );
732 
733             _blog.setTag( listTag );
734             return JsonUtil.buildJsonResponse( new JsonResponse( RESPONSE_SUCCESS ) );
735         }
736         return JsonUtil.buildJsonResponse( new JsonResponse( RESPONSE_FAILURE ) );
737 
738     }
739 
740     /**
741      * Return Json if the tag is updated
742      *
743      * @param request
744      * @return Json The Json success or echec
745      */
746     @Action( ACTION_UPDATE_PRIORITY_TAG )
747     public String doUpdatePriorityTag( HttpServletRequest request )
748     {
749         Tag tg = null;
750         Tag tagMove = null;
751         int nPriorityToSet = 0;
752         int nPriority = 0;
753 
754         String strIdTag = request.getParameter( PARAMETER_TAG );
755         String strAction = request.getParameter( PARAMETER_TAG_ACTION );
756         int nIdBlog = Integer.parseInt( request.getParameter( PARAMETER_ID_BLOG ) );
757         String nIdSession = request.getSession( ).getId( );
758         _blog = _blogServiceSession.getBlogFromSession( request.getSession( ), nIdBlog );
759         if ( _mapLockBlog.get( nIdBlog ) != null && _mapLockBlog.get( nIdBlog ).getSessionId( ).equals( nIdSession ) )
760         {
761 
762             lockBlog( nIdBlog, request.getSession( ).getId( ) );
763         }
764         else
765             if ( _blog.getId( ) != 0 )
766             {
767 
768                 return JsonUtil.buildJsonResponse( new JsonResponse( RESPONSE_BLOG_LOCKED ) );
769             }
770 
771         for ( Tag tag : _blog.getTag( ) )
772         {
773             if ( tag.getIdTag( ) == Integer.parseInt( strIdTag ) )
774             {
775                 tg = tag;
776                 nPriorityToSet = tag.getPriority( );
777                 nPriority = tag.getPriority( );
778             }
779         }
780         for ( Tag tag : _blog.getTag( ) )
781         {
782             if ( strAction.equals( "moveUp" ) && tag.getPriority( ) == nPriority - 1 )
783             {
784                 tagMove = tag;
785                 tagMove.setPriority( tagMove.getPriority( ) + 1 );
786                 nPriorityToSet = nPriority - 1;
787 
788             }
789             else
790                 if ( strAction.equals( "moveDown" ) && tag.getPriority( ) == nPriority + 1 )
791                 {
792                     tagMove = tag;
793                     tagMove.setPriority( tagMove.getPriority( ) - 1 );
794                     nPriorityToSet = nPriority + 1;
795 
796                 }
797         }
798         tg.setPriority( nPriorityToSet );
799 
800         if ( tagMove != null )
801         {
802 
803             return JsonUtil.buildJsonResponse( new JsonResponse( String.valueOf( tagMove.getIdTag( ) ) ) );
804 
805         }
806         return JsonUtil.buildJsonResponse( new JsonResponse( String.valueOf( tg.getIdTag( ) ) ) );
807 
808     }
809 
810     /**
811      * Manages the removal form of a blog whose identifier is in the http request
812      *
813      * @param request
814      *            The Http request
815      * @return the html code to confirm
816      * @throws AccessDeniedException
817      */
818     @Action( ACTION_CONFIRM_REMOVE_BLOG )
819     public String getConfirmRemoveBlog( HttpServletRequest request ) throws AccessDeniedException
820     {
821 
822         String strId = request.getParameter( PARAMETER_ID_BLOG );
823         int nId = Integer.parseInt( strId );
824         if ( !RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, strId, Blog.PERMISSION_DELETE, (User) getUser( ) ) )
825         {
826             throw new AccessDeniedException( UNAUTHORIZED );
827         }
828         if ( checkLockBlog( nId, request.getSession( ).getId( ) ) )
829         {
830 
831             UrlItem url = new UrlItem( getActionUrl( VIEW_MANAGE_BLOGS ) );
832             String strMessageUrl = AdminMessageService.getMessageUrl( request, BLOG_LOCKED, url.getUrl( ), AdminMessage.TYPE_STOP );
833             return redirect( request, strMessageUrl );
834 
835         }
836 
837         UrlItem url = new UrlItem( getActionUrl( ACTION_REMOVE_BLOG ) );
838         url.addParameter( PARAMETER_ID_BLOG, nId );
839 
840         String strMessageUrl = AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_REMOVE_BLOG, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION );
841 
842         return redirect( request, strMessageUrl );
843     }
844 
845     /**
846      * Handles the removal form of a blog
847      *
848      * @param request
849      *            The Http request
850      * @return the jsp URL to display the form to manage blog
851      */
852     @Action( ACTION_REMOVE_BLOG )
853     public String doRemoveBlog( HttpServletRequest request )
854     {
855         String strId = request.getParameter( PARAMETER_ID_BLOG );
856 
857         int nId = Integer.parseInt( strId );
858 
859         if ( RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, strId, Blog.PERMISSION_DELETE, (User) getUser( ) ) )
860         {
861 
862             if ( checkLockBlog( nId, request.getSession( ).getId( ) ) )
863             {
864 
865                 UrlItem url = new UrlItem( getActionUrl( VIEW_MANAGE_BLOGS ) );
866                 String strMessageUrl = AdminMessageService.getMessageUrl( request, BLOG_LOCKED, url.getUrl( ), AdminMessage.TYPE_STOP );
867                 return redirect( request, strMessageUrl );
868 
869             }
870 
871             List<BlogPublication> docPublication = BlogPublicationHome.getDocPublicationByIdDoc( nId );
872 
873             if ( CollectionUtils.isNotEmpty( docPublication ) )
874             {
875                 String strMessageUrl = AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_DOCUMENT_IS_PUBLISHED, AdminMessage.TYPE_STOP );
876 
877                 return redirect( request, strMessageUrl );
878             }
879             BlogService.getInstance( ).deleteBlog( nId );
880             _blogServiceSession.removeBlogFromSession( request.getSession( ), nId );
881             unLockBlog( nId );
882 
883             ExtendableResourceRemovalListenerService.doRemoveResourceExtentions( Blog.PROPERTY_RESOURCE_TYPE, String.valueOf( nId ) );
884 
885             addInfo( INFO_BLOG_REMOVED, getLocale( ) );
886         }
887         return redirectView( request, VIEW_MANAGE_BLOGS );
888     }
889 
890     @Action( ACTION_DUPLICATE_BLOG )
891     public String doDuplicateBlog( HttpServletRequest request ) throws AccessDeniedException
892     {
893 
894         if ( !RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, Blog.PERMISSION_CREATE, (User) getUser( ) ) )
895         {
896             throw new AccessDeniedException( UNAUTHORIZED );
897         }
898 
899         int nIdBlog = Integer.parseInt( request.getParameter( PARAMETER_ID_BLOG ) );
900         _blog = BlogService.getInstance( ).loadBlog( nIdBlog );
901 
902         Timestamp sqlDate = getSqlDate( );
903 
904         _blog.setContentLabel( CONSTANT_DUPLICATE_BLOG_NAME + _blog.getContentLabel( ) );
905         _blog.setCreationDate( sqlDate );
906         _blog.setUpdateDate( sqlDate );
907         _blog.setUser( AdminUserService.getAdminUser( request ).getAccessCode( ) );
908         _blog.setUserCreator( AdminUserService.getAdminUser( request ).getAccessCode( ) );
909         _blog.setVersion( 1 );
910         _blog.setAttachedPortletId( 0 );
911 
912         BlogService.getInstance( ).createBlog( _blog, _blog.getDocContent( ) );
913 
914         return redirectView( request, VIEW_MANAGE_BLOGS );
915     }
916 
917     /**
918      * Returns the form to update info about a blog
919      *
920      * @param request
921      *            The Http request
922      * @return The HTML form to update info
923      * @throws AccessDeniedException
924      */
925     @View( VIEW_MODIFY_BLOG )
926     public String getModifyBlog( HttpServletRequest request ) throws AccessDeniedException
927     {
928         String strId = request.getParameter( PARAMETER_ID_BLOG );
929 
930         if ( !RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, strId, Blog.PERMISSION_MODIFY, (User) getUser( ) ) )
931         {
932             throw new AccessDeniedException( UNAUTHORIZED );
933         }
934         int nId = Integer.parseInt( strId );
935         String strResetVersion = request.getParameter( PARAMETER_VERSION_BLOG );
936         String useCropImage = DatastoreService.getDataValue( PROPERTY_USE_UPLOAD_IMAGE_PLUGIN, "false" );
937         String sessionId = request.getSession( ).getId( );
938 
939         int nVersion = -1;
940         if ( strResetVersion != null )
941         {
942             nVersion = Integer.parseInt( strResetVersion );
943         }
944 
945         if ( strResetVersion != null )
946         {
947 
948             _blog = BlogHome.findVersion( nId, nVersion );
949             _blogServiceSession.saveBlogInSession( request.getSession( ), _blog );
950         }
951         else
952         {
953             _blog = BlogService.getInstance( ).loadBlog( nId );
954             _blogServiceSession.saveBlogInSession( request.getSession( ), _blog );
955 
956         }
957 
958         if ( checkLockBlog( nId, sessionId ) )
959         {
960 
961             UrlItem url = new UrlItem( getActionUrl( VIEW_MANAGE_BLOGS ) );
962             String strMessageUrl = AdminMessageService.getMessageUrl( request, BLOG_LOCKED, url.getUrl( ), AdminMessage.TYPE_STOP );
963             return redirect( request, strMessageUrl );
964         }
965         for ( HttpSession httpSession : BlogSessionListner.getMapSession( ).values( ) )
966         {
967 
968             if ( !httpSession.getId( ).equals( sessionId ) )
969             {
970 
971                 _blogServiceSession.removeBlogFromSession( httpSession, nId );
972             }
973         }
974 
975         lockBlog( nId, sessionId );
976 
977         _blog.getTag( ).sort( ( tg1, tg2 ) -> tg1.getPriority( ) - tg2.getPriority( ) );
978         _blog.getDocContent( ).sort( ( dc1, dc2 ) -> dc1.getPriority( ) - dc2.getPriority( ) );
979         Map<String, Object> model = getModel( );
980 
981         boolean bPermissionCreate = RBACService.isAuthorized( Tag.PROPERTY_RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, Tag.PERMISSION_CREATE,
982                 (User) getUser( ) );
983 
984         model.put( MARK_LIST_IMAGE_TYPE, DocContentHome.getListContentType( ) );
985         model.put( MARK_PERMISSION_CREATE_TAG, bPermissionCreate );
986         model.put( MARK_BLOG, _blog );
987         model.put( MARK_LIST_TAG, getTageList( ) );
988         model.put( MARK_USE_UPLOAD_IMAGE_PLUGIN, Boolean.parseBoolean( useCropImage ) );
989         model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
990 
991         ExtendableResourcePluginActionManager.fillModel( request, getUser( ), model, String.valueOf( nId ), Blog.PROPERTY_RESOURCE_TYPE );
992 
993         return getPage( PROPERTY_PAGE_TITLE_MODIFY_BLOG, TEMPLATE_MODIFY_BLOG, model );
994     }
995 
996     /**
997      * Process the change form of a blog
998      *
999      * @param request
1000      *            The Http request
1001      * @return The Jsp URL of the process result
1002      */
1003     @Action( ACTION_MODIFY_BLOG )
1004     public String doModifyBlog( HttpServletRequest request )
1005     {
1006 
1007         String strId = request.getParameter( PARAMETER_ID_BLOG );
1008         String strAction = request.getParameter( PARAMETER_ACTION_BUTTON );
1009         int nId = Integer.parseInt( strId );
1010         String strHtmlContent = request.getParameter( PARAMETER_HTML_CONTENT );
1011         String strEditComment = request.getParameter( PARAMETER_EDIT_COMMENT );
1012         String strContentLabel = request.getParameter( PARAMETER_CONTENT_LABEL );
1013         String strDescription = request.getParameter( PARAMETER_DESCRIPTION );
1014         String strShareable = request.getParameter( PARAMETER_SHAREABLE );
1015         String strUrl = request.getParameter( PARAMETER_URL );
1016 
1017         if ( RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, strId, Blog.PERMISSION_MODIFY, (User) getUser( ) ) )
1018         {
1019             _blog = _blogServiceSession.getBlogFromSession( request.getSession( ), nId );
1020             if ( checkLockBlog( Integer.parseInt( strId ), request.getSession( ).getId( ) ) || _blog == null )
1021             {
1022 
1023                 UrlItem url = new UrlItem( getActionUrl( VIEW_MANAGE_BLOGS ) );
1024                 String strMessageUrl = AdminMessageService.getMessageUrl( request, BLOG_LOCKED, url.getUrl( ), AdminMessage.TYPE_STOP );
1025                 return redirect( request, strMessageUrl );
1026             }
1027             Blog latestVersionBlog = BlogService.getInstance( ).loadBlog( nId );
1028 
1029             _blog.setContentLabel( strContentLabel );
1030             _blog.setDescription( strDescription );
1031             _blog.setShareable( Boolean.parseBoolean( strShareable ) );
1032             _blog.setHtmlContent( strHtmlContent );
1033             _blog.setEditComment( strEditComment );
1034             _blog.setUpdateDate( getSqlDate( ) );
1035             _blog.setUser( AdminUserService.getAdminUser( request ).getAccessCode( ) );
1036             _blog.setUrl( strUrl );
1037 
1038             // Check constraints
1039             if ( !validateBean( _blog, VALIDATION_ATTRIBUTES_PREFIX ) )
1040             {
1041                 return redirect( request, VIEW_MODIFY_BLOG, PARAMETER_ID_BLOG, _blog.getId( ) );
1042             }
1043 
1044             if ( strAction != null && strAction.equals( PARAMETER_APPLY ) )
1045             {
1046                 BlogService.getInstance( ).updateBlogWithoutVersion( _blog, _blog.getDocContent( ) );
1047                 _blogServiceSession.removeBlogFromSession( request.getSession( ), nId );
1048                 unLockBlog( nId );
1049 
1050                 return redirect( request, VIEW_MODIFY_BLOG, PARAMETER_ID_BLOG, _blog.getId( ) );
1051 
1052             }
1053             else
1054             {
1055                 _blog.setVersion( latestVersionBlog.getVersion( ) + 1 );
1056                 BlogService.getInstance( ).updateBlog( _blog, _blog.getDocContent( ) );
1057                 _blogServiceSession.removeBlogFromSession( request.getSession( ), nId );
1058                 unLockBlog( nId );
1059                 addInfo( INFO_BLOG_UPDATED, getLocale( ) );
1060             }
1061         }
1062         return redirectView( request, VIEW_MANAGE_BLOGS );
1063     }
1064 
1065     /**
1066      * Returns the preview of an blog
1067      *
1068      * @param request
1069      *            The Http request
1070      * @return The HTML form to update info
1071      */
1072     @View( VIEW_PREVIEW_BLOG )
1073     public String getPreviewBlog( HttpServletRequest request )
1074     {
1075         int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_BLOG ) );
1076         String strVersion = request.getParameter( PARAMETER_VERSION_BLOG );
1077         int nVersion = -1;
1078         if ( strVersion != null )
1079         {
1080             nVersion = Integer.parseInt( strVersion );
1081         }
1082 
1083         Blog blog;
1084         if ( strVersion != null )
1085         {
1086             blog = BlogHome.findVersion( nId, nVersion );
1087         }
1088         else
1089         {
1090             blog = BlogService.getInstance( ).loadBlog( nId );
1091         }
1092         blog.setBlogPublication( BlogPublicationHome.getDocPublicationByIdDoc( nId ) );
1093 
1094         Map<String, Object> model = getModel( );
1095         model.put( MARK_LIST_TAG, TagHome.getTagsReferenceList( ) );
1096 
1097         model.put( MARK_BLOG, blog );
1098 
1099         ExtendableResourcePluginActionManager.fillModel( request, getUser( ), model, String.valueOf( nId ), Blog.PROPERTY_RESOURCE_TYPE );
1100 
1101         return getPage( PROPERTY_PAGE_TITLE_PREVIEW_BLOG, TEMPLATE_PREVIEW_BLOG, model );
1102     }
1103 
1104     /**
1105      * Returns the diff of two blog versions
1106      *
1107      * @param request
1108      *            The Http request
1109      * @return The HTML form to update info
1110      */
1111     @View( VIEW_DIFF_BLOG )
1112     public String getDiffBlog( HttpServletRequest request )
1113     {
1114         int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_BLOG ) );
1115         String strVersion = request.getParameter( PARAMETER_VERSION_BLOG );
1116         int nVersion = -1;
1117         if ( strVersion != null )
1118         {
1119             nVersion = Integer.parseInt( strVersion );
1120         }
1121         String strVersion2 = request.getParameter( PARAMETER_VERSION_BLOG2 );
1122 
1123         Blog blog;
1124         if ( strVersion != null )
1125         {
1126             blog = BlogHome.findVersion( nId, nVersion );
1127         }
1128         else
1129         {
1130             blog = BlogHome.findByPrimaryKey( nId );
1131         }
1132 
1133         int nVersion2 = blog.getVersion( ) - 1;
1134         if ( strVersion2 != null )
1135         {
1136             nVersion2 = Integer.parseInt( strVersion2 );
1137         }
1138 
1139         Blog blog2 = BlogHome.findVersion( nId, nVersion2 );
1140         if ( blog2 == null )
1141         {
1142             blog2 = BlogHome.findByPrimaryKey( nId );
1143         }
1144 
1145         if ( blog2.getVersion( ) > blog.getVersion( ) )
1146         {
1147             Blog tmp = blog2;
1148             blog2 = blog;
1149             blog = tmp;
1150         }
1151 
1152         String strDiff = null;
1153         HtmlCleaner cleaner = new HtmlCleaner( );
1154         try
1155         {
1156             SAXTransformerFactory tf = (SAXTransformerFactory) TransformerFactory.newInstance( );
1157             TransformerHandler result = tf.newTransformerHandler( );
1158             result.getTransformer( ).setOutputProperty( OutputKeys.OMIT_XML_DECLARATION, "yes" );
1159             StringWriter resultWriter = new StringWriter( );
1160             result.setResult( new StreamResult( resultWriter ) );
1161             Locale locale = getLocale( );
1162 
1163             DomTreeBuilder oldHandler = new DomTreeBuilder( );
1164             cleaner.cleanAndParse( new InputSource( new ByteArrayInputStream( blog2.getHtmlContent( ).getBytes( StandardCharsets.UTF_8 ) ) ), oldHandler );
1165             TextNodeComparator leftComparator = new TextNodeComparator( oldHandler, locale );
1166 
1167             DomTreeBuilder newHandler = new DomTreeBuilder( );
1168             cleaner.cleanAndParse( new InputSource( new ByteArrayInputStream( blog.getHtmlContent( ).getBytes( StandardCharsets.UTF_8 ) ) ), newHandler );
1169             TextNodeComparator rightComparator = new TextNodeComparator( newHandler, locale );
1170 
1171             HtmlSaxDiffOutput output = new HtmlSaxDiffOutput( result, "" );
1172             HTMLDiffer differ = new HTMLDiffer( output );
1173             differ.diff( leftComparator, rightComparator );
1174 
1175             strDiff = resultWriter.toString( );
1176         }
1177         catch( Exception e )
1178         {
1179             AppLogService.error( "Error generating daisy diff for blog " + nId + ":" + blog.getContentLabel( ) + "; versions (" + blog.getVersion( ) + ","
1180                     + blog2.getVersion( ) + ")", e );
1181         }
1182 
1183         List<Blog> listBlogsVersions = BlogHome.getBlogsVersionsList( nId );
1184 
1185         Map<String, Object> model = getModel( );
1186         model.put( MARK_BLOG, blog );
1187         model.put( MARK_BLOG2, blog2 );
1188         model.put( MARK_DIFF, strDiff );
1189         model.put( MARK_BLOG_VERSION_LIST, listBlogsVersions );
1190 
1191         return getPage( PROPERTY_PAGE_TITLE_DIFF_BLOG, TEMPLATE_DIFF_BLOG, model );
1192     }
1193 
1194     /**
1195      * 
1196      * Added docContent to the htmlDoc content list
1197      * 
1198      * @param request
1199      *            The Http request
1200      * @return
1201      */
1202     @Action( ACTION_ADD_FILE_CONTENT )
1203     public String addContent( HttpServletRequest request )
1204     {
1205 
1206         int nIdBlog = Integer.parseInt( request.getParameter( PARAMETER_ID_BLOG ) );
1207         String nIdSession = request.getSession( ).getId( );
1208         _blog = _blogServiceSession.getBlogFromSession( request.getSession( ), nIdBlog );
1209 
1210         if ( _mapLockBlog.get( nIdBlog ) != null && _mapLockBlog.get( nIdBlog ).getSessionId( ).equals( nIdSession ) )
1211         {
1212 
1213             lockBlog( nIdBlog, request.getSession( ).getId( ) );
1214         }
1215         else
1216             if ( _blog.getId( ) != 0 )
1217             {
1218 
1219                 return JsonUtil.buildJsonResponse( new JsonResponse( RESPONSE_BLOG_LOCKED ) );
1220             }
1221 
1222         /* Gestion du mimeType */
1223         String result = request.getParameter( "fileContent" );
1224         String firstDelimiter = "[;]";
1225         String secondDelimiter = "[:]";
1226         String thirdDelimiter = "[,]";
1227         String [ ] firstParts = result.split( firstDelimiter );
1228         String partAfterFirstDelimiter = firstParts [0];
1229         String [ ] secondParts = partAfterFirstDelimiter.split( secondDelimiter );
1230         // Le mimeType
1231         String mimeType = secondParts[1];
1232         // Le fichier en base64
1233         String base64FileString = StringUtils.EMPTY;
1234         // Gestion des fichiers vides
1235         if ( !result.endsWith( "," ) )
1236         {
1237             String [ ] thirdParts = result.split( thirdDelimiter );
1238             base64FileString = thirdParts [1];
1239         }
1240 
1241         byte [ ] fileByteArray = Base64.getDecoder( ).decode( base64FileString );
1242 
1243         String strFileName = request.getParameter( PARAMETER_FILE_NAME );
1244         String strFileType = request.getParameter( "fileType" );
1245 
1246         if ( StringUtils.isEmpty( mimeType ) )
1247         {
1248 
1249             InputStream is = new ByteArrayInputStream( fileByteArray );
1250 
1251             // Trouver le type du fichier
1252             try
1253             {
1254                 mimeType = URLConnection.guessContentTypeFromStream( is );
1255             }
1256             catch( IOException ioException )
1257             {
1258                 AppLogService.error( ioException.getStackTrace( ), ioException );
1259             }
1260 
1261         }
1262 
1263         DocContentusiness/DocContent.html#DocContent">DocContent docContent = new DocContent( );
1264         docContent.setBinaryValue( fileByteArray );
1265         docContent.setValueContentType( mimeType );
1266         docContent.setTextValue( strFileName );
1267 
1268         if ( strFileType != null )
1269         {
1270 
1271             ContentTypebusiness/ContentType.html#ContentType">ContentType contType = new ContentType( );
1272             contType.setIdContentType( Integer.parseInt( strFileType ) );
1273             docContent.setContentType( contType );
1274         }
1275         docContent.setPriority( _blog.getDocContent( ).size( ) + 1 );
1276         _blog.addContent( docContent );
1277         DocContentHome.create( docContent );
1278         String [ ] results = {
1279                 strFileName, String.valueOf( docContent.getId( ) )
1280         };
1281 
1282         return JsonUtil.buildJsonResponse( new JsonResponse( results ) );
1283 
1284     }
1285 
1286     /**
1287      * delete docContent in the htmlDoc content list
1288      * 
1289      * @param request
1290      *            The Http request
1291      * @return
1292      */
1293     @Action( ACTION_REMOVE_FILE_CONTENT )
1294     public String removeContent( HttpServletRequest request )
1295     {
1296 
1297         int nIdDoc = Integer.parseInt( request.getParameter( PARAMETER_CONTENT_ID ) );
1298         int nIdBlog = Integer.parseInt( request.getParameter( PARAMETER_ID_BLOG ) );
1299         String nIdSession = request.getSession( ).getId( );
1300         _blog = _blogServiceSession.getBlogFromSession( request.getSession( ), nIdBlog );
1301 
1302         if ( _mapLockBlog.get( nIdBlog ) != null && _mapLockBlog.get( nIdBlog ).getSessionId( ).equals( nIdSession ) )
1303         {
1304 
1305             lockBlog( nIdBlog, request.getSession( ).getId( ) );
1306         }
1307         else
1308             if ( _blog.getId( ) != 0 )
1309             {
1310 
1311                 return JsonUtil.buildJsonResponse( new JsonResponse( RESPONSE_BLOG_LOCKED ) );
1312             }
1313 
1314         DocContent docCont = _blog.getDocContent( ).stream( ).filter( dc -> dc.getId( ) == nIdDoc ).collect( Collectors.toList( ) ).get( 0 );
1315         List<DocContent> listDocs = _blog.getDocContent( ).stream( ).map( ( DocContent dc ) -> {
1316             if ( ( dc.getPriority( ) > docCont.getPriority( ) ) && ( docCont.getId( ) != dc.getId( ) ) )
1317             {
1318 
1319                 dc.setPriority( dc.getPriority( ) - 1 );
1320             }
1321             return dc;
1322         } ).collect( Collectors.toList( ) );
1323 
1324         _blog.setDocContent( listDocs );
1325         _blog.deleteDocContent( nIdDoc );
1326         DocContentHome.removeInBlogById( nIdDoc );
1327 
1328         return JsonUtil.buildJsonResponse( new JsonResponse( nIdDoc ) );
1329 
1330     }
1331 
1332     /**
1333      * Return Json if the the content is updated
1334      *
1335      * @param request
1336      * @return Json The Json success or echec
1337      */
1338     @Action( ACTION_UPDATE_PRIORITY_FILE_CONTENT )
1339     public String doUpdatePriorityContent( HttpServletRequest request )
1340     {
1341         DocContent docCont = null;
1342         DocContent docContMove = null;
1343         int nPriorityToSet = 0;
1344         int nPriority = 0;
1345 
1346         String strIdDocContent = request.getParameter( PARAMETER_CONTENT_ID );
1347         String strAction = request.getParameter( PARAMETER_CONTENT_ACTION );
1348         int nIdBlog = Integer.parseInt( request.getParameter( PARAMETER_ID_BLOG ) );
1349         String nIdSession = request.getSession( ).getId( );
1350         _blog = _blogServiceSession.getBlogFromSession( request.getSession( ), nIdBlog );
1351         if ( _mapLockBlog.get( nIdBlog ) != null && _mapLockBlog.get( nIdBlog ).getSessionId( ).equals( nIdSession ) )
1352         {
1353 
1354             lockBlog( nIdBlog, request.getSession( ).getId( ) );
1355         }
1356         else
1357             if ( _blog.getId( ) != 0 )
1358             {
1359 
1360                 return JsonUtil.buildJsonResponse( new JsonResponse( RESPONSE_BLOG_LOCKED ) );
1361             }
1362 
1363         for ( DocContent dc : _blog.getDocContent( ) )
1364         {
1365             if ( dc.getId( ) == Integer.parseInt( strIdDocContent ) )
1366             {
1367                 docCont = dc;
1368                 nPriorityToSet = dc.getPriority( );
1369                 nPriority = dc.getPriority( );
1370             }
1371         }
1372         for ( DocContent dc : _blog.getDocContent( ) )
1373         {
1374             if ( strAction.equals( "moveUp" ) && dc.getPriority( ) == nPriority - 1 )
1375             {
1376                 docContMove = dc;
1377                 docContMove.setPriority( dc.getPriority( ) + 1 );
1378                 nPriorityToSet = nPriority - 1;
1379 
1380             }
1381             else
1382                 if ( strAction.equals( "moveDown" ) && dc.getPriority( ) == nPriority + 1 )
1383                 {
1384                     docContMove = dc;
1385                     docContMove.setPriority( docContMove.getPriority( ) - 1 );
1386                     nPriorityToSet = nPriority + 1;
1387 
1388                 }
1389         }
1390         docCont.setPriority( nPriorityToSet );
1391 
1392         if ( docContMove != null )
1393         {
1394 
1395             return JsonUtil.buildJsonResponse( new JsonResponse( String.valueOf( docContMove.getId( ) ) ) );
1396 
1397         }
1398         return JsonUtil.buildJsonResponse( new JsonResponse( String.valueOf( docCont.getId( ) ) ) );
1399 
1400     }
1401 
1402     /**
1403      * 
1404      * @param request
1405      * @return
1406      */
1407     @Action( ACTION_UPDATE_CONTENT_TYPE )
1408     public String updateContentType( HttpServletRequest request )
1409     {
1410 
1411         String strContentTypeId = request.getParameter( PARAMETER_TYPE_ID );
1412         String strContentId = request.getParameter( PARAMETER_CONTENT_ID );
1413         int nIdBlog = Integer.parseInt( request.getParameter( PARAMETER_ID_BLOG ) );
1414         String nIdSession = request.getSession( ).getId( );
1415         _blog = _blogServiceSession.getBlogFromSession( request.getSession( ), nIdBlog );
1416 
1417         if ( _mapLockBlog.get( nIdBlog ) != null && _mapLockBlog.get( nIdBlog ).getSessionId( ).equals( nIdSession ) )
1418         {
1419 
1420             lockBlog( nIdBlog, request.getSession( ).getId( ) );
1421         }
1422         else
1423             if ( _blog.getId( ) != 0 )
1424             {
1425 
1426                 return JsonUtil.buildJsonResponse( new JsonResponse( RESPONSE_BLOG_LOCKED ) );
1427             }
1428 
1429         for ( DocContent content : _blog.getDocContent( ) )
1430         {
1431 
1432             if ( strContentId != null && content.getId( ) == Integer.parseInt( strContentId ) )
1433             {
1434 
1435                 ContentTypebusiness/ContentType.html#ContentType">ContentType contType = new ContentType( );
1436                 contType.setIdContentType( Integer.parseInt( strContentTypeId ) );
1437 
1438                 content.setContentType( contType );
1439                 break;
1440             }
1441         }
1442 
1443         return JsonUtil.buildJsonResponse( new JsonResponse( RESPONSE_SUCCESS ) );
1444     }
1445 
1446     /**
1447      * Set content of the blog
1448      * 
1449      * @param mRequest
1450      * @param locale
1451      * @return the content of the blog
1452      */
1453 
1454     public DocContent setContent( MultipartHttpServletRequest mRequest, Locale locale )
1455     {
1456 
1457         FileItem fileParameterBinaryValue = mRequest.getFile( "attachment" );
1458 
1459         if ( fileParameterBinaryValue != null ) // If the field is a file
1460         {
1461 
1462             String strContentType = fileParameterBinaryValue.getContentType( );
1463             byte [ ] bytes = fileParameterBinaryValue.get( );
1464             String strFileName = fileParameterBinaryValue.getName( );
1465 
1466             if ( !ArrayUtils.isEmpty( bytes ) )
1467             {
1468 
1469                 DocContentusiness/DocContent.html#DocContent">DocContent docContent = new DocContent( );
1470                 docContent.setBinaryValue( bytes );
1471                 docContent.setValueContentType( strContentType );
1472                 docContent.setTextValue( strFileName );
1473 
1474                 return docContent;
1475             }
1476 
1477         }
1478 
1479         return null;
1480     }
1481 
1482     /**
1483      * 
1484      * @return
1485      */
1486     private ReferenceList getBlogFilterList( )
1487     {
1488         ReferenceList list = new ReferenceList( );
1489         list.addItem( MARK_BLOG_FILTER_NAME, "Nom" );
1490         list.addItem( MARK_BLOG_FILTER_DATE, "Date" );
1491         list.addItem( MARK_BLOG_FILTER_USER, "Utilisateur" );
1492 
1493         return list;
1494     }
1495 
1496     /**
1497      * 
1498      * @return BlogList
1499      */
1500     private ReferenceList getTageList( )
1501     {
1502 
1503         ReferenceList blogList = TagHome.getTagsReferenceList( );
1504 
1505         for ( Tag tg : _blog.getTag( ) )
1506         {
1507             blogList.removeIf( item -> item.getCode( ).equals( String.valueOf( tg.getIdTag( ) ) ) );
1508 
1509         }
1510         return blogList;
1511     }
1512 
1513     /**
1514      * Check if the blog is locked
1515      * 
1516      * @param nIdBlog
1517      *            The Id blog
1518      * @param strIdSession
1519      *            The Id session
1520      * @return return true if the blog is locked else false
1521      */
1522     private boolean checkLockBlog( int nIdBlog, String strIdSession )
1523     {
1524         return _mapLockBlog.get( nIdBlog ) != null && !_mapLockBlog.get( nIdBlog ).getSessionId( ).equals( strIdSession );
1525     }
1526 
1527     /**
1528      * Lock blog
1529      * 
1530      * @param nIdBlog
1531      *            The Id blog
1532      * @param strIdSession
1533      *            The Id session
1534      */
1535     private void lockBlog( int nIdBlog, String strIdSession )
1536     {
1537 
1538         _mapLockBlog.remove( nIdBlog );
1539         _mapLockBlog.put( nIdBlog, new BlogLock( strIdSession, System.currentTimeMillis( ) ) );
1540 
1541     }
1542 
1543     /**
1544      * Unlock Blog
1545      * 
1546      * @param nIdBlog
1547      *            The id Blog
1548      */
1549     private void unLockBlog( int nIdBlog )
1550     {
1551 
1552         _mapLockBlog.remove( nIdBlog );
1553 
1554     }
1555 
1556     /**
1557      * Unlock Blogs By Session Id
1558      * 
1559      * @param strIdSession
1560      *            The Id session
1561      */
1562     public static void unLockedBlogByIdSession( String strIdSession )
1563     {
1564 
1565         _mapLockBlog.values( ).removeIf( id -> id.getSessionId( ).equals( strIdSession ) );
1566     }
1567 
1568     /**
1569      * Unlock the blog if the lock clearance time has passed
1570      * 
1571      * @param nTime
1572      *            the clearance time
1573      */
1574     public static void unLockedBlogByTime( long nTime )
1575     {
1576 
1577         long currentTime = System.currentTimeMillis( );
1578         _mapLockBlog.values( ).removeIf( id -> id.getTime( ) + nTime < currentTime );
1579     }
1580 
1581     /**
1582      * Gets the current
1583      *
1584      * @return the current date in sql format
1585      */
1586     public java.sql.Timestamp getSqlDate( )
1587     {
1588         java.util.Date utilDate = new java.util.Date( );
1589         java.sql.Timestamp sqlDate = new java.sql.Timestamp( utilDate.getTime( ) );
1590 
1591         return ( sqlDate );
1592     }
1593 
1594 }