use of javax.activation.DataHandler in project nhin-d by DirectProject.
the class DefaultXdsDirectDocumentsTransformer method transform.
@Override
public DirectDocuments transform(ProvideAndRegisterDocumentSetRequestType provideAndRegisterDocumentSetRequestType) throws TransformationException {
DirectDocuments documents = new DirectDocuments();
try {
documents.setValues(provideAndRegisterDocumentSetRequestType.getSubmitObjectsRequest());
} catch (MetadataException e) {
throw new TransformationException("Unable to complete transformation due to metadata error", e);
}
for (ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType.Document document : provideAndRegisterDocumentSetRequestType.getDocument()) {
byte[] data = null;
try {
DataHandler dataHandler = document.getValue();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
dataHandler.writeTo(outputStream);
data = outputStream.toByteArray();
} catch (IOException e) {
throw new TransformationException("Unable to complete transformation due to document IO error", e);
}
DirectDocument2 doc = documents.getDocumentByUniqueId(document.getId());
if (doc != null) {
doc.setData(data);
} else {
documents.getDocumentById(document.getId()).setData(data);
}
}
return documents;
}
use of javax.activation.DataHandler in project nhin-d by DirectProject.
the class DefaultXdmXdsTransformerTest method getSampleXdmAsDataHandler.
/**
* Return a sample XDM file as a DataHandler.
*
* @return a sample XDM file.
*/
private static DataHandler getSampleXdmAsDataHandler() {
URL url = DefaultXdmXdsTransformerTest.class.getClassLoader().getResource("samplexdm.zip");
DataHandler dh = new DataHandler(url);
return dh;
}
use of javax.activation.DataHandler in project opennms by OpenNMS.
the class JavaMailer2 method createFileAttachment.
/*
public Message buildMessage(String m_charSet, String m_encoding, String m_contentType) throws JavaMailerException {
try {
String encodedText = MimeUtility.encodeText(getMessageText(), m_charSet, m_encoding);
if (getFileName() == null) {
message.setContent(encodedText, m_contentType+"; charset="+m_charSet);
} else {
BodyPart bp = new MimeBodyPart();
bp.setContent(encodedText, m_contentType+"; charset="+m_charSet);
MimeMultipart mp = new MimeMultipart();
mp.addBodyPart(bp);
mp = new MimeMultipart();
mp.addBodyPart(createFileAttachment(new File(getFileName())));
message.setContent(mp);
}
message.setHeader("X-Mailer", getMailer());
message.setSentDate(new Date());
message.saveChanges();
return message;
} catch (AddressException e) {
log().error("Java Mailer Addressing exception: ", e);
throw new JavaMailerException("Java Mailer Addressing exception: ", e);
} catch (MessagingException e) {
log().error("Java Mailer messaging exception: ", e);
throw new JavaMailerException("Java Mailer messaging exception: ", e);
} catch (UnsupportedEncodingException e) {
log().error("Java Mailer messaging exception: ", e);
throw new JavaMailerException("Java Mailer encoding exception: ", e);
}
}
*/
/**
* Create a file attachment as a MimeBodyPart, checking to see if the file
* exists before we create the attachment.
*
* @param file file to attach
* @return attachment body part
* @throws javax.mail.MessagingException if we can't set the data handler or
* the file name on the MimeBodyPart
* @throws org.opennms.javamail.JavaMailerException if the file does not exist or is not
* readable
*/
public MimeBodyPart createFileAttachment(final File file) throws MessagingException, JavaMailerException {
if (!file.exists()) {
LOG.error("File attachment '{}' does not exist.", file.getAbsolutePath());
throw new JavaMailerException("File attachment '" + file.getAbsolutePath() + "' does not exist.");
}
if (!file.canRead()) {
LOG.error("File attachment '{}' is not readable.", file.getAbsolutePath());
throw new JavaMailerException("File attachment '" + file.getAbsolutePath() + "' is not readable.");
}
MimeBodyPart bodyPart = new MimeBodyPart();
FileDataSource fds = new FileDataSource(file);
bodyPart.setDataHandler(new DataHandler(fds));
bodyPart.setFileName(fds.getName());
return bodyPart;
}
use of javax.activation.DataHandler in project zm-mailbox by Zimbra.
the class JavaMailMimeBodyPart method setContent.
@Override
public void setContent(Object o, String type) throws MessagingException {
if (ZPARSER) {
com.zimbra.common.mime.ContentType ctype = new com.zimbra.common.mime.ContentType(type);
if (o instanceof JavaMailMimeMultipart) {
setContent((Multipart) o);
setHeader("Content-Type", type);
} else if (o instanceof JavaMailMimeMessage) {
replaceInParent(((JavaMailMimeMessage) o).getZimbraMimeMessage());
setHeader("Content-Type", type);
this.jmcontent = o;
} else if (o instanceof String) {
if (ctype.getPrimaryType().equals("text")) {
setText((String) o, ctype.getParameter("charset"), ctype.getSubType());
setHeader("Content-Type", type);
} else {
try {
setDataSource(new ByteArrayDataSource((String) o, type));
} catch (IOException ioe) {
throw new MessagingException("error setting string content", ioe);
}
}
} else {
setDataHandler(new DataHandler(o, type));
}
} else {
super.setContent(o, type);
}
}
use of javax.activation.DataHandler in project zm-mailbox by Zimbra.
the class JavaMailMimeMessage method setContent.
@Override
public void setContent(Object o, String type) throws MessagingException {
if (ZPARSER) {
com.zimbra.common.mime.ContentType ctype = new com.zimbra.common.mime.ContentType(type);
if (o instanceof JavaMailMimeMultipart) {
setContent((Multipart) o);
setHeader("Content-Type", type);
} else if (o instanceof JavaMailMimeMessage) {
zmessage.setBodyPart(((JavaMailMimeMessage) o).getZimbraMimeMessage());
setHeader("Content-Type", type);
jmcontent = o;
} else if (o instanceof String) {
if (ctype.getPrimaryType().equals("text")) {
setText((String) o, ctype.getParameter("charset"), ctype.getSubType());
setHeader("Content-Type", type);
} else {
try {
setDataSource(new ByteArrayDataSource((String) o, type));
} catch (IOException ioe) {
throw new MessagingException("error setting string content", ioe);
}
}
} else {
setDataHandler(new DataHandler(o, type));
}
} else {
super.setContent(o, type);
}
}
Aggregations