有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何使用jcr XPath在jcr:content/@jcr:data中搜索?

我想在CQ 5.6(AEM)实例中包含的JCR存储库中搜索包含给定字符串.jsp的所有xxx文件。由于不熟悉JCR对XPath(或JCR-SQL2)的解释,我在表达查询方面不是很成功

这将获取所有.jsp文件:

//*[jcr:contains(., '.jsp')]

这就是我希望限制上述包含xxx.jsp文件列表的方式:

//*[jcr:contains(., '.jsp')][jcr:contains(jcr:content/@jcr:data, 'xxx')]
//*[jcr:contains(., '.jsp') and jcr:contains(jcr:content/@jcr:data, 'xxx')]
//*[jcr:contains(., '.jsp')]/jcr:content[jcr:contains(@jcr:data, 'xxx')]/..

@jcr:data属于Binary类型。以上这些似乎都不起作用。我哪里做错了


共 (1) 个答案

  1. # 1 楼答案

    看起来查询应该在nt:file节点上,而不是jcr:data节点上。参见对JCR - Jackrabbit - Xpath expression for search content text of a file contained inside a node的回答

    使用querybuilder进行的快速测试显示了来自CQ中JSP文件的结果(在本例中,这些文件包含“/foundation/global.JSP”):

    http://localhost:4502/bin/querybuilder.json?type=nt:file&nodename=*.jsp&group.1_fulltext=foundation/global.jsp
    

    给出:

    {
      success: true,
      results: 10,
      total: 21,
      offset: 0,
      hits: [
        {
          path: "/libs/cq/personalization/components/offerpage/body.jsp",
          excerpt: "  %&gt;&lt;%@include file=&quot;/libs/<strong>foundation/global.jsp</strong>&quot;%&gt;&lt;% I18n i18n = new I18n(slingRequest); String icnCls = ...",
          name: "body.jsp",
          title: "body.jsp",
          lastModified: "2013-04-24 11:45:05",
          created: "2013-04-24 11:32:58",
          size: "3 KB",
          mimeType: "text/plain"
        },
    ...
    }