meta.jsp
5.03 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
<%--
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"%><%
%><%@page import="java.util.ArrayList,
java.util.Calendar,
java.util.Collection,
java.util.List,
javax.jcr.security.Privilege,
javax.jcr.RepositoryException,
javax.jcr.Session,
javax.jcr.security.AccessControlManager,
org.apache.commons.lang.StringUtils,
org.apache.jackrabbit.util.Text,
org.apache.sling.api.resource.ResourceResolver,
com.adobe.cq.screens.binding.ScreensConstants,
com.adobe.granite.ui.components.AttrBuilder,
com.adobe.granite.ui.components.Tag,
com.day.cq.wcm.api.Page,
com.day.cq.wcm.api.PageManager, org.apache.sling.api.resource.ValueMap" %><%
AccessControlManager acm = null;
try {
acm = resourceResolver.adaptTo(Session.class).getAccessControlManager();
} catch (RepositoryException e) {
log.error("Unable to get access manager", e);
}
Page cqPage = resource.adaptTo(Page.class);
String title;
String thumbnailURL = null;
boolean isFolder = false;
String actionRels = StringUtils.join(getActionRels(resource, cqPage, acm), " ");
if (cqPage != null) {
title = cqPage.getTitle();
thumbnailURL = getThumbnailUrl(cqPage, 48, 48);
} else {
ValueMap vm = resource.getValueMap();
title = vm.get("jcr:content/jcr:title", vm.get("jcr:title", resource.getName()));
isFolder = true;
}
Tag tag = cmp.consumeTag();
AttrBuilder attrs = tag.getAttrs();
attrs.addBoolean("hidden", true);
attrs.addClass("foundation-collection-meta");
attrs.add("data-foundation-collection-meta-title", title);
attrs.add("data-foundation-collection-meta-folder", isFolder);
attrs.add("data-foundation-collection-meta-rel", actionRels);
AttrBuilder imgAttrs = new AttrBuilder(request, xssAPI);
imgAttrs.addClass("foundation-collection-meta-thumbnail");
imgAttrs.addHref("src", thumbnailURL);
%><div <%= attrs %>>
<img <%= imgAttrs %>>
</div><%!
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;
}
private List<String> getActionRels(Resource resource, Page page, AccessControlManager acm) {
List<String> actionRels = new ArrayList<String>();
if (hasPermission(acm, resource, Privilege.JCR_ADD_CHILD_NODES)) {
ResourceResolver resourceResolver = resource.getResourceResolver();
PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
Collection<?> templates = pageManager.getTemplates(resource.getPath());
boolean isRoot = page == null;
if (isRoot) {
actionRels.add(ScreensConstants.ACT_CREATE_STRUCTURE);
}
else {
if (!templates.isEmpty() && !page.getContentResource().isResourceType(ScreensConstants.RT_DEVICE_FOLDER)) {
actionRels.add(ScreensConstants.ACT_CREATE);
}
if (page.getContentResource().isResourceType(ScreensConstants.RT_DEVICE_FOLDER)) {
actionRels.add(ScreensConstants.ACT_REGISTER_DEVICE);
} else {
// add live copy support
actionRels.add(ScreensConstants.ACT_CREATE_LIVECOPY);
}
// CQ-73676: Force evaluating the actionRels in column view with common action
if (page.getContentResource().isResourceType(ScreensConstants.RT_CHANNEL)) {
actionRels.add(ScreensConstants.ACT_VIEW_PROPERTIES);
}
}
}
return actionRels;
}
private boolean hasPermission(AccessControlManager acm, String path, String privilege) {
if (acm != null) {
try {
Privilege p = acm.privilegeFromName(privilege);
return acm.hasPrivileges(path, new Privilege[]{p});
} catch (RepositoryException ignore) {
}
}
return false;
}
private boolean hasPermission(AccessControlManager acm, Resource resource, String privilege) {
return hasPermission(acm, resource.getPath(), privilege);
}
%>