Class ListTemplate

  extended by sunlabs.brazil.template.Template
      extended by sunlabs.brazil.sunlabs.ListTemplate (view source)
All Implemented Interfaces:

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 ... />
Access to list elements is only valid between <list>... </list>. See below for details.

Nested Class Summary
static class ListTemplate.MyList
          Implement a list of strings.
Field Summary
Fields inherited from class sunlabs.brazil.template.Template
Constructor Summary
Method Summary
static int clamp(int min, int value, int max)
          Clamp an integer value.
 boolean init(RewriteContext hr)
          Clear any left-over lists.
 void tag_list(RewriteContext hr)
          Process the list tag.
 void tag_slash_list(RewriteContext hr)
          remove the most recent list from the current scope.
Methods inherited from class sunlabs.brazil.template.Template
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public ListTemplate()
Method Detail


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

Specified by:
init in interface TemplateInterface
init in class Template


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)
   load=xxx             load list from a file (created by store)
   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"
   front=true           When specified with "max", items are removed
                                from the front of list instead of the back.
   sort=true            do a dictionary sort.
   delim=d              set the delimiter for retrieving values
                                (defaults to the empty string "")
   store=xxx            store this list to a file
   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 - set to "yes" if "xxx" is in the list       - the range from 0 till the first occurrance of 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         - 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


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


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

min - minimum legal value
value - the value to clamp
max - maximum legal value
"value" clamped between min and max

Version Kenai-svn-r24, Generated 08/18/09
Copyright (c) 2001-2009, Sun Microsystems.