我们有资产api来获取列表,但是为此,我们需要提供AEM用户凭据。
我们有任何接口,可以使用页面管理器获取所有页面的方式,从大坝中获取所有资产列表。
答案 0 :(得分:1)
为此,您可以结合使用JCR的QueryManager API和您的特定查询。 以下是一个示例servlet,其中列出了路径以下的所有资产- / content / dam / we-retail / en / features
import javax.jcr.Session;
import javax.jcr.query.Query;
import javax.jcr.query.QueryManager;
import javax.jcr.query.QueryResult;
import javax.jcr.query.Row;
import javax.jcr.query.RowIterator;
import javax.servlet.Servlet;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.servlets.HttpConstants;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(immediate = true, service = Servlet.class, property = { "sling.servlet.methods=" + HttpConstants.METHOD_GET,
"sling.servlet.paths=" + "/bin/learning/assetlister" })
public class AssetListerServlet extends SlingSafeMethodsServlet {
// Generated serialVersionUID
private static final long serialVersionUID = 7762806638577908286L;
// Default logger
private final Logger log = LoggerFactory.getLogger(this.getClass());
// Instance of ResourceResolver
private ResourceResolver resourceResolver;
// JCR Session instance
private Session session;
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) {
try {
// Getting the ResourceResolver from the current request
resourceResolver = request.getResourceResolver();
// Getting the session instance by adapting ResourceResolver
session = resourceResolver.adaptTo(Session.class);
QueryManager queryManager = session.getWorkspace().getQueryManager();
String queryString = "SELECT * FROM [dam:Asset] AS asset WHERE ISDESCENDANTNODE(asset ,'/content/dam/we-retail/en/features')";
Query query = queryManager.createQuery(queryString, "JCR-SQL2");
QueryResult queryResult = query.execute();
response.getWriter().println("--------------Result-------------");
RowIterator rowIterator = queryResult.getRows();
while (rowIterator.hasNext()) {
Row row = rowIterator.nextRow();
response.getWriter().println(row.toString());
}
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
if (resourceResolver != null) {
resourceResolver.close();
}
}
}
}
Similary根据您的特定要求,可以在组件,服务等中使用此逻辑。希望对您有所帮助。
答案 1 :(得分:0)