HelloWord component

This tutorial learn to you create HelloWord XML component, which is able to generate a file with Hello $user! content. Template used has user parameter type of String.

You can find next sample into usecases-catalog/Components/HelloWord/HelloWord.akgncpt.xml catalog.

Here Wizard page which we wish obtain :

Here the file which we wish obtain :

  Hello word!

Steps of this tutorial are :

Template

In this tutorial, template will be written into Freemarker. See Freemarker Web site for mor einformation about FTL syntax.

Template has user String parameter.

Here Freemarker template helloWord.ftl :

Hello ${user}!  

Create helloWord.ftl template file into Templates/ftl/HelloWord/ directory of the MyAkrogenCatalog catalog .

XML component

XML component is XML description of Wizard page Eclipse. In this file you can define :

  • informations about title, description of the component,...
  • input which are parametres of the template, output file name and output base directory. Content of Wizard page is decribed with XUL.
  • output which concern generation, in other words the the template to use, create, update a file,..

Here XML component which we must use :

<?xml version="1.0" encoding="UTF-8"?>
<component>
  <input>
    <page title="Akrogen Hello Word" >
        <description>HelloWord Akrogen component to generate file with content "Hello $user!".</description>
        <box flex="1" id="" orient="vertical"
             xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
          <hbox>
            <label value="User: ($user)" />
            <textbox id="user" flex="1" />
          </hbox>
          <hbox>
            <label value="Output base dir:" />
            <textbox id="outputBaseDir" flex="1" />
            <button type="folder" target="outputBaseDir" label="Browse..." />
          </hbox>
          <hbox>
            <label value="Output file name:" />
            <textbox id="outputFileName" flex="1" />
          </hbox>       
          <hbox>
            <button type="preview" label="Preview..." />
          </hbox>                       
        </box>                  
    </page>
  </input>
  <output>
    <file>
      <template uri="/ftl/HelloWord/helloWord.ftl" />
    </file>
  </output>
</component>

Create HelloWord.akgncpt.xml XML component file into Components/HelloWord/ directory of the MyAkrogenCatalog catalog.

Here explanation about this XML component :

Input/page element

input/page element describes Wizard page eclipse :

  • XUL textbox with user id is the template parameter.
  • XUL textbox with outputBaseDir id is the output base directory.
  • XUL button type of folder display a button which is able to open folder selection dialog. Once folder is selected, the XUL textbox outputBaseDir is updated, because XUL button define target="outputBaseDir".
  • XUL textbox with outputFileName id is the output file name.
  • XUL button type of preview is able to preview the code generated for this helloWord component.

When you write XUL, you must pay attention to :

  • XUL content of input/page element start with XUL root box, hbox or vbox.
  • XUL root define namespace "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"

Output element

ouptput element describe outpout behaviour :

  • file element is used when file must be generated.
  • template element is used to set th etemplate to use :
    • uri attribute is the template path. Templates base directory is Templates folder of the catalog.
    • Template engine to use is setted with template extension :
      • .ftl for Freemarker.
      • .vm for Velocity.
      • .xsl for XSLT.

XML component use

Refresh catalog view. HelloWord must appear into the catalog view :

Double click on HelloWord component to open Wizard page.