|
|
Catalogue Wizard Implementation Kingsley Elmes, XUI 3.1, 26th June 2007
The catalogue that the catalogue wizard generates is build using java and xml file templates. There is an xml template and java template for each page which are in turn parsed to determine what is to be included in the genereated catalogue. The templates include tags for certain xml elements and java code blocks. As the templates are parsed these tags are used to check if certain elements or code blocks are to be included or removed. The tags are also used to include specific content that the user enters into the catalogue wizard such as setting page titles or setting background and logo images.
In the xml above, the value of the te_content attribute on line 2 is checked against a boolean value to determine whether the Label is to be included or not. Similarly the value of the te_style attribute is checked and if a null value isn't returned, a style attribute is added specifying the style the user selected when running the wizard.
In the java code above, the BEGIN_BLOCK and END_BLOCK tags signify code that is to be included or excluded depending on the user's selections within the wizard. The tags at the end of the BEGIN_BLOCK and END_BLOCK, i.e. NEXT on lines 3 and 8 above, are checked against a boolean value to see if the block is to be included. If the boolean value is false then the block of code is removed. Template Processors The java and xml files are processed using a template processor. There is a specific template processor used for handling both file # types called XJavaTemplateProcessor and XXmlTemplateProcessor respectively. The template processor's job is to parse the java or xml file for tags like those shown above.
The method shown above searchs for a te_include attribute within each xml element then queries the XCustomXmlTemplateEngine class to determine whether the xml element or java code block that the attribute corresponds to is to be included. The XTemplateEngine class contains two HashMap instances. These HashMap instances store the attributes used in the java and xml files as keys and then a boolean or String instance as content.
The above includes method is that which is called in the excludeElements method. The method queries the HashMap using the attribute and returns the corresponding boolean value.
The above includeElements meyhod is responsible for including or excluding tagged blocks of code. The code is searched for instances of BEGIN_BLOCK and if an instance is found, the XCustomJavaTemplateEngineis queried using the tag at the end of the BEGIN_BLOCK string, i.e BEGIN_BLOCK_METHOD1 where METHOD1 is the tag, to see if this code block is to be included or not. If it is not to be included the block of code is removed, otherwise the corresponding BEGIN_BLOCK and END_BLOCK tags are removed.
In the above example, the addInclude method is shown setting a 'true' value for the 'Logo' attribute. When this attribute is then queried while running the XXmlTemplateProcessor the 'true' value is returned and the 'Logo' element is included in the generated xml file. Similarly on line 4, the addContent method adds a String which will be returned when the 'SubTitle' attribute is queried. Copying Resource Files Copying of resource files is handled using the XResourceTemplateProcessor class. This class is primarily used to copy files from one location to another.
In the above example the resources array contains the names of the files that are to be copied from the 'src' directory to the 'dest' directory.
|