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

com.ibm.wbi.Meg
  |
  +--com.ibm.wbi.Generator
        |
        +--com.ibm.wbi.protocol.http.HttpGenerator
              |
              +--com.ibm.wbi.protocol.http.beans.MultipleFileGenerator

public class MultipleFileGenerator
extends HttpGenerator

This Generator serves any of the requested files from a directory, or one of its subdirectories. It has three properties: Directory, UrlPrefix, and ContentType. The Directory property specifies the root directory of the local filesystem in which the served files can be found. UrlPrefix specifies a path prefix that will be expected to be part of the requested URL that should be ignored. For example, if the Directory is "c:\datafiles" and the UrlPrefix is "home/data" and the requested URL is: "http://myserver/home/data/foo/a.html" then the Generator will serve the file "c:\datafiles\foo\a.html". The ContentType property is used to specify the content type that will be reported for served files.

The DefaultFile property is used to redirect a browser to a default file within a directory if the specified filename is itself a directory. If DefaultFile is null, a null string, or points to a non-existent file, this property is ignored.

The ShowDirectories property determines whether references to directories will by rendered as a page of links to the files within the directory or not. This property defaults to false.

Note: this Generator will serve files from the Directory directory and any of its children, but prevents access to files with ".." in their path. If a requested file does not exist, a RequestRejectedException is thrown.

A limitation of this Generator is that all files served will have the same content type. This could be solved with a smarter Generator, or by adding an Editor which fixes the content type.


Fields inherited from class com.ibm.wbi.protocol.http.HttpGenerator
COPYRIGHT, http
 
Fields inherited from class com.ibm.wbi.Meg
EDITOR, GENERATOR, MONITOR, REQUEST_EDITOR, UNDEFINED
 
Constructor Summary
MultipleFileGenerator()
          the default constructor.
MultipleFileGenerator(java.lang.String d)
          construct an instance.
MultipleFileGenerator(java.lang.String d, java.lang.String type)
          construct an instance.
 
Method Summary
 java.lang.String getDefaultFile()
          Access the DefaultFile property.
 java.lang.String getDirectory()
          Access the Directory property.
 java.lang.String getUrlPrefix()
          Access the UrlPrefix property.
 void handleRequest(RequestEvent e)
          Method used by WBI to generate the document.
 boolean isLinkToParentDirectory()
          Access the LinkToParentDirectory property.
 boolean isShowDirectories()
          Access the ShowDirectories property.
 void setDefaultFile(java.lang.String df)
          Set the DefaultFile property.
 void setDirectory(java.lang.String d)
          Set the directory property.
 void setLinkToParentDirectory(boolean ltpd)
          Set the LinkToParentDirectory property.
 void setShowDirectories(boolean sd)
          Set the ShowDirectories property.
 void setUrlPrefix(java.lang.String up)
          Set the UrlPrefix property.
 
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

MultipleFileGenerator

public MultipleFileGenerator()
the default constructor. Directory defaults to ""; UrlPrefix defaults to ""; and ContentType defaults to null (automatically determine based on filename extension)

MultipleFileGenerator

public MultipleFileGenerator(java.lang.String d)
construct an instance. UrlPrefix defaults to ""; ContentType defaults to "text/html".
Parameters:
d - specifies the Directory in which files can be found

MultipleFileGenerator

public MultipleFileGenerator(java.lang.String d,
                             java.lang.String type)
construct an instance. UrlPrefix defaults to "".
Parameters:
d - specifies the Directory in which files can be found
type - specifies the ContentType to pass along to the browser
Method Detail

setDefaultFile

public void setDefaultFile(java.lang.String df)
Set the DefaultFile property. If non-null, attempts to access directories result in a PageMoved response to the browser, redirecting it to the default file within that directory. If null (or if the file doesn't exist), the ShowDirectories property will be checked next to see if the contents of the directory should be displayed.

getDefaultFile

public java.lang.String getDefaultFile()
Access the DefaultFile property.
Returns:
Name of default file.

setShowDirectories

public void setShowDirectories(boolean sd)
Set the ShowDirectories property.
Parameters:
sd - If true, directories will be rendered as an HTML page of links. If false, an error page will be produced.

isShowDirectories

public boolean isShowDirectories()
Access the ShowDirectories property.
Returns:
true if directories should be rendered as HTML page of links, false otherwise.

setDirectory

public void setDirectory(java.lang.String d)
Set the directory property.
Parameters:
d - String specifying the directory on the local file system in which the files to be served can be found.

getDirectory

public java.lang.String getDirectory()
Access the Directory property.
Returns:
Directory on the local filesystem in which the files to be served can be found.

setUrlPrefix

public void setUrlPrefix(java.lang.String up)
Set the UrlPrefix property. This property specifies what leading characters of the URL path should be ignored when determining where to retrieve the file from the server filesystem. For example, if urlPrefix=="/wbi" and directory=="../data" and the URL Path="/wbi/foo/bar.baz" then the file "bar.baz" will be read from the "../data/foo" directory.
Parameters:
up - the UrlPrefix

getUrlPrefix

public java.lang.String getUrlPrefix()
Access the UrlPrefix property.
Returns:
the UrlPrefix

setLinkToParentDirectory

public void setLinkToParentDirectory(boolean ltpd)
Set the LinkToParentDirectory property.
Parameters:
ltpd - If true, there will be a link to the parent directory (i.e. "..")

isLinkToParentDirectory

public boolean isLinkToParentDirectory()
Access the LinkToParentDirectory property.
Returns:
true if there is be a link to the parent directory (i.e. "..")

handleRequest

public void handleRequest(RequestEvent e)
                   throws RequestRejectedException,
                          java.io.IOException
Method used by WBI to generate the document.
Overrides:
handleRequest in class HttpGenerator
Parameters:
e - Request event object.
Throws:
COM.ibm.iawbi.almaden.megBean.RequestRejectedException - is thrown if the request contains ".." in its path, or if the requested file does not exist.