org.apache.catalina.servlets

Class DefaultServlet

Known Direct Subclasses:
WebdavServlet

public class DefaultServlet
extends HttpServlet

The default resource-serving servlet for most web applications, used to serve static resources such as HTML pages and images.

Version:
$Revision: 1.23 $ $Date: 2004/05/26 16:03:06 $

Authors:
Craig R. McClanahan
Remy Maucherat

Nested Class Summary

protected class
DefaultServlet.ResourceInfo

Field Summary

protected static String
RESOURCES_JNDI_NAME
JNDI resources name.
protected int
debug
The debugging detail level for this servlet.
protected String
globalXsltFile
Allow customized directory listing per instance.
protected int
input
The input buffer size to use when serving resources.
protected boolean
listings
Should we generate directory listings?
protected String
localXsltFile
Allow customized directory listing per directory.
protected static MD5Encoder
md5Encoder
The MD5 helper object for this class.
protected static MessageDigest
md5Helper
MD5 message digest provider.
protected static String
mimeSeparation
MIME multipart separation string
protected int
output
The output buffer size to use when serving resources.
protected boolean
readOnly
Read only flag.
protected String
readmeFile
Allow a readme file to be included.
protected static StringManager
sm
The string manager for this package.
protected static URLEncoder
urlEncoder
Array containing the safe characters set.

Method Summary

protected String
appendParameters(HttpServletRequest request, String redirectPath)
Append the request parameters to the redirection string before calling sendRedirect.
protected boolean
checkIfHeaders(HttpServletRequest request, HttpServletResponse response, DefaultServlet.ResourceInfo resourceInfo)
Check if the conditions specified in the optional If headers are satisfied.
void
destroy()
Finalize this servlet.
protected void
displaySize(StringBuffer buf, int filesize)
Display the size of a file.
protected void
doDelete(HttpServletRequest req, HttpServletResponse resp)
Process a POST request for the specified resource.
protected void
doGet(HttpServletRequest request, HttpServletResponse response)
Process a GET request for the specified resource.
protected void
doHead(HttpServletRequest request, HttpServletResponse response)
Process a HEAD request for the specified resource.
protected void
doPost(HttpServletRequest request, HttpServletResponse response)
Process a POST request for the specified resource.
protected void
doPut(HttpServletRequest req, HttpServletResponse resp)
Process a POST request for the specified resource.
protected File
executePartialPut(HttpServletRequest req, org.apache.catalina.servlets.DefaultServlet.Range range, String path)
Handle a partial PUT.
protected InputStream
findXsltInputStream(DirContext directory)
Return the xsl template inputstream (if possible)
protected String
getETag(DefaultServlet.ResourceInfo resourceInfo)
Get the ETag associated with a file.
protected String
getReadme(DirContext directory)
Get the readme file as a string.
protected String
getRelativePath(HttpServletRequest request)
Return the relative path associated with this servlet.
protected DirContext
getResources()
Get resources.
void
init()
Initialize this servlet.
protected String
normalize(String path)
Return a context-relative path, beginning with a "/", that represents the canonical version of the specified path after ".." and "." elements are resolved out.
protected org.apache.catalina.servlets.DefaultServlet.Range
parseContentRange(HttpServletRequest request, HttpServletResponse response)
Parse the content-range header.
protected Vector
parseRange(HttpServletRequest request, HttpServletResponse response, DefaultServlet.ResourceInfo resourceInfo)
Parse the range header.
protected InputStream
render(String contextPath, DefaultServlet.ResourceInfo resourceInfo)
Decide which way to render.
protected InputStream
renderHtml(String contextPath, DefaultServlet.ResourceInfo resourceInfo)
Return an InputStream to an HTML representation of the contents of this directory.
protected String
renderSize(long size)
Render the specified file size (in bytes).
protected InputStream
renderXml(String contextPath, DefaultServlet.ResourceInfo resourceInfo, InputStream xsltInputStream)
Return an InputStream to an HTML representation of the contents of this directory.
protected String
rewriteUrl(String path)
URL rewriter.
protected void
serveResource(HttpServletRequest request, HttpServletResponse response, boolean content)
Serve the specified resource, optionally including the data content.
protected void
showRequestInfo(HttpServletRequest req)
Show HTTP header information.

Field Details

RESOURCES_JNDI_NAME

protected static final String RESOURCES_JNDI_NAME
JNDI resources name.


debug

protected int debug
The debugging detail level for this servlet.


globalXsltFile

protected String globalXsltFile
Allow customized directory listing per instance.


input

protected int input
The input buffer size to use when serving resources.


listings

protected boolean listings
Should we generate directory listings?


localXsltFile

protected String localXsltFile
Allow customized directory listing per directory.


md5Encoder

protected static final MD5Encoder md5Encoder
The MD5 helper object for this class.


md5Helper

protected static MessageDigest md5Helper
MD5 message digest provider.


mimeSeparation

protected static final String mimeSeparation
MIME multipart separation string


output

protected int output
The output buffer size to use when serving resources.


readOnly

protected boolean readOnly
Read only flag. By default, it's set to true.


readmeFile

protected String readmeFile
Allow a readme file to be included.


sm

protected static StringManager sm
The string manager for this package.


urlEncoder

protected static URLEncoder urlEncoder
Array containing the safe characters set.

Method Details

appendParameters

