OOP MimeParser Version 3.5

com.bentofw.mime
Class MimeParser

java.lang.Object
  extended by com.bentofw.mime.MimeParser

public final class MimeParser
extends java.lang.Object

This class parses the HTTP POST request with multipart/form-data encoding.

This class is responsible for analyzing the InputStream from the HTTP POST request. All you need are:

MimeParser implements the 8 types of parseXX(...) methods with different arguments. The 4 of them save the uploaded files into the local file. The rest of them do not save the files. In any case, you can access the contents of the uploaded files.
At the same time of parsing the uploaded files, all of these parseXX(...) methods decode the submitted text values into the Java Strings, i.e. your FORM can include TEXT INPUT or SELECTION along with FILE INPUT.
You can specify: in various ways.
In addition, you can specify the permitted mime-type for the file to be uploaded. (since 2.0) If the user tries to upload the file with mime-types other than the specified ones, this class throws InvalidContentTypeException. So, your Servlet has a chance to catch this exception and show the appropriate message to the user.
The return type of all the parseXX(...) methods are always ParsedData, and you can access: from the returned instance of ParsedData.

The java.io.File object for the saved files are also accessible if you call the parseXX(...) methods which save the uploaded files into the local file on the server side.

Author:
Jun Inamori

Method Summary
 int getDefaultMaximumFileSize()
          Returns the maximum file size which is specified in MimeParser.properties.
 java.lang.String getFileRoot()
          Returns the root directory where the uploaded file will be saved.
static MimeParser getInstance()
          Reads the property file and returns the instance of this class.
 int getMaximumHeight()
          Return the maximum height to be allowed.
 int getMaximumWidth()
          Return the maximum width to be allowed.
 boolean isImageSizeChecked()
          The true if the size of the image file (JPEG, GIF or PNG) will be checked.
 ParsedData parse(javax.servlet.http.HttpServletRequest req, java.lang.String ch)
          Deprecated. 

 ParsedData parse(javax.servlet.http.HttpServletRequest req, java.lang.String ch, int max)
          Deprecated. 

 ParsedData parse(javax.servlet.http.HttpServletRequest req, java.lang.String ch, java.lang.String dir)
          Deprecated. 

 ParsedData parse(javax.servlet.http.HttpServletRequest req, java.lang.String ch, java.lang.String dir, int max)
          Deprecated. 

 ParsedData parseAndSave(javax.servlet.http.HttpServletRequest req, java.lang.String dir)
          Parses the HTTP POST request with multipart/form-data and returns the result as ParsedData instance.
 ParsedData parseAndSave(javax.servlet.http.HttpServletRequest req, java.lang.String dir, int max)
          Parses the HTTP POST request with multipart/form-data and returns the result as ParsedData instance.
 ParsedData parseAndSave(javax.servlet.http.HttpServletRequest req, java.lang.String dir, int max, java.util.Set allow_mime)
          Parses the HTTP POST request with multipart/form-data and returns the result as ParsedData instance.
 ParsedData parseAndSave(javax.servlet.http.HttpServletRequest req, java.lang.String dir, java.util.Set allow_mime)
          Parses the HTTP POST request with multipart/form-data and returns the result as ParsedData instance.
 ParsedData parseAndSave(javax.servlet.http.HttpServletRequest req, java.lang.String ch, java.lang.String dir)
          Parses the HTTP POST request with multipart/form-data and returns the result as ParsedData instance.
 ParsedData parseAndSave(javax.servlet.http.HttpServletRequest req, java.lang.String ch, java.lang.String dir, int max)
          Parses the HTTP POST request with multipart/form-data and returns the result as ParsedData instance.
 ParsedData parseAndSave(javax.servlet.http.HttpServletRequest req, java.lang.String ch, java.lang.String dir, int max, java.util.Set allow_mime)
          Parses the HTTP POST request with multipart/form-data and returns the result as ParsedData instance.
 ParsedData parseAndSave(javax.servlet.http.HttpServletRequest req, java.lang.String ch, java.lang.String dir, java.util.Set allow_mime)
          Parses the HTTP POST request with multipart/form-data and returns the result as ParsedData instance.
 ParsedData parseOnly(javax.servlet.http.HttpServletRequest req)
          Parses the HTTP POST request with multipart/form-data and returns the result as ParsedData instance.
 ParsedData parseOnly(javax.servlet.http.HttpServletRequest req, int max)
          Parses the HTTP POST request with multipart/form-data and returns the result as ParsedData instance.
 ParsedData parseOnly(javax.servlet.http.HttpServletRequest req, int max, java.util.Set allow_mime)
          Parses the HTTP POST request with multipart/form-data and returns the result as ParsedData instance.
 ParsedData parseOnly(javax.servlet.http.HttpServletRequest req, java.util.Set allow_mime)
          Parses the HTTP POST request with multipart/form-data and returns the result as ParsedData instance.
 ParsedData parseOnly(javax.servlet.http.HttpServletRequest req, java.lang.String ch)
          Parses the HTTP POST request with multipart/form-data and returns the result as ParsedData instance.
 ParsedData parseOnly(javax.servlet.http.HttpServletRequest req, java.lang.String ch, int max)
          Parses the HTTP POST request with multipart/form-data and returns the result as ParsedData instance.
 ParsedData parseOnly(javax.servlet.http.HttpServletRequest req, java.lang.String ch, int max, java.util.Set allow_mime)
          Parses the HTTP POST request with multipart/form-data and returns the result as ParsedData instance.
 ParsedData parseOnly(javax.servlet.http.HttpServletRequest req, java.lang.String ch, java.util.Set allow_mime)
          Parses the HTTP POST request with multipart/form-data and returns the result as ParsedData instance.
 void setDebug(boolean db)
           
 void setLogger(GenericLogger logger)
          Set GenericLogger object to which the log messages will be written.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setDebug

