Search in sources :

Example 1 with DataHandlerWrapper

use of org.apache.axiom.util.activation.DataHandlerWrapper in project webservices-axiom by apache.

the class MIMEOutputUtils method writeDataHandlerWithAttachmentsMessage.

/**
     * @deprecated Use {@link OMMultipartWriter} instead.
     */
public static void writeDataHandlerWithAttachmentsMessage(DataHandler rootDataHandler, final String contentType, OutputStream outputStream, Map attachments, OMOutputFormat format, Collection ids) {
    try {
        if (!rootDataHandler.getContentType().equals(contentType)) {
            rootDataHandler = new DataHandlerWrapper(rootDataHandler) {

                @Override
                public String getContentType() {
                    return contentType;
                }
            };
        }
        OMMultipartWriter mpw = new OMMultipartWriter(outputStream, format);
        mpw.writePart(rootDataHandler, format.getRootContentId());
        Iterator idIterator = null;
        if (ids == null) {
            // If ids are not provided, use the attachment map
            // to get the keys
            idIterator = attachments.keySet().iterator();
        } else {
            // if ids are provided (normal case), iterate
            // over the ids so that the attachments are 
            // written in the same order as the id keys.
            idIterator = ids.iterator();
        }
        while (idIterator.hasNext()) {
            String key = (String) idIterator.next();
            mpw.writePart((DataHandler) attachments.get(key), key);
        }
        mpw.complete();
        outputStream.flush();
    } catch (IOException e) {
        throw new OMException("Error while writing to the OutputStream.", e);
    }
}
Also used : Iterator(java.util.Iterator) IOException(java.io.IOException) OMException(org.apache.axiom.om.OMException) DataHandlerWrapper(org.apache.axiom.util.activation.DataHandlerWrapper)

Aggregations

IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 OMException (org.apache.axiom.om.OMException)1 DataHandlerWrapper (org.apache.axiom.util.activation.DataHandlerWrapper)1