use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.
the class XMLMap method getContent.
public Binary getContent() {
String r = getString();
byte[] bytes = r.getBytes(StandardCharsets.UTF_8);
Binary b = new Binary(bytes);
if (debug) {
logger.debug(new String(bytes));
}
return b;
}
use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.
the class ResourceComponent method send.
@Override
public void send(String from, String[] to, String[] cc, String[] bcc, String subject, String body, List<AttachmentMapInterface> attachments, String contentType, boolean relatedMultipart) throws UserException {
javax.mail.Message msg = new MimeMessage(session);
if (from == null || "".equals(from)) {
throw new UserException(-1, "Error: Required sender address not set!");
}
try {
msg.setFrom(new InternetAddress(from));
InternetAddress[] addresses = new InternetAddress[to.length];
for (int i = 0; i < to.length; i++) {
addresses[i] = new InternetAddress(to[i]);
}
msg.setRecipients(javax.mail.Message.RecipientType.TO, addresses);
if (cc != null) {
InternetAddress[] extra = new InternetAddress[cc.length];
for (int i = 0; i < cc.length; i++) {
extra[i] = new InternetAddress(cc[i]);
}
msg.setRecipients(javax.mail.Message.RecipientType.CC, extra);
}
if (bcc != null) {
InternetAddress[] extra = new InternetAddress[bcc.length];
for (int i = 0; i < bcc.length; i++) {
extra[i] = new InternetAddress(bcc[i]);
}
msg.setRecipients(javax.mail.Message.RecipientType.BCC, extra);
}
msg.setSubject(subject);
msg.setSentDate(new java.util.Date());
if (attachments == null && contentType.equals("text/plain")) {
msg.setText(body);
} else {
Multipart multipart = (relatedMultipart ? new MimeMultipart("related") : new MimeMultipart());
BodyPart textBody = new MimeBodyPart();
textBody.setContent(body, contentType);
multipart.addBodyPart(textBody);
if (attachments != null) {
for (int i = 0; i < attachments.size(); i++) {
AttachmentMapInterface am = attachments.get(i);
String file = am.getAttachFile();
String userFileName = am.getAttachFileName();
Binary content = am.getAttachFileContent();
String encoding = am.getEncoding();
MimeBodyPart bp = new MimeBodyPart();
if (file != null) {
if (userFileName == null) {
userFileName = file;
}
FileDataSource fileDatasource = new FileDataSource(file);
bp.setDataHandler(new DataHandler(fileDatasource));
} else if (content != null) {
BinaryDataSource bds = new BinaryDataSource(content, "");
DataHandler dh = new DataHandler(bds);
bp.setDataHandler(dh);
if (encoding != null) {
bp.setHeader("Content-Transfer-Encoding", encoding);
encoding = null;
}
}
bp.setFileName(userFileName);
if (relatedMultipart) {
bp.setHeader("Content-ID", "<attach-nr-" + i + ">");
}
// iPhone headers
// bp.setDisposition("attachment");
bp.setDisposition(am.getAttachContentDisposition());
multipart.addBodyPart(bp);
}
}
msg.setContent(multipart);
}
Transport.send(msg);
} catch (AddressException e) {
throw new UserException("Error sending mail:", e);
} catch (MessagingException e) {
throw new UserException("Error sending mail:", e);
}
}
use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.
the class SFTPResourceTest method testSFTPResourceMap.
@Test
@Ignore
public void testSFTPResourceMap() throws MappableException, UserException {
SFTPResourceMap sf = new SFTPResourceMap();
sf.load(new Access());
sf.setResource("test");
sf.setPath("/share");
sf.setFilename("monkey.gif");
Binary b = new Binary(getClass().getResourceAsStream("logo.gif"));
sf.setContent(b);
sf.store();
}
use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.
the class SFTPResourceTest method testSFTP.
@Test
@Ignore
public void testSFTP() throws MappableException, UserException, IOException {
SFTPResource res = SFTPResourceFactory.getInstance().getHttpResource("test");
Binary b = new Binary(getClass().getResourceAsStream("logo.gif"));
res.send("/share", "monkey2.gif", b);
}
use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.
the class TestSwift method testBrokenMime.
@Test
@Ignore
public void testBrokenMime() throws IOException {
Map<String, String> meta = new HashMap<String, String>();
meta.put("aap", "noot");
URL u = new URL("https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png");
Binary b = new Binary(u, true);
osi.store(b);
// osi.set("test/factory","blablalba", b, meta);
}
Aggregations