Example usage for javax.activation FileDataSource FileDataSource

List of usage examples for javax.activation FileDataSource FileDataSource

Introduction

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

Prototype

public FileDataSource(String name) 

Source Link

Document

Creates a FileDataSource from the specified path name.

Usage

From source file:org.wso2.carbon.service.mgt.ServiceAdmin.java

/**
 * Downloads service archive files//w ww. j  a  v  a 2  s .com
 *
 * @param serviceGroupName name of the service group needs to be downloaded
 * @return the corresponding data handler and the name of the service archive / file that's downloaded
 */
public ServiceDownloadData downloadServiceArchive(String serviceGroupName) {
    AxisConfiguration axisConfig = getAxisConfig();
    AxisServiceGroup asGroup = axisConfig.getServiceGroup(serviceGroupName);
    String fileName = null;
    for (Iterator<AxisService> serviceIter = asGroup.getServices(); serviceIter.hasNext();) {
        AxisService axisService = serviceIter.next();
        URL fn = axisService.getFileName();
        if (fn != null) {
            fileName = fn.getPath();
        }
    }
    DataHandler handler;
    if (fileName != null) {
        File file = new File(fileName);
        FileDataSource datasource = new FileDataSource(file);
        handler = new DataHandler(datasource);

        ServiceDownloadData data = new ServiceDownloadData();
        data.setFileName(file.getName());
        data.setServiceFileData(handler);
        return data;
    } else {
        return null;
    }

}

From source file:FirstStatMain.java

private void btnsendemailActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnsendemailActionPerformed
    final String senderemail = txtEmailfrom.getText();
    final String sendPass = txtPassword.getText();
    String send_to = txtEmailto.getText();
    String email_sub = txtemailsbj.getText();
    String email_body = tABody.getText();

    Properties prop = new Properties();
    prop.put("mail.smtp.host", "smtp.gmail.com");
    prop.put("mail.smtp.socketFactory.port", "465");
    prop.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
    prop.put("mail.smtp.auth", "true");
    prop.put("mail.smtp.port", "465");

    Session session = Session.getDefaultInstance(prop, new javax.mail.Authenticator() {
        @Override/*ww w. j  a  va  2  s  . c  o m*/
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(senderemail, sendPass);
        }
    });
    try {
        /* Message Header*/
        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress(senderemail));
        message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(send_to));
        message.setSubject(email_sub);
        /*setting text message*/
        MimeBodyPart messageBodyPart = new MimeBodyPart();
        messageBodyPart.setText(email_body);
        Multipart multipart = new MimeMultipart();
        multipart.addBodyPart(messageBodyPart);
        /*attaching file*/
        messageBodyPart = new MimeBodyPart();
        DataSource source = new FileDataSource(file_path);
        messageBodyPart.setDataHandler(new DataHandler(source));
        messageBodyPart.setFileName(txtattachmentname.getText());
        multipart.addBodyPart(messageBodyPart);

        message.setContent(multipart);
        Transport.send(message);
        JOptionPane.showMessageDialog(rootPane, "Message sent");
    } catch (Exception e) {
        JOptionPane.showMessageDialog(rootPane, e);
    }
}

From source file:it.cnr.icar.eric.client.ui.thin.RegistryObjectCollectionBean.java

/**
* This method will upload file in registry for Extrensic Objects 
* 
*//*ww  w. j a va2 s .co m*/
public String doUpload(File file, String contentType) {
    String status = "failure";
    RegistryObject ro = getCurrentRegistryObjectBean().getRegistryObject();
    if (ro instanceof ExtrinsicObject) {
        if (file == null) {
            append(WebUIResourceBundle.getInstance().getString("messgeFileUpload"));
            log.error(WebUIResourceBundle.getInstance()
                    .getString("message.NullFileObjectPassedToDoUploadMethod"));
        } else {
            try {
                DataHandler handler = new DataHandler(new FileDataSource(file));
                ((ExtrinsicObject) ro).setRepositoryItem(handler);
                if (contentType == null) {
                    log.error(WebUIResourceBundle.getInstance()
                            .getString("message.NullContentTypePassedToDoUploadMethod"));
                } else {
                    ((ExtrinsicObject) ro).setMimeType(contentType);
                }
                status = "success";
            } catch (JAXRException ex) {
                String errMsg = WebUIResourceBundle.getInstance().getString("errorUploadingFile");
                append(errMsg + " " + ex.getMessage());
                log.error(errMsg + " " + ex.getMessage());
            }
        }
    }
    return status;
}