Example usage for javax.activation CommandMap getDefaultCommandMap

List of usage examples for javax.activation CommandMap getDefaultCommandMap

Introduction

In this page you can find the example usage for javax.activation CommandMap getDefaultCommandMap.

Prototype

public static synchronized CommandMap getDefaultCommandMap() 

Source Link

Document

Get the default CommandMap.

Usage

From source file:gov.nih.nci.cacis.nav.AbstractSendMail.java

/**
 * Set default command cap to support signing, encrypting and multipart
 *//*from  w w w  .  jav  a2s . c  om*/
protected void setCommandCap() {
    final MailcapCommandMap mailcap = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
    // CHECKSTYLE:OFF
    mailcap.addMailcap(
            "application/pkcs7-signature;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.pkcs7_signature");
    mailcap.addMailcap(
            "application/pkcs7-mime;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.pkcs7_mime");
    mailcap.addMailcap(
            "application/x-pkcs7-signature;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.x_pkcs7_signature");
    mailcap.addMailcap(
            "application/x-pkcs7-mime;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.x_pkcs7_mime");
    mailcap.addMailcap(
            "multipart/signed;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.multipart_signed");
    // CHECKSTYLE:ON
    CommandMap.setDefaultCommandMap(mailcap);
}

From source file:uk.ac.gda.dls.client.feedback.FeedbackDialog.java

@Override
protected void createButtonsForButtonBar(Composite parent) {

    GridData data = new GridData(SWT.FILL, SWT.FILL, false, true, 4, 1);
    GridLayout layout = new GridLayout(5, false);
    parent.setLayoutData(data);/*from www . j a  v  a  2s. c o m*/
    parent.setLayout(layout);

    Button attachButton = new Button(parent, SWT.TOGGLE);
    attachButton.setText("Attach File(s)");
    attachButton.setToolTipText("Add files to feedback");

    final Button screenGrabButton = new Button(parent, SWT.CHECK);
    screenGrabButton.setText("Include Screenshot");
    screenGrabButton.setToolTipText("Send screenshot with feedback");

    Label space = new Label(parent, SWT.NONE);
    space.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));

    Button sendButton = new Button(parent, SWT.PUSH);
    sendButton.setText("Send");

    Button cancelButton = new Button(parent, SWT.PUSH);
    cancelButton.setText("Cancel");

    sendButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {

            final String name = nameText.getText();
            final String email = emailText.getText();
            final String subject = subjectText.getText();
            final String description = descriptionText.getText();

            fileList = attachedFileList.getItems();

            Job job = new Job("Send feedback email") {
                @Override
                protected IStatus run(IProgressMonitor monitor) {

                    try {
                        final String recipientsProperty = LocalProperties.get("gda.feedback.recipients",
                                "dag-group@diamond.ac.uk");
                        final String[] recipients = recipientsProperty.split(" ");
                        for (int i = 0; i < recipients.length; i++) {
                            recipients[i] = recipients[i].trim();
                        }

                        final String from = String.format("%s <%s>", name, email);

                        final String beamlineName = LocalProperties.get("gda.beamline.name",
                                "Beamline Unknown");
                        final String mailSubject = String.format("[GDA feedback - %s] %s",
                                beamlineName.toUpperCase(), subject);

                        final String smtpHost = LocalProperties.get("gda.feedback.smtp.host", "localhost");

                        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
                        mailSender.setHost(smtpHost);

                        MimeMessage message = mailSender.createMimeMessage();
                        final MimeMessageHelper helper = new MimeMessageHelper(message,
                                (FeedbackDialog.this.hasFiles && fileList.length > 0)
                                        || FeedbackDialog.this.screenshot);
                        helper.setFrom(from);
                        helper.setTo(recipients);
                        helper.setSubject(mailSubject);
                        helper.setText(description);

                        if (FeedbackDialog.this.screenshot) {
                            PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                                @Override
                                public void run() {
                                    String fileName = "/tmp/feedbackScreenshot.png";
                                    try {
                                        captureScreen(fileName);
                                        FileSystemResource file = new FileSystemResource(new File(fileName));
                                        helper.addAttachment(file.getFilename(), file);
                                    } catch (Exception e) {
                                        logger.error("Could not attach screenshot to feedback", e);
                                    }
                                }
                            });
                        }

                        if (FeedbackDialog.this.hasFiles) {
                            for (String fileName : fileList) {
                                FileSystemResource file = new FileSystemResource(new File(fileName));
                                helper.addAttachment(file.getFilename(), file);
                            }
                        }

                        {//required to workaround class loader issue with "no object DCH..." error
                            MailcapCommandMap mc = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
                            mc.addMailcap(
                                    "text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain");
                            mc.addMailcap(
                                    "multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
                            CommandMap.setDefaultCommandMap(mc);
                        }
                        mailSender.send(message);
                        return Status.OK_STATUS;
                    } catch (Exception ex) {
                        logger.error("Could not send feedback", ex);
                        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, 1, "Error sending email", ex);
                    }

                }
            };

            job.schedule();

            setReturnCode(OK);
            close();
        }
    });

    cancelButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            setReturnCode(CANCEL);
            close();
        }
    });

    attachButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            hasFiles = !hasFiles;
            GridData data = ((GridData) attachments.getLayoutData());
            data.exclude = !hasFiles;
            attachments.setVisible(hasFiles);
            topParent.layout();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });

    screenGrabButton.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            screenshot = ((Button) e.widget).getSelection();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
}

