Bookmarks and hyperlinks generation

The complexity of generating bookmarks and hyperlinks in an output document is the dynamicity of both bookmarks and hyperlinks.

The idea is to find a generated or not unique ID that will link source (hyperlink) and target (bookmark) location in the document.

The following example shows how to create dynamic bookmarks and hyperlinks in templates for a UML model containing classes, with references to other classes inside attributes.

Template content

Output details

Step1

Display classes and their attributes and types :

<context model=’${project_loc}/Models/TrafficLightManager.uml’ element='TrafficLightManager/LogicalView'/>
<gendoc><drop/>
 [for (c:Class|self.ownedElement->filter(Class)->sortedBy(name))]

[c.name/]

  [for (a:Property|c.ownedAttribute->filter(NamedElement)->sortedBy(name))]

-[a.name/]: [a.type.name/]

  [/for]
 [/for]
</gendoc>

TrafficLight

-green fire: GreenFire

-orange fire: OrangeFire

-red fire: RedFire

GreenFire

OrangeFire

RedFire

Step2

Add a (static) bookmark on the class name :

<context model=’${project_loc}/Models/TrafficLightManager.uml’ element='TrafficLightManager/LogicalView'/>
<gendoc><drop/>
 [for (c:Class|self.ownedElement->filter(Class)->sortedBy(name))]

[c.name/] Add a bookmark :

  • On MS Word: Insert > Links > Bookmark
  • On OpenOffice / LibreOffice Writer : / Insert > Bookmark

Name of the bookmark (must be unique in document) :
 c_name_bookmark

  [for (a:Property|c.ownedAttribute->filter(NamedElement)->sortedBy(name))]

-[a.name/]: [a.type.name/]

  [/for]
 [/for]
</gendoc>

TrafficLight
bookmark c_name_bookmark

-green fire: GreenFire

-orange fire: OrangeFire

-red fire: RedFire

GreenFire
bookmark c_name_bookmark

OrangeFire
bookmark c_name_bookmark

RedFire
bookmark c_name_bookmark

Step3

Add dynamicity on the bookmark :

Indicate in a dedicated tag on top of document how to generate a dynamic ID at bookmark location to make bookmark become dynamic.

What will the bookmark point to : class c

How to generate a unique Id for class c : use service getId() from bundle commons.

<context model=’${project_loc}/Models/TrafficLightManager.uml’ element='TrafficLightManager/LogicalView'/>

<bookmarks>
 <alias source=’c_name_bookmark’ target=’[c.getId()/]’/>
</bookmarks>

<gendoc><drop/>
 [for (c:Class|self.ownedElement->filter(Class)->sortedBy(name))]

[c.name/] Bookmark named :c_name_bookmark

  [for (a:Property|c.ownedAttribute->filter(NamedElement)->sortedBy(name))]

-[a.name/]: [a.type.name/]

  [/for]
 [/for]
</gendoc>

TrafficLight
bookmark TrafficLight class ID

-green fire: GreenFire

-orange fire: OrangeFire

-red fire: RedFire

GreenFire
bookmark GreenFire class ID

OrangeFire
bookmark OrangeFire class ID

RedFire
bookmark RedFire class ID

Step4

Add hyperlinks to the (future) bookmark location :

The hyperlink must also be dynamic and point to the future bookmark location, here the generated unique ID for the class.

So the hyperlink must no point on c_name_bookmark (it would be replaced by c.getId() and point to current class), but to the id of the property type class: a.type.getId().

<context model=’${project_loc}/Models/TrafficLightManager.uml’ element='TrafficLightManager/LogicalView'/>
<bookmarks>
 <alias source=’c_name_bookmark’ target=’[c.getId()/]’/>
</bookmarks>
<gendoc><drop/>
 [for (c:Class|self.ownedElement->filter(Class)->sortedBy(name))]

  [c.name/] Bookmark named : c_name_bookmark

  [for (a:Property|c.ownedAttribute->filter(NamedElement)->sortedBy(name))]

  -[a.name/]: [a.type.name/]

    Add an hyperlink (Insert > Hyperlink … )
    to the ID of the property type : #[a.type.getId()/]

  [/for]
 [/for]
</gendoc>

TrafficLight
bookmark TrafficLight class ID

-green fire: GreenFire
hyperlink
to GreenFire class ID

-orange fire: OrangeFire
hyperlink
to GreenFire class ID

-red fire: RedFire
hyperlink
to GreenFire class ID

GreenFire
bookmark GreenFire class ID

OrangeFire
bookmark OrangeFire class ID

RedFire
bookmark RedFire class ID

Final output

GreenFire

OrangeFire

RedFire

TrafficLight

- green fire: GreenFire

- orange fire: OrangeFire

- red fire: RedFire