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 classHolds information about the search results -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadjustReferences(Node node, String path, String destination) Adjusts all references topathtodestinationin the properties below the specifiednode.adjustReferences(Node node, String path, String destination, boolean shallow, Set<String> excludedProperties) adjustReferences(Node node, String path, String destination, boolean shallow, Set<String> excludedProperties, ResourceResolver resolver, boolean withoutChildNodes) Adjusts all references topathtodestinationin the properties below the specifiednode.adjustReferences(Node node, String path, String destination, boolean withoutChildNodes, ResourceResolver resolver) adjustReferences(ResourceResolver resolver, String path, String destination, String[] refPaths) Adjusts all references topathtodestinationin the pages specified byrefPaths.static StringEscapes 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.intReturns the maximum number of references that can be added to a page info.Returns the search root.booleanisExact()Returns the shallow flag.booleanisHollow()Returns thehollowflag.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 theexactflag.setHollow(boolean hollow) Sets thehollowflag.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 rootsetValidatePage(boolean validatePage)
-
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 theexactflag. Iftrueonly exact references are searched (and replaced). otherwise also references to child resources are included.- Parameters:
exact-trueif perform an exact search- Returns:
- this;
-
isHollow
public boolean isHollow()Returns thehollowflag.- Returns:
- the
hollowflag. - See Also:
-
setHollow
Sets thehollowflag. Iftruethe returned info will contain only properties of the page and not the page object itself.- Parameters:
hollow-trueif 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
pathtodestinationin the pages specified byrefPaths. IfisExact()istrueonly exact references topathare adjusted, otherwise all references to child resources are adjusted, too.The resource resolver needs to have sufficient permissions (i.e.
jcr:readandrep: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 topathtodestinationin the properties below the specifiednode. IfisExact()istrueonly exact references topathare 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 - Throws:
RepositoryException
-
adjustReferences
public Collection<String> adjustReferences(Node node, String path, String destination, boolean withoutChildNodes, ResourceResolver resolver) throws RepositoryException - Throws:
RepositoryException
-
adjustReferences
public Collection<String> adjustReferences(Node node, String path, String destination, boolean shallow, Set<String> excludedProperties, ResourceResolver resolver, boolean withoutChildNodes) throws RepositoryException Adjusts all references topathtodestinationin the properties below the specifiednode. IfisExact()istrueonly exact references topathare adjusted, otherwise all references to child resources are adjusted, too.- Parameters:
node- (content) node to adjustpath- source pathdestination- destination pathshallow- iftruechild nodes are not traversedexcludedProperties- a set of excluded property namesresolver- resolver to operate on.withoutChildNodes- with child nodes or not- 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
-
setValidatePage
-