public void setDebug(boolean db)

getInstance

public static MimeParser getInstance()
                              throws SimpleException,
                                     NestedException,
                                     NoPropertyFileException
Reads the property file and returns the instance of this class.

The returned instance is always same one within the web application context. Through this method, all the Servlets within the web application context can share the same instance of this class. Because all the methods of this class is Thread Safe, the concurrent HTTP requests to the multiple Servlets can invoke the methods on the single instance of this class. Before you start to build your Servlet by this class, we strongly recommend you to read: Only at the first invocation, this method reads the property file and initializes its instance. All the subsequent calls just return the same instance, and that's all.

As for the resource file, please read another page.

Returns:
The instance of this class.
Throws:
SimpleException
NestedException
NoPropertyFileException

getFileRoot

public java.lang.String getFileRoot()
Returns the root directory where the uploaded file will be saved.

The root directory is specified by the resource file along with other properties. As for the resource file, please read another page.

Returns:
a String representing the root directory where the uploaded file will be saved.

getDefaultMaximumFileSize

public int getDefaultMaximumFileSize()
Returns the maximum file size which is specified in MimeParser.properties.

Returns:
The maximum file size which is specified in MimeParser.properties.
Since:
2.3

isImageSizeChecked

public boolean isImageSizeChecked()
The true if the size of the image file (JPEG, GIF or PNG) will be checked. Otherwise, false.

With this Java API, your JSP/Servlet can check the width/height of the image file (JPEG, GIF or PNG) to be uploaded. For details about this feature, please read another page.
Please note that even if this method returns true, the width/height of the non-image files (such as TXT or PDF) will not be checked.

Returns:
The true if the size of the image file (JPEG, GIF or PNG) will be checked. Otherwise, false.
Since:
3.0

getMaximumWidth

public int getMaximumWidth()
Return the maximum width to be allowed.

With this Java API, your JSP/Servlet can check the width/height of the image file (JPEG, GIF or PNG) to be uploaded. For details about this feature, please read another page.

Returns:
The maximum width to be allowed.
Since:
3.0

getMaximumHeight

public int getMaximumHeight()
Return the maximum height to be allowed.

With this Java API, your JSP/Servlet can check the width/height of the image file (JPEG, GIF or PNG) to be uploaded. For details about this feature, please read another page.

Returns:
The maximum height to be allowed.
Since:
3.0

parseAndSave

public ParsedData parseAndSave(javax.servlet.http.HttpServletRequest req,
                               java.lang.String ch,
                               java.lang.String dir,
                               int max)
                        throws SimpleException,
                               TooLargeFileException,
                               NestedException,
                               TooLargeBodyException
Parses the HTTP POST request with multipart/form-data and returns the result as ParsedData instance.

Saves the uploaded files into the local file system on the server side. At the same time, the text values from TEXT INPUT or SELECTION in the FORM are decoded. The contents of the uploaded files and the decoded Strings can be accessed through ParsedData. In addition, the instance of java.io.File for the saved files are also available on ParsedData.

Where to save the uploaded files and by which charset the text values are decoded can be specified in various way. This method also allows you to specify the maximum size of the file to be uploaded.
For details, please read:

Parameters:
req - The HTTP request
ch - The charset used to decode the text values from TEXT INPUT and SELECTION. For details about the charset, please read another page.
dir - The sub-directory beneath the root directory, where the uploaded file will be saved. For details about where to save the file, please read another page.
max - The maximum size (in bytes) of the uploaded file. For details about the maximum size, please read another page.
Returns:
The instance of ParsedData

Throws:
SimpleException
TooLargeFileException
NestedException
TooLargeBodyException
Since:
2.0

