Search in sources :

Example 1 with ConfigurableDataHandler

use of org.apache.axiom.attachments.ConfigurableDataHandler in project webservices-axiom by apache.

the class MIMEOutputUtils method createMimeBodyPart.

/**
 * @deprecated This method is only useful in conjunction with
 *             {@link #writeBodyPart(OutputStream, MimeBodyPart, String)}, which is deprecated.
 */
public static MimeBodyPart createMimeBodyPart(String contentID, DataHandler dataHandler, OMOutputFormat omOutputFormat) throws MessagingException {
    String contentType = dataHandler.getContentType();
    // Get the content-transfer-encoding
    String contentTransferEncoding = "binary";
    if (dataHandler instanceof ConfigurableDataHandler) {
        ConfigurableDataHandler configurableDataHandler = (ConfigurableDataHandler) dataHandler;
        contentTransferEncoding = configurableDataHandler.getTransferEncoding();
    }
    if (log.isDebugEnabled()) {
        log.debug("Create MimeBodyPart");
        log.debug("  Content-ID = " + contentID);
        log.debug("  Content-Type = " + contentType);
        log.debug("  Content-Transfer-Encoding = " + contentTransferEncoding);
    }
    boolean useCTEBase64 = omOutputFormat != null && Boolean.TRUE.equals(omOutputFormat.getProperty(OMOutputFormat.USE_CTE_BASE64_FOR_NON_TEXTUAL_ATTACHMENTS));
    if (useCTEBase64) {
        if (!CommonUtils.isTextualPart(contentType) && "binary".equals(contentTransferEncoding)) {
            if (log.isDebugEnabled()) {
                log.debug(" changing Content-Transfer-Encoding from " + contentTransferEncoding + " to base-64");
            }
            contentTransferEncoding = "base64";
        }
    }
    // Now create the mimeBodyPart for the datahandler and add the appropriate content headers
    MimeBodyPart mimeBodyPart = new MimeBodyPart();
    mimeBodyPart.setDataHandler(dataHandler);
    mimeBodyPart.addHeader("Content-ID", "<" + contentID + ">");
    mimeBodyPart.addHeader("Content-Type", contentType);
    mimeBodyPart.addHeader("Content-Transfer-Encoding", contentTransferEncoding);
    return mimeBodyPart;
}
Also used : MimeBodyPart(javax.mail.internet.MimeBodyPart) ConfigurableDataHandler(org.apache.axiom.attachments.ConfigurableDataHandler)

Aggregations

MimeBodyPart (javax.mail.internet.MimeBodyPart)1 ConfigurableDataHandler (org.apache.axiom.attachments.ConfigurableDataHandler)1