Jasper

Creating the host part of the hyperlink using an HTML template

The hyperlink consists of two parts, the main host part and the query string, separated by a question mark '?'. An HTML template is used to create the first of these parts. Because this template does not represent a whole page but is only included, it is placed in the '_inc/' directory of the Jasper distribution's 'template/' directory:

[[appPath]][[procPath]]test[[procExt]]

The 'appPath' token may be familiar but what about the other two? The configuration variables that they reference are to be found in the platform specific configuration file that up until this point has been overlooked. Have a look now at its contents. It is the one that is referenced together with the global configuration file near the top of the test server process. It should contain only two definitions, one for 'procPath' and one for 'procExt' and it may be the case that one or both are left unset.

The purpose of these configuration variables is to make Jasper as platform independant as possible. By creating links and so forth in this manner it is possible to construct entire sites that are independant of platform. If you have some experience web programming for different platforms then have a look at the various configuration files corresponding to the platforms with which you are familiar, it should all make sense.

On very rare occasions you may need to change these variables. For example, the default Java variables are both left unset but if you choose to run servlets using an invoker rather than defining them individually in the 'web.config' file, you may need to change the 'procPath' variable to 'servlet/' or whatever.

One final thing to note is that the 'procPath' configuration variable always immediately follows the 'appPath' configuration variable and since by convention the latter always includes a trailing slash, there is no need for the 'procPath' configuration variable to include a leading one.

To continue, this template needs to be processed and added to the process_token(...) method's return string. To do this, reinstate the following code immediately below the declaration of the 'ret' return string:

TemplateHTML template = new TemplateHTML();

ret += StringUtils.trim( template.process_file( props{ "CONFIG.rootDir" } +
                                                    "template/_inc/" +
                                                        "test" +
                                                            ".html", props ) ) );

The StringUtils class' trim(...) method is used because the contents of the 'link.html' include file are spread over several lines and indented for the sake of readability, and this formatting must be removed if the processed template is to serve as part of an 'href' HTML attribute.

Run the test server process now. View the source and check that the '[[appPath]]', '[[procPath]]' and '[[procExt]]' tokens are all being replaced with their configuration variable equivalents in order to construct the required URI.

Last updated: Sunday, 23rd October 2011, 07:04 PM

User comments:

There are none.

Leave a comment:

Display name Email address Content
Enable HTML content
PreviewSubmit