protected String appendParameters(HttpServletRequest request,
                                  String redirectPath)
Append the request parameters to the redirection string before calling sendRedirect.


checkIfHeaders

protected boolean checkIfHeaders(HttpServletRequest request,
                                 HttpServletResponse response,
                                 DefaultServlet.ResourceInfo resourceInfo)
            throws IOException
Check if the conditions specified in the optional If headers are satisfied.

Parameters:
request - The servlet request we are processing
response - The servlet response we are creating
resourceInfo - File object

Returns:
boolean true if the resource meets all the specified conditions, and false if any of the conditions is not satisfied, in which case request processing is stopped


destroy

public void destroy()
Finalize this servlet.


displaySize

protected void displaySize(StringBuffer buf,
                           int filesize)
Display the size of a file.


doDelete

protected void doDelete(HttpServletRequest req,
                        HttpServletResponse resp)
            throws ServletException,
                   IOException
Process a POST request for the specified resource.

Parameters:


doGet

protected void doGet(HttpServletRequest request,
                     HttpServletResponse response)
            throws IOException,
                   ServletException
Process a GET request for the specified resource.

Parameters:
request - The servlet request we are processing
response - The servlet response we are creating


doHead

protected void doHead(HttpServletRequest request,
                      HttpServletResponse response)
            throws IOException,
                   ServletException
Process a HEAD request for the specified resource.

Parameters:
request - The servlet request we are processing
response - The servlet response we are creating


doPost

protected void doPost(HttpServletRequest request,
                      HttpServletResponse response)
            throws IOException,
                   ServletException
Process a POST request for the specified resource.

Parameters:
request - The servlet request we are processing
response - The servlet response we are creating


doPut

protected void doPut(HttpServletRequest req,
                     HttpServletResponse resp)
            throws ServletException,
                   IOException
Process a POST request for the specified resource.

Parameters:
req - The servlet request we are processing
resp - The servlet response we are creating


executePartialPut

protected File executePartialPut(HttpServletRequest req,
                                 org.apache.catalina.servlets.DefaultServlet.Range range,
                                 String path)
            throws IOException
Handle a partial PUT. New content specified in request is appended to existing content in oldRevisionContent (if present). This code does not support simultaneous partial updates to the same resource.


findXsltInputStream

protected InputStream findXsltInputStream(DirContext directory)
Return the xsl template inputstream (if possible)


getETag

protected String getETag(DefaultServlet.ResourceInfo resourceInfo)
Get the ETag associated with a file.

Parameters:
resourceInfo - File object


getReadme

protected String getReadme(DirContext directory)
Get the readme file as a string.


getRelativePath

protected String getRelativePath(HttpServletRequest request)
Return the relative path associated with this servlet.

Parameters:
request - The servlet request we are processing


getResources

protected DirContext getResources()
Get resources. This method will try to retrieve the resources through JNDI first, then in the servlet context if JNDI has failed (it could be disabled). It will return null.

Returns:
A JNDI DirContext, or null.


init

public void init()
            throws ServletException
Initialize this servlet.


normalize

protected String normalize(String path)
Return a context-relative path, beginning with a "/", that represents the canonical version of the specified path after ".." and "." elements are resolved out. If the specified path attempts to go outside the boundaries of the current context (i.e. too many ".." path elements are present), return null instead.

Parameters:
path - Path to be normalized


parseContentRange

protected org.apache.catalina.servlets.DefaultServlet.Range parseContentRange(HttpServletRequest request,
                                                                              HttpServletResponse response)
            throws IOException
Parse the content-range header.

Parameters:
request - The servlet request we are processing
response - The servlet response we are creating

Returns:
Range


parseRange

protected Vector parseRange(HttpServletRequest request,
                            HttpServletResponse response,
                            DefaultServlet.ResourceInfo resourceInfo)
            throws IOException
Parse the range header.

Parameters:
request - The servlet request we are processing
response - The servlet response we are creating

Returns:
Vector of ranges


render

protected InputStream render(String contextPath,
                             DefaultServlet.ResourceInfo resourceInfo)
Decide which way to render. HTML or XML.


renderHtml

protected InputStream renderHtml(String contextPath,
                                 DefaultServlet.ResourceInfo resourceInfo)
Return an InputStream to an HTML representation of the contents of this directory.

Parameters:
contextPath - Context path to which our internal paths are relative


renderSize

protected String renderSize(long size)
Render the specified file size (in bytes).

Parameters:
size - File size (in bytes)


renderXml

protected InputStream renderXml(String contextPath,
                                DefaultServlet.ResourceInfo resourceInfo,
                                InputStream xsltInputStream)
Return an InputStream to an HTML representation of the contents of this directory.

Parameters:
contextPath - Context path to which our internal paths are relative


rewriteUrl

protected String rewriteUrl(String path)
URL rewriter.

Parameters:
path - Path which has to be rewiten


serveResource

protected void serveResource(HttpServletRequest request,
                             HttpServletResponse response,
                             boolean content)
            throws IOException,
                   ServletException
Serve the specified resource, optionally including the data content.

Parameters:
request - The servlet request we are processing
response - The servlet response we are creating
content - Should the content be included?


showRequestInfo

protected void showRequestInfo(HttpServletRequest req)
Show HTTP header information.


Copyright B) 2000-2003 Apache Software Foundation. All Rights Reserved.