Dynamator Pure HTML for every page generation technology.
           

Dynamator File for JSP


Contents

Description
Identification

DESCRIPTION

This document describes the language-specific format and code generation behavior of a Dynamator File with language specified as "jsp".

A Dynamator File with a root element of "<dynamator language="jsp">" identifies a file containing transformations to be applied to an HTML or XML template in order to produce a JSP source file (i.e. a file with filetype ".jsp"). Dynamator applies the Dynamator file to an HTML or XML file (the "template") to create a JSP that outputs an HTML or XML file with structure corresponding to the template and behavior specified by the Dynamator file.

JSP Elements

Where a Dynamator file allows program lines, any JSP scripting element may be used. (JSP scripting elements are declarations (<%! ... %>), scriptlets (<% ... %>), and expressions (<%= ... %>).)

for

The 'for' element of a Dynamator file for JSP has the following structure:

<for>
    for-statement-remainder
</for>

The content of the 'for' element is the parenthesized 'for' text. The text is treated as CDATA; that is, it may contain special characters such as '<'. The parentheses may be omitted.

For example, the element:

<for>int i = 0; i < array.length; ++i</for>
generates:
for ( int i = 0; i < array.length; ++i )
{
    ...
}

foreach (collections)

The collection form of the 'foreach' element in a Dynamator file for JSP has the following structure:

<foreach 
      type="java-collection-type-name"
      element="element-variable-name"
      { i="iteration-variable-name" }
      { collection="collection-variable-name" }
    >
    <!-- Content: java-collection-expression -->
</foreach>

The content of the foreach element must be a Java expression that evaluates to a compile-time type of array, Vector, Enumeration, Iterator, Dictionary, Map, or Properties.

Although some attributes are optional, every applicable attribute should be specified to improve readability of the generated JSP code.

The 'foreach' element may have the following attributes:

type="java-collection-type-name"
(Required)
Identifies the type of the java-collection. The following patterns are recognized:
Type[] The collection is an array of elements of type Type.
Vector[Type] The collection is a Vector of elements of type Type.
Enumeration[Type] The collection is an Enumeration of elements of type Type.
Iterator[Type] The collection is an Iterator over elements of type Type.
Dictionary[KeyType,ValueType] The collection is a Dictionary with a key type of KeyType and a value type of ValueType.
Map[KeyType,ValueType] The collection is a Map with a key type of KeyType and a value type of ValueType.
Properties The collection is a Properties object.

element="java-variable-name"
(Required)
Identifies the name of the Java variable that refers to the current element of the collection.
i="iteration-variable-name"
(Optional)
Identifies the name of the iteration variable. The iteration variable is in scope for the duration of the iteration. Its value is the number of times the iteration block has been completed (i.e. the offset into the container).

If specified for a collection type that does not require it, Dynamator generates code to declare and increment the variable so that it is available within the iteration block.

If not specified for a collection type that requires it (an array or a Vector), Dynamator generates a variable name as well as the code required.

collection="java-variable-name"
(Optional)
Identifies the name of the Java variable that references the collection. If this attribute is not specified, Dynamator generates a name from java-collection-expression.

A 'foreach' element results in code similar to the following. Names in italics are the attribute names described above. If not specified by a foreach attribute, they are generated by Dynamator.

Value of 'type' attribute
Generates

Type[]
{
  Type[] collection = foreach-collection-expression;
  int limCollection = collection.length;
  Type element;
  for ( int i = 0; i < limCollection; ++i )
  {
    element = collection[i];
    ...
  }
}

Vector[Type]
{
  java.util.Vector collection = foreach-collection-expression;
  int limCollection = collection.size();
  Type element;
  for ( int i = 0; i < limCollection; ++i )
  {
    element = collection.elementAt(i);
    ...
  }
}

Enumeration[Type]
{
  java.util.Enumeration collection = foreach-collection-expression;
  Type element;
  while ( collection.hasMoreElements() )
  {
    element = (Type) collection.nextElement();
    ...
  }
}

Iterator[Type]
{
  java.util.Iterator collection = foreach-collection-expression;
  Type element;
  while ( collection.hasNext() )
  {
    element = (Type) collection.next();
    ...
  }
}

Dictionary[KeyType,ValueType]
{
  java.util.Dictionary collection = foreach-collection-expression;
  ValueType element;
  KeyType elementKey;
  Enumeration collectionKeys = collection.keys();
  while ( collectionKeys.hasMoreElements() )
  {
    elementKey = (KeyType) collectionKeys.nextElement();
    element = (ValueType) collection.get(elementKey);
    ...
  }
}

Map[KeyType,ValueType]
{
  java.util.Map collection = foreach-collection-expression;
  java.util.Map.Entry element;
  KeyType elementKey;
  ValueType elementValue;
  Iterator collectionEntries = collection.entrySet().iterator();
  while ( collectionEntries.hasNext() )
  {
    element = (java.util.Map.Entry) collectionEntries.next();
    elementKey = (KeyType) element.getKey();
    elementValue = (ValueType) element.getValue();
    ...
  }
}

Properties
{
  java.util.Properties collection = foreach-collection-expression;
  Enumeration collectionNames = collection.propertyNames();
  while ( collectionNames.hasMoreElements() )
  {
    elementName = (String) collectionNames.nextElement();
    element = collection.getProperty(elementName);
    ...
  }
}

foreach (sequenced)

The sequenced form of the 'foreach' element has been deprecated. Use the for element instead.

The sequenced form of a 'foreach' element in a Dynamator file for JSP has the following structure:

<foreach 
      init="initialize"
      compare="compare"
      step="increment"
/>

It maps to the following Java statement pattern:

for ( init; compare; step )

The sequenced values form of the 'foreach' element takes no element content. It takes the following attributes:

first="initialize"
(Required)
A Java statement to be placed in the init part of the Java 'for' statement.

last="compare"
(Required)
A Java boolean expression to be placed in the compare part of the Java 'for' statement.

step="increment"
(Required)
A Java statement to be placed in the step part of the Java 'for' statement.

Expressions

This document uses the following special terms to denote varieties of expressions allowed within a Dynamator file for JSP:

java-collection-expression
A java-expression that evaluates to a value with a type of array, Enumeration, Vector, Dictionary, or Properties.

java-expression
A Java expression. Text within a java-expression is treated as CDATA; that is, it may contain special characters such as '<'.


SEE ALSO

dynamate, Dynamator File


IDENTIFICATION
Author: Jay Dunning
Version: 1.5
Copyright: 2000-2004, Jay Dunning