iaik.smime
Class SMimeContent

java.lang.Object
  extended by iaik.smime.SMimeContent
All Implemented Interfaces:
CryptoContent
Direct Known Subclasses:
CompressedContent, EncryptedContent

public abstract class SMimeContent
extends java.lang.Object
implements CryptoContent

Abstract class that implements some methods that are used by both, EncryptedContent and CompressedContent. Some of these method are also used by SignedContent, but are reimplemented there because multiple inheritence is not supported by Java.

See Also:
EncryptedContent, CompressedContent

Constructor Summary
protected SMimeContent()
          Default constructor.
 
Method Summary
 java.lang.Object getContent()
          Returns the content as a Java object.
 java.lang.String getContentType()
          Returns the ContentType header and any attached parameters.
abstract  javax.activation.DataHandler getDataHandler()
          Returns a DataHandler holding the content.
 java.io.InputStream getInputStream()
          Returns an InputStream from which the content can be read.
 void setBlockSize(int blockSize)
          Sets the block size for defining the length of each definite primitive encoded octet string component.
 void setContent(javax.mail.Multipart multipart)
          Supplies the content as MIME Multipart.
 void setContent(java.lang.Object content, java.lang.String type)
          Sets the content to be processed.
 void setContentContentHeaders(javax.mail.Header[] headers)
          Set some headers for the entity to be signed.
 void setContentContentTransferEncoding(java.lang.String cte)
          Sets the content transfer encoding of the entity to be signed.
 void setDataHandler(javax.activation.DataHandler dataHandler)
          Sets the content wrapped by a javax.activation.DataHandler.
 void setText(java.lang.String text)
          Sets the text content.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface iaik.smime.CryptoContent
getSMimeType, setHeaders
 

Constructor Detail

SMimeContent

protected SMimeContent()
Default constructor.

Method Detail

getContentType

public java.lang.String getContentType()
Returns the ContentType header and any attached parameters. This method shall be used when setting this SMIME content object (EncryptedContent, or CompressedContent as the content of a MimeMessage, e.g.:
 MimeMessage msg = ...;
 EncryptedContent ec = new EncryptedContent();
 msg.setContent(ec, ec.getContentType());
 ...
 
or
 MimeMessage msg = ...;
 CompressedContent compressed = ...;
 ...
 msg.setContent(compressed, compressed.getContentType());
 ...
 

Specified by:
getContentType in interface CryptoContent
Returns:
the content type header

setContent

public void setContent(java.lang.Object content,
                       java.lang.String type)
                throws javax.mail.MessagingException
Sets the content to be processed.

Parameters:
content - a Java object
type - MIME type of this object
Throws:
javax.mail.MessagingException - if an error occurs while preparing the content

setContent

public void setContent(javax.mail.Multipart multipart)
                throws javax.mail.MessagingException
Supplies the content as MIME Multipart.

Parameters:
multipart - the multipart content
Throws:
javax.mail.MessagingException - if an error occurs while preparing the content

setText

public void setText(java.lang.String text)
             throws javax.mail.MessagingException
Sets the text content. The supplied text will be packed into a MIME entity with content type "text/plain".

Parameters:
text - the text content
Throws:
javax.mail.MessagingException - if an error occurs while preparing the content

setDataHandler

public void setDataHandler(javax.activation.DataHandler dataHandler)
                    throws javax.mail.MessagingException
Sets the content wrapped by a javax.activation.DataHandler. The DataHandler wraps around the actual content.

For more information about DataHandler usage see the JavaBeans Activation Framework (JAF) sepecification.

Parameters:
dataHandler - the DataHandler with the content to be compressed
Throws:
javax.mail.MessagingException - if an error occurs while preparing the content

getContent

public java.lang.Object getContent()
                            throws java.io.IOException,
                                   javax.mail.MessagingException
Returns the content as a Java object. The type of the returned object depends on the content itself. For example, the object returned for "text/plain" content is usually a String object. For content-types that are unknown to the JAF data content handler system, an input stream is returned as the content.

Returns:
the content as Java object
Throws:
java.io.IOException - if an I/O error occurs when getting the content from the inherent data handler
javax.mail.MessagingException - if an error occurs when fetching the inherent data handler

getDataHandler

public abstract javax.activation.DataHandler getDataHandler()
                                                     throws javax.mail.MessagingException
Returns a DataHandler holding the content.

Returns:
a DataHandler with the content
Throws:
javax.mail.MessagingException - if an error occurs when fetching the data handler

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException,
                                          javax.mail.MessagingException
Returns an InputStream from which the content can be read. Any mail-specific transfer encodings will be decoded before the input stream is provided.

Returns:
an InputStream holding from which the content can be read
Throws:
java.io.IOException - if an I/O error occurs when getting the input stream from the inherent data handler
javax.mail.MessagingException - if an error occurs when fetching the inherent data handler

setContentContentTransferEncoding

public void setContentContentTransferEncoding(java.lang.String cte)
Sets the content transfer encoding of the entity to be signed. This method allows to set the content transfer encoding for the inner entity when method setText or setDataHandler has been used for supplying the content. This method maybe called BEFORE setting the content (to avoid header update overhead during the saveChanges run).

Parameters:
cte - the content transfer encoding to be applied to the inner entity to be signed

setContentContentHeaders

public void setContentContentHeaders(javax.mail.Header[] headers)
Set some headers for the entity to be signed. This method allows to set some headers for the inner entity when method setText or setDataHandler has been used for supplying the content. This method maybe called BEFORE setting the content (to avoid header update overhead during the saveChanges run).

Parameters:
headers - the headers to be applied to the inner entity to be signed

setBlockSize

public void setBlockSize(int blockSize)
Sets the block size for defining the length of each definite primitive encoded octet string component. If the value of blockSize is smaller or equal to zero the whole encrypted data is encoded as definite primitive octet string.

Parameters:
blockSize - for defining the encoding scheme and setting the octet string component length, if positive

This Javadoc may contain text parts from text parts from IETF Internet Standard specifications (see copyright note).

IAIK-CMS 6.0, (c) 2002 IAIK, (c) 2003, 2023 SIC