Package com.day.cq.wcm.commons
Class ReferenceSearch
- java.lang.Object
-
- com.day.cq.wcm.commons.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)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ReferenceSearch.Info
Holds information about the search results
-
Constructor Summary
Constructors Constructor Description ReferenceSearch()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.util.Collection<java.lang.String>
adjustReferences(Node node, java.lang.String path, java.lang.String destination)
Adjusts all references topath
todestination
in the properties below the specifiednode
.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)
Adjusts all references topath
todestination
in the properties below the specifiednode
.java.util.Collection<java.lang.String>
adjustReferences(ResourceResolver resolver, java.lang.String path, java.lang.String destination, java.lang.String[] refPaths)
Adjusts all references topath
todestination
in the pages specified byrefPaths
.static java.lang.String
escapeIllegalXpathSearchChars(java.lang.String s)
Escapes illegal XPath search characters.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.int
getMaxReferencesPerPage()
Returns the maximum number of references that can be added to a page info.java.lang.String
getSearchRoot()
Returns the search root.boolean
isExact()
Returns the shallow flag.boolean
isHollow()
Returns thehollow
flag.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)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.ReferenceSearch
setExact(boolean exact)
Sets theexact
flag.ReferenceSearch
setHollow(boolean hollow)
Sets thehollow
flag.ReferenceSearch
setMaxReferencesPerPage(int maxReferencesPerPage)
Sets the value ofmaxReferencesPerPage
.ReferenceSearch
setPredicate(AbstractResourcePredicate resourcePredicate)
Set theresourcePredicate
, this predicate is evaluated for each search result and can be used to filter results.ReferenceSearch
setRepository(SlingRepository repository)
Deprecated.The repository was used by the implementation to create an administrative session inadjustReferences(ResourceResolver, String, String, String[])
.ReferenceSearch
setSearchRoot(java.lang.String searchRoot)
Sets the search root
-
-
-
Method Detail
-
setRepository
public ReferenceSearch setRepository(SlingRepository repository)
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
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 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(boolean)
-
setHollow
public ReferenceSearch setHollow(boolean hollow)
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(int)
-
setMaxReferencesPerPage
public ReferenceSearch setMaxReferencesPerPage(int maxReferencesPerPage)
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
public ReferenceSearch setPredicate(AbstractResourcePredicate resourcePredicate)
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 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 resolverpath
- 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
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 java.util.Collection<java.lang.String> adjustReferences(Node node, java.lang.String path, java.lang.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 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 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
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
-
-