我正在尝试基于 jcr API 为 CQ 创建一个页面。我想查询在属性中包含特定字符串的页面。
查询本身 (JCR-SQL2) 如下(我在 CQ Web 界面上对其进行了测试并提供了结果):
SELECT
*
FROM
[nt:base] AS s
WHERE
ISDESCENDANTNODE([/content])
AND
s.[sling:resourceType] = 'some/path/to/destination'
这是我在 JSP 页面中的尝试:
String stmt = "SELECT * FROM [nt:base] AS s WHERE ISDESCENDANTNODE([/content]) AND s.[cq:template] = 'some/path/to/destination'";
Query query = currentNode.getSession().getWorkspace().getQueryManager().createQuery(stmt, Query.JCR_SQL2);
QueryResult results = query.execute();
if (results.getNodes() != null && results.getNodes().hasNext()) {
NodeIterator it = results.getNodes();
while (it.hasNext()) {
Node node = it.nextNode();
String npath = node.getPath();
Page contentPage = pageManager.getContainingPage(resourceResolver.getResource(npath));
String title = contentPage.getTitle();
String path = contentPage.getPath() + ".html";
%>
<div class="searchresult"><a href="<%= path %>"><%= title %></a></div>
<%
}
}
抛出的错误如下:
Caused by: javax.jcr.RepositoryException: This query result has already been iterated through