Table of Contents

What are if tags - The basics

Aspire allows "if" tags in your html pages. Here is an example.


<!--RLF_TAG BGN_IF aspire_key_name=literal_value if1 -->
..html segment
<!--RLF_TAG END_IF aspire_key_name=literal_value if1 -->

Aspire will take the "aspire_key_name" and try to locate it in the aspire data set. If it is there its value is taken and compared to the literal_value. The key is not case sensitive but the values are. If the strings are the same (or match) then the html segment will be included in the page otherwise not.

There are two types of if tag expressions

Aspire allows two variations on if tag expressions. These are

  1. Direct expression evaluation
  2. Function based evaluation

What we saw above is the direct expression evaluation. An example of a function based evaluation is:


<!--RLF_TAG BGN_IF MyFunc(key1,key2,key3) if1 -->
..html segment
<!--RLF_TAG END_IF MyFunc(key1,key2,key3) if1 -->

Here Aspire will try to locate a java class indirectly identified by "MyFunc" and pass it a vector of arguments whose values are values of the keys mentioned. Keys are case insensitive and the values are case sensitive. If "MyFunc" returns a true then the html segment is included and otherwise not.

More on these tags follows

Direct expression evaluation


<!--RLF_TAG BGN_IF aspire_key_name=literal_value if1 -->
..html segment
<!--RLF_TAG END_IF aspire_key_name=literal_value if1 -->

The rules here are as follows:

  1. "aspire_key_name=liternal_value" is an if expression
  2. In this expression the characters "(),=." are reserved (left bracket, right bracket, comma, equals, dot)
  3. aspire_key_name is a single word with no spaces in it
  4. literal_value can have spaces, but it is typically trimmed at both ends

What is documented here is true for the release 17.2 and up. For previous releases if you see variations, please email me any problems. You can find out the exact rules by looking at the java source file called "SimpleBEEvaluator1.java" in one of the sub directories.

Another slight variation possible is as follows:


<!--RLF_TAG BGN_IF aspire_key_name=another_aspire_key.key if1 -->
..html segment
<!--RLF_TAG END_IF aspire_key_name=another_aspire_key.key if1 -->

If the literal_value is a single word with a ".key" at the end, then Aspire will consider this a key and use the key portion of it to retrieve the right hand side value. Essentially in this scenario there are two keys. Left side key and the right side key. These keys will yield two values. Left side value and right side value. These values will be compared in a case sensitive manner to arrive at a true or a false.

This key support is only available if you use build 17.2 and use the Aspire transformation AITransform5 and above.

Function based evaluation


<!--RLF_TAG BGN_IF gt(key1,key2) if1 -->
..html segment
<!--RLF_TAG END_IF gt(key1,key2) if1 -->

Where "gt" stands for greater than. To make use of the function based evaluation, You need the following in the master "aspire.properties"

The following entries are mandatory in the properties file:


request.Aspire.BooleanExpressionEvaluator.className=com.ai.htmlgen.SimpleBEEvaluator1

And you need to point to an AITransform that is greated than AITransform1


request.AppObjects.transform.className=com.ai.xml.AITransform2

Test function

In addition you need to point the "gt" to a java class as follows


request.Aspire.BooleanFunction.gt.className=com.ai.htmlgen.GTEvaluator

Where "Aspire.BooleanFunction." is prepended to the "gt"

How to write your own function: Model it after the following code:


package com.ai.htmlgen;
import com.ai.common.*;
import com.ai.application.defaultpkg.*;
import com.ai.application.interfaces.*;
import com.ai.application.utils.*;
import java.util.*;
             
public class GTEvaluator implements ICreator 
{

   public Object executeRequest(String requestName, Object args)
      throws RequestExecutionException
   {
      if (!(args instanceof Vector))
      {
         throw new RequestExecutionException("Invalid args");
      }
      Vector vArgs = (Vector)args;
      String arg1 = (String)vArgs.elementAt(0);
      String arg2 = (String)vArgs.elementAt(1);
      int iArg1 = Integer.parseInt(arg1);
      int iArg2 = Integer.parseInt(arg2);
      boolean b = iArg1 > iArg2;
      return new Boolean(b);
   }   
} 

Build information

To use all the features documented you need build 17.2 or later. Previous builds support the basic expression evaluation with out the ".key" option. In addition these builds seem to support only literal values in lower case. This has been corrected in the latest release. Function evaluation is also supported in the previous builds and should work.

Recommended parts

Use AITransform6, GenericTableHandler6, DBHashTableFormHandler1

Java source files where this facility is implemented in the order of importance


"com.ai.htmlgen.SimpleBEEvaluator1.java"
"com.ai.htmlgen.AITransform*"

satya - Tue Nov 20 2012 11:24:23 GMT-0500 (Eastern Standard Time)

Take a look at CommonBEEvaluator.java

This file has a list of functions..