See Also:



parse

public ParsedData parse(javax.servlet.http.HttpServletRequest req,
                        java.lang.String ch,
                        java.lang.String dir,
                        int max)
                 throws java.io.IOException,
                        javax.mail.MessagingException,
                        javax.mail.internet.ParseException,
                        SimpleException,
                        TooLargeFileException,
                        java.util.MissingResourceException,
                        java.lang.ClassNotFoundException,
                        TooLargeBodyException
Deprecated. 

This method works exactly same as parseAndSave(HttpServletRequest,String,String,int)

For backward compatiblity only. Please use parseAndSave(HttpServletRequest,String,String,int) instead.

Parameters:
req - The HTTP request
ch - The charset used to decode the text values from TEXT INPUT and SELECTION. For details about the charset, please read another page.
dir - The sub-directory beneath the root directory, where the uploaded file will be saved. For details about where to save the file, please read another page.
max - The maximum size (in bytes) of the uploaded file. For details about the maximum size, please read another page.
Returns:
The instance of ParsedData

Throws:
java.io.IOException
javax.mail.MessagingException
javax.mail.internet.ParseException
SimpleException
TooLargeFileException
java.util.MissingResourceException
java.lang.ClassNotFoundException
TooLargeBodyException

parseAndSave

public ParsedData parseAndSave(javax.servlet.http.HttpServletRequest req,
                               java.lang.String ch,
                               java.lang.String dir)
                        throws SimpleException,
                               TooLargeFileException,
                               NestedException,
                               TooLargeBodyException
Parses the HTTP POST request with multipart/form-data and returns the result as ParsedData instance.

Saves the uploaded files into the local file system on the server side. At the same time, the text values from TEXT INPUT or SELECTION in the FORM are decoded. The contents of the uploaded files and the decoded Strings can be accessed through ParsedData. In addition, the instance of java.io.File for the saved files are also available on ParsedData.

Where to save the uploaded files and by which charset the text values are decoded can be specified in various way.
For details, please read:

Parameters:
req - The HTTP request
ch - The charset used to decode the text values from TEXT INPUT and SELECTION. For details about the charset, please read another page.
dir - The sub-directory beneath the root directory, where the uploaded file will be saved. For details about where to save the file, please read another page.
Returns:
The instance of ParsedData

Throws:
SimpleException
TooLargeFileException
NestedException
TooLargeBodyException
Since:
2.0

See Also:



parse

public ParsedData parse(javax.servlet.http.HttpServletRequest req,
                        java.lang.String ch,
                        java.lang.String dir)
                 throws java.io.IOException,
                        javax.mail.MessagingException,
                        javax.mail.internet.ParseException,
                        SimpleException,
                        TooLargeFileException,
                        java.util.MissingResourceException,
                        java.lang.ClassNotFoundException,
                        TooLargeBodyException
Deprecated. 

This method works exactly same as parseAndSave(HttpServletRequest,String,String)

For backward compatiblity only. Please use parseAndSave(HttpServletRequest,String,String) instead.

Parameters:
req - The HTTP request
ch - The charset used to decode the text values from TEXT INPUT and SELECTION. For details about the charset, please read another page.
dir - The sub-directory beneath the root directory, where the uploaded file will be saved. For details about where to save the file, please read another page.
Returns:
The instance of ParsedData

Throws:
java.io.IOException
javax.mail.MessagingException
javax.mail.internet.ParseException
SimpleException
TooLargeFileException
java.util.MissingResourceException
java.lang.ClassNotFoundException
TooLargeBodyException
See Also:
ParsedData

parseAndSave

public ParsedData parseAndSave(javax.servlet.http.HttpServletRequest req,
                               java.lang.String ch,
                               java.lang.String dir,
                               int max,
                               java.util.Set allow_mime)
                        throws SimpleException,
                               TooLargeFileException,
                               InvalidContentTypeException,
                               NestedException,
                               TooLargeBodyException,
                               LargeImageException
Parses the HTTP POST request with multipart/form-data and returns the result as ParsedData instance.

Saves the uploaded files into the local file system on the server side. At the same time, the text values from TEXT INPUT or SELECTION in the FORM are decoded. The contents of the uploaded files and the decoded Strings can be accessed through ParsedData. In addition, the instance of java.io.File for the saved files are also available on ParsedData.

Where to save the uploaded files and by which charset the text values are decoded can be specified in various way. This method also allows you to specify the maximum size of the file to be uploaded.
For details, please read:

This method can restrict the mime-type of the file to be uploaded. A series of permitted mime-types can be specified by the instance of java.util.Set as the last parameter. For example, the last parameter can contain the following Strings to restrict the files to be uploaded. If the files other than these mime-type is being uploaded, this method throws InvalidContentTypeException. Your Servlet can catch this exception and show the appropriate message to the user.

