Class ReferenceSearch


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

      • ReferenceSearch

        public ReferenceSearch()
    • Method Detail

      • getSearchRoot

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

        public ReferenceSearch setSearchRoot​(java.lang.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(boolean)
      • 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(boolean)
      • 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(int)
      • 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;
      • findPageReferencesForResource

        public java.util.List<Page> findPageReferencesForResource​(ResourceResolver resolver,
                                                                  java.lang.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 java.util.Map<java.lang.String,​ReferenceSearch.Info> search​(ResourceResolver resolver,
                                                                                 java.lang.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 java.util.Map<java.lang.String,​ReferenceSearch.Info> search​(ResourceResolver resolver,
                                                                                 java.lang.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 java.util.Collection<java.lang.String> adjustReferences​(ResourceResolver resolver,
                                                                       java.lang.String path,
                                                                       java.lang.String destination,
                                                                       java.lang.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 java.util.Collection<java.lang.String> adjustReferences​(Node node,
                                                                       java.lang.String path,
                                                                       java.lang.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 java.util.Collection<java.lang.String> adjustReferences​(Node node,
                                                                       java.lang.String path,
                                                                       java.lang.String destination,
                                                                       boolean shallow,
                                                                       java.util.Set<java.lang.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 java.lang.String escapeIllegalXpathSearchChars​(java.lang.String s)
        Escapes illegal XPath search characters.
        Parameters:
        s - the string to encode
        Returns:
        the escaped string