Search in sources :

Example 26 with Binary

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;
}
Also used : Binary(com.dexels.navajo.document.types.Binary)

Example 27 with Binary

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);
    }
}
Also used : MimeBodyPart(javax.mail.internet.MimeBodyPart) BodyPart(javax.mail.BodyPart) InternetAddress(javax.mail.internet.InternetAddress) MimeMultipart(javax.mail.internet.MimeMultipart) Multipart(javax.mail.Multipart) MessagingException(javax.mail.MessagingException) AttachmentMapInterface(com.dexels.navajo.adapter.mailmap.AttachmentMapInterface) DataHandler(javax.activation.DataHandler) BinaryDataSource(com.dexels.navajo.datasource.BinaryDataSource) MimeMessage(javax.mail.internet.MimeMessage) MimeMultipart(javax.mail.internet.MimeMultipart) AddressException(javax.mail.internet.AddressException) FileDataSource(javax.activation.FileDataSource) UserException(com.dexels.navajo.script.api.UserException) Binary(com.dexels.navajo.document.types.Binary) MimeBodyPart(javax.mail.internet.MimeBodyPart)

Example 28 with Binary

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();
}
Also used : SFTPResourceMap(com.dexels.navajo.resource.sftp.SFTPResourceMap) Access(com.dexels.navajo.script.api.Access) Binary(com.dexels.navajo.document.types.Binary) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 29 with Binary

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);
}
Also used : Binary(com.dexels.navajo.document.types.Binary) SFTPResource(com.dexels.navajo.resource.sftp.SFTPResource) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 30 with Binary

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);
}
Also used : HashMap(java.util.HashMap) Binary(com.dexels.navajo.document.types.Binary) URL(java.net.URL) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Binary (com.dexels.navajo.document.types.Binary)139 Test (org.junit.Test)38 IOException (java.io.IOException)32 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)26 File (java.io.File)25 Ignore (org.junit.Ignore)17 Property (com.dexels.navajo.document.Property)16 URL (java.net.URL)16 UserException (com.dexels.navajo.script.api.UserException)14 OutputStream (java.io.OutputStream)13 FileOutputStream (java.io.FileOutputStream)12 Navajo (com.dexels.navajo.document.Navajo)11 MappableException (com.dexels.navajo.script.api.MappableException)11 FileInputStream (java.io.FileInputStream)9 InputStream (java.io.InputStream)9 Message (com.dexels.navajo.document.Message)8 StringWriter (java.io.StringWriter)8 OutputStreamWriter (java.io.OutputStreamWriter)7 NavajoException (com.dexels.navajo.document.NavajoException)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6