breadcrumbs.jsp
6.3 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<%--
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="java.util.ArrayList,
java.util.Calendar,
java.util.HashMap,
java.util.Iterator,
java.util.List,
org.apache.commons.collections.Transformer,
org.apache.commons.collections.iterators.TransformIterator,
org.apache.commons.lang.StringUtils,
org.apache.jackrabbit.util.Text,
org.apache.sling.api.resource.Resource,
org.apache.sling.api.resource.ResourceMetadata,
org.apache.sling.api.resource.ValueMap,
org.apache.sling.api.wrappers.ValueMapDecorator,
com.adobe.cq.screens.binding.ScreensConstants,
com.adobe.cq.screens.device.Device,
com.adobe.granite.ui.components.AttrBuilder,
com.adobe.granite.ui.components.Config,
com.adobe.granite.ui.components.ds.DataSource,
com.adobe.granite.ui.components.ds.SimpleDataSource,
com.adobe.granite.ui.components.ds.ValueMapResource,
com.day.cq.commons.Filter,
com.day.cq.wcm.api.Page"%><%
final Config cfg = cmp.getConfig();
final String path = StringUtils.trimToNull(cmp.getExpressionHelper().getString(cfg.get("path", String.class)));
final String parentPage = StringUtils.trimToNull(cmp.getExpressionHelper().getString(cfg.get("parentPage", String.class)));
final String pageId = cfg.get("pageId", String.class);
Resource contentResource = resourceResolver.getResource(path);
if (contentResource == null) {
return;
}
final String rootPath = "/content/screens";
final List<Resource> crumbs = new ArrayList<Resource>();
Resource current = contentResource;
while (current != null) {
ValueMap crumbVM = new ValueMapDecorator(new HashMap<String, Object>());
boolean isRoot = current.getPath().equals(rootPath);
String title;
boolean isFolder = false;
String thumbnailURL = null;
Page cqPage = current.adaptTo(Page.class);
Device device = current.adaptTo(Device.class);
if (cqPage != null) {
title = cqPage.getTitle();
thumbnailURL = getThumbnailUrl(cqPage, 48, 48);
} else if (device != null) {
ValueMap deviceProps = device.adaptTo(ValueMap.class);
title = deviceProps.get("jcr:title", String.class);
if (title == null || title.isEmpty()) {
title = device.getId();
}
isFolder = false;
}
else if (isRoot) {
title = i18n.get("Screens");
isFolder = true;
} else {
ValueMap vm = current.getValueMap();
title = vm.get("jcr:content/jcr:title", vm.get("jcr:title", current.getName()));
isFolder = true;
}
if (cqPage != null && cqPage.getContentResource().isResourceType(ScreensConstants.RT_DEVICE_FOLDER)) {
if (pageId != null && "screens-PendingDevices".equals(pageId)) {
crumbVM.put("title", i18n.get("Pending Devices"));
crumbVM.put("href", "/screens/devices.html" + current.getPath());
crumbs.add(new ValueMapResource(resourceResolver, new ResourceMetadata(), "nt:unstructured", crumbVM));
crumbVM = new ValueMapDecorator(new HashMap<String, Object>());
}
crumbVM.put("href", "/screens/devices.html" + current.getPath());
}
else if (parentPage != null && current != contentResource) {
crumbVM.put("href", parentPage + current.getPath());
}
else {
crumbVM.put("path", current.getPath());
}
crumbVM.put("title", title);
crumbVM.put("thumbnail", thumbnailURL);
crumbVM.put("isFolder", isFolder);
crumbs.add(new ValueMapResource(resourceResolver, new ResourceMetadata(), "nt:unstructured", crumbVM));
if (isRoot) {
break;
}
if (device != null) {
Resource tenantResource = resourceResolver.resolve("/content/screens/" + current.getParent().getParent().getName());
Page tenantPage = tenantResource != null ? tenantResource.adaptTo(Page.class) : null;
if (tenantPage != null) {
Iterator<Page> deviceFolderIterator = tenantPage.listChildren(new Filter<Page>() {
public boolean includes(Page child) {
return child.getContentResource().isResourceType(ScreensConstants.RT_DEVICE_FOLDER);
}
});
if (deviceFolderIterator.hasNext()) {
current = deviceFolderIterator.next().adaptTo(Resource.class);
} else {
current = current.getParent();
}
} else {
current = current.getParent();
}
}
else {
current = current.getParent();
}
}
request.setAttribute(DataSource.class.getName(), new SimpleDataSource(crumbs.iterator()));
%><%!
private String getThumbnailUrl(Page page, int width, int height) {
String ck = "";
ValueMap metadata = page.getProperties("image/file/jcr:content");
if (metadata != null) {
Calendar cal = metadata.get("jcr:lastModified", Calendar.class);
if (cal != null) {
ck = "" + (cal.getTimeInMillis() / 1000);
}
}
return Text.escapePath(page.getPath()) + ".thumb." + width + "." + height + ".png?ck=" + ck;
}
%>