Taxonomy Root Node:
Generally
all tags in the repository are stored in Taxonomy Root Node.
The
taxonomy root node must be a node of type cq:Tag
In AEM base path is
/etc/tags and root node of type cq:Folder
Tag
Characterstics:
· node
type is cq:Tag
· node
name is a component of the TagID
· optional jcr:title property
(the Title to display in the UI)
· optional jcr:description property
· when
containing child nodes, is referred to as a container tag
· is
stored in the repository below a base path called the taxonomy root node
Understanding
of the Tagging structure in tabe format:
TagID
|
Namespace
|
Local
ID
|
Container
tag(s)
|
Leaf
tag
|
Repository
Absolute tag path |
dam:fruit/apple/braeburn
|
dam
|
fruit/apple/braeburn
|
fruit,
apple
|
braeburn
|
/etc/tags/dam/fruit/apple/braeburn
|
color/red
|
default
|
color/red
|
color
|
red
|
/etc/tags/default/color/red
|
sky
|
default
|
sky
|
(none)
|
sky
|
/etc/tags/default/sky
|
dam:
|
dam
|
(none)
|
(none)
|
(none,
the namespace)
|
/etc/tags/dam
|
/etc/tags/category/car
|
category
|
car
|
car
|
car
|
/etc/tags/category/car
|
Moving and Merging Tags(Important point
to be understood):
· When a tag A is moved or merged into tag B
under /etc/tags:
· tag A is not deleted and gets a cq:movedTo property.
· tag B is created (in case of a move) and gets
a cq:backlinks property.
· cq:movedTo points to tag B.
This property means that tag A has been moved or merged into tag B. Moving tag B will update this property accordingly. Tag A is thus hidden and is only kept in the repository to resolve tag IDs in content nodes pointing to tag A. The tag garbage collector removes tags like tag A once no more content nodes point to them.
A special value for the cq:movedTo property is nirvana: it is applied when the tag is deleted but cannot be removed from the repository because there are subtags with a cq:movedTo that must be kept.
This property means that tag A has been moved or merged into tag B. Moving tag B will update this property accordingly. Tag A is thus hidden and is only kept in the repository to resolve tag IDs in content nodes pointing to tag A. The tag garbage collector removes tags like tag A once no more content nodes point to them.
A special value for the cq:movedTo property is nirvana: it is applied when the tag is deleted but cannot be removed from the repository because there are subtags with a cq:movedTo that must be kept.
· cq:backlinks keeps the references in the other direction, i.e. it keeps
a list of all the tags that have been moved to or merged with tag B. This is
mostly required to keep cq:movedTo properties up to date when tag B is
moved/merged/deleted as well or when tag B is activated, in which case all its
backlinks tags must be activated as well.
· Reading a cq:tags property of a
content node involves the following resolving:
1.
If there is no match under /etc/tags, no
tag is returned.
2. If the tag has a cq:movedTo property set, the referenced tag ID is followed.
This step is repeated as long as the followed tag has a cq:movedTo property.
This step is repeated as long as the followed tag has a cq:movedTo property.
3. If the followed tag does not have a cq:movedTo property, the tag is read.
· To publish the change when a tag has been
moved or merged, the cq:Tag node and all its backlinks must be
replicated: this is automatically done when the tag is activated in the tag
administration console.
· Later updates to the page's cq:tags property automatically clean up the "old"
references. This is triggered because resolving a moved tag through the API
returns the destination tag, thus providing the destination tag ID
TAGGING API AND TAGGING FRAMEWORK:
Tagging Framework implementation in AEM allows management of the
tags andtag conten using JCR API.
·
JcrTagManagerFactory - returns a JCR-based
implementation of a TagManager. It is the reference implementation of the
Tagging API.
Ex: To retrieve
a TagManager instance, you need to have a JCR Session and to
call getTagManager(Session):
2
3
4
|
@Reference
JcrTagManagerFactory
jcrTagManagerFactory;
TagManager tagManager =
jcrTagManagerFactory.getTagManager(session);
|
·
TagManager - allows for resolving
and creating tags by paths and names.
Ex: In the typical Sling
context you can also adapt to a TagManager from the ResourceResolver:
TagManager tagManager =
resourceResolver.adaptTo(TagManager.class);
|
·
Tag - defines the tag object.
Retriving Tag Object
EX: A Tag can be retrieved through
the TagManager, by either resolving an existing tag or creating a new one:
2
3
|
Tag tag =
tagManager.resolve("my/tag"); // for existing tags
Tag tag =
tagManager.createTag("my/tag"); // for new tags
|
For the JCR-based implementation, which
maps Tags onto JCR Nodes, you can directly use Sling's adaptTo mechanism
if you have the resource (e.g. such as /etc/tags/default/my/tag):
Tag tag =
resource.adaptTo(Tag.class);
|
While a tag may only be
converted from a resource (not a node), a tag can be converted to both
a node and a resource :
2
|
Node node =
tag.adaptTo(Node.class);
Resource node =
tag.adaptTo(Resource.class);
|