sunlabs.brazil.template
Class DirectoryTemplate

java.lang.Object
  extended by sunlabs.brazil.template.Template
      extended by sunlabs.brazil.template.DirectoryTemplate (view source)
All Implemented Interfaces:
Handler, TemplateInterface

public class DirectoryTemplate
extends Template
implements Handler

Put current directory information (based on the URL) into the request properties. The <filelist> tag, if present in the document, triggers the generation of a directory and file listing, based on the current URL.

Template Properties:

prepend
String to prepend to the properties "Directories" and "Files" That contain the directory and file lists respectively. Defaults to the Templates properties prefix.
delimiter
Delimiter character to separate entries, defaults to " ".
directory
The directory to use instead of the one implied by the URL. If it starts with "/", then it is resolved relative to the document root, otherwise it is resolved relative to the directory implied by the URL. The document root is found in the porperty "[prefix].root", or in "root", or (if neither exists), the current directory of the server.
DirectoryName
If set (usually by an upstream handler, such as the FileHandler, or TemplateHandler), this is used as the directory name instead of deriving it from the URL.
debug
if set, a comment is emitted indicating where the file-list entitiy was encountered.
[prepend].Directories
List of sub-directories in current directory is set by this template.
[prepend].Files
List of files with valid suffixes in current directory. is set by this template.
mime.xxx
An indication that suffix "xxx" is valid. Only valid file names are returned. See FileHandler for a description of how to set mime types for url suffixes.
select
Specifies a "glob" pattern to restrict the names of files and directories returned. The form "![pattern]" selects the inverse of the glob pattern.
stats
If specified, then for each file, the properties: [prepend].[file].mod and [prepend].[file].size are set, containing the file last modified time (seconds since epoch) and size (bytes) respectively.
This class may also be used as a handler, in which case the property prefix is used to match the leading portion of a URL.

The tag takes the optional parameters: prepend and stats that override the corrosponding request properties (above). In addition, the attribute dir may be used to select an alternate directory for files.


Field Summary
 
Fields inherited from class sunlabs.brazil.template.Template
debug
 
Constructor Summary
DirectoryTemplate()
           
 
Method Summary
static void getFiles(String dir, String glob, Request request, String prefix)
          Generate properties containing the files and directories in the "current" directory.
 boolean init(RewriteContext hr)
          Reset at each page
 boolean init(Server server, String prefix)
          Initializes the handler.
 boolean respond(Request request)
          Compute the directory info, and add it to the request properties.
 void tag_filelist(RewriteContext hr)
          Turn on the directory calculator.
 
Methods inherited from class sunlabs.brazil.template.Template
done
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DirectoryTemplate

public DirectoryTemplate()
Method Detail

init

public boolean init(Server server,
                    String prefix)
Description copied from interface: Handler
Initializes the handler.

Specified by:
init in interface Handler
Parameters:
server - The HTTP server that created this Handler. Typical Handlers will use Server.props to obtain run-time configuration information.
prefix - The handlers name. The string this Handler may prepend to all of the keys that it uses to extract configuration information from Server.props. This is set (by the Server and ChainHandler) to help avoid configuration parameter namespace collisions.
Returns:
true if this Handler initialized successfully, false otherwise. If false is returned, this Handler should not be used.

respond

public boolean respond(Request request)
Compute the directory info, and add it to the request properties.

Specified by:
respond in interface Handler
Parameters:
request - The Request object that represents the HTTP request.
Returns:
true if the request was handled. A request was handled if a response was supplied to the client, typically by calling Request.sendResponse() or Request.sendError.

init

public boolean init(RewriteContext hr)
Reset at each page

Specified by:
init in interface TemplateInterface
Overrides:
init in class Template

tag_filelist

public void tag_filelist(RewriteContext hr)
Turn on the directory calculator. The presense of this tag causes the files and subdirectories in the current directory to be added to the request properties.

The attribute "stats" may be specified to enable additional statistics, overriding the request properties.


getFiles

public static void getFiles(String dir,
                            String glob,
                            Request request,
                            String prefix)
Generate properties containing the files and directories in the "current" directory. The current directory is taken from the "DirectoryName" request property, or derived from the URL. This functionality was culled from the FileHandler and the Directory Handler.

If "directory" is specified (e.g. not null), then it is used as the directory instead. If "directory" starts with "/" then the directory is resolved relative to the document root, otherwise it is resolved relative to the current directory. If "select" is specified, then only files or directories matching the supplied glob pattern are selected. If the first character of "select" is "!", then the sense of the glob pattern is inverted.


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