sunlabs.brazil.template
Class DirectoryTemplate
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.
Version: %V% DirectoryTemplate.java
Author: Stephen Uhler
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.
public boolean init(
Server server, String prefix)
Reset at each page
public boolean respond(
Request request)
Compute the directory info, and add it to the request properties.
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.