1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.util.html;
35
36 import fr.paris.lutece.util.url.UrlItem;
37
38 import org.apache.commons.lang3.StringUtils;
39
40 import java.io.Serializable;
41
42 import java.util.List;
43
44
45
46
47
48
49 public class ItemNavigator implements Serializable
50 {
51 private static final long serialVersionUID = -6240496590042563143L;
52 private List<String> _listItems;
53 private int _nCurrentItemId;
54 private String _strBaseUrl;
55 private String _strParameterName;
56
57
58
59
60
61
62
63
64
65
66
67
68
69 public ItemNavigator( List<String> listItems, int nCurrentItemId, String strBaseUrl, String strParameterName )
70 {
71 _listItems = listItems;
72 _nCurrentItemId = nCurrentItemId;
73 _strBaseUrl = strBaseUrl;
74 _strParameterName = strParameterName;
75 }
76
77
78
79
80
81
82
83 public void setCurrentItemId( String strItem )
84 {
85 int nCurrentItemId = _nCurrentItemId;
86
87 if ( ( strItem != null ) && ( _listItems != null ) && !_listItems.isEmpty( ) && !strItem.equals( _listItems.get( _nCurrentItemId ) ) )
88 {
89 int nPreviousItemId = _nCurrentItemId - 1;
90 int nNextItemId = _nCurrentItemId + 1;
91
92 if ( ( nPreviousItemId >= 0 ) && strItem.equals( _listItems.get( nPreviousItemId ) ) )
93 {
94
95 nCurrentItemId = nPreviousItemId;
96 }
97 else
98 if ( ( nNextItemId < _listItems.size( ) ) && strItem.equals( _listItems.get( nNextItemId ) ) )
99 {
100
101 nCurrentItemId = nNextItemId;
102 }
103 else
104 {
105
106 for ( int nIndex = 0; nIndex < _listItems.size( ); nIndex++ )
107 {
108 if ( strItem.equals( _listItems.get( nIndex ) ) )
109 {
110 nCurrentItemId = nIndex;
111
112 break;
113 }
114 }
115 }
116 }
117
118 _nCurrentItemId = nCurrentItemId;
119 }
120
121
122
123
124
125
126 public String getPreviousPageLink( )
127 {
128 int nPreviousItemId = _nCurrentItemId - 1;
129
130 if ( ( _listItems != null ) && !_listItems.isEmpty( ) && ( nPreviousItemId >= 0 ) )
131 {
132 UrlIteml/UrlItem.html#UrlItem">UrlItem url = new UrlItem( _strBaseUrl );
133 url.addParameter( _strParameterName, _listItems.get( nPreviousItemId ) );
134
135 return url.getUrl( );
136 }
137
138 return StringUtils.EMPTY;
139 }
140
141
142
143
144
145
146 public String getNextPageLink( )
147 {
148 int nNextItemId = _nCurrentItemId + 1;
149
150 if ( ( _listItems != null ) && !_listItems.isEmpty( ) && ( nNextItemId < _listItems.size( ) ) )
151 {
152 UrlIteml/UrlItem.html#UrlItem">UrlItem url = new UrlItem( _strBaseUrl );
153 url.addParameter( _strParameterName, _listItems.get( nNextItemId ) );
154
155 return url.getUrl( );
156 }
157
158 return StringUtils.EMPTY;
159 }
160
161
162
163
164
165
166 public String getBaseUrl( )
167 {
168 return _strBaseUrl;
169 }
170
171
172
173
174
175
176
177 public void setBaseUrl( String strBaseUrl )
178 {
179 _strBaseUrl = strBaseUrl;
180 }
181
182
183
184
185
186
187 public int getListItemSize( )
188 {
189 if ( _listItems != null )
190 {
191 return _listItems.size( );
192 }
193
194 return 0;
195 }
196
197
198
199
200
201
202 public int getCurrentItemId( )
203 {
204 return _nCurrentItemId;
205 }
206 }