资产编辑器是在单击通过资产共享找到的资产后打开的页面,它允许用户编辑资产的元数据、缩略图、标题和标记等方面。
创建和配置资产编辑器页面中介绍了使用预定义编辑组件配置编辑器的相关内容。
除了使用预先存在的编辑器组件之外,Adobe Experience Manager开发人员还可以创建他们自己的组件。
geometrixx中包含以下示例页面:
/content/geometrixx/en/press/asseteditor.html
/apps/geometrixx/templates/asseteditor
/apps/geometrixx/components/asseteditor
Experience Manager Assets 组件使用WCM edit clientlib的扩展。clientlib通常在init.jsp
中加载。
与默认的clientlib加载(在核心的init.jsp
中)相比,Assets模板必须具有以下内容:
模板必须包含cq.dam.edit
clientlib(而不是cq.wcm.edit
)。
clientlib 还必须包含在禁用的 WCM 模式中(例如,在发布时加载)才能渲染谓词、操作和镜头。
在大多数情况下,复制现有示例init.jsp
(/apps/geometrixx/components/asseteditor/init.jsp
)应满足这些需求。
某些Assets组件需要在component.js
中定义的JS函数。 将此文件复制到组件目录并链接它。
<script type="text/javascript" src="<%= component.getPath() %>/component.js"></script>
此示例在head.jsp
(/apps/geometrixx/components/asseteditor/head.jsp
)中加载此JavaScript源。
某些Assets组件使用Experience Manager小组件库。 要在内容上下文中正确呈现,必须加载其他样式表。 标记操作组件需要再一个。
<link href="/etc/designs/geometrixx/ui.widgets.css" rel="stylesheet" type="text/css">
示例页面组件要求所有选择器以static.css
(/etc/designs/geometrixx/static.css
)的.asseteditor
开头。 最佳实践:将所有.asseteditor
选择器复制到样式表,并根据需要调整规则。
资产编辑器使用表单选择器,该选择器允许您通过只添加表单选择器和表单路径到资产URL来编辑同一表单页面上的资源(在本例中为资产)。
例如:
head.jsp
(/apps/geometrixx/components/asseteditor/head.jsp
)中的示例句柄执行以下操作:
List<Resource> resources = FormsHelper.getFormEditResources(slingRequest);
if (resources != null) {
if (resources.size() == 1) {
// single resource
FormsHelper.setFormLoadResource(slingRequest, resources.get(0));
} else if (resources.size() > 1) {
// multiple resources
// not supported by CQ 5.3
}
}
Resource loadResource = (Resource) request.getAttribute("cq.form.loadresource");
String title;
if (loadResource != null) {
// an asset is loaded: disable WCM
WCMMode.DISABLED.toRequest(request);
String path = loadResource.getPath();
Asset asset = loadResource.adaptTo(Asset.class);
try {
// it might happen that the adobe xmp lib creates an array
Object titleObj = asset.getMetadata("dc:title");
if (titleObj instanceof Object[]) {
Object[] titleArray = (Object[]) titleObj;
title = (titleArray.length > 0) ? titleArray[0].toString() : "";
} else {
title = titleObj.toString();
}
}
catch (NullPointerException e) {
title = path.substring(path.lastIndexOf("/") + 1);
}
}
else {
title = currentPage.getTitle() == null ? currentPage.getName() : currentPage.getTitle();
}
在HTML部分中,使用之前的标题集(资产或页面标题):
<title><%= title %></title>
此示例介绍如何构建可显示和显示已加载资产元数据的组件。
在项目目录中创建组件文件夹,例如/apps/geometrixx/components/samplemeta
。
使用以下代码片段添加content.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="https://sling.apache.org/jcr/sling/1.0" xmlns:cq="https://www.day.com/jcr/cq/1.0" xmlns:jcr="https://www.jcp.org/jcr/1.0"
jcr:primaryType="cq:Component"
jcr:title="Image Dimension"
sling:resourceSuperType="foundation/components/parbase"
allowedParents="[*/parsys]"
componentGroup="Asset Editor"/>
使用以下代码片段添加samplemeta.jsp
:
<%--
Sample metadata field component
--%><%@ page import="com.day.cq.dam.api.Asset,
java.security.AccessControlException" %><%
%><%@include file="/libs/foundation/global.jsp"%><%
String value = "";
String name = "dam:sampleMetadata";
boolean readOnly = false;
// If the form page is requested for an asset loadResource will be the asset.
Resource loadResource = (Resource) request.getAttribute("cq.form.loadresource");
if (loadResource != null) {
// Determine if the loaded asset is read only.
Session session = slingRequest.getResourceResolver().adaptTo(Session.class);
try {
session.checkPermission(loadResource.getPath(), "set_property");
readOnly = false;
}
catch (AccessControlException ace) {
// checkPermission throws exception if asset is read only
readOnly = true;
}
catch (RepositoryException re) {}
// Get the value of the metadata.
Asset asset = loadResource.adaptTo(Asset.class);
try {
value = asset.getMetadata(name).toString();
}
catch (NullPointerException npe) {
// no metadata dc:description available
}
}
%>
<div class="form_row">
<div class="form_leftcol">
<div class="form_leftcollabel">Sample Metadata</div>
</div>
<div class="form_rightcol">
<%
if (readOnly) {
%><c:out value="<%= value %>"/><%
}
else {
%><input class="text" type="text" name="./jcr:content/metadata/<%= name %>" value="<c:out value="<%= value %>" />"><%
}%>
</div>
</div>
为了使组件可用,您需要能够对其进行编辑。要使组件可编辑,请在CRXDE Lite中添加主类型cq:EditConfig
的节点cq:editConfig
。 为了删除段落,请添加带有单个值 cq:actions
的多值属性 DELETE
。
导航到浏览器,然后在示例页面(例如asseteditor.html
)上切换到设计模式,然后为段落系统启用新组件。
在编辑模式中,新组件(例如,示例元数据)现在可在 Sidekick 中使用(位于资产编辑器组中)。插入组件。要能够存储元数据,必须将其添加到元数据表单中。
您可以修改元数据表单中可用的命名空间。
/libs/dam/options/metadata
中定义了当前可用的元数据:
可以在/apps/dam/options/metadata
中覆盖以下选项:
将目录从/libs
复制到/apps
。
删除、修改或添加项目。
如果添加新的命名空间,则必须在您的存储库/CRX中注册它们。 否则,提交元数据表单将导致错误。