org.cofax.cms
Class MultipartRequest

java.lang.Object
  |
  +--org.cofax.cms.MultipartRequest

public class MultipartRequest
extends java.lang.Object

A MuliPart form data parser. Parses an input stream and writes out any files found, making available a hashtable of other url parameters.

Copyright (C)2000 Jason Pell.
Note: restraints have been added to this class so it does not throw errors when trying to check a key/ value combination where key does not exist. This class also now returns a hashtable that is populated with filename/ location in addition to any other HTTPRequest variables that already existed in the querystring. - Charles Harvey.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Email: [email protected] Url: http://www.geocities.com/SiliconValley/Haven/9778

Version:
1.13 If an upload directory is not specified, then all file contents are sent into oblivion, but the rest of the parsing works as normal.
Author:
Jason Pell

Field Summary
static int MAX_READ_BYTES
          Prevent a denial of service by defining this, will never read more data.
static int READ_LINE_BLOCK
          Defines the number of bytes to read per readLine call.
 
Constructor Summary
MultipartRequest(java.io.PrintWriter debug, java.lang.String strContentTypeText, int intContentLength, java.io.InputStream in, java.lang.String strSaveDirectory)
          Constructor.
MultipartRequest(java.lang.String strContentTypeText, int intContentLength, java.io.InputStream in, java.lang.String strSaveDirectory)
          Constructor.
 
Method Summary
 java.lang.String getContentType(java.lang.String strName)
          Returns the Content-Type of a file.
 java.io.File getFile(java.lang.String strName)
          Because the strSaveDirectory you specify is really only the temporary location to stream the files to, we want a way to get at the files contents to put it in the correct location.
 java.util.Enumeration getFileParameterNames()
           
 long getFileSize(java.lang.String strName)
          Returns the File Size of a file.
 java.lang.String getFileSystemName(java.lang.String strName)
          Returns the File System name of a file.
 java.lang.String getHtmlTable()
          For debugging.
 java.util.Enumeration getParameterNames()
          An enumeration of all URL Parameters for the current HTTP Request.
 java.lang.String getURLParameter(java.lang.String strParameter)
          If an error occurs will return null.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_READ_BYTES

public static final int MAX_READ_BYTES
Prevent a denial of service by defining this, will never read more data. If Content-Length is specified to be more than this, will throw an exception.

READ_LINE_BLOCK

public static final int READ_LINE_BLOCK
Defines the number of bytes to read per readLine call. 128K
Constructor Detail

MultipartRequest

public MultipartRequest(java.lang.String strContentTypeText,
                        int intContentLength,
                        java.io.InputStream in,
                        java.lang.String strSaveDirectory)
                 throws java.lang.IllegalArgumentException,
                        java.io.IOException
Constructor.
Parameters:
strContentTypeText - The "Content-Type" HTTP header value.
intContentLength - The "Content-Length" HTTP header value.
in - The InputStream to read and parse.
strSaveDirectory - The temporary directory to save the file from where they can then be moved to wherever by the calling process. If you specify null for this parameter, then any files uploaded will be silently ignored.
Throws:
java.lang.IllegalArgumentException - If the strContentTypeText does not contain a Content-Type of "multipart/form-data" or the boundary is not found.
java.io.IOException - If the intContentLength is higher than MAX_READ_BYTES or strSaveDirectory is invalid or cannot be written to.
See Also:
MAX_READ_BYTES

MultipartRequest

public MultipartRequest(java.io.PrintWriter debug,
                        java.lang.String strContentTypeText,
                        int intContentLength,
                        java.io.InputStream in,
                        java.lang.String strSaveDirectory)
                 throws java.lang.IllegalArgumentException,
                        java.io.IOException
Constructor.
Parameters:
debug - A PrintWriter that can be used for debugging.
strContentTypeText - The "Content-Type" HTTP header value.
intContentLength - The "Content-Length" HTTP header value.
in - The InputStream to read and parse.
strSaveDirectory - The temporary directory to save the file from where they can then be moved to wherever by the calling process. If you specify null for this parameter, then any files uploaded will be silently ignored.
Throws:
java.lang.IllegalArgumentException - If the strContentTypeText does not contain a Content-Type of "multipart/form-data" or the boundary is not found.
java.io.IOException - If the intContentLength is higher than MAX_READ_BYTES or strSaveDirectory is invalid or cannot be written to.
See Also:
MAX_READ_BYTES
Method Detail

getURLParameter

public java.lang.String getURLParameter(java.lang.String strParameter)
If an error occurs will return null.

getParameterNames

public java.util.Enumeration getParameterNames()
An enumeration of all URL Parameters for the current HTTP Request.

getFileParameterNames

public java.util.Enumeration getFileParameterNames()

getContentType

public java.lang.String getContentType(java.lang.String strName)
Returns the Content-Type of a file.

getFile

public java.io.File getFile(java.lang.String strName)
Because the strSaveDirectory you specify is really only the temporary location to stream the files to, we want a way to get at the files contents to put it in the correct location. Once you have a File reference, you can copy/move the file elsewhere. Return a null file reference if a call to getFileSize(strName) returns zero.
See Also:
getFileSize(java.lang.String)

getFileSystemName

public java.lang.String getFileSystemName(java.lang.String strName)
Returns the File System name of a file.

getFileSize

public long getFileSize(java.lang.String strName)
Returns the File Size of a file.
Returns:
-1 if file size not defined.

getHtmlTable

public java.lang.String getHtmlTable()
For debugging.


Copyright 2001 KnightRidder.com. All Rights Reserved.