com.ibm.wbi.protocol.http.beans
Class DirectoryGenerator

com.ibm.wbi.Meg
  |
  +--com.ibm.wbi.Generator
        |
        +--com.ibm.wbi.protocol.http.HttpGenerator
              |
              +--com.ibm.wbi.protocol.http.beans.FourStepHttpGenerator
                    |
                    +--com.ibm.wbi.protocol.http.beans.HtmlGenerator
                          |
                          +--com.ibm.wbi.protocol.http.beans.DirectoryGenerator

public class DirectoryGenerator
extends HtmlGenerator

A Generator for delivering an HTML rendition of a disk directory.

The LinkToParentDirectory property, when set to true (the default is false), means that HTML renditions of directories will contain a link to the ".." directory, the parent of the current directory. When set to false, this link will not be shown.

By default, the browser is allowed to cache the document. This property can be can be adjusted with the setCache(boolean) and isCache() methods of HttpGenerator.

See Also:
HttpGenerator

Fields inherited from class com.ibm.wbi.protocol.http.beans.HtmlGenerator
COPYRIGHT
 
Fields inherited from class com.ibm.wbi.protocol.http.HttpGenerator
http
 
Fields inherited from class com.ibm.wbi.Meg
EDITOR, GENERATOR, MONITOR, REQUEST_EDITOR, UNDEFINED
 
Constructor Summary
DirectoryGenerator()
          construct an instance with a null File, and not to link to the parent directory.
DirectoryGenerator(java.io.File _file)
          construct an instance with the given File and not to link to parent directory.
DirectoryGenerator(java.lang.String filename)
          construct an instance with the given Filename and not to link to parent directory.
 
Method Summary
 java.lang.String getFilename()
          access the Filename property
protected  java.lang.String getHtmlString(RequestEvent e)
          Produce an HTML rendition of the specified directory.
 void handleRequest(RequestEvent e)
          Override the inherited handleRequest(...) method so that we can ensure that the requested URL ends with a '/'.
 boolean isLinkToParentDirectory()
          Retrieve the LinkToParentDirectory property status.
 void setFile(java.io.File f)
          Set the file property.
 void setFile(java.io.File directory, java.lang.String filename)
          Set the file property.
 void setFile(java.lang.String directory, java.lang.String filename)
          Set the file property.
 void setFilename(java.lang.String fn)
          set the Filename property with the name of the file to be served, (either an absolute filepath, or relative to the WBI working directory).
 void setLinkToParentDirectory(boolean ltpd)
          Set the LinkToParentDirectory property.
protected  boolean verify()
          Make sure a file has been set and that the file exists.
 
Methods inherited from class com.ibm.wbi.protocol.http.beans.HtmlGenerator
writeContent
 
Methods inherited from class com.ibm.wbi.protocol.http.beans.FourStepHttpGenerator
getHeader, initialize, verify
 
Methods inherited from class com.ibm.wbi.protocol.http.HttpGenerator
add, addCookie, getContentType, getHttpResponse, getHttpResponseString, getResponseCode, getResponseText, isCache, produceHeader, set, setCache, setContentLength, setContentType, setResponseCode, setResponseText, setServer, writeHeader
 
Methods inherited from class com.ibm.wbi.Generator
getType
 
Methods inherited from class com.ibm.wbi.Meg
forwardRequest, getCondition, getEnabled, getMegProperty, getMegProperty, getMegPropertyKeys, getName, getPlugin, getPriority, getSystemContext, initialize, initialize, isEnabled, isMegApplicable, loadMegResources, run, setCondition, setEnabled, setMegProperty, setName, setPriority, setSystemContext, setup, setup, setup, setup
 

Constructor Detail

DirectoryGenerator

public DirectoryGenerator()
construct an instance with a null File, and not to link to the parent directory.

DirectoryGenerator

public DirectoryGenerator(java.io.File _file)
construct an instance with the given File and not to link to parent directory.
Parameters:
_file - the File whose directory is to be generated

DirectoryGenerator

public DirectoryGenerator(java.lang.String filename)
construct an instance with the given Filename and not to link to parent directory.
Parameters:
filename - the name of the file to be served.
See Also:
setFilename(String)
Method Detail

setLinkToParentDirectory

public void setLinkToParentDirectory(boolean ltpd)
Set the LinkToParentDirectory property.
Parameters:
ltpd - Boolean value indicating whether a ".." link is provided or not.

isLinkToParentDirectory

public boolean isLinkToParentDirectory()
Retrieve the LinkToParentDirectory property status.
Returns:
Boolean value indicating whether a ".." link is provided true or not false.

setFilename

public void setFilename(java.lang.String fn)
set the Filename property with the name of the file to be served, (either an absolute filepath, or relative to the WBI working directory). If the current WBI base directory is needed in order to construct an appropriate filename, it can be found by calling WBIInstPackage.locateWBIDirectory().
Parameters:
fn - the Filename

getFilename

public java.lang.String getFilename()
access the Filename property
Returns:
fn the Filename

setFile

public void setFile(java.io.File f)
Set the file property.
Parameters:
f - The file to be used by the DirectoryGenerator.

setFile

public void setFile(java.lang.String directory,
                    java.lang.String filename)
Set the file property.
Parameters:
directory - Name of the directory (path) the file resides in.
filename - Filename relative to the directory specified in the first parameter.

setFile

public void setFile(java.io.File directory,
                    java.lang.String filename)
Set the file property.
Parameters:
directory - File object representing the directory (path) the file resides in.
filename - Filename relative to the directory specified in the first parameter.

verify

protected boolean verify()
Make sure a file has been set and that the file exists.

getHtmlString

protected java.lang.String getHtmlString(RequestEvent e)
Produce an HTML rendition of the specified directory.
Overrides:
getHtmlString in class HtmlGenerator
Parameters:
e - RequestEvent object.

handleRequest

public void handleRequest(RequestEvent e)
                   throws RequestRejectedException,
                          java.io.IOException
Override the inherited handleRequest(...) method so that we can ensure that the requested URL ends with a '/'. If it doesn't, the browser will not handle relative links properly, so we need to send a 'page moved' response. If it does, handle normally.
Overrides:
handleRequest in class FourStepHttpGenerator
Parameters:
e - RequestEvent object.