%--
ADOBE CONFIDENTIAL
Copyright 2012 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.
--%><%
%><%@page session="false" contentType="text/html; charset=utf-8"%><%
%><%@page import="java.util.ArrayList,
java.util.Arrays,
java.util.Calendar,
java.util.Iterator,
java.util.List,
java.util.Locale,
java.util.ResourceBundle,
javax.jcr.Node,
javax.jcr.Property,
javax.jcr.RepositoryException,
javax.jcr.Session,
javax.jcr.Value,
javax.jcr.lock.LockManager,
javax.jcr.security.AccessControlManager,
javax.jcr.security.Privilege,
org.apache.commons.io.FilenameUtils,
org.apache.jackrabbit.api.security.user.Authorizable,
org.apache.jackrabbit.api.security.user.User,
org.apache.jackrabbit.util.Text,
org.apache.sling.api.resource.Resource,
org.apache.sling.api.resource.ResourceResolver,
org.apache.sling.api.resource.ValueMap,
org.apache.sling.featureflags.Features,
com.adobe.granite.comments.CommentCollection,
com.adobe.granite.comments.CommentManager,
com.adobe.granite.security.authorization.AuthorizationService,
com.adobe.granite.security.user.UserProperties,
com.adobe.granite.security.user.UserPropertiesManager,
com.adobe.granite.security.user.util.AuthorizableUtil,
com.adobe.granite.ui.components.ComponentHelper,
com.adobe.granite.ui.components.Config,
com.adobe.granite.ui.components.ExpressionHelper,
com.adobe.granite.xss.XSSAPI,
com.day.cq.commons.LabeledResource,
com.day.cq.commons.LanguageUtil,
com.day.cq.commons.date.RelativeTimeFormat,
com.day.cq.commons.jcr.JcrConstants,
com.day.cq.dam.api.Asset,
com.day.cq.dam.api.DamConstants,
com.day.cq.dam.api.Rendition,
com.day.cq.dam.api.s7dam.constants.S7damConstants,
com.day.cq.dam.commons.util.DamUtil,
com.day.cq.dam.commons.util.PrivateFolderAndCollectionUtil,
com.day.cq.dam.commons.util.S73DHelper,
com.day.cq.dam.commons.util.S7SetHelper,
com.day.cq.dam.commons.util.UIHelper,
com.day.cq.dam.entitlement.api.EntitlementConstants,
com.day.cq.dam.usage.api.AssetUsageTracker,
com.day.cq.i18n.I18n"%>
<%
%><%@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.0"%><%
%><%@taglib prefix="cq" uri="http://www.day.com/taglibs/cq/1.0"%><%
%><%@taglib prefix="ui" uri="http://www.adobe.com/taglibs/granite/ui/1.0"%><%
%><%
ComponentHelper cmp = new ComponentHelper(pageContext);
ExpressionHelper ex = cmp.getExpressionHelper();
I18n i18n = new I18n(slingRequest);
Session session = resourceResolver.adaptTo(Session.class);
AccessControlManager acm = session.getAccessControlManager();
ResourceBundle resourceBundle = slingRequest.getResourceBundle(slingRequest.getLocale());
boolean showQuickActions = true;
Object quickActionsAttr = request.getAttribute("com.adobe.cq.item.quickActions");
if (quickActionsAttr != null) {
if (quickActionsAttr.getClass().getName().equals("java.lang.String")) {
showQuickActions = ((String)quickActionsAttr).equals("true");
} else {
showQuickActions = ((Boolean)quickActionsAttr).booleanValue();
}
}
String requestSuffix = "";
Object requestSuffixAttr = request.getAttribute("com.adobe.cq.item.requestSuffix");
if (requestSuffixAttr != null) {
if (requestSuffixAttr.getClass().getName().equals("java.lang.String")) {
requestSuffix = (String)requestSuffixAttr;
requestSuffix = xssAPI.encodeForHTML(ex.get(requestSuffix, String.class));
}
}
String requestPrefix = "";
Object requestPrefixAttr = request.getAttribute("com.adobe.cq.item.requestPrefix");
if (requestPrefixAttr != null) {
if (requestPrefixAttr.getClass().getName().equals("java.lang.String")) {
requestPrefix = (String)requestPrefixAttr;
requestPrefix = xssAPI.encodeForHTML(ex.get(requestPrefix, String.class));
}
}
UserPropertiesManager upm = resourceResolver.adaptTo(UserPropertiesManager.class);
UserProperties userProps = upm.getUserProperties(resourceResolver.adaptTo(Authorizable.class), "");
final boolean showDesktopLinks = "true".equals(userProps.getProperty("preferences/showAssetDesktopLinks"));
final Features featureManager = sling.getService(Features.class);
boolean isProcessingProfileEntitled = false;
if (featureManager.getFeature(EntitlementConstants.ASSETS_PROCESSINGPROFILE_FEATURE_FLAG_PID)!=null && featureManager.isEnabled(EntitlementConstants.ASSETS_PROCESSINGPROFILE_FEATURE_FLAG_PID)) {
isProcessingProfileEntitled = true;
}
String assetsVanity = "/assets.html";
String assetDetailsVanity = "/assetdetails.html";
int assetCardSize = 240;
String type = "";
String adminUrl = request.getContextPath() + assetsVanity;
Node childAsset = resource.adaptTo(Node.class);
Node parentNode = childAsset.getParent();
String childPath = childAsset.getPath();
boolean isDAMAdmin = false;
AuthorizationService authorizationService = sling.getService(AuthorizationService.class);
if (authorizationService != null && session != null) {
isDAMAdmin = authorizationService.hasAdministrativeAccess(session);
}
boolean hasJcrWrite = false, hasReplicate = false, hasJcrRead = false, hasRemoveNode = false, hasModifyProperties = false, hasAddChild = false, hasModifyAccessControl = false;
if (isDAMAdmin) {
hasJcrWrite = hasReplicate = hasJcrRead = hasRemoveNode = hasModifyProperties = hasAddChild = hasModifyAccessControl = true;
} else {
Privilege p[] = UIHelper.getAllPermission(acm, resource);
if (p[0].equals(acm.privilegeFromName(Privilege.JCR_ALL))) {
hasJcrWrite = hasReplicate = hasJcrRead = hasRemoveNode = hasModifyProperties = hasAddChild = hasModifyAccessControl = true;
} else {
for(int i=0;i
assetAggregateStats = null;
String [] usagesStatsRequired = {"campaign","target","social","mediaOptimizer","aem","unknown"};
assetAggregateStats = assetUsageTracker.getUsageStats(asset,new ArrayList(Arrays.asList(usagesStatsRequired)));
if(assetAggregateStats!=null && !assetAggregateStats.isEmpty()) {
assetUsageCount = assetAggregateStats.size();
assetRecentUsage = assetAggregateStats.get(0).usageType;
}
assetScore = assetUsageTracker.getAssetScore(asset);
//comments
CommentManager cm = sling.getService(CommentManager.class);
final CommentCollection collection = cm.getCollection(resource, CommentCollection.class);
int commentsCount = 0;
if (null != collection) {
commentsCount = collection.getCommentList().size();
if (commentsCount > 0) {
comments = ""+""+ commentsCount;
}
}
//pull s7damType to see if it is a video we can preview in grid view
if (childAsset.hasNode(JcrConstants.JCR_CONTENT) &&
childAsset.getNode(JcrConstants.JCR_CONTENT).hasProperty("dam:s7damType")) {
s7damType = childAsset.getNode(JcrConstants.JCR_CONTENT).getProperty("dam:s7damType").getString();
}
//lastModified & lastModifiedBy
RelativeTimeFormat rtf = new RelativeTimeFormat("r", resourceBundle);
long assetLastModification = asset.getLastModified();
ValueMap vm = resource.adaptTo(ValueMap.class);
if (assetLastModification == 0) {
Calendar created = vm.get("jcr:created", Calendar.class);
assetLastModification = (null != created) ? created.getTimeInMillis() : 0;
}
lastModified = outVar(xssAPI, i18n, rtf.format(assetLastModification, true));
String assetModifier = asset.getModifier();
lastModifiedBy = AuthorizableUtil.getFormattedName(resource.getResourceResolver(), assetModifier);
if (null == assetModifier) {
assetModifier = "";
}
// Also check asset modifier should not be empty. see CQ-39542
if (!"".equals(assetModifier) && upm.getUserProperties(assetModifier, "profile") == null) {
lastModifiedBy = i18n.get("External User");
}
if (S7SetHelper.isS7Set(resource)){
String assetType = "set";
String setType = xssAPI.encodeForHTML(vm.get(JcrConstants.JCR_CONTENT+ "/" + S7damConstants.PN_S7_TYPE,"").toUpperCase());
boolean canEdit = hasJcrWrite;
boolean canEditMetadata = hasModifyProperties;
applicableRelationships += " foundation-damadmin-properties-activator cq-damadmin-admin-actions-add-to-collection-activator";
if (canEdit) {
applicableRelationships += " dam-assetedit-action-select";
}
String setThumbnailUrl="";
int setThumbnailWidth =0;
String setManualThumbnailUrl = xssAPI.getValidHref(vm.get(JcrConstants.JCR_CONTENT+ "/metadata/manualThumbnail", ""));
//check custom thumbnail
if (setManualThumbnailUrl.isEmpty() ) {
Rendition setThumbnailRendition = UIHelper.getBestfitRendition(asset, 319);
if(setThumbnailRendition != null) {
try {
//use the existing thumbnail
setThumbnailWidth = (int)width;
setThumbnailUrl = asset.getPath() + "/jcr:content/renditions/" + setThumbnailRendition.getName();
} catch(Exception e) {
}
} else {
//default thumbnail
setThumbnailUrl = asset.getPath() + ".thumb.319.319.png";
}
}
else {
setThumbnailUrl = setManualThumbnailUrl + ".thumb.319.319.png";
}
%>
" data-path="<%= xssAPI.encodeForHTMLAttr(resource.getPath()) %>" data-type="<%= type %>" data-asset-type ="<%= assetType %>" data-can-edit-metadata="<%= canEditMetadata %>" data-can-edit = "<%=canEdit%>">
<%if (hasJcrWrite) { %>
<% } %>
<%=resourceTitle%>
<%=getDisplayLanguage(resource.getPath(), true)%>
<%= xssAPI.encodeForHTML(setType) %>
<% if (publishDateInMillis < assetLastModification) {%>
"> <%= lastModified%> <%= xssAPI.encodeForHTML(lastModifiedBy)%>
<% } else {%>
<%} %>
<% if (publishedDate != null && !deactivated) {%>
">
"> <%= i18n.get("Published") %> <%= publishedDate %> <%= xssAPI.encodeForHTML(publishedBy) %>
<% } else if (publishedDate != null && deactivated) { // expecting a previous publishing date otherwise it couldn't be deactivated
%>
">
"> <%= i18n.get("Unpublished") %> <%= publishedDate %> <%= xssAPI.encodeForHTML(publishedBy) %>
<% } %>
<% if (showQuickActions) { %>
<%} %>
<% }
else {
boolean isProduct = false;
boolean hasSubassets = false;
if (resource.getChild("subassets") != null){
hasSubassets = true;
}
//size, width & height, status
if (childAsset.hasNode("jcr:content/metadata")) {
Node metadataNode = childAsset.getNode("jcr:content" + "/" + "metadata");
try {
width = Long.valueOf(DamUtil.getValue(metadataNode, "tiff:ImageWidth", DamUtil.getValue(metadataNode, "exif:PixelXDimension", "")));
height = Long.valueOf(DamUtil.getValue(metadataNode, "tiff:ImageLength", DamUtil.getValue(metadataNode, "exif:PixelYDimension", "")));
} catch (Exception e) {
}
try {
isProduct = !DamUtil.getValue(metadataNode,"cq:productReference", "").isEmpty();
}
catch(Exception e) {}
try {
bytes = Long.valueOf(DamUtil.getValue(metadataNode, "dam:size", "0"));
//size
if (bytes == 0 && asset.getOriginal() != null) {
bytes = asset.getOriginal().getSize();
}
size = UIHelper.getSizeLabel(bytes, slingRequest);
} catch(Exception e) {}
try {
status = DamUtil.getValue(metadataNode, "dam:status", "");
} catch(Exception e) {
}
}
// display mime type is shown on card (in grid view) and in list view
String displayMimeType="";
Resource lookupResource = resourceResolver.getResource("/mnt/overlay/dam/gui/content/assets/jcr:content/mimeTypeLookup");
boolean canCompare = false;
String[] comparableMimeTypes = {
"image/jpeg",
"image/jpg",
"image/png",
"image/gif",
"image/bmp",
"image/tiff",
"image/vnd.adobe.photoshop",
"application/x-photoshop",
"application/photoshop",
"application/psd",
"image/psd"
};
//mimeType
if (asset.getMimeType() != null) {
mimeType = asset.getMimeType();
String ext = mimeType.substring(mimeType.lastIndexOf('/') + 1, mimeType.length());
if((displayMimeType = UIHelper.lookupMimeType(ext,lookupResource,true)) == null) {
displayMimeType = "";
}
if (displayMimeType.length() == 0 && mimeType.startsWith("image")) {
displayMimeType = "IMAGE";
} else if (displayMimeType.length() == 0 && mimeType.startsWith("text")) {
displayMimeType = "DOCUMENT";
} else if (displayMimeType.length() == 0 && (mimeType.startsWith("video") || mimeType.startsWith("audio"))) {
displayMimeType = "MULTIMEDIA";
} else if (S73DHelper.isS73D(resource)) {
Resource assetContent = resource.getChild("jcr:content");
displayMimeType = (assetContent != null) ? assetContent.getValueMap().get("dam:s7damType", "").toUpperCase() : "";
String extension = FilenameUtils.getExtension(resource.getName());
if (!extension.isEmpty()) {
displayMimeType += " (" + extension + ")";
}
} else if (displayMimeType.length() == 0 && mimeType.startsWith("application")) {
int idx_1 = ext.lastIndexOf('.');
int idx_2 = ext.lastIndexOf('-');
int lastWordIdx = (idx_1 > idx_2)?idx_1:idx_2;
displayMimeType = ext.substring(lastWordIdx+1).toUpperCase();
}
// Content Fragments need an additional check to be detected precisely
if (displayMimeType.equals("DOCUMENT") && isContentFragment) {
displayMimeType = "CONTENT FRAGMENT";
}
if (contains(comparableMimeTypes, mimeType)) {
canCompare = true;
}
}
if(displayMimeType.length() == 0 && asset.getName() != null) {
String filename = asset.getName();
String ext = filename.substring(filename.lastIndexOf(".") + 1, filename.length());
if((displayMimeType = UIHelper.lookupMimeType(ext,lookupResource,true)) == null) {
displayMimeType = "";
}
}
//resolution
if (width != 0 && height != 0) {
resolution = UIHelper.getResolutionLabel(width, height, slingRequest);
}
//thumbnailUrl
adminUrl = adminUrl.replace(assetsVanity, assetDetailsVanity);
String thumbnailUrl="";
int thumbnailWidth =0;
if (isContentFragment) {
thumbnailUrl = "/libs/dam/cfm/admin/content/static/thumbnail_fragment.png";
if (resourceResolver.getResource(thumbnailUrl) == null) {
thumbnailUrl = asset.getPath() + ".thumb.319.319.png";
}
} else {
Rendition thumbnailRendition = UIHelper.getBestfitRendition(asset, 319);
if (thumbnailRendition != null) {
try {
//use the existing thumbnail
thumbnailWidth = (int) width;
thumbnailUrl = asset.getPath() + "/jcr:content/renditions/" + thumbnailRendition.getName();
} catch (Exception e) {
}
} else {
//default thumbnail
thumbnailUrl = asset.getPath() + ".thumb.319.319.png";
}
}
thumbnailUrl = Text.escapePath(thumbnailUrl);
if (hasJcrRead) {
applicableRelationships += " foundation-damadmin-properties-activator cq-damadmin-admin-actions-add-to-collection-activator";
}
if (hasJcrWrite) {
applicableRelationships += " cq-damadmin-admin-actions-open-activator dam-assetedit-action-select aem-assets-admin-actions-shoppableedit-activator";
}
if (hasAddChild) {
applicableRelationships += " cq-damadmin-admin-actions-open-activator icon-note";
}
boolean canAnnotate = false;
String[] annotatableMimeTypes = { "image/jpeg", "image/jpg", "image/png", "image/gif" };
if (hasAddChild && hasModifyProperties) {
if (contains(annotatableMimeTypes, mimeType) || UIHelper.getBestfitRendition(asset, 319) != null) {
canAnnotate = true;
}
}
boolean canEdit = false;
boolean canEditMetadata = false;
boolean isLocked = isLocked(resourceResolver, childAsset);
// attempt to find a editor that can handle this resource if has the
// permission to edit
if (hasJcrWrite) {
canEditMetadata = true;
if (!isLocked) {
Resource editors = resource.getResourceResolver().getResource("/libs/dam/gui/content/assets/editors");
for (Iterator it = editors.listChildren(); it.hasNext();) {
Resource child = it.next();
Config editorPropCfg = new Config(child);
String[] mimeTypes = editorPropCfg.get("mimetypes", String[].class);
if (mimeTypes != null && contains(mimeTypes, mimeType)) {
canEdit = true;
break;
}
}
}
} else if (hasModifyProperties) {
canEditMetadata = true;
}
boolean isCheckedOut = UIHelper.isCheckedOutByDrive(asset);
boolean isVideo = false;
String oggRenditionPath = "";
String mp4RenditionPath = "";
String m4VRenditionPath = "";
if (mimeType.contains("video") && !s7damType.equals(S7damConstants.S7_VIDEO_AVS)) {
for (Iterator it = asset.listRenditions(); it.hasNext();) {
Rendition rendition = it.next();
String renditionMimeType = rendition.getMimeType();
if (null != renditionMimeType) {
if (renditionMimeType.equals("video/ogg")) {
oggRenditionPath = rendition.getPath();
}
if (renditionMimeType.equals("video/mp4")) {
mp4RenditionPath = rendition.getPath();
}
// handling mime types video/m4v, video/x-m4v
if ( rendition.getMimeType().endsWith("m4v")) {
m4VRenditionPath = rendition.getPath();
}
}
}
if (mimeType.equals("video/mp4") || mimeType.equals("video/ogg") ||
!oggRenditionPath.equals("") || !mp4RenditionPath.equals("") || !m4VRenditionPath.equals("") ||
mimeType.equals("video/quicktime") || mimeType.equals("video/x-ms-wmv")) {
isVideo = true;
canAnnotate = true;
canEdit = true;
}
}
boolean isAudio = false;
String mpegAudioRenditionPath = "";
String oggAudioRenditionPath = "";
String wavAudioRendtionPath = "";
if(mimeType.contains("audio")){
for (Iterator it = asset.listRenditions(); it.hasNext();) {
Rendition rendition = it.next();
String renditionMimeType = rendition.getMimeType();
if (null != renditionMimeType) {
if (renditionMimeType.equals("audio/mpeg") ) {
mpegAudioRenditionPath = rendition.getPath();
}
if (renditionMimeType.equals("audio/ogg") ) {
oggAudioRenditionPath = rendition.getPath();
}
if( renditionMimeType.equals("audio/x-wav") || renditionMimeType.equals("audio/wav") ) {
wavAudioRendtionPath = rendition.getPath();
}
}
}
if ( ! mpegAudioRenditionPath.equals("") || ! oggAudioRenditionPath.equals("") || ! wavAudioRendtionPath.equals("")){
isAudio = true;
}
}
//ids print
String assetType = "";
if (asset.getRendition("cq-indesign-print")!=null){
assetType = "idsprint";
}
if (mimeType.contains("video") && childAsset.isNodeType("dam:Asset") && enabledDynamicMedia &&
(s7damType.equals(S7damConstants.S7_VIDEO_AVS) || s7damType.equals(S7damConstants.S7_VIDEO))) {
dynamicVideo = true;
canEdit = true;
}
%>
<%if (hasJcrWrite) { %>
<% } %>
<%
String classname = (thumbnailWidth > 0 && thumbnailWidth < assetCardSize) ? "low-resolution" : "";
%> <%
// for DM videos, use BasicVideoViewer for preview
// otherwise, use
<% if(assetUsageCount > 0 )
{
%>
<%
for(int i =0;i
-
<%
if(usage.usageType.equals("campaign") )
{
%>
<%
} else if(usage.usageType.equals("target") ) {
%>
<%
} else if(usage.usageType.equals("social") ) {
%>
<%
} else if(usage.usageType.equals("mediaOptimizer") ) {
%>
<%
} else if(usage.usageType.equals("aem") ) {
%>
<%
} else if(usage.usageType.equals("unknown") ) {
%>
<%
}
%>
<%=usage.lastUsedTime %>
<%=usage.usageCount %>
<%
}
%>
<%
} else {
%>
<%=i18n.get("Not used with any solution.") %>
<%
}
%>
<%if(isCheckedOut) {%>
" title="<%=i18n.get("Checked out by {0}", null, UIHelper.getCheckedOutby(asset)) %>"><%=resourceTitle%>
<%} else { %>
<%=resourceTitle%>
<%} %>
<%=getDisplayLanguage(resource.getPath(), true)%>
<%if (isProduct) {%> <%}%><%= xssAPI.encodeForHTML(i18n.getVar(displayMimeType)) %>
<%= xssAPI.encodeForHTML(resolution)%>
<%=size%>
<% if (commentsCount > 0) {%>
<% } %>
<% if (publishDateInMillis < assetLastModification) {%>
"> <%= lastModified%> <%= xssAPI.encodeForHTML(lastModifiedBy)%>
<%} else { %>
<%} %>
<% if(assetScore > 0 ) { %>
<%=assetScore%>
<% } %>
<% if (publishedDate != null && !deactivated) {%>
" itemprop="publish" itemscope="">
"> <%= i18n.get("Published") %> <%= publishedDate %> <%= xssAPI.encodeForHTML(publishedBy) %>
<% } else if (publishedDate != null && deactivated) { // expecting a previous publishing date otherwise it couldn't be deactivated
%>
" itemprop="publish" itemscope="">
"> <%= i18n.get("Unpublished") %> <%= publishedDate %> <%= xssAPI.encodeForHTML(publishedBy) %>
<% } else { %>
" itemprop="publish" itemscope="">
<% } %>
<% if(assetUsageCount > 0 ) {
if("campaign".equals(assetRecentUsage)) {
%>
<% } else if ("target".equals(assetRecentUsage)) {
%>
<% } else if("social".equals(assetRecentUsage)) {
%>
<% } else if("mediaOptimizer".equals(assetRecentUsage)) {
%>
<% } else if("aem".equals(assetRecentUsage)) {
%>
<% } else if("unknown".equals(assetRecentUsage)) {
%>
<% } if(assetUsageCount >1) {
%>
+<%=assetUsageCount-1 %>
<%
}
}
%>
<%
boolean isAssetExpired = false;
boolean isSubAssetExpired = false;
boolean isDownloadAllowedForAdmins = false;
boolean canShare = false;
if(request.getAttribute("com.adobe.assets.expiry.status") != null)
isAssetExpired = (Boolean)request.getAttribute("com.adobe.assets.expiry.status");
if(request.getAttribute("com.adobe.assets.subasset.expiry.status") != null)
isSubAssetExpired = (Boolean)request.getAttribute("com.adobe.assets.subasset.expiry.status");
if(request.getAttribute("com.adobe.assets.expiry.isDownloadAllowedForAdmins") != null)
isDownloadAllowedForAdmins = (Boolean)request.getAttribute("com.adobe.assets.expiry.isDownloadAllowedForAdmins");
if (isDownloadAllowedForAdmins || (!isAssetExpired && !isSubAssetExpired)) {
applicableRelationships += " cq-damadmin-admin-actions-download-activator ";
}
if(!(isAssetExpired || isSubAssetExpired) && hasModifyAccessControl) {
canShare = true;
applicableRelationships +=" cq-damadmin-admin-actions-adhocassetshare-activator";
applicableRelationships +=" cq-damadmin-admin-actions-publicLinkShare-activator";
}
if (canShare) {
applicableRelationships +=" cq-damadmin-admin-actions-share-activator";
}
else {
applicableRelationships.replace("cq-damadmin-admin-actions-share-activator", "");
}
if (showQuickActions) {
%>
<%} %>
<%}
} else if (childAsset.isNodeType("nt:folder")) {
type = "directory";
boolean canShare = false;
boolean isMACShared = false;
boolean isCCShared = false;
boolean isMPShared = false;
String sharedParentPath = null;
boolean isRootMACShared = false;
boolean isRootMPShared = false;
if (childAsset.hasProperty("dam:ccTeamMembers")) {
isCCShared = true;
} else {
Node sharedCCParent = findSharedParent(childAsset, "dam:ccTeamMembers");
if (sharedCCParent != null) {
isCCShared = true;
}
}
if (childAsset.hasProperty("macConfig") ) {
isMACShared = true;
} else {
Node sharedParent = findSharedParent(childAsset, "macConfig");
if (sharedParent != null) {
sharedParentPath = sharedParent.getPath();
isRootMACShared = true;
}
}
if (childAsset.hasProperty("mpConfig") ) {
isMPShared = true;
} else {
Node sharedParent = findSharedParent(childAsset, "mpConfig");
if (sharedParent != null) {
sharedParentPath = sharedParent.getPath();
isRootMPShared = true;
}
}
// Processing profile details
String[] profileTitleList = new String[]{"","","","",""};
String[] profilePropertyList = new String[]{"jcr:content/metadataProfile", "jcr:content/processingProfile", "jcr:content/imageProfile", "jcr:content/videoProfile", "jcr:content/batchSetPreset"};
String[] profileNamePropertyList = new String[]{"jcr:content/jcr:title", "name", "jcr:content/jcr:title", "", "jcr:content/jcr:title"};
for(int i=0; i< profileNamePropertyList.length; i++) {
if (childAsset.hasProperty(profilePropertyList[i])) {
Property prop = childAsset.getProperty(profilePropertyList[i]);
ArrayList profilePaths = new ArrayList();
if("jcr:content/batchSetPreset".equals(profilePropertyList[i])) {
Value[] vals = prop.getValues();
for(Value val : vals) {
profilePaths.add(val.getString());
}
} else {
profilePaths.add(prop.getValue().getString());
}
ArrayList profileNames = new ArrayList<>();
for(String profilePath : profilePaths) {
if(profilePath.trim().isEmpty()){
continue;
}
Resource res = resourceResolver.getResource(profilePath);
if (res != null) {
Node node = res.adaptTo(Node.class);
if (node != null) {
String jcrTitle = "";
if(node.hasProperty(profileNamePropertyList[i])){
jcrTitle = node.getProperty(profileNamePropertyList[i]).getValue().getString();
}
// store jcr:title value if available, as that is always preferable over name
profileNames.add(jcrTitle != null && !jcrTitle.trim().isEmpty() ? jcrTitle : node.getName());
}
}
}
profileTitleList[i] = String.join(", ", profileNames);
}
}
// Metadata Schema details
String metadataSchema = "";
if (childAsset.hasProperty("jcr:content/metadataSchema")) {
metadataSchema = childAsset.getProperty("jcr:content/metadataSchema").getValue().getString();
}
if (hasJcrRead) {
applicableRelationships +=" foundation-damadmin-properties-activator icon-share cq-damadmin-admin-actions-download-activator dam-asset-createtask-action-activator cq-damadmin-admin-actions-add-to-collection-activator";
}
if (hasModifyAccessControl) {
canShare = true;
applicableRelationships +=" cq-damadmin-admin-actions-foldershare";
applicableRelationships +=" cq-damadmin-admin-actions-adhocassetshare-activator";
applicableRelationships +=" cq-damadmin-admin-actions-publicLinkShare-activator";
}
boolean showCCQuickAction = false;
if (hasJcrWrite && hasReplicate) {
canShare = true;
applicableRelationships += " cq-damadmin-admin-actions-macshare-activator";
applicableRelationships += " cq-damadmin-admin-actions-ccshare-activator";
applicableRelationships += " cq-damadmin-admin-actions-mpshare-activator";
showCCQuickAction = true;
}
if (isMACShared || isCCShared || isRootMACShared || isMPShared || isRootMPShared) {
applicableRelationships = applicableRelationships.replace("cq-damadmin-admin-actions-move-activator", "").replace("cq-damadmin-admin-actions-delete-activator", "");
}
if (canShare) {
applicableRelationships += " cq-damadmin-admin-actions-share-activator";
}
else {
applicableRelationships.replace("cq-damadmin-admin-actions-share-activator", "");
}
boolean manualThumbnailExists = false;
// Path at which the manual thumbnail(if present) exists
String manualThumbnailPath = resource.getPath() + "/jcr:content/manualThumbnail.jpg";
Resource manualThumbnail = resourceResolver.getResource(manualThumbnailPath);
if (null != manualThumbnail) {
manualThumbnailExists = true;
}
if (!(childAsset.hasProperty("hidden") && childAsset.getProperty("hidden").getString().equals("true"))) {
%>
<%if (hasJcrWrite) { %>
<% } %>
<% if (manualThumbnailExists) {
//UIHelper.getCacheKiller() generates the cache killer based on default thumbnail's last modified time.
int cck = 600000 + (int)(Math.random() * (600001));
%>
<% } else { %>
<% } %>
">
<%=resourceTitle%>
<%=getDisplayLanguage(resource.getPath(), false)%>
<%= i18n.get("FOLDER") %>
<% if (isCCShared) {
String title = i18n.get("Shared with Creative Cloud");
%>
is-selected" title="<%=title %>"><%= " " + title %>
<%} else if(isMACShared || isRootMACShared) {
String title = i18n.get("Shared with Marketing Cloud");%>
is-selected" title="<%= title %>"><%= " " + title %>
<%}
else if(isMPShared || isRootMPShared) {
String title = i18n.get("Shared with Brand Portal");%>
is-selected" title="<%= title %>"><%= " " + title %>
<%}%>
<% if (publishedDate != null && !deactivated) {%>
" title="<%= i18n.get("Asset Publication Status") %>"> <%= i18n.get("Published") %> <%= publishedDate %> <%= xssAPI.encodeForHTML(publishedBy) %>
<% } else if (publishedDate != null && deactivated) { // expecting a previous publishing date otherwise it couldn't be deactivated
%>
" title="<%= i18n.get("Asset Publication Status") %>"> <%= i18n.get("Unpublished") %> <%= publishedDate %> <%= xssAPI.encodeForHTML(publishedBy) %>
<% }%>
<%if(PrivateFolderAndCollectionUtil.isPrivate(resource.getResourceResolver().adaptTo(Session.class), resource.getPath())){
%>
">
<%
}%>
<% if(isProcessingProfileEntitled && (!profileTitleList[0].trim().isEmpty() || !profileTitleList[1].trim().isEmpty() || !profileTitleList[2].trim().isEmpty())){ %>
<%
if (!profileTitleList[0].trim().isEmpty()) {
String toolTip = i18n.get("Metadata Profile:") + " " + xssAPI.encodeForHTML(profileTitleList[0].trim());
%><%= xssAPI.encodeForHTML(profileTitleList[0].trim()) %>
<% } %>
<%
if (!profileTitleList[1].trim().isEmpty()) {
String toolTip = i18n.get("Processing Profile:") + " " + xssAPI.encodeForHTML(profileTitleList[1].trim());
%><%= xssAPI.encodeForHTML(profileTitleList[3].trim()) %>
<% } %>
<%
if (!profileTitleList[2].trim().isEmpty()) {
String toolTip = i18n.get("Image Profile:") + " " + xssAPI.encodeForHTML(profileTitleList[2].trim());
%><%= xssAPI.encodeForHTML(profileTitleList[1].trim()) %>
<% } %>
<%
if (!profileTitleList[3].trim().isEmpty()) {
String toolTip = i18n.get("Video Profile:") + " " + xssAPI.encodeForHTML(profileTitleList[3].trim());
%><%= xssAPI.encodeForHTML(profileTitleList[2].trim()) %>
<% } %>
<%
if (!profileTitleList[4].trim().isEmpty()) {
String toolTip = i18n.get("Batch Set Preset(s):") + " " + xssAPI.encodeForHTML(profileTitleList[4].trim());
%><%= xssAPI.encodeForHTML(profileTitleList[4].trim()) %>
<% } %>
<% } else { %>
<% } %>
<% if (showQuickActions) { %>
<%if (showCCQuickAction) { %>
<% }%>
" href="<%=request.getContextPath()%>/mnt/overlay/dam/gui/content/collections/addtocollectionwizard.html/content/dam/collections?item=<%=childPath%>">
">
<%
if (showDesktopLinks) {
%>
<%
}
}
%>
<%
}
}
%>
<%!String outVar(XSSAPI xssAPI, I18n i18n, String text) {
if (text != null) return xssAPI.encodeForHTML(i18n.getVar(text));
return "";
}
boolean isContentFragment(Resource resource) {
Resource contentResource = resource.getChild(JcrConstants.JCR_CONTENT);
boolean isFragment = false;
if (contentResource != null) {
ValueMap contentProps = contentResource.adaptTo(ValueMap.class);
isFragment = contentProps.get("contentFragment", false);
}
return isFragment;
}
String getDescription(Resource resource) {
try {
Asset asset = resource.adaptTo(Asset.class);
if (asset != null) {
if (this.isContentFragment(resource)) {
ValueMap contentProps = resource.getChild(JcrConstants.JCR_CONTENT)
.adaptTo(ValueMap.class);
return contentProps.get(JcrConstants.JCR_DESCRIPTION, "");
}
Node metadataNode = asset.adaptTo(Node.class).getNode("jcr:content" + "/" + "metadata");
return DamUtil.getValue(metadataNode, "dc:description", resource.getName());
} else {
LabeledResource lr = resource.adaptTo(LabeledResource.class);
if (lr != null) {
return lr.getDescription() != null ? lr.getDescription() : "";
}
}
} catch (Exception e) {
log("getTitle: " + e.getMessage());
}
return resource.getName();
}
String formatDate(Calendar cal, String defaultValue, ResourceBundle rb) {
if (cal == null) return defaultValue;
RelativeTimeFormat rtf = new RelativeTimeFormat("r", rb);
return rtf.format(cal.getTimeInMillis(), true);
}
boolean contains(String[] mimeTypes, String mimeType) {
for (String item:mimeTypes) {
if (item.equalsIgnoreCase(mimeType)) {
return true;
}
}
return false;
}
String getCoralIconClasses(ComponentHelper cmp, String icon) {
return "coral-Icon coral-Icon--sizeXS " + cmp.getIconClass(icon);
}
String getDisplayLanguage(String sourcePath, Boolean asset) {
String locale = null;
Locale localeObj = null;
String langValue = "";
String root = LanguageUtil.getLanguageRoot(sourcePath);
if (root != null && !(asset && root.equals(sourcePath))) {
locale = root.substring(root.lastIndexOf("/") + 1);
}
if (locale != null) {
localeObj = LanguageUtil.getLocale(locale);
if (localeObj != null) {
langValue = localeObj.getDisplayLanguage();
}
langValue += " (" + locale + ")";
}
return langValue;
}
Node findSharedParent(Node currentNode, String propName) throws RepositoryException {
if (currentNode == null || DamConstants.MOUNTPOINT_ASSETS.equals(currentNode.getPath())) {
return null;
}
Node parent = currentNode.getParent();
if (parent.hasProperty(propName)) {
return parent;
}
return findSharedParent(parent, propName);
}
boolean isLocked(ResourceResolver resourceResolver, Node node) {
boolean isLocked = false;
try {
String lockedBy="";
final LockManager lockManager = resourceResolver.adaptTo(
Session.class).getWorkspace().getLockManager();
if(node != null) {
if (node.isLocked()) {
isLocked=true;
lockedBy = lockManager.getLock(
node.getPath()).getLockOwner();
}else if (node.hasNode(JcrConstants.JCR_CONTENT)){
Node contentNode = node.getNode(JcrConstants.JCR_CONTENT);
if(contentNode.isLocked()){
isLocked = true;
lockedBy = lockManager.getLock(contentNode.getPath()).getLockOwner();
}
}
if(isLocked){
User self = resourceResolver.adaptTo(User.class);
String selfId = self.getID();
isLocked = !selfId.equals(lockedBy);
}
return isLocked;
}
} catch (Exception ex) {
log("Exception occurred while checking whether the node is locked: "
+ ex.getMessage());
}
return true;
}
%>