LocalizedPaginator.java

  1. /*
  2.  * Copyright (c) 2002-2022, 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.portal.web.util;

  35. import fr.paris.lutece.portal.service.i18n.I18nService;
  36. import fr.paris.lutece.util.html.Paginator;

  37. import java.util.List;
  38. import java.util.Locale;

  39. /**
  40.  * Localized Paginator
  41.  *
  42.  * @param <E>
  43.  *            Item of the list
  44.  */
  45. public class LocalizedPaginator<E> extends Paginator<E>
  46. {
  47.     private static final long serialVersionUID = 6863575639914868230L;
  48.     private static final String KEY_FIRST = "portal.util.labelFirst";
  49.     private static final String KEY_PREVIOUS = "portal.util.labelPrevious";
  50.     private static final String KEY_NEXT = "portal.util.labelNext";
  51.     private static final String KEY_LAST = "portal.util.labelLast";
  52.     private static final String KEY_ITEM_COUNT = "portal.util.labelItemCount";
  53.     private static final String KEY_ITEM_COUNT_PER_PAGE = "portal.util.labelItemCountPerPage";
  54.     private Locale _locale;

  55.     /**
  56.      * Creates a new instance of Paginator
  57.      *
  58.      * @param list
  59.      *            The collection to paginate
  60.      * @param nItemPerPage
  61.      *            Number of items to display per page
  62.      * @param strBaseUrl
  63.      *            The base Url for build links on each page link
  64.      * @param strPageIndexParameterName
  65.      *            The parameter name for the page index
  66.      * @param strPageIndex
  67.      *            The current page index
  68.      * @param locale
  69.      *            The Locale
  70.      */
  71.     public LocalizedPaginator( List<E> list, int nItemPerPage, String strBaseUrl, String strPageIndexParameterName, String strPageIndex, Locale locale )
  72.     {
  73.         super( list, nItemPerPage, strBaseUrl, strPageIndexParameterName, strPageIndex );
  74.         _locale = locale;
  75.     }

  76.     /**
  77.      * Creates a new instance of Paginator
  78.      *
  79.      * @param list
  80.      *            The collection to paginate
  81.      * @param nItemPerPage
  82.      *            Number of items to display per page
  83.      * @param strBaseUrl
  84.      *            The base Url for build links on each page link
  85.      * @param strPageIndexParameterName
  86.      *            The parameter name for the page index
  87.      * @param strPageIndex
  88.      *            The current page index
  89.      * @param strItemsPerPageParameterName
  90.      *            The parameter name of the number items per page
  91.      * @param locale
  92.      *            The Locale
  93.      */
  94.     public LocalizedPaginator( List<E> list, int nItemPerPage, String strBaseUrl, String strPageIndexParameterName, String strPageIndex,
  95.             String strItemsPerPageParameterName, Locale locale )
  96.     {
  97.         this( list, nItemPerPage, strBaseUrl, strPageIndexParameterName, strPageIndex, locale );
  98.         setItemsPerPageParameterName( strItemsPerPageParameterName );
  99.     }

  100.     /**
  101.      * {@inheritDoc }
  102.      */
  103.     @Override
  104.     public String getLabelFirst( )
  105.     {
  106.         return I18nService.getLocalizedString( KEY_FIRST, _locale );
  107.     }

  108.     /**
  109.      * {@inheritDoc }
  110.      */
  111.     @Override
  112.     public String getLabelPrevious( )
  113.     {
  114.         return I18nService.getLocalizedString( KEY_PREVIOUS, _locale );
  115.     }

  116.     /**
  117.      * {@inheritDoc }
  118.      */
  119.     @Override
  120.     public String getLabelNext( )
  121.     {
  122.         return I18nService.getLocalizedString( KEY_NEXT, _locale );
  123.     }

  124.     /**
  125.      * {@inheritDoc }
  126.      */
  127.     @Override
  128.     public String getLabelLast( )
  129.     {
  130.         return I18nService.getLocalizedString( KEY_LAST, _locale );
  131.     }

  132.     /**
  133.      * {@inheritDoc }
  134.      */
  135.     @Override
  136.     public String getLabelItemCount( )
  137.     {
  138.         return I18nService.getLocalizedString( KEY_ITEM_COUNT, _locale );
  139.     }

  140.     /**
  141.      * {@inheritDoc }
  142.      */
  143.     @Override
  144.     public String getLabelItemCountPerPage( )
  145.     {
  146.         return I18nService.getLocalizedString( KEY_ITEM_COUNT_PER_PAGE, _locale );
  147.     }
  148. }