Search code examples
osgiaemjcrosgi-bundlesling

How to find a node by name in adobe cq5


I am trying to find out the best way to get the Node in repository by its name. I can make sure that no 2 nodes will have the same name in the repository.

I can write a recursive code to get the node by name but that can degrade the system performance if my node is at root --> level 1000 --> level 1k

if Adobe CQ5(CRX) provides any api to do the same?


Solution

  • Use a JCR query:

    String query = "SELECT * FROM [nt:base] AS s WHERE NAME(s) = '%s'";
    resourceResolver.findResources(String.format(query, "node-name"), "JCR-SQL2");