Rakesh API

org.rakeshv.mail
Class WriteFormParser

java.lang.Object
  extended by org.rakeshv.mail.WriteFormParser

public class WriteFormParser
extends java.lang.Object

This class parses the HttpServletRequest generated by the write.jsp HTML form encoded as multipart/form-data. Any attachments included in the form that was POSTed are converted to BodyPart objects, and stored in a List (attachments).

Copyright 2003 Rakesh Vidyadharan

Version:
$Id: WriteFormParser.java,v 1.4 2004/05/26 11:42:38 rakesh Exp $
Author:
Rakesh Vidyadharan 2003 March 18

Field Summary
private  java.util.List attachments
          The List in which extracted attachments will be stored.
private  java.lang.String bcc
          A String object that holds the email address(es) to which the new message being sent is to be blind carbon copied (bcc).
private  java.lang.String body
          A String object that holds the text body for the new message being composed.
private  java.lang.String cc
          A String object that holds the email address(es) to which the new message being sent is to be copied (cc).
private  java.lang.String command
          A String object that holds the hidden form variable that specifies the type of action being performed (send).
private  java.lang.String forward
          The message number in the IMAP store which is to be forwarded along with any additional text and attachments.
private  java.lang.String from
          A String object that holds the email address of the person who is composing the message.
private  java.util.List groups
          A List to hold groups from the addressbook that were selected in the groups select list in the write form.
private  int pageNumber
          An integer that holds the value of the pageNumber URL query string.
private  java.util.List persons
          A List to hold people from the addressbook that were selected in the persons select list in the write form.
private  java.lang.String reply
          The message number in the IMAP store to which the current message being composed is a reply to.
private  javax.servlet.http.HttpServletRequest request
          A reference to the HttpServletRequest object from which the attachments are to be extracted.
private  java.lang.String subject
          A String object that holds the subject line for the new message being composed.
private  java.lang.String to
          A String object that holds the email address(es) to which the new message is to be sent.
 
Constructor Summary
protected WriteFormParser()
          Default constructor.
  WriteFormParser(javax.servlet.http.HttpServletRequest request)
          The only constructor supported.
 
Method Summary
private  void extractAttachment(javax.servlet.ServletInputStream in, java.lang.String boundary, java.lang.String fileName, java.lang.String contentType)
          Extracts the contents of the file encoded in the multipart/ form-data request.
private  java.lang.String extractBoundary()
          Extracts and returns the boundary token from the HTTP request header (request).
private  java.lang.String[] extractContentDisposition(java.lang.String line)
          Extract the contents of the Content-Disposition headers that succeed a boundary delimiter in the request stream.
private  java.lang.String extractContentType(java.lang.String line)
          Extract the Content-Type header that succeeds the Content-Disposition header separating a part in the multipart HTTP request.
 java.util.List getAttachments()
          Returns attachments.
 java.lang.String getBcc()
          Returns bcc.
 java.lang.String getBody()
          Returns body.
 java.lang.String getCc()
          Returns cc.
 java.lang.String getCommand()
          Returns command.
 java.lang.String getForward()
          Returns forward.
 java.lang.String getFrom()
          Returns from.
 java.util.List getGroups()
          Returns groups.
 int getPageNumber()
          Returns pageNumber.
 java.util.List getPersons()
          Returns persons.
 java.lang.String getReply()
          Returns reply.
 java.lang.String getSubject()
          Returns subject.
 java.lang.String getTo()
          Returns to.
private  void parseFormData()
          Processes the parts included in the multipart/form-data request.
private  java.lang.String readLine(javax.servlet.ServletInputStream in)
          Reads a line from the ServletInputStream using the ServletInputStream.readLine method.
 java.lang.String toString()
          Over-ridden form of the toString method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

attachments

private java.util.List attachments
The List in which extracted attachments will be stored. The attachments in the List will be objects of type javax.mail.internet.MimeBodyPart.


persons

private java.util.List persons
A List to hold people from the addressbook that were selected in the persons select list in the write form.


groups

private java.util.List groups
A List to hold groups from the addressbook that were selected in the groups select list in the write form.


from

private java.lang.String from
A String object that holds the email address of the person who is composing the message. This field holds the contents of the from form element.


to

private java.lang.String to
A String object that holds the email address(es) to which the new message is to be sent. This field holds the contents of the to form element.


cc

private java.lang.String cc
A String object that holds the email address(es) to which the new message being sent is to be copied (cc). This field holds the contents of the cc form element.


bcc

private java.lang.String bcc
A String object that holds the email address(es) to which the new message being sent is to be blind carbon copied (bcc). This field holds the contents of the bcc form element.


subject

private java.lang.String subject
A String object that holds the subject line for the new message being composed. This field holds the contents of the subject form element.


body

private java.lang.String body
A String object that holds the text body for the new message being composed. This field holds the contents of the body form element.


reply

private java.lang.String reply
The message number in the IMAP store to which the current message being composed is a reply to. This field holds the contents of the reply hidden form element.


forward

private java.lang.String forward
The message number in the IMAP store which is to be forwarded along with any additional text and attachments. This field holds the contents of the forward hidden form element.


command

private java.lang.String command
A String object that holds the hidden form variable that specifies the type of action being performed (send). This field holds the contents of the command hidden form element.


pageNumber

private int pageNumber
An integer that holds the value of the pageNumber URL query string.


request

private javax.servlet.http.HttpServletRequest request
A reference to the HttpServletRequest object from which the attachments are to be extracted.

