sunlabs.brazil.sunlabs

Class ListTemplate

public class ListTemplate extends Template

Manage lists of strings in a (hopefully) useful way. A vector is used to store list elements. Attributes to the <list> tag are used to manipulate the list, whereas "smart properties" are used to retrieve list members.
 <list name=x [namespace=xx clear=true|false delete=xx remove=n insert=xx
                  append=xx unique=true|false sort=true|false delim=d
                  overlap=n chunksize=n chunk=n next=true|false previous=true|false]">
 <list name=x ... />
 </list>
 
Access to list elements is only valid between <list>... </list>. See below for details.
Nested Class Summary
static classListTemplate.MyList
Implement a list of strings.
Method Summary
static intclamp(int min, int value, int max)
Clamp an integer value.
booleaninit(RewriteContext hr)
Clear any left-over lists.
voidtag_list(RewriteContext hr)
Process the list tag.
voidtag_slash_list(RewriteContext hr)
remove the most recent list from the current scope.

Method Detail

clamp

public static int clamp(int min, int value, int max)
Clamp an integer value.

Parameters: min minimum legal value value the value to clamp max maximum legal value

Returns: "value" clamped between min and max

init

public boolean init(RewriteContext hr)
Clear any left-over lists.

tag_list

public void tag_list(RewriteContext hr)
Process the list tag.
   name=nnn		list name (required)
   namespace=xxxx		namespace for list.  See below
 The following options are processed in order:
   clear=true|false	clear the list if it exists
   delete=xxx  [delim=d]  delete item(s) by value  (items with delimiter d)
   remove  [location=n]	remove an item by index (defaults to 0)
   insert=xxx [delim=d] [location=n]
				insert item (or items with delimiter=d)
				insert in front of element "n" - defaults to 0
   append=xxx [delim=d]	append item(s) to the end of the list
   unique=true|false	eliminate all duplicate items
   max=n			set the maximum size of the list "n"
   sort=true		do a dictionary sort.
   delim=d		set the delimiter for retrieving values
   track=true|false	track all changes to the console

 Once a "list" tag is seen, the following properties are
  available (for list foo):
   foo.last    	- last item on the list
   for.first   	- first item on the list
   foo.count   	- number of items on the list
   foo.all     	- the entire list
   list.gone   	- the last single element removed from the list
   foo.n	     	- the nth element (0 is the first element)
   foo.n:m     	- the range from n-m, inclusive, starting from 0
   foo.ismember.xxx - set to "yes" if "xxx" is in the list
   foo.before.xxx	- the range from 0 till the first occurrance of xxx
   foo.after.xxx	- the range after the 1st occurance of xxx til the end
 
The first 4 items, above, always appear (for non empty lists) when the properties are enumerated (as with <foreach>

In the current implementation, "ismember" checks are very fast. However once an "ismember" is accessed, insersion and deletion slows down a bit. Using "clear" will speed up insertion and deletion again.

If no namespace parameter is provided, the request property [prefix].namespace is used, where [prefix] is Rewrite.templatePrefix. Otherwise the SessionID is used. This results in per-session lists by default. Specifying a namespace allows lists to be shared across sessions.

An additional set of attributes and properties may be used to manage "chunking", to access a list in pieces for paging. Additional <list> attributes to support chunking:

   overlap=nn		- how many items to overlap between each chunk (default=0)
   chunksize=n		- max items per chunk (default=20)
   chunk=n		- Set the current chunk number (starts at 0)
   next=true|false	- it true, advance to the next page (if available)
   previous=true|false	- it true, advance to the previous page (if available)
 
None of the above properties change the contents of the list, only how chunks are extracted using the properties below:
   foo.chunk.[n]		- the list of items in chunk "n"
   foo.chunk.chunk	- the current list "chunk" (same as foo.chunk,${foo.chunk.current})

   foo.chunk.count	- the number of chunks
   foo.chunk.chunks	- the list of chunks: "0 1 2 ... n"
   foo.chunk.first	- the first chunk number (always 0)
   foo.chunk.before	- the list of chunk numbers before current chunk (if any)
   foo.chunk.previous	- The previous chunk number (if any)
   foo.chunk.current	- The current chunk number
   foo.chunk.next		- The next chunk number (if any)
   foo.chunk.after	- the list of chunk numbers after current chunk
   foo.chunk.last		- the last chunk number
   foo.chunk.size		- The max # of items/chunk
   foo.chunk.overlap	- The current chunk overlap
 

tag_slash_list

public void tag_slash_list(RewriteContext hr)
remove the most recent list from the current scope.