To create the java.util.Set object with the acceptable mime-types, please use AcceptMime. This class loads the list of the mime-types from the property resource file and returns the java.util.Set object. As for the resource file, please read another page.

As for the image files (JPEG, PNG or GIF), you can optionally set the maximum width/height. To enable this feature, please copy: into: In addition, please specify max_width and max_height in: If the width or height of the image file to be uploaded is larger than the maximum width/height, this method will throw LargeImageException.

Parameters:
req - The HTTP request
ch - The charset used to decode the text values from TEXT INPUT and SELECTION. For details about the charset, please read another page.
dir - The sub-directory beneath the root directory, where the uploaded file will be saved. For details about where to save the file, please read another page.
max - The maximum size (in bytes) of the uploaded file. For details about the maximum size, please read another page.
allow_mime - The instance of java.util.Set, which contains the Strings for permitted mime-types.
Returns:
The instance of ParsedData

Throws:
SimpleException
TooLargeFileException
InvalidContentTypeException
NestedException
TooLargeBodyException
LargeImageException
Since:
2.0

See Also:



parseAndSave

public ParsedData parseAndSave(javax.servlet.http.HttpServletRequest req,
                               java.lang.String ch,
                               java.lang.String dir,
                               java.util.Set allow_mime)
                        throws SimpleException,
                               TooLargeFileException,
                               InvalidContentTypeException,
                               NestedException,
                               TooLargeBodyException,
                               LargeImageException
Parses the HTTP POST request with multipart/form-data and returns the result as ParsedData instance.

Saves the uploaded files into the local file system on the server side. At the same time, the text values from TEXT INPUT or SELECTION in the FORM are decoded. The contents of the uploaded files and the decoded Strings can be accessed through ParsedData. In addition, the instance of java.io.File for the saved files are also available on ParsedData.

Where to save the uploaded files and by which charset the text values are decoded can be specified in various way.
For details, please read:

This method can restrict the mime-type of the file to be uploaded. A series of permitted mime-types can be specified by the instance of java.util.Set as the last parameter. For example, the last parameter can contain the following Strings to restrict the files to be uploaded. If the files other than these mime-type is being uploaded, this method throws InvalidContentTypeException. Your Servlet can catch this exception and show the appropriate message to the user.

To create the java.util.Set object with the acceptable mime-types, please use AcceptMime. This class loads the list of the mime-types from the property resource file and returns the java.util.Set object. As for the resource file, please read another page.

As for the image files (JPEG, PNG or GIF), you can optionally set the maximum width/height. To enable this feature, please copy: into: and specify max_width and max_height in: If the width or height of the image file to be uploaded is larger than the maximum width/height, this method will throw LargeImageException.

Parameters:
req - The HTTP request
ch - The charset used to decode the text values from TEXT INPUT and SELECTION. For details about the charset, please read another page.
dir - The sub-directory beneath the root directory, where the uploaded file will be saved. For details about where to save the file, please read another page.
allow_mime - The instance of java.util.Set, which contains the Strings for permitted mime-types.
Returns:
The instance of ParsedData

Throws:
SimpleException
TooLargeFileException
InvalidContentTypeException
NestedException
TooLargeBodyException
LargeImageException
Since:
2.0

See Also:
ParsedData

parseOnly

public ParsedData parseOnly(javax.servlet.http.HttpServletRequest req,
                            java.lang.String ch,
                            int max)
                     throws SimpleException,
                            TooLargeFileException,
                            NestedException,
                            TooLargeBodyException
Parses the HTTP POST request with multipart/form-data and returns the result as ParsedData instance.

This method gets the contents of the uploaded files, but does NOT save them into the local file on the server side. At the same time, the text values from TEXT INPUT or SELECTION in the FORM are decoded. The contents of the uploaded files and the decoded Strings can be accessed through ParsedData.

By which charset the text values are decoded can be specified in various way. This method also allows you to specify the maximum size of the file to be uploaded.
For details, please read:

Parameters:
req - The HTTP request
ch - The charset used to decode the text values from TEXT INPUT and SELECTION. For details about the charset, please read another page.
max - The maximum size (in bytes) of the uploaded file. For details about the maximum size, please read another page.
Returns:
The instance of ParsedData

Throws:
SimpleException
TooLargeFileException
NestedException
TooLargeBodyException
Since:
2.0

See Also:



parse

public ParsedData parse(javax.servlet.http.HttpServletRequest req,
                        java.lang.String ch,
                        int max)
                 throws java.io.IOException,
                        javax.mail.MessagingException,
                        javax.mail.internet.ParseException,
                        SimpleException,
                        TooLargeFileException,
                        java.util.MissingResourceException,
                        java.lang.ClassNotFoundException,
                        TooLargeBodyException
