ikrs.httpd.resource
Class AbstractDirectoryResource

java.lang.Object
  extended by ikrs.httpd.resource.AbstractResource
      extended by ikrs.httpd.resource.AbstractDirectoryResource
All Implemented Interfaces:
Resource, DirectoryResource
Direct Known Subclasses:
DefaultDirectoryResource, PHPDirectoryResource

public abstract class AbstractDirectoryResource
extends AbstractResource
implements DirectoryResource


Constructor Summary
AbstractDirectoryResource(HTTPHandler handler, CustomLogger logger, HTTPFileFilter fileFilter, java.io.File dir, java.net.URI requestURI, java.util.UUID sid, boolean useFairLocks)
          Create a new AbstractDirectoryResource.
 
Method Summary
 boolean close()
          Closes this resource.
abstract  void generateDirectoryListing(java.util.UUID sid, java.io.OutputStream out)
          This method is designated to build the data for the directory listing.
 java.text.DateFormat getDateFormat()
          Get the date format to use.
 java.io.File getDirectoryFile()
          Get the actual directory to generate the listing for.
abstract  MIMEType getDirectoryListingType()
          This method returns the Content-Type this class generates.
 HTTPFileFilter getFileFilter()
          Get the file filter to use for directory listing.
 java.io.InputStream getInputStream()
          Get the input stream from this resource.
 long getLength()
          This method returns the *actual* length of the underlying resource.
 java.io.OutputStream getOutputStream()
          Get the output stream to this resource.
 java.net.URI getRequestURI()
          Get the URI the directory file was requested through.
 boolean isOpen()
          This method determines if this resource was alerady opened or not.
 boolean isReadOnly()
          This method returns true if the underlying resource is read-only (in general).
 void open(boolean readOnly)
          This method opens the underlying resource.
 
Methods inherited from class ikrs.httpd.resource.AbstractResource
getHTTPHandler, getHypertextAccessFile, getLogger, getMetaData, getReadLock, getWriteLock, setHypertextAccessFile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface ikrs.httpd.Resource
getHypertextAccessFile, getMetaData, getReadLock, getWriteLock
 

Constructor Detail

AbstractDirectoryResource

public AbstractDirectoryResource(HTTPHandler handler,
                                 CustomLogger logger,
                                 HTTPFileFilter fileFilter,
                                 java.io.File dir,
                                 java.net.URI requestURI,
                                 java.util.UUID sid,
                                 boolean useFairLocks)
                          throws java.lang.NullPointerException
Create a new AbstractDirectoryResource.

Parameters:
logger - A custom logger to write log messages to.
fileFilter - The file filter to use.
dir - The directory.
requestURI - The uri from the request (will be used to avoid printing the absolute file path).
useFairLocks - If set to true the created resource will use fair locks.
Throws:
java.lang.NullPointerException
Method Detail

generateDirectoryListing

public abstract void generateDirectoryListing(java.util.UUID sid,
                                              java.io.OutputStream out)
                                       throws java.io.IOException
This method is designated to build the data for the directory listing. Subclasses must implement this method and write the generated data into the given output stream.

Specified by:
generateDirectoryListing in interface DirectoryResource
Parameters:
sid - The current session's ID.
out - The output stream to write the list data to.
Throws:
java.io.IOException - If any IO errors occur.

getDirectoryListingType

public abstract MIMEType getDirectoryListingType()
This method returns the Content-Type this class generates. The returned MIME type must not be null.

Specified by:
getDirectoryListingType in interface DirectoryResource
Returns:
The Content-Type this class generates.

getDirectoryFile

public java.io.File getDirectoryFile()
Get the actual directory to generate the listing for. The returned file SHOULD be a directory but that's not guaranteed; so be prepared for the case the returned file is a regular file, a link or anything else. Security notice: if the returned file is a link it MUST NOT be followed!

Returns:
The actual directory to generate the listing for.

getRequestURI

public java.net.URI getRequestURI()
Get the URI the directory file was requested through.

Returns:
The URI the directory file was requested through.

getDateFormat

public java.text.DateFormat getDateFormat()
Get the date format to use. The returned object is never null.

Returns:
The date format to use.

getFileFilter

public HTTPFileFilter getFileFilter()
Get the file filter to use for directory listing. If the file filter's acceptLising(File)-method does not return true the passed file MUST NOT be printed in the directory list. The returned file filter is never null.

Returns:
The file filter to use for directory listing.

isOpen

public boolean isOpen()
               throws java.io.IOException
This method determines if this resource was alerady opened or not.

Specified by:
isOpen in interface Resource
Specified by:
isOpen in class AbstractResource
Throws:
java.io.IOException - If any IO error occurs.

open

public void open(boolean readOnly)
          throws ReadOnlyException,
                 java.io.IOException
This method opens the underlying resource. Don't forget to close.

Specified by:
open in interface Resource
Specified by:
open in class AbstractResource
Parameters:
readOnly - if set to true, the resource will be opned in read-only mode.
Throws:
ReadOnlyException - If the underlying resource is read-only in general.
java.io.IOException - If any other IO error occurs.
See Also:
isReadOnly()

isReadOnly

public boolean isReadOnly()
                   throws java.io.IOException
This method returns true if the underlying resource is read-only (in general).

Specified by:
isReadOnly in interface Resource
Specified by:
isReadOnly in class AbstractResource
Throws:
java.io.IOException - If any IO error occurs.

getLength

public long getLength()
               throws java.io.IOException
This method returns the *actual* length of the underlying resource. This length will be used in the HTTP header fields to specify the transaction length. During read-process (you used the locks, didn't you?) the length MUST NOT change.

Specified by:
getLength in interface Resource
Specified by:
getLength in class AbstractResource
Returns:
the length of the resource's data in bytes.
Throws:
java.io.IOException - If any IO error occurs.

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws ReadOnlyException,
                                            java.io.IOException
Get the output stream to this resource.

Specified by:
getOutputStream in interface Resource
Specified by:
getOutputStream in class AbstractResource
Throws:
ReadOnlyException - If this resource was opened with the read-only flag set.
java.io.IOException - If any other IO error occurs.

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Get the input stream from this resource.

Specified by:
getInputStream in interface Resource
Specified by:
getInputStream in class AbstractResource
Throws:
java.io.IOException - If any IO error occurs.

close

public boolean close()
              throws java.io.IOException
Closes this resource.

Specified by:
close in interface Resource
Specified by:
close in class AbstractResource
Returns:
false if the resource was already closed, false otherwise.
Throws:
java.io.IOException