com.opencms.core
Class CmsRequestHttpServlet

java.lang.Object
  |
  +--com.opencms.core.CmsRequestHttpServlet
All Implemented Interfaces:
I_CmsRequest

public class CmsRequestHttpServlet
extends Object
implements I_CmsRequest

Implementation of the I_CmsRequest interface which wraps a HttpServletRequest and includes handling of multipart - requests.

This implementation uses a HttpServletRequest as original request to create a CmsRequestHttpServlet. This either can be a normal HttpServletRequest or a CmsMultipartRequest which is used to upload file into the OpenCms.

This class contains a modification of the MultipartRequest published in the O'Reilly book Java Servlet Programming by J. Junte, www.servlets.com

It Constructs a new MultipartRequest to handle the specified request, saving any uploaded files to the given directory, and limiting the upload size to a maximum size of 8 MB by default.

The idea is to modify the given MultiPartRequest to make it transparent to normal requests and store file into CmsFile objects so that they can be transferred into the OpenCms document database.

Version:
$Revision: 1.36 $ $Date: 2003/02/15 11:14:57 $
Author:
Michael Emmerich, Alexander Lucas

Method Summary
 byte[] getFile(String name)
          Returns the content of an uploaded file.
 Enumeration getFileNames()
          Returns the names of all uploaded files in this request.
 Object getOriginalRequest()
          Returns the original request that was used to create the CmsRequest.
 int getOriginalRequestType()
          Returns the type of the request that was used to create the CmsRequest.
 String getParameter(String name)
          Returns the value of a named parameter as a String.
 Enumeration getParameterNames()
          Returns all parameter names as an Enumeration of String objects.
 String[] getParameterValues(String key)
          Returns all parameter values of a parameter key.
 String getRequestedResource()
          This funtion returns the name of the requested resource.
 String getScheme()
          Methods to get the data from the original request.
 String getServerName()
          Methods to get the data from the original request.
 int getServerPort()
          Methods to get the data from the original request.
 String getServletUrl()
          Gets the part of the Url that describes the current servlet of this Web-Application.
 String getWebAppUrl()
          Returns the part of the Url that descibes the Web-Application.
 void setOriginalRequest(Object request)
          Overwrites the original request that was used to create the CmsRequest.
 void setRequestedResource(String resourceName)
          Set the name returned by getRequestedResource().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getFile

public byte[] getFile(String name)
Returns the content of an uploaded file. Returns null if no file with this name has been uploaded with this request. Returns an empty byte[] if a file without content has been uploaded.

Specified by:
getFile in interface I_CmsRequest
Parameters:
name - The name of the uploaded file.
Returns:
The selected uploaded file content.

getFileNames

public Enumeration getFileNames()
Returns the names of all uploaded files in this request. Returns an empty eumeration if no files were included in the request.

Specified by:
getFileNames in interface I_CmsRequest
Returns:
An Enumeration of file names.

getOriginalRequest

public Object getOriginalRequest()
Returns the original request that was used to create the CmsRequest.

Specified by:
getOriginalRequest in interface I_CmsRequest
Returns:
The original request of the CmsRequest.

setOriginalRequest

public void setOriginalRequest(Object request)
Overwrites the original request that was used to create the CmsRequest.

Specified by:
setOriginalRequest in interface I_CmsRequest

getOriginalRequestType

public int getOriginalRequestType()
Returns the type of the request that was used to create the CmsRequest. The returned int must be one of the constants defined above in this interface.

Specified by:
getOriginalRequestType in interface I_CmsRequest
Returns:
The type of the CmsRequest.

getParameter

public String getParameter(String name)
Returns the value of a named parameter as a String. Returns null if the parameter does not exist or an empty string if the parameter exists but without a value.

Specified by:
getParameter in interface I_CmsRequest
Parameters:
name - The name of the parameter.
Returns:
The value of the parameter.

getParameterNames

public Enumeration getParameterNames()
Returns all parameter names as an Enumeration of String objects. Returns an empty Enumeratrion if no parameters were included in the request.

Specified by:
getParameterNames in interface I_CmsRequest
Returns:
Enumeration of parameter names.

getParameterValues

public String[] getParameterValues(String key)
Returns all parameter values of a parameter key.

Specified by:
getParameterValues in interface I_CmsRequest
Returns:
Aarray of String containing the parameter values.

getRequestedResource

public String getRequestedResource()
This funtion returns the name of the requested resource.

For a http request, the name of the resource is extracted as follows: http://{servername}/{servletpath}/{path to the cms resource} In the following example: http://my.work.server/servlet/opencms/system/def/explorer the requested resource is /system/def/explorer.

Specified by:
getRequestedResource in interface I_CmsRequest
Returns:
The path to the requested resource.

setRequestedResource

public void setRequestedResource(String resourceName)
Set the name returned by getRequestedResource(). This is required in case there was a folder name requested and a default file (e.g. index.html) has to be used instead of the folder.

Specified by:
setRequestedResource in interface I_CmsRequest
Parameters:
resourceName - The name to set the requested resource name to

getWebAppUrl

public String getWebAppUrl()
Returns the part of the Url that descibes the Web-Application. E.g: http://www.myserver.com/opencms/engine/index.html returns http://www.myserver.com/opencms

Specified by:
getWebAppUrl in interface I_CmsRequest

getServletUrl

public String getServletUrl()
Gets the part of the Url that describes the current servlet of this Web-Application.

Specified by:
getServletUrl in interface I_CmsRequest

getServerName

public String getServerName()
Methods to get the data from the original request.

Specified by:
getServerName in interface I_CmsRequest

getServerPort

public int getServerPort()
Methods to get the data from the original request.

Specified by:
getServerPort in interface I_CmsRequest

getScheme

public String getScheme()
Methods to get the data from the original request.

Specified by:
getScheme in interface I_CmsRequest