Deprecated. 

This method works exactly same as parseOnly(HttpServletRequest,String,int)

For backward compatiblity only. Please use parseOnly(HttpServletRequest,String,int) instead.

Parameters:
req - The HTTP request
ch - The charset used to decode the text values from TEXT INPUT and SELECTION. For details about the charset, please read another page.
max - The maximum size (in bytes) of the uploaded file. For details about the maximum size, please read another page.
Returns:
The instance of ParsedData

Throws:
java.io.IOException
javax.mail.MessagingException
javax.mail.internet.ParseException
SimpleException
TooLargeFileException
java.util.MissingResourceException
java.lang.ClassNotFoundException
TooLargeBodyException

parseOnly

public ParsedData parseOnly(javax.servlet.http.HttpServletRequest req,
                            java.lang.String ch)
                     throws SimpleException,
                            TooLargeFileException,
                            NestedException,
                            TooLargeBodyException
Parses the HTTP POST request with multipart/form-data and returns the result as ParsedData instance.

This method gets the contents of the uploaded files, but does NOT save them into the local file on the server side. At the same time, the text values from TEXT INPUT or SELECTION in the FORM are decoded. The contents of the uploaded files and the decoded Strings can be accessed through ParsedData.

By which charset the text values are decoded can be specified in various way.
For details, please read:

Parameters:
req - The HTTP request
ch - The charset used to decode the text values from TEXT INPUT and SELECTION. For details about the charset, please read another page.
Returns:
The instance of ParsedData

Throws:
SimpleException
TooLargeFileException
NestedException
TooLargeBodyException
Since:
2.0

See Also:



parse

public ParsedData parse(javax.servlet.http.HttpServletRequest req,
                        java.lang.String ch)
                 throws java.io.IOException,
                        javax.mail.MessagingException,
                        javax.mail.internet.ParseException,
                        SimpleException,
                        TooLargeFileException,
                        java.util.MissingResourceException,
                        java.lang.ClassNotFoundException,
                        TooLargeBodyException
Deprecated. 

This method works exactly same as parseOnly(HttpServletRequest,String)

For backward compatiblity only. Please use parseOnly(HttpServletRequest,String) instead.

Parameters:
req - The HTTP request
ch - The charset used to decode the text values from TEXT INPUT and SELECTION. For details about the charset, please read another page.
Returns:
The instance of ParsedData

Throws:
java.io.IOException
javax.mail.MessagingException
javax.mail.internet.ParseException
SimpleException
TooLargeFileException
java.util.MissingResourceException
java.lang.ClassNotFoundException
TooLargeBodyException

parseOnly

public ParsedData parseOnly(javax.servlet.http.HttpServletRequest req,
                            java.lang.String ch,
                            int max,
                            java.util.Set allow_mime)
                     throws SimpleException,
                            TooLargeFileException,
                            InvalidContentTypeException,
                            NestedException,
                            TooLargeBodyException,
                            LargeImageException
Parses the HTTP POST request with multipart/form-data and returns the result as ParsedData instance.

This method gets the contents of the uploaded files, but does NOT save them into the local file on the server side. At the same time, the text values from TEXT INPUT or SELECTION in the FORM are decoded. The contents of the uploaded files and the decoded Strings can be accessed through ParsedData.

By which charset the text values are decoded can be specified in various way. This method also allows you to specify the maximum size of the file to be uploaded.
For details, please read:

This method can restrict the mime-type of the file to be uploaded. A series of permitted mime-types can be specified by the instance of java.util.Set as the last parameter. For example, the last parameter can contain the following Strings to restrict the files to be uploaded. If the files other than these mime-type is being uploaded, this method throws InvalidContentTypeException. Your Servlet can catch this exception and show the appropriate message to the user.

To create the java.util.Set object with the acceptable mime-types, please use AcceptMime. This class loads the list of the mime-types from the property resource file and returns the java.util.Set object. As for the resource file, please read another page.

As for the image files (JPEG, PNG or GIF), you can optionally set the maximum width/height. To enable this feature, please copy: into: and specify max_width and max_height in: If the width or height of the image file to be uploaded is larger than the maximum width/height, this method will throw LargeImageException.

Parameters:
req - The HTTP request
ch - The charset used to decode the text values from TEXT INPUT and SELECTION. For details about the charset, please read another page.
max - The maximum size (in bytes) of the uploaded file. For details about the maximum size, please read another page.
allow_mime - The instance of java.util.Set, which contains the Strings for permitted mime-types.
Returns:
The instance of ParsedData

Throws:
SimpleException
TooLargeFileException
InvalidContentTypeException
NestedException
TooLargeBodyException
LargeImageException
Since:
2.0

