com.mirth.connect.server.userutil
Class AttachmentUtil

java.lang.Object
  extended by com.mirth.connect.server.userutil.AttachmentUtil

public class AttachmentUtil
extends java.lang.Object

Provides utility methods for creating, retrieving, and re-attaching message attachments.


Method Summary
static Attachment addAttachment(java.util.List<Attachment> attachments, java.lang.Object content, java.lang.String type)
          Creates an Attachment and adds it to the provided list.
static Attachment createAttachment(ImmutableConnectorMessage connectorMessage, java.lang.Object content, java.lang.String type)
          Creates an attachment associated with a given connector message, and inserts it into the database.
static java.util.List<Attachment> getMessageAttachments(ImmutableConnectorMessage connectorMessage)
          Retrieves all attachments associated with a connector message.
static java.util.List<Attachment> getMessageAttachments(MessageObject messageObject)
          Deprecated. This method is deprecated and will soon be removed. Please use getMessageAttachments(connectorMessage) instead.
static java.lang.String reAttachMessage(ImmutableConnectorMessage connectorMessage)
          Replaces any unique attachment tokens (e.g.
static java.lang.String reAttachMessage(MessageObject messageObject)
          Deprecated. This method is deprecated and will soon be removed. Please use reAttachMessage(connectorMessage) instead.
static java.lang.String reAttachMessage(java.lang.String raw, ImmutableConnectorMessage connectorMessage)
          Replaces any unique attachment tokens (e.g.
static byte[] reAttachMessage(java.lang.String raw, ImmutableConnectorMessage connectorMessage, java.lang.String charsetEncoding, boolean binary)
          Replaces any unique attachment tokens (e.g.
static java.lang.String reAttachRawMessage(ImmutableConnectorMessage connectorMessage)
          Deprecated. This method is deprecated and will soon be removed. Please use reAttachMessage(raw, connectorMessage) instead.
static java.lang.String reAttachRawMessage(MessageObject messageObject)
          Deprecated. This method is deprecated and will soon be removed. Please use reAttachMessage(raw, connectorMessage) instead.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

reAttachMessage

public static byte[] reAttachMessage(java.lang.String raw,
                                     ImmutableConnectorMessage connectorMessage,
                                     java.lang.String charsetEncoding,
                                     boolean binary)
Replaces any unique attachment tokens (e.g. "${ATTACH:id}") with the corresponding attachment content, and returns the full post-replacement message as a byte array.

Parameters:
raw - The message string to re-attach attachments to.
connectorMessage - The connector message associated with the attachments.
charsetEncoding - The charset encoding to use when returning the re-attached message
binary - If true, the message string passed in is assumed to be Base64 encoded.
Returns:
The resulting message as a byte array, with all applicable attachment content re-inserted.

reAttachMessage

public static java.lang.String reAttachMessage(MessageObject messageObject)
Deprecated. This method is deprecated and will soon be removed. Please use reAttachMessage(connectorMessage) instead.

Replaces any unique attachment tokens (e.g. "${ATTACH:id}") with the corresponding attachment content, and returns the full post-replacement message.

Parameters:
messageObject - The connector message associated with the attachments. The encoded data will be used as the raw message string to re-attach attachments to, if it exists. Otherwise, the connector message's raw data will be used.
Returns:
The resulting message with all applicable attachment content re-inserted.

reAttachMessage

public static java.lang.String reAttachMessage(ImmutableConnectorMessage connectorMessage)
Replaces any unique attachment tokens (e.g. "${ATTACH:id}") with the corresponding attachment content, and returns the full post-replacement message.

Parameters:
connectorMessage - The connector message associated with the attachments. The encoded data will be used as the raw message string to re-attach attachments to, if it exists. Otherwise, the connector message's raw data will be used.
Returns:
The resulting message with all applicable attachment content re-inserted.

reAttachRawMessage

public static java.lang.String reAttachRawMessage(MessageObject messageObject)
Deprecated. This method is deprecated and will soon be removed. Please use reAttachMessage(raw, connectorMessage) instead.

Replaces any unique attachment tokens (e.g. "${ATTACH:id}") with the corresponding attachment content, and returns the full post-replacement message.

Parameters:
messageObject - The connector message associated with the attachments. The raw data will be used as the raw message string to re-attach attachments to.
Returns:
The resulting message with all applicable attachment content re-inserted.

reAttachRawMessage

public static java.lang.String reAttachRawMessage(ImmutableConnectorMessage connectorMessage)
Deprecated. This method is deprecated and will soon be removed. Please use reAttachMessage(raw, connectorMessage) instead.

Replaces any unique attachment tokens (e.g. "${ATTACH:id}") with the corresponding attachment content, and returns the full post-replacement message.

Parameters:
connectorMessage - The connector message associated with the attachments. The raw data will be used as the raw message string to re-attach attachments to.
Returns:
The resulting message with all applicable attachment content re-inserted.

reAttachMessage

public static java.lang.String reAttachMessage(java.lang.String raw,
                                               ImmutableConnectorMessage connectorMessage)
Replaces any unique attachment tokens (e.g. "${ATTACH:id}") with the corresponding attachment content, and returns the full post-replacement message.

Parameters:
raw - The message string to re-attach attachments to.
connectorMessage - The connector message associated with the attachments. The raw data will be used as the raw message string to re-attach attachments to.
Returns:
The resulting message with all applicable attachment content re-inserted.

getMessageAttachments

public static java.util.List<Attachment> getMessageAttachments(MessageObject messageObject)
                                                        throws com.mirth.connect.donkey.model.message.XmlSerializerException
Deprecated. This method is deprecated and will soon be removed. Please use getMessageAttachments(connectorMessage) instead.

Retrieves all attachments associated with a connector message.

Parameters:
messageObject - The connector message associated with the attachments.
Returns:
A list of attachments associated with the connector message.
Throws:
com.mirth.connect.donkey.model.message.XmlSerializerException

getMessageAttachments

public static java.util.List<Attachment> getMessageAttachments(ImmutableConnectorMessage connectorMessage)
                                                        throws com.mirth.connect.donkey.model.message.XmlSerializerException
Retrieves all attachments associated with a connector message.

Parameters:
connectorMessage - The connector message associated with the attachments.
Returns:
A list of attachments associated with the connector message.
Throws:
com.mirth.connect.donkey.model.message.XmlSerializerException

addAttachment

public static Attachment addAttachment(java.util.List<Attachment> attachments,
                                       java.lang.Object content,
                                       java.lang.String type)
                                throws javax.activation.UnsupportedDataTypeException
Creates an Attachment and adds it to the provided list.

Parameters:
attachments - The list of attachments to add to.
content - The attachment content (must be a string or byte array).
type - The MIME type of the attachment.
Returns:
The attachment added to the list.
Throws:
javax.activation.UnsupportedDataTypeException

createAttachment

public static Attachment createAttachment(ImmutableConnectorMessage connectorMessage,
                                          java.lang.Object content,
                                          java.lang.String type)
                                   throws javax.activation.UnsupportedDataTypeException
Creates an attachment associated with a given connector message, and inserts it into the database.

Parameters:
connectorMessage - The connector message to be associated with the attachment.
content - The attachment content (must be a string or byte array).
type - The MIME type of the attachment.
Returns:
The attachment that was created and inserted.
Throws:
javax.activation.UnsupportedDataTypeException