Defining Specialized Topic Models (Java)
Define specialized Strongly Typed Topic Models for different DITA Topic types, such as the Concept, Task and Reference.
DXA enables mapping all Tridion Docs Topics to a single Strongly Typed Topic Model. In your implementation, however, you may want to create additional Strongly Typed Topic Models. For example, you may want to use a different Strongly Typed Topic Model for each of the typical DITA Topic Types of Concept, Task and Reference.
You can register multiple Strongly Typed Topic Models and use the EntityName of the SemanticEntity annotations to identify an distinguish them. The EntityName specifies the name of a DITA element. If this element is present, then the Strongly Typed Topic Model is considered to be a candidate for mapping. All registered Strongly Typed Topic Models are considered and the one with the best match is selected.
Example TopicBody XHTML
In the following XHTML example, you can identify the topic title from the class containing the name "title". The content of this element is the title of the topic. Likewise other specific pieces of information can be identified and extracted from the XHTML.
<h1 class="title topictitle1 " id="GUID-4A75B581-0D81-412A-A5E1-5E601A7E6DDF__GUID-2D3CF861-276F-4871-9BE0-68B0669A4953">Types of penguins</h1>
<div class="body learningBasebody learningOverviewbody ">
<div class="section lcIntro " id="GUID-4A75B581-0D81-412A-A5E1-5E601A7E6DDF__LCINTRO_130B2AADEA86480D918C112D4EA3CDC1 ">
<p class="p ">Nowadays 17 species of penguins exist, subdivided in 6 groups or genus (genera) </p>
<p class="p ">Some scientists mention the white-flippered little penguin as an 18th species, but most of them consider it as
a subspecies of the little penguin. So, we will not adress that one. </p>
</div>
<div class="section lcObjectives " id="GUID-4A75B581-0D81-412A-A5E1-5E601A7E6DDF__LCOBJECTIVES_253452FF6D334E78AE47820C20A89B9F ">
<span class="ph lcObjectivesStem ">The following topics describe the different species per genus.</span> </div>
</div>
<div class="related-links ">
<ul class="ullinks ">
<li class="link ulchildlink "><strong><a href="/2778701/1184170/brush-tailed-penguins.jpg" class="link">Brush-tailed penguins
(Pygoscelis)</a></strong>
<br/> </li>
<li class="link ulchildlink "><strong><a href="/2778701/1184177/banded-penguins.jpg" class="link">Banded penguins (Spheniscus)</a></strong>
<br/> </li>
</ul>
</div>
Java example of a specialized Strongly Typed Topic Model
Take, for example, the following model:
@SemanticEntity(vocabulary = SemanticVocabulary.SDL_DITA, entityName = "body")
public class Topic extends AbstractEntityModel {
@SemanticProperty("title")
public String Title;
@SemanticProperty("body")
public RichText Body;
};
@SemanticEntity(vocabulary = SemanticVocabulary.SDL_DITA, entityName = "learningBasebody")
public class LearningBaseTopic extends AbstractEntityModel {
@SemanticProperty("title")
public String Title;
@SemanticProperty("lcIntro")
public RichText Intro;
@SemanticProperty("lcObjectives")
public RichText Objectives;
};
In the first SemanticEntity element, the class Topic matches on any Topic that has a body element. As a result of DITA's specialization model, this basically means it matches on any DITA Topic.
In the second SemanticEntity entity element, the class LearningBaseTopic only matches on Topics that have a learningBasebody element, and these elements are only present on Learning Base Topics. In these topics, both Strongly Typed Topic Models match (LearningBaseTopic and Topic), but LearningBaseTopic is more specific and thus considered the best match.