@ProviderType public interface Tag extends Adaptable
Tag
is a keyword or label that can be assigned to any
content. Multiple tags can be assigned to a content element, which allows to
classify them by several different categorizations at the same time, as
opposed to a single hierarchical model. Tags became popular with the wave of
Web 2.0 websites, but the CQ5 tagging model goes even further in flexibility
by offering both namespaces, hierarchical tags and the
ability to restrict users to use only predefined tags.
TagManager
, by either resolving
an existing tag or creating a new one:
Tag tag = tagManger.resolve("my/tag"); // for existing tags
Tag tag = tagManger.createTag("my/tag"); // for new tags
For the JCR-based implementation, which
maps tags onto JCR Node
s, you can directly use Sling's apaptTo
mechanism if you happen to have the resource (eg. such as
{base.path}/default/my/tag
):
Tag tag = resource.adaptTo(Tag.class);
(Note: adapting from Node
to a tag is not possible directly, since
Node
does not implement the Adaptable.adaptTo(Class)
method).
Node node = tag.adaptTo(Node.class);
Resource node = tag.adaptTo(Resource.class);
beautiful
) or
represent a hierarchical taxonomy (eg. planet/earth
, meaning
both the generic planet
and the more specific
earth
). Tags are typically identified by strings, either by a
so-called short
tag ID (typical case) or an
absolute path to the tag (a rather rare case). A tag has meta
information such as a title (that should be displayed in UIs instead of the
tag ID, if present) and a description.
Furthermore, container tags (or super-tags) in a taxonomy serve as
the sub-summation of all sub-tags, eg. content tagged with
fruit/banana
is considered to be tagged with fruit
as
well, ie. searching for content just tagged with fruit
would
find the ones with fruit/banana
as well.
Finally, namespaces allow to group things. The most typical use-case is to have a namespace per (web)site (eg. public, internal, portal, etc.) or for larger applications (eg. wcm, dam, collab) - but you are free to use namespaces for whatever you need. Namespaces are used in the UI to only show the subset of tags (ie. tags of a certain namespace) that is applicable for the current content.
A tag ID is either a shorthand or an absolute path refering to a tag.
It must be resolved to an absolute tag path. A tag is contained
within a certain namespace (which is default
if no
namespace is given in the tag ID). The part after the namespace is called the
local tag ID and can be a path itself. container tags have
sub-tags that represent a hierarchical order in the taxonomy. They can be
used as tags (an actually referenced tag) like any other tag below a
namespace (eg. tagging something with planet
is not forbidden
if it has sub-tags like planet/earth
and
planet/mars
for example).
dam:fruit/apple/braeburn
dam
fruit/apple/braeburn
fruit
and apple
braeburn
{base.path}/dam/fruit/apple/braeburn
color/red
default
color/red
color
red
{base.path}/default/color/red
sky
default
sky
sky
{base.path}/default/sky
dam:
dam
{base.path}/dam
Modifier and Type | Method and Description |
---|---|
java.util.Iterator<Resource> |
find() |
long |
getCount() |
java.lang.String |
getDescription() |
java.lang.String |
getGQLSearchExpression(java.lang.String property)
Returns the GQL query constraint for searching this tag.
|
long |
getLastModified()
Returns the date of last modification of the tag.
|
java.lang.String |
getLastModifiedBy()
Return the user id that last modified the Tag or
null if this
information is not available. |
java.lang.String |
getLocalizedTitle(java.util.Locale locale) |
java.util.Map<java.util.Locale,java.lang.String> |
getLocalizedTitlePaths() |
java.util.Map<java.util.Locale,java.lang.String> |
getLocalizedTitles() |
java.lang.String |
getLocalTagID() |
java.lang.String |
getName() |
Tag |
getNamespace() |
Tag |
getParent() |
java.lang.String |
getPath() |
java.lang.String |
getTagID() |
java.lang.String |
getTitle() |
java.lang.String |
getTitle(java.util.Locale locale) |
java.lang.String |
getTitlePath() |
java.lang.String |
getTitlePath(java.util.Locale locale) |
java.lang.String |
getXPathSearchExpression(java.lang.String property)
Returns the jcr xpath query constraint for searching this tag.
|
boolean |
isNamespace() |
java.util.Iterator<Tag> |
listAllSubTags() |
java.util.Iterator<Tag> |
listChildren() |
java.util.Iterator<Tag> |
listChildren(Filter<Tag> filter) |
java.lang.String getName()
java.lang.String getTagID()
default
, it
will be left out. If this tag represents a namespace, null
is returned.java.lang.String getLocalTagID()
null
is returned.java.lang.String getPath()
java.lang.String getTitle()
java.lang.String getTitle(java.util.Locale locale)
locale
- given localenull
, this will return the same as
getTitle()
. If you only want localized titles (and
null
if no localization exists), use
getLocalizedTitle(Locale)
.java.lang.String getLocalizedTitle(java.util.Locale locale)
locale
- given localenull
null
. If a
fallback to the default getTitle()
is desired, use
getTitle(Locale)
instead.java.util.Map<java.util.Locale,java.lang.String> getLocalizedTitles()
getLocalizedTitle(Locale)
java.lang.String getDescription()
null
is returned.java.lang.String getTitlePath()
java.lang.String getTitlePath(java.util.Locale locale)
locale
- given localenull
, this will return the same as
getTitlePath()
.java.util.Map<java.util.Locale,java.lang.String> getLocalizedTitlePaths()
getTitlePath(Locale)
long getCount()
long getLastModified()
java.lang.String getLastModifiedBy()
null
if this
information is not available.null
boolean isNamespace()
true
if this tag object refers to a tag namespace.Tag getNamespace()
Tag getParent()
null
if this object is a tag namespace.java.util.Iterator<Tag> listChildren()
java.util.Iterator<Tag> listChildren(Filter<Tag> filter)
filter
- given filterjava.util.Iterator<Tag> listAllSubTags()
java.util.Iterator<Resource> find()
cq:tags
property that contains either the tagID or the
full absolute path to that tag. Returns null
in case of
errors.TagManager.find(String)
,
TagManager.find(String, String[])
java.lang.String getXPathSearchExpression(java.lang.String property)
relative/path/@cq:tags = "tag:id" or relative/path/@cq:tags = "tag:previous/id"
considering child tags and different tag ids because of moved or merged tags.property
- relative path to cq:tags
property,
e.g. cq:tags
or relative/path/@cq:tags
//*[...]
)java.lang.String getGQLSearchExpression(java.lang.String property)
"cq:tags":"c" OR "cq:tags":"{base.path}/default/c" OR "cq:tags":"c/b" OR "cq:tags":"{base.path}/default/c/b"
considering child tags and different tag ids because of moved or merged tags.property
- relative path to cq:tags
property,
e.g. cq:tags
or relative/path/@cq:tags
Copyright © 2010 - 2023 Adobe. All Rights Reserved