See Also:



parseOnly

public ParsedData parseOnly(javax.servlet.http.HttpServletRequest req,
                            java.lang.String ch,
                            java.util.Set allow_mime)
                     throws SimpleException,
                            TooLargeFileException,
                            InvalidContentTypeException,
                            NestedException,
                            TooLargeBodyException,
                            LargeImageException
Parses the HTTP POST request with multipart/form-data and returns the result as ParsedData instance.

This method gets the contents of the uploaded files, but does NOT save them into the local file on the server side. At the same time, the text values from TEXT INPUT or SELECTION in the FORM are decoded. The contents of the uploaded files and the decoded Strings can be accessed through ParsedData.

By which charset the text values are decoded can be specified in various way.
For details, please read:

This method can restrict the mime-type of the file to be uploaded. A series of permitted mime-types can be specified by the instance of java.util.Set as the last parameter. For example, the last parameter can contain the following Strings to restrict the files to be uploaded. If the files other than these mime-type is being uploaded, this method throws InvalidContentTypeException. Your Servlet can catch this exception and show the appropriate message to the user.

To create the java.util.Set object with the acceptable mime-types, please use AcceptMime. This class loads the list of the mime-types from the property resource file and returns the java.util.Set object. As for the resource file, please read another page.

As for the image files (JPEG, PNG or GIF), you can optionally set the maximum width/height. To enable this feature, please copy: into: and specify max_width and max_height in: If the width or height of the image file to be uploaded is larger than the maximum width/height, this method will throw LargeImageException.

Parameters:
req - The HTTP request
ch - The charset used to decode the text values from TEXT INPUT and SELECTION. For details about the charset, please read another page.
allow_mime - The instance of java.util.Set, which contains the Strings for permitted mime-types.
Returns:
The instance of ParsedData

Throws:
SimpleException
TooLargeFileException
InvalidContentTypeException
NestedException
TooLargeBodyException
LargeImageException
Since:
2.0

See Also:



parseAndSave

public ParsedData parseAndSave(javax.servlet.http.HttpServletRequest req,
                               java.lang.String dir,
                               int max)
                        throws SimpleException,
                               TooLargeFileException,
                               NestedException,
                               TooLargeBodyException
Parses the HTTP POST request with multipart/form-data and returns the result as ParsedData instance.

Saves the uploaded files into the local file system on the server side. At the same time, the text values from TEXT INPUT or SELECTION in the FORM are decoded. The contents of the uploaded files and the decoded Strings can be accessed through ParsedData. In addition, the instance of java.io.File for the saved files are also available on ParsedData.

Where to save the uploaded files and by which charset the text values are decoded can be specified in various way. This method also allows you to specify the maximum size of the file to be uploaded.
For details, please read:

Parameters:
req - The HTTP request
dir - The sub-directory beneath the root directory, where the uploaded file will be saved. For details about where to save the file, please read another page.
max - The maximum size (in bytes) of the uploaded file. For details about the maximum size, please read another page.
Returns:
The instance of ParsedData

Throws:
SimpleException
TooLargeFileException
NestedException
TooLargeBodyException
Since:
2.4

See Also:



parseAndSave

public ParsedData parseAndSave(javax.servlet.http.HttpServletRequest req,
                               java.lang.String dir)
                        throws SimpleException,
                               TooLargeFileException,
                               NestedException,
                               TooLargeBodyException
Parses the HTTP POST request with multipart/form-data and returns the result as ParsedData instance.

Saves the uploaded files into the local file system on the server side. At the same time, the text values from TEXT INPUT or SELECTION in the FORM are decoded. The contents of the uploaded files and the decoded Strings can be accessed through ParsedData. In addition, the instance of java.io.File for the saved files are also available on ParsedData.

Where to save the uploaded files and by which charset the text values are decoded can be specified in various way.
For details, please read:

Parameters:
req - The HTTP request
dir - The sub-directory beneath the root directory, where the uploaded file will be saved. For details about where to save the file, please read another page.
Returns:
The instance of ParsedData

Throws:
SimpleException
TooLargeFileException
NestedException
TooLargeBodyException
Since:
2.4

See Also:



parseAndSave

public ParsedData parseAndSave(javax.servlet.http.HttpServletRequest req,
                               java.lang.String dir,
                               int max,
                               java.util.Set allow_mime)
                        throws SimpleException,
                               TooLargeFileException,
                               InvalidContentTypeException,
                               NestedException,
                               TooLargeBodyException,
                               LargeImageException
Parses the HTTP POST request with multipart/form-data and returns the result as ParsedData instance.

Saves the uploaded files into the local file system on the server side. At the same time, the text values from TEXT INPUT or SELECTION in the FORM are decoded. The contents of the uploaded files and the decoded Strings can be accessed through ParsedData. In addition, the instance of java.io.File for the saved files are also available on ParsedData.

