FileDocCategorySizeDatePackage
ContentDisposition.javaAPI DocJavaMail 1.4.35792Tue Nov 17 10:38:12 GMT 2009javax.mail.internet

ContentDisposition

public class ContentDisposition extends Object
This class represents a MIME ContentDisposition value. It provides methods to parse a ContentDisposition string into individual components and to generate a MIME style ContentDisposition string.
author
John Mani

Fields Summary
private String
disposition
private ParameterList
list
Constructors Summary
public ContentDisposition()
No-arg Constructor.

 
public ContentDisposition(String disposition, ParameterList list)
Constructor.

param
disposition disposition
param
list ParameterList
since
JavaMail 1.2

	this.disposition = disposition;
	this.list = list;
    
public ContentDisposition(String s)
Constructor that takes a ContentDisposition string. The String is parsed into its constituents: dispostion and parameters. A ParseException is thrown if the parse fails.

param
s the ContentDisposition string.
exception
ParseException if the parse fails.
since
JavaMail 1.2

	HeaderTokenizer h = new HeaderTokenizer(s, HeaderTokenizer.MIME);
	HeaderTokenizer.Token tk;

	// First "disposition" ..
	tk = h.next();
	if (tk.getType() != HeaderTokenizer.Token.ATOM)
	    throw new ParseException("Expected disposition, got " +
					tk.getValue());
	disposition = tk.getValue();

	// Then parameters ..
	String rem = h.getRemainder();
	if (rem != null)
	    list = new ParameterList(rem);
    
Methods Summary
public java.lang.StringgetDisposition()
Return the disposition value.

return
the disposition
since
JavaMail 1.2

	return disposition;
    
public java.lang.StringgetParameter(java.lang.String name)
Return the specified parameter value. Returns null if this parameter is absent.

return
parameter value
since
JavaMail 1.2

	if (list == null)
	    return null;

	return list.get(name);
    
public javax.mail.internet.ParameterListgetParameterList()
Return a ParameterList object that holds all the available parameters. Returns null if no parameters are available.

return
ParameterList
since
JavaMail 1.2

	return list;
    
public voidsetDisposition(java.lang.String disposition)
Set the disposition. Replaces the existing disposition.

param
disposition the disposition
since
JavaMail 1.2

	this.disposition = disposition;
    
public voidsetParameter(java.lang.String name, java.lang.String value)
Set the specified parameter. If this parameter already exists, it is replaced by this new value.

param
name parameter name
param
value parameter value
since
JavaMail 1.2

	if (list == null)
	    list = new ParameterList();

	list.set(name, value);
    
public voidsetParameterList(javax.mail.internet.ParameterList list)
Set a new ParameterList.

param
list ParameterList
since
JavaMail 1.2

	this.list = list;
    
public java.lang.StringtoString()
Retrieve a RFC2045 style string representation of this ContentDisposition. Returns null if the conversion failed.

return
RFC2045 style string
since
JavaMail 1.2

	if (disposition == null)
	    return null;

	if (list == null)
	    return disposition;

	StringBuffer sb = new StringBuffer(disposition);

        // append the parameter list  
        // use the length of the string buffer + the length of 
        // the header name formatted as follows "Content-Disposition: "
	sb.append(list.toString(sb.length() + 21));
	return sb.toString();