Package com.day.cq.wcm.commons
Class ReferenceSearch
java.lang.Object
com.day.cq.wcm.commons.ReferenceSearch
ReferenceSearch
provides methods that search references to
resources (e.g. a path in a property to an image)-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
Holds information about the search results -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadjustReferences
(Node node, String path, String destination) Adjusts all references topath
todestination
in the properties below the specifiednode
.adjustReferences
(Node node, String path, String destination, boolean shallow, Set<String> excludedProperties) Adjusts all references topath
todestination
in the properties below the specifiednode
.adjustReferences
(ResourceResolver resolver, String path, String destination, String[] refPaths) Adjusts all references topath
todestination
in the pages specified byrefPaths
.static String
Escapes illegal XPath search characters.findPageReferencesForResource
(ResourceResolver resolver, String path, int limit, int offset) This Method is to get page references of the given resource path.int
Returns the maximum number of references that can be added to a page info.Returns the search root.boolean
isExact()
Returns the shallow flag.boolean
isHollow()
Returns thehollow
flag.search
(ResourceResolver resolver, String path) Deprecated.use Search(ResourceResolver resolver, String path, String limit, String offset)search
(ResourceResolver resolver, String path, int limit, int offset) This method is to get page references of the given resource path.setExact
(boolean exact) Sets theexact
flag.setHollow
(boolean hollow) Sets thehollow
flag.setMaxReferencesPerPage
(int maxReferencesPerPage) Sets the value ofmaxReferencesPerPage
.setPredicate
(AbstractResourcePredicate resourcePredicate) Deprecated.UsesetPredicate(ResourcePredicate)
instead.setPredicate
(ResourcePredicate resourcePredicate) Set theresourcePredicate
, this predicate is evaluated for each search result and can be used to filter results.setRepository
(SlingRepository repository) Deprecated.The repository was used by the implementation to create an administrative session inadjustReferences(ResourceResolver, String, String, String[])
.setSearchRoot
(String searchRoot) Sets the search root
-
Constructor Details
-
ReferenceSearch
public ReferenceSearch()
-
-
Method Details
-
setRepository
Deprecated.The repository was used by the implementation to create an administrative session inadjustReferences(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
Returns the search root. default is '/'- Returns:
- the search root.
-
setSearchRoot
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
Sets theexact
flag. Iftrue
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 thehollow
flag.- Returns:
- the
hollow
flag. - See Also:
-
setHollow
Sets thehollow
flag. Iftrue
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
Sets the value ofmaxReferencesPerPage
. 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
Set theresourcePredicate
, this predicate is evaluated for each search result and can be used to filter results.- Parameters:
resourcePredicate
- an instance ofResourcePredicate
- Returns:
- this;
-
setPredicate
Deprecated.UsesetPredicate(ResourcePredicate)
instead.Set theresourcePredicate
, this predicate is evaluated for each search result and can be used to filter results.- Parameters:
resourcePredicate
- an instance ofAbstractResourcePredicate
- 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
Deprecated.use Search(ResourceResolver resolver, String path, String limit, String offset)Searches for references to the given path.- Parameters:
resolver
- the resource resolverpath
- 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
todestination
in the pages specified byrefPaths
. IfisExact()
istrue
only exact references topath
are adjusted, otherwise all references to child resources are adjusted, too.The resource resolver needs to have sufficient permissions (i.e.
jcr:read
andrep:alterProperties
) on the nodes containing references.- Parameters:
resolver
- resolver to operate on.path
- source pathdestination
- destination pathrefPaths
- 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 topath
todestination
in the properties below the specifiednode
. IfisExact()
istrue
only exact references topath
are adjusted, otherwise all references to child resources are adjusted, too.- Parameters:
node
- (content) node to traversepath
- source pathdestination
- 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 topath
todestination
in the properties below the specifiednode
. IfisExact()
istrue
only exact references topath
are adjusted, otherwise all references to child resources are adjusted, too.- Parameters:
node
- (content) node to adjustpath
- source pathdestination
- destination pathshallow
- iftrue
child nodes are not traversedexcludedProperties
- 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
Escapes illegal XPath search characters.- Parameters:
s
- the string to encode- Returns:
- the escaped string
-