code: @SuppressWarnings("null")
    private NodeIterator searchNodesByTemplate(String[] templates, String rootPath, SlingHttpServletRequest request) throws RepositoryException {
      String queryString = "/jcr:root" + ISO9075.encodePath(rootPath) + "//*"
          + "[@cq:template='" + StringUtils.join(escapeXPathQueryExpressions(templates), "' or @cq:template='") + "']";
      QueryManager queryManager = request.getResourceResolver().adaptTo(Session.class).getWorkspace().getQueryManager();
      @SuppressWarnings("deprecation")
      Query query = queryManager.createQuery(queryString, Query.XPATH);
      QueryResult result = query.execute();
      return result.getNodes();
    }
docs: Searches for page content nodes under the {@code pRootPath} with given
  template It uses a XPATH query and return the node iterator of results.
  
  @param templates
  @param rootPath
  @return results node iterator
  @throws RepositoryException