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.portlet;
35  
36  import java.sql.Date;
37  import java.text.ParseException;
38  import java.text.SimpleDateFormat;
39  import java.util.ArrayList;
40  import java.util.HashMap;
41  import java.util.List;
42  
43  import javax.servlet.http.HttpServletRequest;
44  
45  import org.apache.commons.lang3.StringUtils;
46  import org.apache.commons.lang3.ArrayUtils;
47  
48  import fr.paris.lutece.plugins.blog.business.Blog;
49  import fr.paris.lutece.plugins.blog.business.BlogHome;
50  import fr.paris.lutece.plugins.blog.business.BlogSearchFilter;
51  import fr.paris.lutece.plugins.blog.business.BlogSerializable;
52  import fr.paris.lutece.plugins.blog.business.TagHome;
53  
54  import fr.paris.lutece.plugins.blog.business.portlet.BlogListPortlet;
55  import fr.paris.lutece.plugins.blog.business.portlet.BlogListPortletHome;
56  import fr.paris.lutece.plugins.blog.business.portlet.BlogPublication;
57  import fr.paris.lutece.plugins.blog.business.portlet.BlogPublicationHome;
58  import fr.paris.lutece.plugins.blog.service.BlogService;
59  import fr.paris.lutece.plugins.blog.service.PublishingService;
60  import fr.paris.lutece.plugins.blog.service.docsearch.BlogSearchService;
61  import fr.paris.lutece.plugins.blog.web.BlogPublicationJspBean;
62  import fr.paris.lutece.portal.business.portlet.PortletHome;
63  import fr.paris.lutece.portal.business.user.AdminUser;
64  import fr.paris.lutece.portal.service.admin.AdminUserService;
65  import fr.paris.lutece.portal.service.util.AppPathService;
66  import fr.paris.lutece.portal.service.util.AppPropertiesService;
67  import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
68  import fr.paris.lutece.portal.web.portlet.PortletJspBean;
69  import fr.paris.lutece.portal.web.util.LocalizedPaginator;
70  import fr.paris.lutece.util.date.DateUtil;
71  import fr.paris.lutece.util.html.AbstractPaginator;
72  import fr.paris.lutece.util.html.HtmlTemplate;
73  import fr.paris.lutece.util.json.JsonResponse;
74  import fr.paris.lutece.util.json.JsonUtil;
75  import java.util.Map;
76  
77  /**
78   * This class provides the user interface to manage BlogList Portlet
79   */
80  public class BlogListPortletJspBean extends PortletJspBean
81  {
82      // Right
83      public static final String RIGHT_MANAGE_ADMIN_SITE = "CORE_ADMIN_SITE";
84  
85      public static final String MARK_WEBAPP_URL = "webapp_url";
86      public static final String MARK_LIST_HTMLDOC = "blog_list";
87      public static final String MARK_LIST_PAGES = "pages_list";
88      public static final String MARK_LIST_HTMLDOC_PUBLISHED = "blog_list_published";
89  
90      public static final String PARAMETER_ACTION_PORTLET_ADD = "add";
91      public static final String PARAMETER_ACTION_PORTLET_REMOVE = "remove";
92      public static final String PARAMETER_ACTION_PORTLET = "action";
93      private static final String PARAMETER_PAGE_TEMPLATE_CODE = "page_template_code";
94  
95      private static final String PARAMETER_DOCUMENT_ID = "idDocument";
96      private static final String PARAMETER_DOCUMENT_ORDER = "orderDocument";
97      private static final String PARAMETER_REFRESH_BUTTON = "refresh";
98      protected static final String PARAMETER_TAG = "tag_doc";
99  
100     protected static final String PARAMETER_SEARCH_TEXT = "search_text";
101     protected static final String PARAMETER_UNPUBLISHED = "unpublished";
102     protected static final String PARAMETER_DATE_UPDATE_BLOG_AFTER = "dateUpdateBlogAfter";
103     protected static final String PARAMETER_DATE_UPDATE_BLOG_BEFOR = "dateUpdateBlogBefor";
104 
105     protected static final String PARAMETER_BUTTON_SEARCH = "button_search";
106     protected static final String PARAMETER_BUTTON_RESET = "button_reset";
107 
108     protected static final String MARK_IS_CHECKED = "is_checked";
109     protected static final String MARK_CURRENT_USER = "current_user";
110     protected static final String MARK_ID_BLOG = "id";
111     protected static final String MARK_SEARCH_TEXT = "search_text";
112 
113     protected static final String MARK_PAGINATOR = "paginator";
114     protected static final String MARK_NB_ITEMS_PER_PAGE = "nb_items_per_page";
115     protected static final String MARK_DATE_UPDATE_BLOG_AFTER = "dateUpdateBlogAfter";
116     protected static final String MARK_DATE_UPDATE_BLOG_BEFOR = "dateUpdateBlogBefor";
117     protected static final String MARK_UNPUBLISHED = "unpublished";
118     protected static final String MARK_LIST_TAG = "list_tag";
119 
120     // Properties
121     private static final String PROPERTY_DEFAULT_LIST_ITEM_PER_PAGE = "blog.listItems.itemsPerPage";
122 
123     private static final String VIEW_MODIFY_PORTLET = "getModify";
124 
125     private static final String RESPONSE_SUCCESS = "SUCCESS";
126 
127     // //////////////////////////////////////////////////////////////////////////
128     // Constants
129     private static final long serialVersionUID = 1L;
130 
131     // //////////////////////////////////////////////////////////////////////////
132     // Class attributes
133 
134     private BlogListPortlet _portlet;
135 
136     protected String _strCurrentPageIndex;
137     protected int _nItemsPerPage;
138 
139     protected int _nDefaultItemsPerPage = AppPropertiesService.getPropertyInt( PROPERTY_DEFAULT_LIST_ITEM_PER_PAGE, 20 );
140 
141     // Session variable to store working values
142     protected boolean _bIsChecked = false;
143     protected String _strSearchText;
144     protected boolean _bIsUnpulished = false;
145     protected String _dateUpdateBlogAfter;
146     protected String _dateUpdateBlogBefor;
147     protected boolean _bIsSorted = false;
148     protected String _strSortedAttributeName;
149     protected Boolean _bIsAscSort;
150     protected String [ ] _strTag;
151 
152     /**
153      * Returns portlet's properties prefix
154      *
155      * @return prefix
156      */
157     public String getPropertiesPrefix( )
158     {
159         return "portlet.blogdocument";
160     }
161 
162     /**
163      * Return a model that contains the list and paginator infos
164      * 
165      * @param request
166      *            The HTTP request
167      * @return The map
168      */
169     protected Map<String, Object> getPaginatedListModel( HttpServletRequest request )
170     {
171         List<Integer> listBlogsId = filterBlogIds( request );
172 
173         _strCurrentPageIndex = AbstractPaginator.getPageIndex( request, AbstractPaginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex );
174         _nItemsPerPage = AbstractPaginator.getItemsPerPage( request, AbstractPaginator.PARAMETER_ITEMS_PER_PAGE, _nDefaultItemsPerPage, _nItemsPerPage );
175         List<Blog> listBlogPublished = new ArrayList<>( );
176         List<Blog> listBlogNotPublished = new ArrayList<>( );
177 
178         for ( BlogPublication i : _portlet.getArrayBlogs( ) )
179         {
180             Blog blog = BlogService.getInstance( ).findByPrimaryKeyWithoutBinaries( i.getIdBlog( ) );
181             listBlogPublished.add( blog );
182             listBlogsId.removeIf( blg -> blg.equals( blog.getId( ) ) );
183         }
184 
185         LocalizedPaginator<Integer> paginator = new LocalizedPaginator<>( listBlogsId, _nItemsPerPage, getCurrentUrlFromRequest( request ),
186                 AbstractPaginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex, getLocale( ) );
187         List<Blog> listBlog = new ArrayList<>( );
188 
189         for ( Integer documentId : paginator.getPageItems( ) )
190         {
191             Blog blog = BlogService.getInstance( ).findByPrimaryKeyWithoutBinaries( documentId );
192 
193             if ( blog != null )
194             {
195                 listBlog.add( blog );
196             }
197         }
198 
199         listBlogNotPublished.addAll( listBlog );
200 
201         HashMap<String, Object> model = new HashMap<>( );
202         model.put( MARK_PAGINATOR, paginator );
203         model.put( MARK_NB_ITEMS_PER_PAGE, "" + _nItemsPerPage );
204         model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
205         model.put( MARK_LIST_HTMLDOC, listBlogNotPublished );
206         model.put( MARK_LIST_HTMLDOC_PUBLISHED, listBlogPublished );
207 
208         model.put( MARK_LIST_TAG, TagHome.getTagsReferenceList( ) );
209         model.put( MARK_IS_CHECKED, _bIsChecked );
210         model.put( MARK_SEARCH_TEXT, _strSearchText );
211         model.put( MARK_DATE_UPDATE_BLOG_AFTER, _dateUpdateBlogAfter );
212         model.put( MARK_DATE_UPDATE_BLOG_BEFOR, _dateUpdateBlogBefor );
213         model.put( MARK_UNPUBLISHED, _bIsUnpulished );
214 
215         model.put( MARK_LIST_PAGES, BlogListPortletHome.loadPages( BlogListPortlet.RESOURCE_ID ) );
216 
217         return model;
218     }
219 
220     /**
221      * Get the list of filtered blog ids.
222      *
223      * @param request
224      * @return list of blog id.
225      */
226     private List<Integer> filterBlogIds( HttpServletRequest request )
227     {
228         List<Integer> listBlogsId = new ArrayList<>( );
229         AdminUser user = AdminUserService.getAdminUser( request );
230 
231         if ( StringUtils.isNotBlank( _strSearchText ) || ArrayUtils.isNotEmpty(
232                 _strTag ) || _bIsChecked || _bIsUnpulished || _dateUpdateBlogAfter != null || _dateUpdateBlogBefor != null )
233         {
234             BlogSearchFilterbusiness/BlogSearchFilter.html#BlogSearchFilter">BlogSearchFilter filter = new BlogSearchFilter( );
235             if ( StringUtils.isNotBlank( _strSearchText ) )
236             {
237                 filter.setKeywords( _strSearchText );
238             }
239             if ( ArrayUtils.isNotEmpty( _strTag ) )
240             {
241                 filter.setTag( _strTag );
242             }
243             if ( _bIsChecked )
244             {
245                 filter.setUser( user.getAccessCode( ) );
246             }
247             if ( _bIsUnpulished )
248             {
249                 filter.setIsUnpulished( _bIsUnpulished );
250             }
251             if ( _dateUpdateBlogAfter != null )
252             {
253                 filter.setUpdateDateAfter( DateUtil.formatDate( _dateUpdateBlogAfter, getLocale( ) ) );
254             }
255             if ( _dateUpdateBlogBefor != null )
256             {
257                 filter.setUpdateDateBefor( DateUtil.formatDate( _dateUpdateBlogBefor, getLocale( ) ) );
258             }
259 
260             BlogSearchService.getInstance( ).getSearchResults( filter, listBlogsId );
261 
262         }
263         else
264         {
265 
266             listBlogsId = BlogHome.getIdBlogsList( );
267         }
268 
269         return listBlogsId;
270     }
271 
272 
273     /**
274      *
275      * @param request
276      */
277     private void setSearchBlog( HttpServletRequest request, String strButtonSearch, String strButtonReset )
278     {
279 
280         if ( strButtonSearch != null )
281         {
282             // CURRENT USER
283             _bIsChecked = request.getParameter( MARK_CURRENT_USER ) != null;
284             _strSearchText = request.getParameter( PARAMETER_SEARCH_TEXT );
285             _strTag = request.getParameterValues( PARAMETER_TAG );
286             _bIsUnpulished = request.getParameter( PARAMETER_UNPUBLISHED ) != null;
287             _dateUpdateBlogAfter = request.getParameter( PARAMETER_DATE_UPDATE_BLOG_AFTER );
288             _dateUpdateBlogBefor = request.getParameter( PARAMETER_DATE_UPDATE_BLOG_BEFOR );
289 
290         }
291         else
292             if ( strButtonReset != null )
293             {
294 
295                 _bIsChecked = false;
296                 _strSearchText = null;
297                 _strTag = null;
298                 _bIsUnpulished = false;
299                 _dateUpdateBlogAfter = null;
300                 _dateUpdateBlogBefor = null;
301 
302             }
303     }
304 
305     public String getSearch( HttpServletRequest request )
306     {
307         Map<String, Object> data = new HashMap<>( );
308         String strButtonSearch = request.getParameter( PARAMETER_BUTTON_SEARCH );
309         String strButtonReset = request.getParameter( PARAMETER_BUTTON_RESET );
310         _nItemsPerPage = AbstractPaginator.getItemsPerPage( request, AbstractPaginator.PARAMETER_ITEMS_PER_PAGE, _nItemsPerPage, _nDefaultItemsPerPage);
311         setSearchBlog( request, strButtonSearch, strButtonReset );
312 
313         List<Integer> listBlogsId = filterBlogIds( request );
314 
315         List<BlogSerializable> listBlogNotPublished = new ArrayList<>( );
316 
317         for ( BlogPublication i : _portlet.getArrayBlogs( ) )
318         {
319             Blog blog = BlogService.getInstance( ).findByPrimaryKeyWithoutBinaries( i.getIdBlog( ) );
320             listBlogsId.removeIf( blg -> blg.equals( blog.getId( ) ) );
321         }
322         LocalizedPaginator<Integer> paginator = new LocalizedPaginator<>( listBlogsId, _nItemsPerPage, getCurrentUrlFromRequest( request ),
323                 AbstractPaginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex, getLocale( ) );
324 
325         for ( Integer nBlogId : paginator.getPageItems( ) )
326         {
327             Blog blog = BlogService.getInstance( ).findByPrimaryKeyWithoutBinaries( nBlogId );
328             if ( blog != null )
329             {
330                 listBlogNotPublished.add( new BlogSerializable( blog.getId( ), blog.getContentLabel( ) ) );
331             }
332         }
333         data.put( MARK_LIST_HTMLDOC, listBlogNotPublished );
334         JsonResponse json = new JsonResponse( data );
335         return JsonUtil.buildJsonResponse( json );
336     }
337 
338     /**
339      * Returns the Download portlet creation form
340      *
341      * @param request
342      *            The http request
343      * @return The HTML form
344      */
345     @Override
346     public String getCreate( HttpServletRequest request )
347     {
348         String strIdPage = request.getParameter( PARAMETER_PAGE_ID );
349         String strIdPortletType = request.getParameter( PARAMETER_PORTLET_TYPE_ID );
350         _portlet = ( _portlet != null && request.getParameter( AbstractPaginator.PARAMETER_PAGE_INDEX ) != null ) ? _portlet : new BlogListPortlet( );
351         Map<String, Object> model = getPaginatedListModel( request );
352         HtmlTemplate template = getCreateTemplate( strIdPage, strIdPortletType, model );
353 
354         return template.getHtml( );
355     }
356 
357     /**
358      * Returns the Download portlet modification form
359      *
360      * @param request
361      *            The Http request
362      * @return The HTML form
363      */
364     @View( VIEW_MODIFY_PORTLET )
365     @Override
366     public String getModify( HttpServletRequest request )
367     {
368         String strPortletId = request.getParameter( PARAMETER_PORTLET_ID );
369         int nPortletId = Integer.parseInt( strPortletId );
370         _portlet = ( _portlet != null && request.getParameter( AbstractPaginator.PARAMETER_PAGE_INDEX ) != null ) ? _portlet
371                 : (BlogListPortlet) PortletHome.findByPrimaryKey( nPortletId );
372         Map<String, Object> model = getPaginatedListModel( request );
373 
374         HtmlTemplate template = getModifyTemplate( _portlet, model );
375 
376         return template.getHtml( );
377     }
378 
379     /**
380      * Process portlet's creation
381      *
382      * @param request
383      *            The Http request
384      * @return The Jsp management URL of the process result
385      */
386     @Override
387     public String doCreate( HttpServletRequest request )
388     {
389 
390         String button = request.getParameter( PARAMETER_REFRESH_BUTTON );
391         _nDefaultItemsPerPage = AbstractPaginator.getItemsPerPage( request, AbstractPaginator.PARAMETER_ITEMS_PER_PAGE, _nItemsPerPage, _nDefaultItemsPerPage );
392         String strIdPage = request.getParameter( PARAMETER_PAGE_ID );
393         String strButtonSearch = request.getParameter( PARAMETER_BUTTON_SEARCH );
394         String strButtonReset = request.getParameter( PARAMETER_BUTTON_RESET );
395         int nIdPage = Integer.parseInt( strIdPage );
396 
397         if ( ( button != null && button.equals( PARAMETER_REFRESH_BUTTON ) ) || strButtonSearch != null || strButtonReset != null )
398         {
399 
400             setSearchBlog( request, strButtonSearch, strButtonReset );
401             return "../../DoCreatePortlet.jsp?portlet_type_id=" + BlogListPortlet.RESOURCE_ID + "&page_id=" + strIdPage + "&"
402                     + AbstractPaginator.PARAMETER_PAGE_INDEX + "=1";
403         }
404 
405         int order = 1;
406 
407         // gets the identifier of the parent page
408         String strTemplateCode = request.getParameter( PARAMETER_PAGE_TEMPLATE_CODE );
409 
410         // get portlet common attributes
411         String strErrorUrl = setPortletCommonData( request, _portlet );
412 
413         if ( strErrorUrl != null )
414         {
415             return strErrorUrl;
416         }
417 
418         _portlet.setPageId( nIdPage );
419 
420         // gets the specific parameters
421         _portlet.setPageTemplateDocument( Integer.parseInt( strTemplateCode ) );
422 
423         for ( BlogPublication doc : _portlet.getArrayBlogs( ) )
424         {
425 
426             doc.setBlogOrder( order );
427             order++;
428 
429         }
430         // Portlet creation
431         BlogListPortletHome.getInstance( ).create( _portlet );
432 
433         for ( BlogPublication doc : _portlet.getArrayBlogs( ) )
434         {
435             int nbPublication = BlogPublicationHome.countPublicationByIdBlogAndDate( doc.getIdBlog( ), new java.util.Date( ) );
436             // First publication of this blog -> indexing needed
437             if ( nbPublication == 1 )
438             {
439                 BlogService.getInstance( ).fireCreateBlogEvent( doc.getIdBlog( ) );
440             }
441         }
442 
443         // Displays the page with the new Portlet
444         return getPageUrl( nIdPage );
445     }
446 
447     /**
448      * Process portlet's modification
449      *
450      * @param request
451      *            The http request
452      * @return Management's Url
453      */
454     @Override
455     public String doModify( HttpServletRequest request )
456     {
457 
458         _nDefaultItemsPerPage = AbstractPaginator.getItemsPerPage( request, AbstractPaginator.PARAMETER_ITEMS_PER_PAGE, _nItemsPerPage, _nDefaultItemsPerPage );
459         String button = request.getParameter( PARAMETER_REFRESH_BUTTON );
460         String strButtonSearch = request.getParameter( PARAMETER_BUTTON_SEARCH );
461         String strButtonReset = request.getParameter( PARAMETER_BUTTON_RESET );
462 
463         if ( ( button != null && button.equals( PARAMETER_REFRESH_BUTTON ) ) || strButtonSearch != null || strButtonReset != null )
464         {
465 
466             setSearchBlog( request, strButtonSearch, strButtonReset );
467             return "../../DoModifyPortlet.jsp?portlet_id=" + _portlet.getId( ) + "&" + AbstractPaginator.PARAMETER_PAGE_INDEX + "=1";
468         }
469 
470         int order = 1;
471 
472         // recovers portlet attributes
473         String strDocumentTypeCode = request.getParameter( PARAMETER_PAGE_TEMPLATE_CODE );
474         // retrieve portlet common attributes
475         String strErrorUrl = setPortletCommonData( request, _portlet );
476 
477         if ( strErrorUrl != null )
478         {
479             return strErrorUrl;
480         }
481 
482         _portlet.setPageTemplateDocument( Integer.parseInt( strDocumentTypeCode ) );
483 
484         for ( BlogPublication doc : _portlet.getArrayBlogs( ) )
485         {
486 
487             doc.setBlogOrder( order );
488             order++;
489 
490         }
491         // updates the portlet
492         _portlet.update( );
493 
494         for ( Integer removedBlog : _portlet.getRemovedBlogsId( ) )
495         {
496             int nbPublication = BlogPublicationHome.countPublicationByIdBlogAndDate( removedBlog, new java.util.Date( ) );
497             // Last publication of this blog removed -> removing from index
498             if ( nbPublication == 0 )
499             {
500                 BlogService.getInstance( ).fireDeleteBlogEvent( removedBlog );
501             }
502         }
503 
504         for ( BlogPublication doc : _portlet.getArrayBlogs( ) )
505         {
506             int nbPublication = BlogPublicationHome.countPublicationByIdBlogAndDate( doc.getIdBlog( ), new java.util.Date( ) );
507             // First publication of this blog -> indexing needed
508             if ( nbPublication == 1 )
509             {
510                 BlogService.getInstance( ).fireCreateBlogEvent( doc.getIdBlog( ) );
511             }
512         }
513 
514         // displays the page withe the potlet updated
515         return getPageUrl( _portlet.getPageId( ) );
516     }
517 
518     /**
519      * Update blog portlet
520      *
521      * @param request
522      * @return Json The Json succes or echec
523      * @throws ParseException
524      */
525     public String updatePortletDocument( HttpServletRequest request ) throws ParseException
526     {
527         // recovers portlet attributes
528 
529         String strAction = request.getParameter( PARAMETER_ACTION_PORTLET );
530         String strIdDocument = request.getParameter( PARAMETER_DOCUMENT_ID );
531         String strOrderDocument = request.getParameter( PARAMETER_DOCUMENT_ORDER );
532 
533         int nIdDocument = Integer.parseInt( strIdDocument );
534         BlogPublication doc = PublishingService.getInstance( ).getBlogPublication( _portlet.getId( ), nIdDocument );
535         if ( doc == null )
536         {
537             doc = new BlogPublication( );
538             SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );
539             doc.setDateEndPublishing( new Date( sdf.parse( BlogPublicationJspBean.DATE_END_PUBLICATION ).getTime( ) ) );
540             doc.setIdBlog( nIdDocument );
541         }
542         if ( strAction != null && !strAction.isEmpty( ) && strAction.equals( PARAMETER_ACTION_PORTLET_ADD ) )
543         {
544 
545             int nDocumentOrder = Integer.parseInt( strOrderDocument );
546             _portlet.addIdBlogs( nDocumentOrder, doc );
547 
548         }
549         else
550             if ( strAction != null && !strAction.isEmpty( ) && strAction.equals( PARAMETER_ACTION_PORTLET_REMOVE ) )
551             {
552 
553                 _portlet.removeBlogs( doc );
554 
555             }
556 
557         return JsonUtil.buildJsonResponse( new JsonResponse( RESPONSE_SUCCESS ) );
558     }
559 
560     /**
561      *
562      * @param request
563      * @return
564      */
565     public static String getCurrentUrlFromRequest( HttpServletRequest request )
566     {
567         StringBuffer sbRequestURL = request.getRequestURL( );
568         String queryString = request.getQueryString( );
569 
570         if ( queryString == null )
571         {
572 
573             return sbRequestURL.toString( );
574 
575         }
576         else
577             if ( request.getParameter( AbstractPaginator.PARAMETER_PAGE_INDEX ) != null )
578             {
579 
580                 String [ ] query = queryString.split( "&" + AbstractPaginator.PARAMETER_PAGE_INDEX );
581                 queryString = query [0];
582             }
583 
584         return sbRequestURL.append( '?' ).append( queryString ).toString( );
585     }
586 
587 }