Constructor Detail

WriteFormParser

protected WriteFormParser()
Default constructor. Not used.


WriteFormParser

public WriteFormParser(javax.servlet.http.HttpServletRequest request)
                throws java.io.IOException,
                       javax.mail.MessagingException
The only constructor supported. Parses the form elements and attachments out of the specified HttpServletRequest object.

Parameters:
request - - The HttpServletRequest from which to extract attachments.
Throws:
java.io.IOException - - If errors are encountered while parsing the form elements out of the request.
javax.mail.MessagingException - - If errors are encountered while converting the form attachments into BodyPart objects.
See Also:
parseFormData()
Method Detail

parseFormData

private void parseFormData()
                    throws java.io.IOException,
                           javax.mail.MessagingException
Processes the parts included in the multipart/form-data request. Parses the ServletInputStream associated with the request and extracts all the form elements included in the write.jsp form. Use the accessor methods to fetch the parsed out parts and attributes of the email message being composed.

Throws:
java.io.IOException - - If errors are encountered while parsing the form elements out of the request.
javax.mail.MessagingException - - If errors are encountered while converting the form attachments into BodyPart objects.

extractBoundary

private java.lang.String extractBoundary()
Extracts and returns the boundary token from the HTTP request header (request). Look for the header Content-Type or content-type. Java Application Servers seem to convert Content-Type to content-type.

Returns:
String - The boundary token.

readLine

private java.lang.String readLine(javax.servlet.ServletInputStream in)
                           throws java.io.IOException
Reads a line from the ServletInputStream using the ServletInputStream.readLine method. Fills a temporary byte buffer with the results of the call to ServletInputStream.readLine, converts it into a String, and adds that to a StringBuffer. The contents of the StringBuffer are returned.

Note: - This method strips out the trailing new line characters which the ServletInputStream.readLine method returns at the end of the line. Calling classes will need to add new line characters as appropriate.

Parameters:
in - - The ServletInputStream from which to extact a line of text.
Returns:
String - The line of text read from the input stream.
Throws:
java.io.IOException - - If errors are encountered while reading from the input stream.

extractContentDisposition

private java.lang.String[] extractContentDisposition(java.lang.String line)
Extract the contents of the Content-Disposition headers that succeed a boundary delimiter in the request stream. The header contains information about the name of the form element, any filename associated if a file was being uploaded etc.

Parameters:
line - - The line of text that was read from the SerlvetInputStream.
Returns:
String[] - A String array with two entries. The first entry is the form element name, and the second the file name.

extractContentType

private java.lang.String extractContentType(java.lang.String line)
Extract the Content-Type header that succeeds the Content-Disposition header separating a part in the multipart HTTP request.

Parameters:
line - - The line of text read from the ServletInputStream from which the content type is to be extracted.
Returns:
String - The content type that was indicated in the header.

extractAttachment

private void extractAttachment(javax.servlet.ServletInputStream in,
                               java.lang.String boundary,
                               java.lang.String fileName,
                               java.lang.String contentType)
                        throws java.io.IOException,
                               javax.mail.MessagingException
Extracts the contents of the file encoded in the multipart/ form-data request. This method extracts the attachment contents and creates BodyPart objects with them. The extracted BodyPart objects are added to the attachments List.

Parameters:
in - - The InputStream from which the contents of the file being uploaded is to be extracted.
boundary - - The boundary token with which the various parts of the form data are delimited.
fileName - - The filename that was used by the client making the file upload.
contentType - - The content-type indicated by the client/browser making the file upload.
Throws:
java.io.IOException - - Any errors encountered while reading the contents from the ServletInputStream.
javax.mail.MessagingException - - If any errors are encountered while creating the BodyPart.

toString

public java.lang.String toString()
Over-ridden form of the toString method. Returns all the values parsed from the multipart request.

Overrides:
toString in class java.lang.Object
Returns:
String - A String representation of all the fields in this class.

getAttachments

public final java.util.List getAttachments()
Returns attachments.

Returns:
List - The value/reference of/to attachments.

getPersons

public final java.util.List getPersons()
Returns persons.

Returns:
List - The value/reference of/to persons.

getGroups

public final java.util.List getGroups()
Returns groups.

Returns:
List - The value/reference of/to groups.

getFrom

public final java.lang.String getFrom()
Returns from.

Returns:
String - The value/reference of/to from.

getTo

public final java.lang.String getTo()
Returns to.

Returns:
String - The value/reference of/to to.

getCc

public final java.lang.String getCc()
Returns cc.

Returns:
String - The value/reference of/to cc.

getBcc

public final java.lang.String getBcc()
Returns bcc.

Returns:
String - The value/reference of/to bcc.

getSubject

public final java.lang.String getSubject()
Returns subject.

Returns:
String - The value/reference of/to subject.

getBody

public final java.lang.String getBody()
Returns body.

Returns:
String - The value/reference of/to body.

getReply

public final java.lang.String getReply()
Returns reply.

Returns:
String - The value/reference of/to reply.

getForward

public final java.lang.String getForward()
Returns forward.

Returns:
String - The value/reference of/to forward.

getCommand

public final java.lang.String getCommand()
Returns command.

Returns:
String - The value/reference of/to command.

getPageNumber

public final int getPageNumber()
Returns pageNumber.

Returns:
int - The value/reference of/to pageNumber.

Rakesh API

Copyright © 2002-2005 - Rakesh Vidyadharan