32
32
import javax .jcr .RepositoryException ;
33
33
34
34
import com .adobe .cq .wcm .core .components .util .AbstractComponentImpl ;
35
+ import com .day .cq .search .PredicateGroup ;
35
36
import com .day .cq .search .result .SearchResult ;
36
37
import org .apache .commons .lang3 .ArrayUtils ;
37
38
import org .apache .commons .lang3 .ObjectUtils ;
@@ -91,6 +92,11 @@ public class ListImpl extends AbstractComponentImpl implements List {
91
92
*/
92
93
private static final String PN_CHILD_DEPTH = "childDepth" ;
93
94
95
+ /**
96
+ * Property name for flag that indicates if current page should be excluded.
97
+ */
98
+ private static final String PN_EXCLUDE_CURRENT_PAGE = "excludeCurrentPage" ;
99
+
94
100
/**
95
101
* Search query property name.
96
102
*/
@@ -175,6 +181,11 @@ public class ListImpl extends AbstractComponentImpl implements List {
175
181
*/
176
182
protected boolean linkItems ;
177
183
184
+ /**
185
+ * Flag indicating if the current request page should be excluded.
186
+ */
187
+ protected boolean excludeCurrentPage ;
188
+
178
189
/**
179
190
* The list items.
180
191
*/
@@ -191,6 +202,7 @@ protected void initModel() {
191
202
PN_SHOW_MODIFICATION_DATE , currentStyle .get (PN_SHOW_MODIFICATION_DATE , SHOW_MODIFICATION_DATE_DEFAULT ));
192
203
linkItems = properties .get (PN_LINK_ITEMS , currentStyle .get (PN_LINK_ITEMS , LINK_ITEMS_DEFAULT ));
193
204
dateFormatString = properties .get (PN_DATE_FORMAT , currentStyle .get (PN_DATE_FORMAT , DATE_FORMAT_DEFAULT ));
205
+ excludeCurrentPage = properties .get (PN_EXCLUDE_CURRENT_PAGE , Boolean .FALSE );
194
206
}
195
207
196
208
@ Override
@@ -279,6 +291,11 @@ protected java.util.List<Page> getPages() {
279
291
break ;
280
292
}
281
293
294
+ // filter out current page
295
+ if (this .excludeCurrentPage ) {
296
+ itemStream = itemStream .filter (page -> !page .getPath ().equals (this .currentPage .getPath ()));
297
+ }
298
+
282
299
// order the results
283
300
OrderBy orderBy = OrderBy .fromString (properties .get (PN_ORDER_BY , StringUtils .EMPTY ));
284
301
if (orderBy != null ) {
@@ -376,6 +393,17 @@ private Stream<Page> getSearchListItems() {
376
393
search .setQuery (query );
377
394
search .setSearchIn (searchRoot .get ().getPath ());
378
395
search .addPredicate (new Predicate ("type" , "type" ).set ("type" , NameConstants .NT_PAGE ));
396
+
397
+ if (this .excludeCurrentPage ) {
398
+ PredicateGroup pg = new PredicateGroup ();
399
+ pg .setNegated (true );
400
+ pg .add (new Predicate ("path" )
401
+ .set ("path" , this .currentPage .getPath ())
402
+ .set ("exact" , Boolean .TRUE .toString ())
403
+ .set ("self" , Boolean .TRUE .toString ()));
404
+ search .addPredicate (pg );
405
+ }
406
+
379
407
int limit = properties .get (PN_SEARCH_LIMIT , SEARCH_LIMIT_DEFAULT );
380
408
search .setHitsPerPage (limit );
381
409
return safeGetSearchResult (search )
0 commit comments