Where to save the uploaded files and by which charset the text values are decoded can be specified in various way. This method also allows you to specify the maximum size of the file to be uploaded.
For details, please read:

This method can restrict the mime-type of the file to be uploaded. A series of permitted mime-types can be specified by the instance of java.util.Set as the last parameter. For example, the last parameter can contain the following Strings to restrict the files to be uploaded. If the files other than these mime-type is being uploaded, this method throws InvalidContentTypeException. Your Servlet can catch this exception and show the appropriate message to the user.

To create the java.util.Set object with the acceptable mime-types, please use AcceptMime. This class loads the list of the mime-types from the property resource file and returns the java.util.Set object. As for the resource file, please read another page.

As for the image files (JPEG, PNG or GIF), you can optionally set the maximum width/height. To enable this feature, please copy: into: and specify max_width and max_height in: If the width or height of the image file to be uploaded is larger than the maximum width/height, this method will throw LargeImageException.

Parameters:
req - The HTTP request
dir - The sub-directory beneath the root directory, where the uploaded file will be saved. For details about where to save the file, please read another page.
max - The maximum size (in bytes) of the uploaded file. For details about the maximum size, please read another page.
allow_mime - The instance of java.util.Set, which contains the Strings for permitted mime-types.
Returns:
The instance of ParsedData

Throws:
SimpleException
TooLargeFileException
InvalidContentTypeException
NestedException
TooLargeBodyException
LargeImageException
Since:
2.4

See Also:



parseAndSave

public ParsedData parseAndSave(javax.servlet.http.HttpServletRequest req,
                               java.lang.String dir,
                               java.util.Set allow_mime)
                        throws SimpleException,
                               TooLargeFileException,
                               InvalidContentTypeException,
                               NestedException,
                               TooLargeBodyException,
                               LargeImageException
Parses the HTTP POST request with multipart/form-data and returns the result as ParsedData instance.

Saves the uploaded files into the local file system on the server side. At the same time, the text values from TEXT INPUT or SELECTION in the FORM are decoded. The contents of the uploaded files and the decoded Strings can be accessed through ParsedData. In addition, the instance of java.io.File for the saved files are also available on ParsedData.

Where to save the uploaded files and by which charset the text values are decoded can be specified in various way.
For details, please read:

This method can restrict the mime-type of the file to be uploaded. A series of permitted mime-types can be specified by the instance of java.util.Set as the last parameter. For example, the last parameter can contain the following Strings to restrict the files to be uploaded. If the files other than these mime-type is being uploaded, this method throws InvalidContentTypeException. Your Servlet can catch this exception and show the appropriate message to the user.

To create the java.util.Set object with the acceptable mime-types, please use AcceptMime. This class loads the list of the mime-types from the property resource file and returns the java.util.Set object. As for the resource file, please read another page.

As for the image files (JPEG, PNG or GIF), you can optionally set the maximum width/height. To enable this feature, please copy: into: and specify max_width and max_height in: If the width or height of the image file to be uploaded is larger than the maximum width/height, this method will throw LargeImageException.

Parameters:
req - The HTTP request
dir - The sub-directory beneath the root directory, where the uploaded file will be saved. For details about where to save the file, please read another page.
allow_mime - The instance of java.util.Set, which contains the Strings for permitted mime-types.
Returns:
The instance of ParsedData

Throws:
SimpleException
TooLargeFileException
InvalidContentTypeException
NestedException
TooLargeBodyException
LargeImageException
Since:
2.4

See Also:
ParsedData

parseOnly

public ParsedData parseOnly(javax.servlet.http.HttpServletRequest req,
                            int max)
                     throws SimpleException,
                            TooLargeFileException,
                            NestedException,
                            TooLargeBodyException
Parses the HTTP POST request with multipart/form-data and returns the result as ParsedData instance.

This method gets the contents of the uploaded files, but does NOT save them into the local file on the server side. At the same time, the text values from TEXT INPUT or SELECTION in the FORM are decoded. The contents of the uploaded files and the decoded Strings can be accessed through ParsedData.

By which charset the text values are decoded can be specified in various way. This method also allows you to specify the maximum size of the file to be uploaded.
For details, please read:

Parameters:
req - The HTTP request
max - The maximum size (in bytes) of the uploaded file. For details about the maximum size, please read another page.
Returns:
The instance of ParsedData

Throws:
SimpleException
TooLargeFileException
NestedException
TooLargeBodyException
Since:
2.4

See Also:



parseOnly

public ParsedData parseOnly(javax.servlet.http.HttpServletRequest req)
                     throws SimpleException,
                            TooLargeFileException,
                            NestedException,
                            TooLargeBodyException
