Class DirectoryTemplate

  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:

String to prepend to the properties "Directories" and "Files" That contain the directory and file lists respectively. Defaults to the Templates properties prefix.
Delimiter character to separate entries, defaults to " ".
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.
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.
if set, a comment is emitted indicating where the file-list entitiy was encountered.
List of sub-directories in current directory is set by this template.
List of files with valid suffixes in current directory. is set by this template.
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.
Specifies a "glob" pattern to restrict the names of files and directories returned. The form "![pattern]" selects the inverse of the glob pattern.
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
Constructor Summary
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
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public DirectoryTemplate()
Method Detail


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

Specified by:
init in interface Handler
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.
true if this Handler initialized successfully, false otherwise. If false is returned, this Handler should not be used.


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

Specified by:
respond in interface Handler
request - The Request object that represents the HTTP request.
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.


public boolean init(RewriteContext hr)
Reset at each page

Specified by:
init in interface TemplateInterface
init in class Template


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.


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.