@ProviderType
public interface TagManager
TagManager
allows for resolving and creating tags by paths and
names. See Tag
for a detailed description of tagging concepts,
terminology and the structure of tag IDs.
This interface is generic, but there is a JCR-based reference implementation
which can be obtained by the JcrTagManagerFactory
- all you need is
an existing JCR Session
(what tags can be "seen" and which can be
created depends on the user of that session):
TagManager tagManager = JcrTagManagerFactory.getTagManager(session);
In the typical Sling context you can also adapt to a TagManager
from
the ResourceResolver
:
TagManager tagManager = resourceResolver.adaptTo(TagManager.class);
Modifier and Type | Interface and Description |
---|---|
static class |
TagManager.FindResults |
Modifier and Type | Method and Description |
---|---|
boolean |
canCreateTag(java.lang.String tagID)
Returns whether the current user (eg.
|
boolean |
canCreateTagByTitle(java.lang.String tagTitlePath)
Returns whether the current user (eg.
|
boolean |
canCreateTagByTitle(java.lang.String tagTitlePath,
java.util.Locale locale)
Returns whether the current user (eg.
|
Tag |
createTag(java.lang.String tagID,
java.lang.String title,
java.lang.String description)
Creates a new tag (or namespace) by creating it in the tag store, eg.
|
Tag |
createTag(java.lang.String tagID,
java.lang.String title,
java.lang.String description,
boolean autoSave)
Creates a new tag (or namespace) by creating it in the tag store, eg.
|
Tag |
createTagByTitle(java.lang.String titlePath)
Creates a new tag (not namespace, can be specified at the beginning, but
must exist) from a title or a path of titles (corresponding to
Tag.getTitlePath() ). |
Tag |
createTagByTitle(java.lang.String titlePath,
boolean autoSave)
Creates a new tag (not namespace, can be specified at the beginning, but
must exist) from a title or a path of titles (corresponding to
Tag.getTitlePath() ). |
Tag |
createTagByTitle(java.lang.String tagTitlePath,
java.util.Locale locale)
Creates a new tag (not namespace, can be specified at the beginning, but
must exist) from a title or a path of titles (corresponding to
Tag.getTitlePath() ). |
void |
deleteTag(Tag tag)
Deletes the given tag.
|
void |
deleteTag(Tag tag,
boolean autoSave)
Deletes the given tag.
|
RangeIterator<Resource> |
find(java.lang.String tagID)
|
RangeIterator<Resource> |
find(java.lang.String basePath,
java.util.List<java.lang.String[]> tagSetIDs)
Returns all content (Sling Resources, typically JCR
Nodes) tagged with all or one of the given tags, but
only content that lies below the given base path.
In the standard JCR-implementation, these are all nodes with a cq:tags property that contains either the tagID or the full
absolute path to that tag.Furthermore, when passing a container tag, such as fruit
with eg. |
RangeIterator<Resource> |
find(java.lang.String basePath,
java.lang.String[] tagIDs)
Returns all content (Sling Resources, typically
JCR Nodes) tagged with all of the given tags, but
only content that lies below the given base path.
In the standard JCR-implementation, these are all nodes with a cq:tags property that contains either the tagID or the full
absolute path to that tag.Furthermore, when passing a container tag, such as fruit
with eg. |
RangeIterator<Resource> |
find(java.lang.String basePath,
java.lang.String[] tagIDs,
boolean oneMatchIsEnough)
Returns all content (Sling Resources, typically
JCR Nodes) tagged with all or one of the given tags,
but only content that lies below the given base path.
In the standard JCR-implementation, these are all nodes with a cq:tags property that contains either the tagID or the full
absolute path to that tag.Furthermore, when passing a container tag, such as fruit
with eg. |
TagManager.FindResults |
findByTitle(java.lang.String title)
Searches for all content that is tagged with a tag that contains the
given title as tag title.
|
java.lang.Iterable<Tag> |
findTagsByKeyword(java.lang.String keyword,
java.util.Locale locale,
java.lang.String tagId)
Partial Searches for tags with the given keyword from the title.
|
Tag[] |
findTagsByTitle(java.lang.String keyword,
java.util.Locale locale)
Searches for tags with the given keyword in the title.
|
Tag[] |
getNamespaces()
Retrieves all available tag namespaces as array.
|
java.util.Iterator<Tag> |
getNamespacesIter()
Retrieves all available tag namespaces as iterator.
|
ResourceResolver |
getResourceResolver()
Convenience method that returns the underlying resource resolver.
|
Session |
getSession()
Deprecated.
Deprecate in favor of
getResourceResolver() . This is consistent with recommended
api JcrTagManagerFactory.getTagManager(ResourceResolver)
Convenience method that returns the underlying session. Can be used to
easily save the session when eg. creating tags with autoSave = false . |
java.util.List<java.lang.String> |
getSupportedLanguageCodes()
Returns the List of language codes support by Tag
|
Tag[] |
getTags(Resource resource)
Retrieves the tags set on the given resource.
|
Tag[] |
getTagsForSubtree(Resource resource,
boolean shallow)
Retrieves the tags set on the given resource and/or all its child resources
(aka subtree).
|
void |
mergeTag(Tag tag,
Tag destination)
Merges a tag with another one.
|
Tag |
moveTag(Tag tag,
java.lang.String destination)
Moves a tag.
|
Tag |
resolve(java.lang.String tagID)
Resolves a tag (or namespace) object by a shorthand tag id, such as
sky or dam:fruit/apple , or by the absolute
path to a tag, such as {base.path}/dam/fruit/apple . |
Tag |
resolveByTitle(java.lang.String tagTitlePath)
Resolves a tag (or namespace) object by a title or path of titles
(corresponding to
Tag.getTitlePath() ). |
Tag |
resolveByTitle(java.lang.String tagTitlePath,
java.util.Locale locale)
Resolves a tag (or namespace) object by a title or path of titles
(corresponding to
Tag.getTitlePath() ) in the given locale. |
void |
setTags(Resource resource,
Tag[] tags)
Sets tags on the given resource.
|
void |
setTags(Resource resource,
Tag[] tags,
boolean autoSave)
Sets tags on the given resource.
|
Tag resolve(java.lang.String tagID)
sky
or dam:fruit/apple
, or by the absolute
path to a tag, such as {base.path}/dam/fruit/apple
. Namespaces
can be resolved by either using the absolute path to a namespace (one
level below the tag base path, eg. normally
{base.path}/namespace
) or by using the tag id form for
namespaces: namespace:
tagID
- a shorthand tag id or an absolute tag pathnull
if the tag does not existTag resolveByTitle(java.lang.String tagTitlePath)
Tag.getTitlePath()
). Note that the system does
not ensure unique title paths, but this method should be used before
creating a new tag using createTagByTitle(String)
to avoid basic
collisions.tagTitlePath
- a path that includes titles rather than IDsnull
if a tag with such a title path does not
existTag resolveByTitle(java.lang.String tagTitlePath, java.util.Locale locale)
Tag.getTitlePath()
) in the given locale.
Note that the system does not ensure unique title paths, but this method
should be used before creating a new tag using
createTagByTitle(String)
to avoid basic collisions.
tagTitlePath
- a path that includes titles rather than IDslocale
- the locale of the titlePathnull
if a tag with such a title path does not existboolean canCreateTag(java.lang.String tagID) throws InvalidTagFormatException
false
is returned. Basically it checks if a call
to createTag(String, String, String)
will be successful.tagID
- a shorthand tag id or an absolute tag pathtrue
if the current user could create the tag,
false
if not or if the tag already existsInvalidTagFormatException
- if the parameter tagID
is not a valid tag IDboolean canCreateTagByTitle(java.lang.String tagTitlePath) throws InvalidTagFormatException
Tag.getTitlePath()
). If the tag already
exists, false
is returned. Basically it checks if a call
to createTagByTitle(String)
will be successful.tagTitlePath
- a path that includes titles rather than IDstrue
if the current user could create the tag,
false
if not. There is no check if the tag exists
already, ie. it could return true
if the tag is
already existing.InvalidTagFormatException
- if the parameter titlePath
references a
non-existing namespace (please note that you cannot create
namespaces via createTagByTitle(String)
)boolean canCreateTagByTitle(java.lang.String tagTitlePath, java.util.Locale locale) throws InvalidTagFormatException
Tag.getTitlePath()
). If the tag already exists,
false
is returned. Basically it checks if a call to
createTagByTitle(String)
will be successful.
This will resolve the parent tag or namespace using the title in the given locale and then set both the default title and the localized title for the new tag.
tagTitlePath
- a path that includes titles rather than IDslocale
- the locale of the titlePathtrue
if the current user could create the tag,
false
if not. There is no check if the tag exists
already, ie. it could return true
if the tag is
already existing.InvalidTagFormatException
- if the parameter titlePath
references a
non-existing namespace (please note that you cannot create
namespaces via createTagByTitle(String)
)Tag createTag(java.lang.String tagID, java.lang.String title, java.lang.String description) throws java.security.AccessControlException, InvalidTagFormatException
{base.path}/dam/fruit/apple
. If it exists already, the
existing tag will be returned, otherwise the object representing the
newly created tag. If the current user is not allowed to create a tag, an
AccessControlException
will be thrown and no changes will be
made.
The tag is defined by a shorthand tag id, such as sky
or
dam:fruit/apple
, or by the absolute path to a tag, such as
{base.path}/dam/fruit/apple
. Namespaces can be created by
either using the absolute path to a namespace (one level below the tag
base path, eg. normally {base.path}/namespace
) or by using
the tag id form for namespaces: namespace:
This will automatically save the node or session.
tagID
- a shorthand tag id or an absolute tag pathtitle
- a title for the tag (can be null
)description
- a longer description for the tag (can be null
)null
)java.security.AccessControlException
- if the tag must be created, but the user is not allowed to do
soInvalidTagFormatException
- if the parameter tagID
is not a valid tag IDTag createTag(java.lang.String tagID, java.lang.String title, java.lang.String description, boolean autoSave) throws java.security.AccessControlException, InvalidTagFormatException
{base.path}/dam/fruit/apple
. If it exists already, the
existing tag will be returned, otherwise the object representing the
newly created tag. If the current user is not allowed to create a tag, an
AccessControlException
will be thrown and no changes will be
made.
The tag is defined by a shorthand tag id, such as sky
or
dam:fruit/apple
, or by the absolute path to a tag, such as
{base.path}/dam/fruit/apple
. Namespaces can be created by
either using the absolute path to a namespace (one level below the tag
base path, eg. normally {base.path}/namespace
) or by using
the tag id form for namespaces: namespace:
tagID
- a shorthand tag id or an absolute tag pathtitle
- a title for the tag (can be null
)description
- a longer description for the tag (can be null
)autoSave
- whether the session should be automatically saved or notnull
)java.security.AccessControlException
- if the tag must be created, but the user is not allowed to do
soInvalidTagFormatException
- if the parameter tagID
is not a valid tag IDTag createTagByTitle(java.lang.String titlePath) throws java.security.AccessControlException, InvalidTagFormatException
Tag.getTitlePath()
).
This will automatically save the node or session.
titlePath
- a path that includes titles rather than IDsnull
)java.security.AccessControlException
- if the tag must be created, but the user is not allowed to do
soInvalidTagFormatException
- if the parameter titlePath
references a
non-existing namespace (please note that this method won't
create namespaces)Tag createTagByTitle(java.lang.String titlePath, boolean autoSave) throws java.security.AccessControlException, InvalidTagFormatException
Tag.getTitlePath()
).titlePath
- a path that includes titles rather than IDsautoSave
- whether the session should be automatically saved or notnull
)java.security.AccessControlException
- if the tag must be created, but the user is not allowed to do
soInvalidTagFormatException
- if the parameter titlePath
references a
non-existing namespace (please note that this method won't
create namespaces)Tag createTagByTitle(java.lang.String tagTitlePath, java.util.Locale locale) throws java.security.AccessControlException, InvalidTagFormatException
Tag.getTitlePath()
). This will resolve the parent tag or
namespace using the title in the given locale and then set both the
default title and the localized title for the new tag.
This will automatically save the node or session.
tagTitlePath
- a path that includes titles rather than IDslocale
- the locale of the titlePathnull
)java.security.AccessControlException
- if the tag must be created, but the user is not allowed to do
soInvalidTagFormatException
- if the parameter titlePath
references a
non-existing namespace (please note that this method won't
create namespaces)void deleteTag(Tag tag) throws java.security.AccessControlException
This will automatically save the session.
tag
- tag to deletejava.security.AccessControlException
- if the user is not allowed to delete the tagvoid deleteTag(Tag tag, boolean autoSave) throws java.security.AccessControlException
tag
- tag to deleteautoSave
- whether the session should be automatically saved or not;
note that if the tag was activated already, it gets automatically
replicated, and as part of this the session will be saved anyway,
thus autoSave=false will only be respected if the tag and its
backlinks have never been activated beforejava.security.AccessControlException
- if the user is not allowed to delete the tagRangeIterator<Resource> find(java.lang.String tagID)
cq:tags
property that contains either the tagID or the full absolute path to that
tag. Furthermore, when passing a container tag, such as fruit
with eg. sub-tags fruit/apple
, fruit/apple/braeburn
and
fruit/banana
, all content tagged with it or one of the
sub-tags will be found. Convenience method, see also
find(String, String[])
.tagID
- a tag ID or the full path to a tagRangeIterator
containing all found resources (Note:
this is a version of the RangeIterator
that
supports generics. Returns null
if the tag does
not existTag.find()
,
find(String, String[])
TagManager.FindResults findByTitle(java.lang.String title)
TagManager.FindResults
struct-like class.title
- title of tag to findTag[] findTagsByTitle(java.lang.String keyword, java.util.Locale locale)
keyword
- The tag title to be searchedlocale
- to search in a certain localized tag title only; use null
to search in the default titleRangeIterator<Resource> find(java.lang.String basePath, java.lang.String[] tagIDs)
cq:tags
property that contains either the tagID or the full
absolute path to that tag.fruit
with eg. sub-tags fruit/apple
,
fruit/apple/braeburn
and fruit/banana
, all
content tagged with it or one of the sub-tags will be found.basePath
- The starting node of the searchtagIDs
- a list of tag IDs or full paths to tagsRangeIterator
containing all found resources (Note:
this is a version of the RangeIterator
that
supports generics. Returns null
if the tag does
not existTag.find()
,
find(String)
,
find(String, String[], boolean)
RangeIterator<Resource> find(java.lang.String basePath, java.lang.String[] tagIDs, boolean oneMatchIsEnough)
cq:tags
property that contains either the tagID or the full
absolute path to that tag.fruit
with eg. sub-tags fruit/apple
,
fruit/apple/braeburn
and fruit/banana
, all
content tagged with it or one of the sub-tags will be found.basePath
- The starting node of the searchtagIDs
- a list of tag IDs or full paths to tagsoneMatchIsEnough
- if true
all the resources are returned that
contain at least one of the given tags.RangeIterator
containing all found resources (Note:
this is a version of the RangeIterator
that
supports generics. Returns null
if the tag does not
existTag.find()
,
find(String)
RangeIterator<Resource> find(java.lang.String basePath, java.util.List<java.lang.String[]> tagSetIDs)
cq:tags
property that contains either the tagID or the full
absolute path to that tag.fruit
with eg. sub-tags fruit/apple
,
fruit/apple/braeburn
and fruit/banana
, all
content tagged with it or one of the sub-tags will be found.(a or b) and (c or d)
"basePath
- The starting node of the searchtagSetIDs
- a list of lists of tag IDs or full paths to tagsRangeIterator
containing all found resources (Note:
this is a version of the RangeIterator
that
supports generics. Returns null
if the tag does not
existTag.find()
,
find(String)
,
find(String, String[], boolean)
Tag[] getNamespaces()
getNamespacesIter()
java.util.Iterator<Tag> getNamespacesIter()
getNamespaces()
Tag[] getTags(Resource resource)
getTagsForSubtree(org.apache.sling.api.resource.Resource, boolean)
).
Note that there is no defined order, the result is effectively a set of tags.
resource
- the resource to get the tags fromvoid setTags(Resource resource, Tag[] tags)
This will automatically save the node or session.
resource
- the resource to set the tags ontags
- the tags to setvoid setTags(Resource resource, Tag[] tags, boolean autoSave)
resource
- the resource to set the tags ontags
- the tags to setautoSave
- whether the session should be automatically saved or notTag[] getTagsForSubtree(Resource resource, boolean shallow)
resource
- the resource to get the tags fromshallow
- whether tags only directly on this resource should be used (true)
or the whole subtree is taken into account (false)@Deprecated Session getSession()
getResourceResolver()
. This is consistent with recommended
api JcrTagManagerFactory.getTagManager(ResourceResolver)
Convenience method that returns the underlying session. Can be used to
easily save the session when eg. creating tags with autoSave = false
.ResourceResolver getResourceResolver()
autoSave = false
.Tag moveTag(Tag tag, java.lang.String destination) throws java.security.AccessControlException, InvalidTagFormatException, TagException
tag
- the tag to movedestination
- new location of the tag, given as shorthand tag id or an
absolute tag pathjava.security.AccessControlException
- if user is not allowed to move the tagInvalidTagFormatException
- if the parameter destination
is not a valid tag IDTagException
- if the tag could not be movedvoid mergeTag(Tag tag, Tag destination) throws java.security.AccessControlException, TagException
tag
- the tag to merge into another one (will no longer exist afterwards)destination
- the tag to merge with (will exist afterwards)java.security.AccessControlException
- if user is not allowed to merge the tagTagException
- if the tag could not be mergedjava.util.List<java.lang.String> getSupportedLanguageCodes()
java.lang.Iterable<Tag> findTagsByKeyword(java.lang.String keyword, java.util.Locale locale, java.lang.String tagId)
keyword
- The tag title to be searchedlocale
- to search in a certain localized tag title only; use null
to search in the default titletagId
- Tag Id of the Tag/NameSpace under which tag to be searched.Copyright © 2010 - 2023 Adobe. All Rights Reserved