Package com.volantis.mps.attachment

Examples of com.volantis.mps.attachment.DeviceMessageAttachment


     */
    private MimeMultipart addAttachments( MimeMultipart mimeMultipart,
                                          MessageAttachments attachments ) {
        Iterator itr = attachments.iterator();
        while( itr.hasNext() ) {
            DeviceMessageAttachment attachment =
                    ( DeviceMessageAttachment ) itr.next();
            DataSource ds;
            BodyPart bodyPart;

            try {
                if( attachment.getValueType() == MessageAttachment.FILE ) {
                    // The attachment is a file type so create a FileDataSource
                    ds = new FileDataSource( attachment.getValue() );
                } else {
                    // If for some reason the URL does not return a content
                    // type then this type of datasource defaults to
                    // application/octet-stream.
                    ds = new URLDataSource( new URL( attachment.getValue() ) );
                }

                bodyPart = new MimeBodyPart();
                bodyPart.setDataHandler( new DataHandler( ds ) );
                bodyPart.setDisposition( Part.ATTACHMENT );
                bodyPart.setFileName( getFileName( attachment.getValue(),
                                                   attachment.getMimeType() ) );
            } catch( Exception me ) {
                // If we catch an exception above we might as well
                // skip this attachment
                logger.error( "body-part-creation-failure-skipping-attachment",
                              me );
                continue;
            }
            try {
                String bodyMimeType = bodyPart.getContentType();
                String messageMimeType = attachment.getMimeType();

                // Check if the Content-Type determined by the DataHandler
                // is the same or a more specific than the mimeType specified
                // in the attachment. E.g. "text/html; charset=us-ascii" as
                // against "text/html;" If it is more specific then leave as is,
View Full Code Here


            MessageAttachments clonedAttachments = new MessageAttachments();
            if( messageAttachments != null ) {
                i = messageAttachments.iterator();
                while (i.hasNext()) {
                    DeviceMessageAttachment clonedAttachment =
                        (DeviceMessageAttachment)i.next();

                    clonedAttachments.addAttachment(clonedAttachment);
                }
                clone.addAttachments(clonedAttachments);
View Full Code Here

        MultiChannelMessage message = new MultiChannelMessageImpl();

        MessageAttachments attachments = new MessageAttachments();

        DeviceMessageAttachment attachment = new DeviceMessageAttachment();

        String attachmentChannel = "SMTP";
        String attachmentDevice = "Outlook";
        String attachmentMimeType = "text/plain";
        String attachmentValue = LOCAL_FILE_URLS[0];

        attachment.setChannelName(attachmentChannel);
        attachment.setDeviceName(attachmentDevice);
        attachment.setMimeType(attachmentMimeType);
        attachment.setValue(attachmentValue);
        attachment.setValueType(DeviceMessageAttachment.URL);

        attachments.addAttachment(attachment);

        message.addAttachments(attachments);

        MessageAttachments retrievedMessageAttachments =
                message.getAttachments();

        Iterator i = retrievedMessageAttachments.iterator();

        int count = 0;

        while (i.hasNext()) {
            count++;
            DeviceMessageAttachment retrievedAttachment =
                    (DeviceMessageAttachment) i.next();
            assertEquals(retrievedAttachment.getChannelName(),
                    attachmentChannel);
            assertEquals(retrievedAttachment.getDeviceName(),
                    attachmentDevice);
            assertEquals(retrievedAttachment.getMimeType(),
                    attachmentMimeType);
            assertEquals(retrievedAttachment.getValue(),
                    attachmentValue);
        }

        if (count != 1) {
            fail("Expected one attachment got " + count);
View Full Code Here

        String[] attachmentValues = { LOCAL_FILE_URLS[0],
                                      LOCAL_FILE_URLS[1],
                                      LOCAL_FILE_URLS[2] };

        for (int n = 0; n < attachmentValues.length; n++) {
            DeviceMessageAttachment attachment = new DeviceMessageAttachment();

            attachment.setChannelName(attachmentChannel);
            attachment.setDeviceName(attachmentDevice);
            attachment.setMimeType(attachmentMimeType);
            attachment.setValue(attachmentValues[n]);
            attachment.setValueType(DeviceMessageAttachment.URL);

            attachments.addAttachment(attachment);
        }

        message.addAttachments(attachments);
View Full Code Here

        MultiChannelMessage message = new MultiChannelMessageImpl();

        MessageAttachments attachments = new MessageAttachments();

        DeviceMessageAttachment attachment = new DeviceMessageAttachment();

        String attachmentChannel = "SMTP";
        String attachmentDevice = "Outlook";
        String attachmentMimeType = "text/plain";
        String attachmentValue = LOCAL_FILE_URLS[0];

        attachment.setChannelName(attachmentChannel);
        attachment.setDeviceName(attachmentDevice);
        attachment.setMimeType(attachmentMimeType);
        attachment.setValue(attachmentValue);
        attachment.setValueType(DeviceMessageAttachment.URL);

        attachments.addAttachment(attachment);

        message.addAttachments(attachments);

        MessageAttachments retrievedMessageAttachments =
                message.getAttachments();

        Iterator i = retrievedMessageAttachments.iterator();

        int count = 0;

        while (i.hasNext()) {
            count++;
            DeviceMessageAttachment retrievedAttachment =
                    (DeviceMessageAttachment) i.next();
            assertEquals(retrievedAttachment.getChannelName(),
                    attachmentChannel);
            assertEquals(retrievedAttachment.getDeviceName(),
                    attachmentDevice);
            assertEquals(retrievedAttachment.getMimeType(),
                    attachmentMimeType);
            assertEquals(retrievedAttachment.getValue(),
                    attachmentValue);
        }

        if (count != 1) {
            fail("Expected one attachment got " + count);
View Full Code Here

        String headerMHTMLName = "HeaderMHTML1";
        String headerMHTMLValue = "value1";

        MessageAttachments attachments = new MessageAttachments();

        DeviceMessageAttachment attachment = new DeviceMessageAttachment();

        String attachmentChannel = "SMTP";
        String attachmentDevice = "Outlook";
        String attachmentMimeType = "text/plain";
        String attachmentValue = LOCAL_FILE_URLS[0];

        MultiChannelMessageImpl message = new MultiChannelMessageImpl();

        message.setMessage(messageText);
        message.setMessageURL(url);
        message.setSubject(subject);
        message.addHeader(MultiChannelMessage.ALL,
                headerAllName,
                headerAllValue);
        message.addHeader(MultiChannelMessage.MMS,
                headerMMSName,
                headerMMSValue);
        message.addHeader(MultiChannelMessage.MHTML,
                headerMHTMLName,
                headerMHTMLValue);


        attachment.setChannelName(attachmentChannel);
        attachment.setDeviceName(attachmentDevice);
        attachment.setMimeType(attachmentMimeType);
        attachment.setValue(attachmentValue);
        attachment.setValueType(DeviceMessageAttachment.URL);

        attachments.addAttachment(attachment);

        message.addAttachments(attachments);

        MultiChannelMessage clone = (MultiChannelMessage) message.clone();

        message.removeAttachments();
        message.setMessage(null);
        message.setMessageURL(null);
        message.setSubject(null);
        message = null;

        assertEquals(clone.getMessage(), messageText);
        assertEquals(clone.getMessageURL(), url);
        assertEquals(clone.getSubject(), subject);

        MessageAttachments retrievedMessageAttachments =
                clone.getAttachments();

        Iterator i = retrievedMessageAttachments.iterator();

        int count = 0;

        while (i.hasNext()) {
            count++;
            DeviceMessageAttachment retrievedAttachment =
                    (DeviceMessageAttachment) i.next();
            assertEquals(retrievedAttachment.getChannelName(),
                    attachmentChannel);
            assertEquals(retrievedAttachment.getDeviceName(),
                    attachmentDevice);
            assertEquals(retrievedAttachment.getMimeType(),
                    attachmentMimeType);
            assertEquals(retrievedAttachment.getValue(),
                    attachmentValue);
        }

        if (count != 1) {
            fail("Expected one attachment got " + count);
View Full Code Here

                "attachmentMimeType");

        MessageAttachments messageAttachments = new MessageAttachments();
        for (int i = 0; i < attachment.length; i++) {
            if (!attachment[i].equals("")) {
                DeviceMessageAttachment dma = new DeviceMessageAttachment();
                try {
                    dma.setChannelName(attachmentChannel[i]);
                    dma.setDeviceName(attachmentDevice[i]);
                    dma.setValue(attachment[i]);
                    dma.setValueType(Integer.parseInt(attachmentValueType[i]));
                    if (!attachmentMimeType[i].equals("")) {
                        dma.setMimeType(attachmentMimeType[i]);
                    }
                    messageAttachments.addAttachment(dma);
                } catch (MessageException me) {
                    logger.error("Failed to create attachment for " + attachment[i],
                        me);
View Full Code Here

TOP

Related Classes of com.volantis.mps.attachment.DeviceMessageAttachment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.