Parses the HTTP POST request with multipart/form-data and returns the result as ParsedData instance.

This method gets the contents of the uploaded files, but does NOT save them into the local file on the server side. At the same time, the text values from TEXT INPUT or SELECTION in the FORM are decoded. The contents of the uploaded files and the decoded Strings can be accessed through ParsedData.

By which charset the text values are decoded can be specified in various way.
For details, please read:

Parameters:
req - The HTTP request
Returns:
The instance of ParsedData

Throws:
SimpleException
TooLargeFileException
NestedException
TooLargeBodyException
Since:
2.4

See Also:



parseOnly

public ParsedData parseOnly(javax.servlet.http.HttpServletRequest req,
                            int max,
                            java.util.Set allow_mime)
                     throws SimpleException,
                            TooLargeFileException,
                            InvalidContentTypeException,
                            NestedException,
                            TooLargeBodyException,
                            LargeImageException
Parses the HTTP POST request with multipart/form-data and returns the result as ParsedData instance.

This method gets the contents of the uploaded files, but does NOT save them into the local file on the server side. At the same time, the text values from TEXT INPUT or SELECTION in the FORM are decoded. The contents of the uploaded files and the decoded Strings can be accessed through ParsedData.

By which charset the text values are decoded can be specified in various way. This method also allows you to specify the maximum size of the file to be uploaded.
For details, please read:

This method can restrict the mime-type of the file to be uploaded. A series of permitted mime-types can be specified by the instance of java.util.Set as the last parameter. For example, the last parameter can contain the following Strings to restrict the files to be uploaded. If the files other than these mime-type is being uploaded, this method throws InvalidContentTypeException. Your Servlet can catch this exception and show the appropriate message to the user.

To create the java.util.Set object with the acceptable mime-types, please use AcceptMime. This class loads the list of the mime-types from the property resource file and returns the java.util.Set object. As for the resource file, please read another page.

As for the image files (JPEG, PNG or GIF), you can optionally set the maximum width/height. To enable this feature, please copy: into: and specify max_width and max_height in: If the width or height of the image file to be uploaded is larger than the maximum width/height, this method will throw LargeImageException.

Parameters:
req - The HTTP request
max - The maximum size (in bytes) of the uploaded file. For details about the maximum size, please read another page.
allow_mime - The instance of java.util.Set, which contains the Strings for permitted mime-types.
Returns:
The instance of ParsedData

Throws:
SimpleException
TooLargeFileException
InvalidContentTypeException
NestedException
TooLargeBodyException
LargeImageException
Since:
2.4

See Also:



parseOnly

public ParsedData parseOnly(javax.servlet.http.HttpServletRequest req,
                            java.util.Set allow_mime)
                     throws SimpleException,
                            TooLargeFileException,
                            InvalidContentTypeException,
                            NestedException,
                            TooLargeBodyException,
                            LargeImageException
Parses the HTTP POST request with multipart/form-data and returns the result as ParsedData instance.

This method gets the contents of the uploaded files, but does NOT save them into the local file on the server side. At the same time, the text values from TEXT INPUT or SELECTION in the FORM are decoded. The contents of the uploaded files and the decoded Strings can be accessed through ParsedData.

By which charset the text values are decoded can be specified in various way.
For details, please read:

This method can restrict the mime-type of the file to be uploaded. A series of permitted mime-types can be specified by the instance of java.util.Set as the last parameter. For example, the last parameter can contain the following Strings to restrict the files to be uploaded. If the files other than these mime-type is being uploaded, this method throws InvalidContentTypeException. Your Servlet can catch this exception and show the appropriate message to the user.

To create the java.util.Set object with the acceptable mime-types, please use AcceptMime. This class loads the list of the mime-types from the property resource file and returns the java.util.Set object. As for the resource file, please read another page.

As for the image files (JPEG, PNG or GIF), you can optionally set the maximum width/height. To enable this feature, please copy: into: and specify max_width and max_height in: If the width or height of the image file to be uploaded is larger than the maximum width/height, this method will throw LargeImageException.

Parameters:
req - The HTTP request
allow_mime - The instance of java.util.Set, which contains the Strings for permitted mime-types.
Returns:
The instance of ParsedData

Throws:
SimpleException
TooLargeFileException
InvalidContentTypeException
NestedException
TooLargeBodyException
LargeImageException
Since:
2.4

See Also:



setLogger

public void setLogger(GenericLogger logger)
Set GenericLogger object to which the log messages will be written.

Parameters:
logger - GenericLogger object to which the log messages will be written.

OOP MimeParser Version 3.5

ALL CONTENTS COPYRIGHT 2005, OOP-Research Corporation. All rights reserved.
Any questions and comments are welcome to OOP-Research Corporation.