displays.jsp
4.41 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<%--
ADOBE CONFIDENTIAL
Copyright 2015 Adobe Systems Incorporated
All Rights Reserved.
NOTICE: All information contained herein is, and remains
the property of Adobe Systems Incorporated and its suppliers,
if any. The intellectual and technical concepts contained
herein are proprietary to Adobe Systems Incorporated and its
suppliers and may be covered by U.S. and Foreign Patents,
patents in process, and are protected by trade secret or copyright law.
Dissemination of this information or reproduction of this material
is strictly forbidden unless prior written permission is obtained
from Adobe Systems Incorporated.
--%><%
%><%@include file="/libs/granite/ui/global.jsp"%><%
%><%@page session="false"
import="com.adobe.granite.ui.components.Config,
com.adobe.granite.ui.components.ExpressionHelper,
com.adobe.granite.ui.components.PagingIterator,
com.adobe.granite.ui.components.ds.AbstractDataSource,
com.adobe.granite.ui.components.ds.DataSource,
com.adobe.granite.ui.components.ds.EmptyDataSource,
org.apache.commons.collections.Predicate,
org.apache.commons.collections.Transformer,
org.apache.commons.collections.iterators.FilterIterator,
org.apache.commons.collections.iterators.TransformIterator,
org.apache.sling.api.resource.Resource,
org.apache.sling.api.resource.ResourceWrapper,
java.util.Iterator,
java.util.regex.Pattern,
com.day.cq.wcm.api.NameConstants,
com.adobe.cq.screens.binding.ScreensConstants,
com.adobe.cq.screens.assignment.AssignmentService,
com.adobe.cq.screens.channel.ChannelService"%>
<%@ page import="org.slf4j.Logger" %><%
/**
A datasource returning the displays of a given channel or schedule.
@datasource
@name ChildPages
@location /libs/screens/dcc/components/datasources/displays
@property {StringEL} path The path of the parent page
@property {String} itemResourceType
*/
ExpressionHelper ex = cmp.getExpressionHelper();
Config dsCfg = new Config(resource.getChild(Config.DATASOURCE));
String path = ex.get(dsCfg.get("path", String.class), String.class);
final Integer offset = ex.get(dsCfg.get("offset", String.class), Integer.class);
final Integer limit = ex.get(dsCfg.get("limit", String.class), Integer.class);
final String filter = dsCfg.get("exclude", "");
final Pattern pattern = Pattern.compile(filter);
if (path == null) {
path = slingRequest.getRequestPathInfo().getSuffix();
}
if (path == null) {
return;
}
final AssignmentService assignmentSvc = resourceResolver.adaptTo(AssignmentService.class);
Resource channelResource = resourceResolver.resolve(path);
final Iterator<Resource> displaysResourcesIterator = assignmentSvc != null && channelResource != null ? assignmentSvc.findDisplaysForEntity(channelResource) : null;
DataSource ds;
if (displaysResourcesIterator == null) {
ds = EmptyDataSource.instance();
} else {
final String itemRT = dsCfg.get("itemResourceType", String.class);
@SuppressWarnings("unchecked")
DataSource datasource = new AbstractDataSource() {
public Iterator<Resource> iterator() {
Iterator<Resource> it = new PagingIterator<Resource>(new FilterIterator(displaysResourcesIterator, new Predicate() {
public boolean evaluate(Object o) {
Resource r = ((Resource) o);
if (pattern.matcher(r.getPath()).matches()) {
return false;
}
return true;
}
}), offset, limit);
return new TransformIterator(it, new Transformer() {
public Object transform(Object o) {
Resource r = ((Resource) o);
return new ResourceWrapper(r) {
public String getResourceType() {
return itemRT;
}
};
}
});
}
};
ds = datasource;
}
request.setAttribute(DataSource.class.getName(), ds);
%>