Java Code Examples for org.apache.sling.api.resource.ResourceResolver#findResources()

The following examples show how to use org.apache.sling.api.resource.ResourceResolver#findResources() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SeeAlsoDataFetcher.java    From sling-samples with Apache License 2.0 6 votes vote down vote up
/**
 * For "see also", our articles have just the article name but no path or
 * section. This maps those names (which are Sling Resource names) to their
 * Resource, so we can use the full path + title to render links.
 */
private static Map<String, Object> toArticleRef(ResourceResolver resolver, String nodeName) {
    final String jcrQuery = String.format("/jcr:root%s//*[@filename='%s']", Constants.ARTICLES_ROOT, nodeName);
    final Iterator<Resource> it = resolver.findResources(jcrQuery, "xpath");

    // We want exactly one result
    if (!it.hasNext()) {
        throw new RuntimeException("No Resource found:" + jcrQuery);
    }
    final Map<String, Object> result = SlingWrappers.resourceWrapper(it.next());
    if (it.hasNext()) {
        throw new RuntimeException("More than one Resource found:" + jcrQuery);
    }

    return result;
}
 
Example 2
Source File: ProductsSuggestionOmniSearchHandler.java    From commerce-cif-connector with Apache License 2.0 5 votes vote down vote up
Iterator<Resource> getVirtualResults(ResourceResolver resolver, Map<String, Object> predicateParameters, long limit, long offset) {
    Map<String, Object> queryParameters = new HashMap<>();
    queryParameters.putAll(predicateParameters);
    queryParameters.put(PARAMETER_OFFSET, String.valueOf(offset));
    queryParameters.put(PARAMETER_LIMIT, String.valueOf(limit));
    String queryString = mapToString(queryParameters);
    Iterator<Resource> virtualResults = null;
    try {
        virtualResults = resolver.findResources(queryString, VIRTUAL_PRODUCT_QUERY_LANGUAGE);
    } catch (Exception x) {
        LOGGER.error("Error searching virtual products", x);
    }
    return virtualResults;
}
 
Example 3
Source File: HistoryImpl.java    From APM with Apache License 2.0 4 votes vote down vote up
@Override
public List<Resource> findAllResources(ResourceResolver resourceResolver) {
  Iterator<Resource> resources = resourceResolver.findResources(HISTORY_ENTRIES_QUERY, Query.JCR_SQL2);
  return Lists.newArrayList(resources);
}
 
Example 4
Source File: HistoryAutocleanService.java    From APM with Apache License 2.0 4 votes vote down vote up
private void deleteHistoryByQuery(ResourceResolver resolver, String query, int offset) {
  Iterable<Resource> iterable = () -> resolver.findResources(query, Query.JCR_SQL2);
  StreamSupport.stream(iterable.spliterator(), false)
      .skip(offset)
      .forEach(resource -> deleteItem(resolver, resource));
}