// Check that content has not already been added. For this sample there
// is no point in attaching the same file twice. Note that every
// MessagePart contained within a MultipartMessage must have a unique
// content id.
for (int i = 0; i < getMessageParts().getNumberOfRows(); i++) {
final MessagePart messagePart =
(MessagePart) getMessageParts().getRow(i);
final String contentLocation = messagePart.getContentLocation();
if (contentLocation.equals(FOLDER_NAMES[type] + '0'
+ EXTENSIONS[type])) {
exists = true;
}
}
if (!exists) {
// Obtain content data from project resource
final String filename = FOLDER_NAMES[type] + "0" + EXTENSIONS[type];
final StringBuffer path = new StringBuffer("/media/");
path.append(FOLDER_NAMES[type]);
path.append("/");
path.append(filename);
final InputStream inputStream =
getClass().getResourceAsStream(path.toString());
try {
final byte[] contentData =
IOUtilities.streamToBytes(inputStream);
// Create a MessagePart object with the contentData and add it
// to the message parts vector
final MessagePart messagePart =
new MessagePart(contentData, MIME_TYPES[type],
FOLDER_NAMES[type], filename, null);
addMessagePart(messagePart);
} catch (final IOException ioe) {
errorDialog(ioe.toString());
}