Class ReferenceSearch

java.lang.Object
com.day.cq.wcm.commons.ReferenceSearch

public class ReferenceSearch extends Object
ReferenceSearch provides methods that search references to resources (e.g. a path in a property to an image)
  • Constructor Details

    • ReferenceSearch

      public ReferenceSearch()
  • Method Details

    • setRepository

      public ReferenceSearch setRepository(SlingRepository repository)
      Deprecated.
      The repository was used by the implementation to create an administrative session in adjustReferences(ResourceResolver, String, String, String[]). Instead, specify a resource resolver which is sufficiently authorized to adjust references at the desired locations.
      Parameters:
      repository - The repository
      Returns:
      this
    • getSearchRoot

      public String getSearchRoot()
      Returns the search root. default is '/'
      Returns:
      the search root.
    • setSearchRoot

      public ReferenceSearch setSearchRoot(String searchRoot)
      Sets the search root
      Parameters:
      searchRoot - the search root
      Returns:
      this
    • isExact

      public boolean isExact()
      Returns the shallow flag.
      Returns:
      the shallow flag.
      See Also:
    • setExact

      public ReferenceSearch setExact(boolean exact)
      Sets the exact flag. If true only exact references are searched (and replaced). otherwise also references to child resources are included.
      Parameters:
      exact - true if perform an exact search
      Returns:
      this;
    • isHollow

      public boolean isHollow()
      Returns the hollow flag.
      Returns:
      the hollow flag.
      See Also:
    • setHollow

      public ReferenceSearch setHollow(boolean hollow)
      Sets the hollow flag. If true the returned info will contain only properties of the page and not the page object itself.
      Parameters:
      hollow - true if perform a hollow search
      Returns:
      this;
    • getMaxReferencesPerPage

      public int getMaxReferencesPerPage()
      Returns the maximum number of references that can be added to a page info.
      Returns:
      the reference limit per page.
      See Also:
    • setMaxReferencesPerPage

      public ReferenceSearch setMaxReferencesPerPage(int maxReferencesPerPage)
      Sets the value of maxReferencesPerPage. The maximum number of references that can be added to a page info.
      Parameters:
      maxReferencesPerPage - The maximum number of references that can be added to a page info.
      Returns:
      this;
    • setPredicate

      public ReferenceSearch setPredicate(ResourcePredicate resourcePredicate)
      Set the resourcePredicate, this predicate is evaluated for each search result and can be used to filter results.
      Parameters:
      resourcePredicate - an instance of ResourcePredicate
      Returns:
      this;
    • setPredicate

      @Deprecated public ReferenceSearch setPredicate(AbstractResourcePredicate resourcePredicate)
      Deprecated.
      Set the resourcePredicate, this predicate is evaluated for each search result and can be used to filter results.
      Parameters:
      resourcePredicate - an instance of AbstractResourcePredicate
      Returns:
      this;
    • findPageReferencesForResource

      public List<Page> findPageReferencesForResource(ResourceResolver resolver, String path, int limit, int offset)
      This Method is to get page references of the given resource path. This API is recommended to use where reference count is required or where only page references are need to prepare reports. This API should't be used to adjust the references as it doesn't provide exact path to the descendant node of a page which actually hold the given resource path.
      Parameters:
      resolver - ResourceResolver.
      path - It's given path for which page references need to be fetch.
      limit - upper limit on size of result in current request.
      offset - offset.
      Returns:
      List of Pages having reference to the given resource path.
    • search

      public Map<String,ReferenceSearch.Info> search(ResourceResolver resolver, String path, int limit, int offset)
      This method is to get page references of the given resource path. This API provides exact location of the child node of a page which actually holds the given resource path. This API is recommended to use where reference are need to be adjusted.
      Parameters:
      resolver - ResourceResolver.
      path - It's given path for which page references need to be fetch.
      limit - upper limit on size of result in current request.
      offset - offset.
      Returns:
      Map having resorce path a key and Info object as key. Info Holds information about the search results.
    • search

      public Map<String,ReferenceSearch.Info> search(ResourceResolver resolver, String path)
      Deprecated.
      use Search(ResourceResolver resolver, String path, String limit, String offset)
      Searches for references to the given path.
      Parameters:
      resolver - the resource resolver
      path - the path to search for
      Returns:
      reference infos
    • adjustReferences

      public Collection<String> adjustReferences(ResourceResolver resolver, String path, String destination, String[] refPaths)

      Adjusts all references to path to destination in the pages specified by refPaths. If isExact() is true only exact references to path are adjusted, otherwise all references to child resources are adjusted, too.

      The resource resolver needs to have sufficient permissions (i.e. jcr:read and rep:alterProperties) on the nodes containing references.

      Parameters:
      resolver - resolver to operate on.
      path - source path
      destination - destination path
      refPaths - paths of pages to be adjusted
      Returns:
      collection of path to properties that were adjusted
    • adjustReferences

      public Collection<String> adjustReferences(Node node, String path, String destination) throws RepositoryException
      Adjusts all references to path to destination in the properties below the specified node. If isExact() is true only exact references to path are adjusted, otherwise all references to child resources are adjusted, too.
      Parameters:
      node - (content) node to traverse
      path - source path
      destination - destination path
      Returns:
      collection of paths to properties that were adjusted
      Throws:
      RepositoryException - if an error during repository access occurs
    • adjustReferences

      public Collection<String> adjustReferences(Node node, String path, String destination, boolean shallow, Set<String> excludedProperties) throws RepositoryException
      Adjusts all references to path to destination in the properties below the specified node. If isExact() is true only exact references to path are adjusted, otherwise all references to child resources are adjusted, too.
      Parameters:
      node - (content) node to adjust
      path - source path
      destination - destination path
      shallow - if true child nodes are not traversed
      excludedProperties - a set of excluded property names
      Returns:
      collection of paths to properties that were adjusted
      Throws:
      RepositoryException - if an error during repository access occurs
    • escapeIllegalXpathSearchChars

      public static String escapeIllegalXpathSearchChars(String s)
      Escapes illegal XPath search characters.
      Parameters:
      s - the string to encode
      Returns:
      the escaped string