From source file:com.zotoh.crypto.CryptoUte.java

private static void inizMapCap() {
    MailcapCommandMap mc = (MailcapCommandMap) CommandMap.getDefaultCommandMap();

    mc.addMailcap("application/pkcs7-signature;; "
            + "x-java-content-handler=org.bouncycastle.mail.smime.handlers.pkcs7_signature");

    mc.addMailcap("application/pkcs7-mime;; "
            + "x-java-content-handler=org.bouncycastle.mail.smime.handlers.pkcs7_mime");

    mc.addMailcap("application/x-pkcs7-signature;; " + ""
            + "x-java-content-handler=org.bouncycastle.mail.smime.handlers.x_pkcs7_signature");

    mc.addMailcap("application/x-pkcs7-mime;; "
            + "x-java-content-handler=org.bouncycastle.mail.smime.handlers.x_pkcs7_mime");

    mc.addMailcap("multipart/signed;; "
            + "x-java-content-handler=org.bouncycastle.mail.smime.handlers.multipart_signed");

}

From source file:org.apache.synapse.transport.mail.MailTransportSender.java

/**
 * Initialize the Mail sender and be ready to send messages
 * @param cfgCtx the axis2 configuration context
 * @param transportOut the transport-out description
 * @throws org.apache.axis2.AxisFault on error
 *//*w  ww  .j  a  v  a2s  .  c o  m*/
public void init(ConfigurationContext cfgCtx, TransportOutDescription transportOut) throws AxisFault {
    setTransportName(MailConstants.TRANSPORT_NAME);
    super.init(cfgCtx, transportOut);

    // initialize SMTP session
    Properties props = new Properties();
    List<Parameter> params = transportOut.getParameters();
    for (Parameter p : params) {
        props.put(p.getName(), p.getValue());
    }

    if (props.containsKey(MailConstants.MAIL_SMTP_FROM)) {
        try {
            smtpFromAddress = new InternetAddress((String) props.get(MailConstants.MAIL_SMTP_FROM));
        } catch (AddressException e) {
            handleException("Invalid default 'From' address : " + props.get(MailConstants.MAIL_SMTP_FROM), e);
        }
    }

    if (props.containsKey(MailConstants.MAIL_SMTP_BCC)) {
        try {
            smtpBccAddresses = InternetAddress.parse((String) props.get(MailConstants.MAIL_SMTP_BCC));
        } catch (AddressException e) {
            handleException("Invalid default 'Bcc' address : " + props.get(MailConstants.MAIL_SMTP_BCC), e);
        }
    }

    if (props.containsKey(MailConstants.TRANSPORT_MAIL_FORMAT)) {
        defaultMailFormat = (String) props.get(MailConstants.TRANSPORT_MAIL_FORMAT);
    }

    smtpUsername = (String) props.get(MailConstants.MAIL_SMTP_USERNAME);
    smtpPassword = (String) props.get(MailConstants.MAIL_SMTP_PASSWORD);

    if (smtpUsername != null && smtpPassword != null) {
        session = Session.getInstance(props, new Authenticator() {
            public PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(smtpUsername, smtpPassword);
            }
        });
    } else {
        session = Session.getInstance(props, null);
    }

    // add handlers for main MIME types
    MailcapCommandMap mc = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
    mc.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html");
    mc.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml");
    mc.addMailcap("application/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml");
    mc.addMailcap("application/soap+xml;; x-java-content-handler=com.sun.mail.handlers.text_xml");
    mc.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain");
    mc.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
    mc.addMailcap("message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822");
    CommandMap.setDefaultCommandMap(mc);

    session.setDebug(log.isTraceEnabled());
}