11package org .thymeleaf .dialect .springdata .decorator ;
22
3- import java .util .Locale ;
4-
53import org .springframework .data .domain .Page ;
64import org .thymeleaf .context .ITemplateContext ;
75import org .thymeleaf .dialect .springdata .Keys ;
6+ import org .thymeleaf .dialect .springdata .SpringDataDialect ;
87import org .thymeleaf .dialect .springdata .util .Messages ;
98import org .thymeleaf .dialect .springdata .util .PageUtils ;
109import org .thymeleaf .dialect .springdata .util .Strings ;
1110import org .thymeleaf .model .IProcessableElementTag ;
1211
12+ import java .util .Locale ;
13+ import java .util .Map ;
14+
1315public final class FullPaginationDecorator implements PaginationDecorator {
1416 private static final String DEFAULT_CLASS = "pagination" ;
1517 private static final String BUNDLE_NAME = FullPaginationDecorator .class .getSimpleName ();
1618 private static final int DEFAULT_PAGE_SPLIT = 7 ;
19+ private static final String CSS_ATTR_PREFIX = SpringDataDialect .PREFIX + ":" + DEFAULT_CLASS + "-" ;
20+
21+ // define custom CSS tags
22+ private String cssLaquo = "page-item" ;
23+ private String cssRaquo = "page-item" ;
24+ private String cssPrevious = "page-item" ;
25+ private String cssNext = "page-item" ;
26+ private String cssPageItem = "page-item" ;
27+ private String cssPageLink = "page-link" ;
28+ private String cssDisabled = "disabled" ;
29+ private String cssActive = "active" ;
1730
1831 public String getIdentifier () {
1932 return "full" ;
@@ -23,6 +36,8 @@ public String decorate(final IProcessableElementTag tag, final ITemplateContext
2336
2437 Page <?> page = PageUtils .findPage (context );
2538
39+ configureCss (tag .getAttributeMap ());
40+
2641 // laquo
2742 String firstPage = PageUtils .createPageUrl (context , 0 );
2843 Locale locale = context .getLocale ();
@@ -93,27 +108,27 @@ private String createPageLinks(final Page<?> page, final ITemplateContext contex
93108 }
94109
95110 private String getLaquo (Locale locale ) {
96- return Messages .getMessage (BUNDLE_NAME , "laquo" , locale );
111+ return Messages .getMessage (BUNDLE_NAME , "laquo" , locale , cssLaquo , cssPageLink , cssDisabled );
97112 }
98113
99114 private String getLaquo (String firstPage , Locale locale ) {
100- return Messages .getMessage (BUNDLE_NAME , "laquo.link" , locale , firstPage );
115+ return Messages .getMessage (BUNDLE_NAME , "laquo.link" , locale , firstPage , cssLaquo , cssPageLink );
101116 }
102117
103118 private String getRaquo (Locale locale ) {
104- return Messages .getMessage (BUNDLE_NAME , "raquo" , locale );
119+ return Messages .getMessage (BUNDLE_NAME , "raquo" , locale , cssRaquo , cssPageLink , cssDisabled );
105120 }
106121
107122 private String getRaquo (String lastPage , Locale locale ) {
108- return Messages .getMessage (BUNDLE_NAME , "raquo.link" , locale , lastPage );
123+ return Messages .getMessage (BUNDLE_NAME , "raquo.link" , locale , lastPage , cssRaquo , cssPageLink );
109124 }
110125
111126 private String getLink (int pageNumber , Locale locale ) {
112- return Messages .getMessage (BUNDLE_NAME , "link.active" , locale , pageNumber );
127+ return Messages .getMessage (BUNDLE_NAME , "link.active" , locale , pageNumber , cssActive , cssPageLink );
113128 }
114129
115130 private String getLink (int pageNumber , String url , Locale locale ) {
116- return Messages .getMessage (BUNDLE_NAME , "link" , locale , url , pageNumber );
131+ return Messages .getMessage (BUNDLE_NAME , "link" , locale , url , pageNumber , cssPageItem , cssPageLink );
117132 }
118133
119134 private String getPreviousPageLink (Page <?> page , final ITemplateContext context ) {
@@ -122,7 +137,7 @@ private String getPreviousPageLink(Page<?> page, final ITemplateContext context)
122137 int previousPage = page .getNumber ()-1 ;
123138 String link = PageUtils .createPageUrl (context , previousPage );
124139
125- return Messages .getMessage (BUNDLE_NAME , msgKey , locale , link );
140+ return Messages .getMessage (BUNDLE_NAME , msgKey , locale , link , cssPrevious , cssPageLink , cssDisabled );
126141 }
127142
128143 private String getNextPageLink (Page <?> page , final ITemplateContext context ) {
@@ -131,7 +146,42 @@ private String getNextPageLink(Page<?> page, final ITemplateContext context) {
131146 int nextPage = page .getNumber () + 1 ;
132147 String link = PageUtils .createPageUrl (context , nextPage );
133148
134- return Messages .getMessage (BUNDLE_NAME , msgKey , locale , link );
149+ return Messages .getMessage (BUNDLE_NAME , msgKey , locale , link , cssNext , cssPageLink , cssDisabled );
150+ }
151+
152+ private void configureCss (Map <String ,String > attributeMap ) {
153+
154+ if (attributeMap .get (CSS_ATTR_PREFIX + "laquo" ) != null ) {
155+ this .cssLaquo = attributeMap .get (CSS_ATTR_PREFIX + "laquo" );
156+ }
157+
158+ if (attributeMap .get (CSS_ATTR_PREFIX + "raquo" ) != null ) {
159+ this .cssRaquo = attributeMap .get (CSS_ATTR_PREFIX + "raquo" );
160+ }
161+
162+ if (attributeMap .get (CSS_ATTR_PREFIX + "previous" ) != null ) {
163+ this .cssPrevious = attributeMap .get (CSS_ATTR_PREFIX + "previous" );
164+ }
165+
166+ if (attributeMap .get (CSS_ATTR_PREFIX + "next" ) != null ) {
167+ this .cssNext = attributeMap .get (CSS_ATTR_PREFIX + "next" );
168+ }
169+
170+ if (attributeMap .get (CSS_ATTR_PREFIX + "page-item" ) != null ) {
171+ this .cssPageItem = attributeMap .get (CSS_ATTR_PREFIX + "page-item" );
172+ }
173+
174+ if (attributeMap .get (CSS_ATTR_PREFIX + "page-link" ) != null ) {
175+ this .cssPageLink = attributeMap .get (CSS_ATTR_PREFIX + "page-link" );
176+ }
177+
178+ if (attributeMap .get (CSS_ATTR_PREFIX + "disabled" ) != null ) {
179+ this .cssDisabled = attributeMap .get (CSS_ATTR_PREFIX + "disabled" );
180+ }
181+
182+ if (attributeMap .get (CSS_ATTR_PREFIX + "active" ) != null ) {
183+ this .cssActive = attributeMap .get (CSS_ATTR_PREFIX + "active" );
184+ }
135185 }
136186
137187}
0 commit comments