MagicDraw 18.5 Documentation

Skip to end of metadata
Go to start of metadata

Preparatory Step

Define a child template that you will use as in examples 1, 2, and 3. This child template contains the following header line and named sections ('Section A' and 'Section B'):

This is the child template.
#sectionBegin(Section A)
This is Section A.
#sectionEnd
#sectionBegin(Section B)
This is Section B.
#sectionEnd

Usage in Example 1

This example shows how to statically include the complete child template as shown in the Preparatory Step. To include it, call the $import.include('child.rtf') method. Note that there is no specified path, this path to the child template tells you that the main and child templates reside in the same directory.

#import ('import', 'com.nomagic.reportwizard.tools.ImportTool')
This is the 1st main template
Include child template
$import.include('child.rtf')

The output right below will include the entire text from the main template (right above) and from the child template (see the Preparatory Step) minus the template directives. The included content will be then parsed and stripped of all velocity directives. The output is as follows:

This is the 1st main template
Include child template
This is the child template.
This is Section A.
This is Section B.

Usage in Example 2

This example shows how to statically include a section of the child template as shown in the Preparatory Step. To include the section, named 'Section A' from the child template, call the $import.includeSection('templates/child.rtf', 'Section A') method. In this example, the main and child templates reside in different directories, which means that the child template will reside in a subdirectory called 'templates'. This 'templates' directory will thus reside in the same directory as the main template.

#import ('import', 'com.nomagic.reportwizard.tools.ImportTool')
This is the 2nd main template
Include Section A
$import.includeSection('templates/child.rtf', 'Section A')

The output will be:

This is the 2nd  main template
Include Section A
This is Section A.

Usage in Example 3

This example shows how to dynamically include the section of a child template as shown in the Preparatory Step. Before dynamically including the section of the child template named 'Section B', set a variable for the file location of the child template [#set ($child = "C:/ImportTool/child.rtf")] and another one for the section name to be included [#set ($section = "Section B")]. To include the ‘Section B’ section from the child template, call the $import.includeSection($child, $section) method. In this example, the child's template location is provided by an absolute path. Note that dynamic values must not be specified in a pair of quote marks, otherwise the section will not be included.

#import ('import', 'com.nomagic.reportwizard.tools.ImportTool')
This is the 3rd main template
Include Section B
#set ($child = "C:/ImportTool/child.rtf")
#set ($section = "Section B")
$import.includeSection($child, $section)

The output will be:

This is the 3rd main template
Include Section B
This is Section B.

The Import Tool supports RTF, HTML, XML, and text files only.

 

  • No labels