Example usage for org.apache.commons.vfs FileObject getURL

List of usage examples for org.apache.commons.vfs FileObject getURL

Introduction

In this page you can find the example usage for org.apache.commons.vfs FileObject getURL.

Prototype

public URL getURL() throws FileSystemException;

Source Link

Document

Returns a URL representing this file.

Usage

From source file:org.pentaho.di.job.entries.hadooptransjobexecutor.DistributedCacheUtilTest.java

@Test
public void stagePluginsForCache() throws Exception {
    DistributedCacheUtil ch = new DistributedCacheUtil();

    Configuration conf = new Configuration();
    org.apache.hadoop.fs.FileSystem fs = org.apache.hadoop.fs.FileSystem.getLocal(conf);

    Path pluginsDir = new Path("bin/test/plugins-installation-dir");

    FileObject pluginDir = createTestFolderWithContent();

    try {/*  w  w w .ja  va2s  .  co  m*/
        ch.stagePluginsForCache(fs, pluginsDir, true, Arrays.asList(pluginDir));
        Path pluginInstallPath = new Path(pluginsDir, pluginDir.getURL().toURI().getPath());
        assertTrue(fs.exists(pluginInstallPath));
        ContentSummary summary = fs.getContentSummary(pluginInstallPath);
        assertEquals(3, summary.getFileCount());
        assertEquals(2, summary.getDirectoryCount());
    } finally {
        pluginDir.delete(new AllFileSelector());
        fs.delete(pluginsDir, true);
    }
}

From source file:org.pentaho.di.job.entries.mail.JobEntryMail.java

public Result execute(Result result, int nr) {
    File masterZipfile = null;//from w  ww.  j  a  v  a  2 s. c  o  m

    // Send an e-mail...
    // create some properties and get the default Session
    Properties props = new Properties();
    if (Const.isEmpty(server)) {
        logError(BaseMessages.getString(PKG, "JobMail.Error.HostNotSpecified"));

        result.setNrErrors(1L);
        result.setResult(false);
        return result;
    }

    String protocol = "smtp";
    if (usingSecureAuthentication) {
        if (secureConnectionType.equals("TLS")) {
            // Allow TLS authentication
            props.put("mail.smtp.starttls.enable", "true");
        } else {

            protocol = "smtps";
            // required to get rid of a SSL exception :
            // nested exception is:
            // javax.net.ssl.SSLException: Unsupported record version Unknown
            props.put("mail.smtps.quitwait", "false");
        }

    }

    props.put("mail." + protocol + ".host", environmentSubstitute(server));
    if (!Const.isEmpty(port)) {
        props.put("mail." + protocol + ".port", environmentSubstitute(port));
    }

    if (log.isDebug()) {
        props.put("mail.debug", "true");
    }

    if (usingAuthentication) {
        props.put("mail." + protocol + ".auth", "true");

        /*
         * authenticator = new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new
         * PasswordAuthentication( StringUtil.environmentSubstitute(Const.NVL(authenticationUser, "")),
         * StringUtil.environmentSubstitute(Const.NVL(authenticationPassword, "")) ); } };
         */
    }

    Session session = Session.getInstance(props);
    session.setDebug(log.isDebug());

    try {
        // create a message
        Message msg = new MimeMessage(session);

        // set message priority
        if (usePriority) {
            String priority_int = "1";
            if (priority.equals("low")) {
                priority_int = "3";
            }
            if (priority.equals("normal")) {
                priority_int = "2";
            }

            msg.setHeader("X-Priority", priority_int); // (String)int between 1= high and 3 = low.
            msg.setHeader("Importance", importance);
            // seems to be needed for MS Outlook.
            // where it returns a string of high /normal /low.
            msg.setHeader("Sensitivity", sensitivity);
            // Possible values are normal, personal, private, company-confidential

        }

        // Set Mail sender (From)
        String sender_address = environmentSubstitute(replyAddress);
        if (!Const.isEmpty(sender_address)) {
            String sender_name = environmentSubstitute(replyName);
            if (!Const.isEmpty(sender_name)) {
                sender_address = sender_name + '<' + sender_address + '>';
            }
            msg.setFrom(new InternetAddress(sender_address));
        } else {
            throw new MessagingException(BaseMessages.getString(PKG, "JobMail.Error.ReplyEmailNotFilled"));
        }

        // set Reply to addresses
        String reply_to_address = environmentSubstitute(replyToAddresses);
        if (!Const.isEmpty(reply_to_address)) {
            // Split the mail-address: space separated
            String[] reply_Address_List = environmentSubstitute(reply_to_address).split(" ");
            InternetAddress[] address = new InternetAddress[reply_Address_List.length];
            for (int i = 0; i < reply_Address_List.length; i++) {
                address[i] = new InternetAddress(reply_Address_List[i]);
            }
            msg.setReplyTo(address);
        }

        // Split the mail-address: space separated
        String[] destinations = environmentSubstitute(destination).split(" ");
        InternetAddress[] address = new InternetAddress[destinations.length];
        for (int i = 0; i < destinations.length; i++) {
            address[i] = new InternetAddress(destinations[i]);
        }
        msg.setRecipients(Message.RecipientType.TO, address);

        String realCC = environmentSubstitute(getDestinationCc());
        if (!Const.isEmpty(realCC)) {
            // Split the mail-address Cc: space separated
            String[] destinationsCc = realCC.split(" ");
            InternetAddress[] addressCc = new InternetAddress[destinationsCc.length];
            for (int i = 0; i < destinationsCc.length; i++) {
                addressCc[i] = new InternetAddress(destinationsCc[i]);
            }

            msg.setRecipients(Message.RecipientType.CC, addressCc);
        }

        String realBCc = environmentSubstitute(getDestinationBCc());
        if (!Const.isEmpty(realBCc)) {
            // Split the mail-address BCc: space separated
            String[] destinationsBCc = realBCc.split(" ");
            InternetAddress[] addressBCc = new InternetAddress[destinationsBCc.length];
            for (int i = 0; i < destinationsBCc.length; i++) {
                addressBCc[i] = new InternetAddress(destinationsBCc[i]);
            }

            msg.setRecipients(Message.RecipientType.BCC, addressBCc);
        }
        String realSubject = environmentSubstitute(subject);
        if (!Const.isEmpty(realSubject)) {
            msg.setSubject(realSubject);
        }

        msg.setSentDate(new Date());
        StringBuffer messageText = new StringBuffer();
        String endRow = isUseHTML() ? "<br>" : Const.CR;
        String realComment = environmentSubstitute(comment);
        if (!Const.isEmpty(realComment)) {
            messageText.append(realComment).append(Const.CR).append(Const.CR);
        }
        if (!onlySendComment) {

            messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.Job")).append(endRow);
            messageText.append("-----").append(endRow);
            messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.JobName") + "    : ")
                    .append(parentJob.getJobMeta().getName()).append(endRow);
            messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.JobDirectory") + "  : ")
                    .append(parentJob.getJobMeta().getRepositoryDirectory()).append(endRow);
            messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.JobEntry") + "   : ")
                    .append(getName()).append(endRow);
            messageText.append(Const.CR);
        }

        if (includeDate) {
            messageText.append(endRow).append(BaseMessages.getString(PKG, "JobMail.Log.Comment.MsgDate") + ": ")
                    .append(XMLHandler.date2string(new Date())).append(endRow).append(endRow);
        }
        if (!onlySendComment && result != null) {
            messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.PreviousResult") + ":")
                    .append(endRow);
            messageText.append("-----------------").append(endRow);
            messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.JobEntryNr") + "         : ")
                    .append(result.getEntryNr()).append(endRow);
            messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.Errors") + "               : ")
                    .append(result.getNrErrors()).append(endRow);
            messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.LinesRead") + "           : ")
                    .append(result.getNrLinesRead()).append(endRow);
            messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.LinesWritten") + "        : ")
                    .append(result.getNrLinesWritten()).append(endRow);
            messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.LinesInput") + "          : ")
                    .append(result.getNrLinesInput()).append(endRow);
            messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.LinesOutput") + "         : ")
                    .append(result.getNrLinesOutput()).append(endRow);
            messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.LinesUpdated") + "        : ")
                    .append(result.getNrLinesUpdated()).append(endRow);
            messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.LinesRejected") + "       : ")
                    .append(result.getNrLinesRejected()).append(endRow);
            messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.Status") + "  : ")
                    .append(result.getExitStatus()).append(endRow);
            messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.Result") + "               : ")
                    .append(result.getResult()).append(endRow);
            messageText.append(endRow);
        }

        if (!onlySendComment && (!Const.isEmpty(environmentSubstitute(contactPerson))
                || !Const.isEmpty(environmentSubstitute(contactPhone)))) {
            messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.ContactInfo") + " :")
                    .append(endRow);
            messageText.append("---------------------").append(endRow);
            messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.PersonToContact") + " : ")
                    .append(environmentSubstitute(contactPerson)).append(endRow);
            messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.Tel") + "  : ")
                    .append(environmentSubstitute(contactPhone)).append(endRow);
            messageText.append(endRow);
        }

        // Include the path to this job entry...
        if (!onlySendComment) {
            JobTracker jobTracker = parentJob.getJobTracker();
            if (jobTracker != null) {
                messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.PathToJobentry") + ":")
                        .append(endRow);
                messageText.append("------------------------").append(endRow);

                addBacktracking(jobTracker, messageText);
                if (isUseHTML()) {
                    messageText.replace(0, messageText.length(),
                            messageText.toString().replace(Const.CR, endRow));
                }
            }
        }

        MimeMultipart parts = new MimeMultipart();
        MimeBodyPart part1 = new MimeBodyPart(); // put the text in the
        // Attached files counter
        int nrattachedFiles = 0;

        // 1st part

        if (useHTML) {
            if (!Const.isEmpty(getEncoding())) {
                part1.setContent(messageText.toString(), "text/html; " + "charset=" + getEncoding());
            } else {
                part1.setContent(messageText.toString(), "text/html; " + "charset=ISO-8859-1");
            }
        } else {
            part1.setText(messageText.toString());
        }

        parts.addBodyPart(part1);

        if (includingFiles && result != null) {
            List<ResultFile> resultFiles = result.getResultFilesList();
            if (resultFiles != null && !resultFiles.isEmpty()) {
                if (!zipFiles) {
                    // Add all files to the message...
                    //
                    for (ResultFile resultFile : resultFiles) {
                        FileObject file = resultFile.getFile();
                        if (file != null && file.exists()) {
                            boolean found = false;
                            for (int i = 0; i < fileType.length; i++) {
                                if (fileType[i] == resultFile.getType()) {
                                    found = true;
                                }
                            }
                            if (found) {
                                // create a data source
                                MimeBodyPart files = new MimeBodyPart();
                                URLDataSource fds = new URLDataSource(file.getURL());

                                // get a data Handler to manipulate this file type;
                                files.setDataHandler(new DataHandler(fds));
                                // include the file in the data source
                                files.setFileName(file.getName().getBaseName());

                                // insist on base64 to preserve line endings
                                files.addHeader("Content-Transfer-Encoding", "base64");

                                // add the part with the file in the BodyPart();
                                parts.addBodyPart(files);
                                nrattachedFiles++;
                                logBasic("Added file '" + fds.getName() + "' to the mail message.");
                            }
                        }
                    }
                } else {
                    // create a single ZIP archive of all files
                    masterZipfile = new File(System.getProperty("java.io.tmpdir") + Const.FILE_SEPARATOR
                            + environmentSubstitute(zipFilename));
                    ZipOutputStream zipOutputStream = null;
                    try {
                        zipOutputStream = new ZipOutputStream(new FileOutputStream(masterZipfile));

                        for (ResultFile resultFile : resultFiles) {
                            boolean found = false;
                            for (int i = 0; i < fileType.length; i++) {
                                if (fileType[i] == resultFile.getType()) {
                                    found = true;
                                }
                            }
                            if (found) {
                                FileObject file = resultFile.getFile();
                                ZipEntry zipEntry = new ZipEntry(file.getName().getBaseName());
                                zipOutputStream.putNextEntry(zipEntry);

                                // Now put the content of this file into this archive...
                                BufferedInputStream inputStream = new BufferedInputStream(
                                        KettleVFS.getInputStream(file));
                                try {
                                    int c;
                                    while ((c = inputStream.read()) >= 0) {
                                        zipOutputStream.write(c);
                                    }
                                } finally {
                                    inputStream.close();
                                }
                                zipOutputStream.closeEntry();
                                nrattachedFiles++;
                                logBasic("Added file '" + file.getName().getURI()
                                        + "' to the mail message in a zip archive.");
                            }
                        }
                    } catch (Exception e) {
                        logError("Error zipping attachement files into file [" + masterZipfile.getPath()
                                + "] : " + e.toString());
                        logError(Const.getStackTracker(e));
                        result.setNrErrors(1);
                    } finally {
                        if (zipOutputStream != null) {
                            try {
                                zipOutputStream.finish();
                                zipOutputStream.close();
                            } catch (IOException e) {
                                logError("Unable to close attachement zip file archive : " + e.toString());
                                logError(Const.getStackTracker(e));
                                result.setNrErrors(1);
                            }
                        }
                    }

                    // Now attach the master zip file to the message.
                    if (result.getNrErrors() == 0) {
                        // create a data source
                        MimeBodyPart files = new MimeBodyPart();
                        FileDataSource fds = new FileDataSource(masterZipfile);
                        // get a data Handler to manipulate this file type;
                        files.setDataHandler(new DataHandler(fds));
                        // include the file in the data source
                        files.setFileName(fds.getName());
                        // add the part with the file in the BodyPart();
                        parts.addBodyPart(files);
                    }
                }
            }
        }

        int nrEmbeddedImages = 0;
        if (embeddedimages != null && embeddedimages.length > 0) {
            FileObject imageFile = null;
            for (int i = 0; i < embeddedimages.length; i++) {
                String realImageFile = environmentSubstitute(embeddedimages[i]);
                String realcontenID = environmentSubstitute(contentids[i]);
                if (messageText.indexOf("cid:" + realcontenID) < 0) {
                    if (log.isDebug()) {
                        log.logDebug("Image [" + realImageFile + "] is not used in message body!");
                    }
                } else {
                    try {
                        boolean found = false;
                        imageFile = KettleVFS.getFileObject(realImageFile, this);
                        if (imageFile.exists() && imageFile.getType() == FileType.FILE) {
                            found = true;
                        } else {
                            log.logError("We can not find [" + realImageFile + "] or it is not a file");
                        }
                        if (found) {
                            // Create part for the image
                            MimeBodyPart messageBodyPart = new MimeBodyPart();
                            // Load the image
                            URLDataSource fds = new URLDataSource(imageFile.getURL());
                            messageBodyPart.setDataHandler(new DataHandler(fds));
                            // Setting the header
                            messageBodyPart.setHeader("Content-ID", "<" + realcontenID + ">");
                            // Add part to multi-part
                            parts.addBodyPart(messageBodyPart);
                            nrEmbeddedImages++;
                            log.logBasic("Image '" + fds.getName() + "' was embedded in message.");
                        }
                    } catch (Exception e) {
                        log.logError(
                                "Error embedding image [" + realImageFile + "] in message : " + e.toString());
                        log.logError(Const.getStackTracker(e));
                        result.setNrErrors(1);
                    } finally {
                        if (imageFile != null) {
                            try {
                                imageFile.close();
                            } catch (Exception e) { /* Ignore */
                            }
                        }
                    }
                }
            }
        }

        if (nrEmbeddedImages > 0 && nrattachedFiles == 0) {
            // If we need to embedd images...
            // We need to create a "multipart/related" message.
            // otherwise image will appear as attached file
            parts.setSubType("related");
        }
        // put all parts together
        msg.setContent(parts);

        Transport transport = null;
        try {
            transport = session.getTransport(protocol);
            String authPass = getPassword(authenticationPassword);

            if (usingAuthentication) {
                if (!Const.isEmpty(port)) {
                    transport.connect(environmentSubstitute(Const.NVL(server, "")),
                            Integer.parseInt(environmentSubstitute(Const.NVL(port, ""))),
                            environmentSubstitute(Const.NVL(authenticationUser, "")), authPass);
                } else {
                    transport.connect(environmentSubstitute(Const.NVL(server, "")),
                            environmentSubstitute(Const.NVL(authenticationUser, "")), authPass);
                }
            } else {
                transport.connect();
            }
            transport.sendMessage(msg, msg.getAllRecipients());
        } finally {
            if (transport != null) {
                transport.close();
            }
        }
    } catch (IOException e) {
        logError("Problem while sending message: " + e.toString());
        result.setNrErrors(1);
    } catch (MessagingException mex) {
        logError("Problem while sending message: " + mex.toString());
        result.setNrErrors(1);

        Exception ex = mex;
        do {
            if (ex instanceof SendFailedException) {
                SendFailedException sfex = (SendFailedException) ex;

                Address[] invalid = sfex.getInvalidAddresses();
                if (invalid != null) {
                    logError("    ** Invalid Addresses");
                    for (int i = 0; i < invalid.length; i++) {
                        logError("         " + invalid[i]);
                        result.setNrErrors(1);
                    }
                }

                Address[] validUnsent = sfex.getValidUnsentAddresses();
                if (validUnsent != null) {
                    logError("    ** ValidUnsent Addresses");
                    for (int i = 0; i < validUnsent.length; i++) {
                        logError("         " + validUnsent[i]);
                        result.setNrErrors(1);
                    }
                }

                Address[] validSent = sfex.getValidSentAddresses();
                if (validSent != null) {
                    // System.out.println("    ** ValidSent Addresses");
                    for (int i = 0; i < validSent.length; i++) {
                        logError("         " + validSent[i]);
                        result.setNrErrors(1);
                    }
                }
            }
            if (ex instanceof MessagingException) {
                ex = ((MessagingException) ex).getNextException();
            } else {
                ex = null;
            }
        } while (ex != null);
    } finally {
        if (masterZipfile != null && masterZipfile.exists()) {
            masterZipfile.delete();
        }
    }

    if (result.getNrErrors() > 0) {
        result.setResult(false);
    } else {
        result.setResult(true);
    }

    return result;
}

From source file:org.pentaho.di.job.entries.talendjobexec.JobEntryTalendJobExec.java

private URL[] prepareJarFiles(FileObject zipFile) throws Exception {

    // zip:file:///tmp/foo.zip
    FileInputList fileList = FileInputList.createFileList(this, new String[] { "zip:" + zipFile.toString(), },
            new String[] { ".*\\.jar$", }, // Include mask: only jar files
            new String[] { ".*classpath\\.jar$", }, // Exclude mask: only jar files
            new String[] { "Y", }, // File required
            new boolean[] { true, }); // Search sub-directories

    List<URL> files = new ArrayList<URL>();

    // Copy the jar files in the temp folder...
    ////from  w ww  .j a v  a  2 s.c o  m
    for (FileObject file : fileList.getFiles()) {
        FileObject jarfilecopy = KettleVFS.createTempFile(file.getName().getBaseName(), ".jar",
                environmentSubstitute("${java.io.tmpdir}"));
        jarfilecopy.copyFrom(file, new AllFileSelector());
        files.add(jarfilecopy.getURL());
    }

    return files.toArray(new URL[files.size()]);
}

From source file:org.pentaho.di.resource.NameResourceTest.java

/**
 * This tests ResourceNamingInterface.nameResouce(), comparing the directory maps generated by the legacy and new
 * method./*  www  .  j a  v a  2  s.c  om*/
 *
 * @param fileName
 * @param pathOnly
 *          Resolve the path - leave out the file name
 * @throws Exception
 *
 *           Legacy: namingResource(String, String, String, FileNamingType) New: namingResource(FileObject, TransMeta)
 */
private void testNamingResourceLegacyAndNew(String fileName, String extension, String fileMask)
        throws Exception {

    // Create a new transformation.
    TransMeta transMeta = new TransMeta();

    FileObject fileObject = KettleVFS.getFileObject(fileName, transMeta);

    // This code is modeled after the legacy code in legacy step meta classes
    // that have an exportResources method that deal with file masks
    // e.g., ExcelInputMeta
    //
    // There is a big exception: where the legacy code does a "getName()"
    // this code does a "getURL()". This is because of the JIRA case
    // that resulted in the refactoring of ResourceNamingInterface.
    //
    // The UNC and VFS protocols where being dropped.
    // The code you see here would be the fix for that without adding
    // the new nameResource() to ResourceNamingInterface.
    //

    String path = null;
    String prefix = null;
    if (Const.isEmpty(fileMask)) {
        prefix = fileObject.getName().getBaseName();
        path = fileObject.getParent().getURL().toString();
    } else {
        prefix = "";
        path = fileObject.getURL().toString();
    }

    // Create a resource naming interface to use the legacy method call
    ResourceNamingInterface resourceNamingInterface_LEGACY = new SequenceResourceNaming();

    // Create two resource naming interfaces, one for legacy call, the other for new method call
    ResourceNamingInterface resourceNamingInterface_NEW = new SequenceResourceNaming();

    // The old and new interfaces to get the file name.
    String resolvedFileName_LEGACY = resourceNamingInterface_LEGACY.nameResource(prefix, path, extension,
            FileNamingType.DATA_FILE);
    String resolvedFileName_NEW = resourceNamingInterface_NEW.nameResource(fileObject, transMeta,
            Const.isEmpty(fileMask));

    // get the variable name from both naming interfaces directory maps
    String pathFromMap_LEGACY = resourceNamingInterface_LEGACY.getDirectoryMap().get(path);
    String pathFromMap_NEW = resourceNamingInterface_NEW.getDirectoryMap().get(path);

    // The paths in both directories should be the same
    assertEquals(pathFromMap_LEGACY, pathFromMap_NEW);

    // The file names should be the same
    assertEquals(resolvedFileName_LEGACY, resolvedFileName_NEW);
}

From source file:org.pentaho.di.resource.SimpleResourceNaming.java

public String nameResource(FileObject fileObject, VariableSpace space, boolean includeFileName)
        throws FileSystemException {
    if (includeFileName) {
        return handleDataFile(fileObject.getName().getBaseName(), fileObject.getParent().getURL().toString(),
                "");
    } else {/*w  w w .  j ava2 s . co  m*/
        return handleDataFile("", fileObject.getURL().toString(), "");
    }
}

From source file:org.pentaho.di.scoring.WekaScoringDialog.java

/**
 * Open the dialog// www .  ja  va 2 s . c  o m
 * 
 * @return the step name
 */
public String open() {

    // Make sure that all Weka packages have been loaded!
    weka.core.WekaPackageManager.loadPackages(false);

    Shell parent = getParent();
    Display display = parent.getDisplay();

    shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MIN | SWT.MAX);

    props.setLook(shell);
    setShellImage(shell, m_currentMeta);

    // used to listen to a text field (m_wStepname)
    ModifyListener lsMod = new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            m_currentMeta.setChanged();
        }
    };

    changed = m_currentMeta.hasChanged();

    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = Const.FORM_MARGIN;
    formLayout.marginHeight = Const.FORM_MARGIN;

    shell.setLayout(formLayout);
    shell.setText(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.Shell.Title")); //$NON-NLS-1$

    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;

    // Stepname line
    m_wlStepname = new Label(shell, SWT.RIGHT);
    m_wlStepname.setText(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.StepName.Label")); //$NON-NLS-1$
    props.setLook(m_wlStepname);

    m_fdlStepname = new FormData();
    m_fdlStepname.left = new FormAttachment(0, 0);
    m_fdlStepname.right = new FormAttachment(middle, -margin);
    m_fdlStepname.top = new FormAttachment(0, margin);
    m_wlStepname.setLayoutData(m_fdlStepname);
    m_wStepname = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    m_wStepname.setText(stepname);
    props.setLook(m_wStepname);
    m_wStepname.addModifyListener(lsMod);

    // format the text field
    m_fdStepname = new FormData();
    m_fdStepname.left = new FormAttachment(middle, 0);
    m_fdStepname.top = new FormAttachment(0, margin);
    m_fdStepname.right = new FormAttachment(100, 0);
    m_wStepname.setLayoutData(m_fdStepname);

    m_wTabFolder = new CTabFolder(shell, SWT.BORDER);
    props.setLook(m_wTabFolder, Props.WIDGET_STYLE_TAB);
    m_wTabFolder.setSimple(false);

    // Start of the file tab
    m_wFileTab = new CTabItem(m_wTabFolder, SWT.NONE);
    m_wFileTab.setText(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.FileTab.TabTitle")); //$NON-NLS-1$

    Composite wFileComp = new Composite(m_wTabFolder, SWT.NONE);
    props.setLook(wFileComp);

    FormLayout fileLayout = new FormLayout();
    fileLayout.marginWidth = 3;
    fileLayout.marginHeight = 3;
    wFileComp.setLayout(fileLayout);

    // Filename line
    m_wlFilename = new Label(wFileComp, SWT.RIGHT);
    m_wlFilename.setText(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.Filename.Label")); //$NON-NLS-1$
    props.setLook(m_wlFilename);
    m_fdlFilename = new FormData();
    m_fdlFilename.left = new FormAttachment(0, 0);
    m_fdlFilename.top = new FormAttachment(0, margin);
    m_fdlFilename.right = new FormAttachment(middle, -margin);
    m_wlFilename.setLayoutData(m_fdlFilename);

    // file browse button
    m_wbFilename = new Button(wFileComp, SWT.PUSH | SWT.CENTER);
    props.setLook(m_wbFilename);
    m_wbFilename.setText(BaseMessages.getString(WekaScoringMeta.PKG, "System.Button.Browse")); //$NON-NLS-1$
    m_fdbFilename = new FormData();
    m_fdbFilename.right = new FormAttachment(100, 0);
    m_fdbFilename.top = new FormAttachment(0, 0);
    m_wbFilename.setLayoutData(m_fdbFilename);

    // combined text field and env variable widget
    m_wFilename = new TextVar(transMeta, wFileComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(m_wFilename);
    m_wFilename.addModifyListener(lsMod);
    m_fdFilename = new FormData();
    m_fdFilename.left = new FormAttachment(middle, 0);
    m_fdFilename.top = new FormAttachment(0, margin);
    m_fdFilename.right = new FormAttachment(m_wbFilename, -margin);
    m_wFilename.setLayoutData(m_fdFilename);

    // store model in meta data
    Label saveModelMetaLab = new Label(wFileComp, SWT.RIGHT);
    props.setLook(saveModelMetaLab);
    saveModelMetaLab
            .setText(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.SaveModelToMeta.Label")); //$NON-NLS-1$
    FormData fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    fd.top = new FormAttachment(m_wFilename, margin);
    fd.right = new FormAttachment(middle, -margin);
    saveModelMetaLab.setLayoutData(fd);

    m_storeModelInStepMetaData = new Button(wFileComp, SWT.CHECK);
    props.setLook(m_storeModelInStepMetaData);
    fd = new FormData();
    fd.left = new FormAttachment(middle, 0);
    fd.top = new FormAttachment(m_wFilename, margin);
    fd.right = new FormAttachment(100, 0);
    m_storeModelInStepMetaData.setLayoutData(fd);

    m_wUpdateModelLab = new Label(wFileComp, SWT.RIGHT);
    m_wUpdateModelLab
            .setText(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.UpdateModel.Label")); //$NON-NLS-1$
    props.setLook(m_wUpdateModelLab);
    m_fdlUpdateModel = new FormData();
    m_fdlUpdateModel.left = new FormAttachment(0, 0);
    m_fdlUpdateModel.top = new FormAttachment(m_storeModelInStepMetaData, margin);
    m_fdlUpdateModel.right = new FormAttachment(middle, -margin);
    m_wUpdateModelLab.setLayoutData(m_fdlUpdateModel);
    m_wUpdateModel = new Button(wFileComp, SWT.CHECK);
    props.setLook(m_wUpdateModel);
    m_fdUpdateModel = new FormData();
    m_fdUpdateModel.left = new FormAttachment(middle, 0);
    m_fdUpdateModel.top = new FormAttachment(m_storeModelInStepMetaData, margin);
    m_fdUpdateModel.right = new FormAttachment(100, 0);
    m_wUpdateModel.setLayoutData(m_fdUpdateModel);
    m_wUpdateModel.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            m_currentMeta.setChanged();
            m_wbSaveFilename.setEnabled(m_wUpdateModel.getSelection());
            m_wSaveFilename.setEnabled(m_wUpdateModel.getSelection());
        }
    });

    // ----------------------------

    // Save filename line
    m_wlSaveFilename = new Label(wFileComp, SWT.RIGHT);
    m_wlSaveFilename
            .setText(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.SaveFilename.Label")); //$NON-NLS-1$
    props.setLook(m_wlSaveFilename);
    m_fdlSaveFilename = new FormData();
    m_fdlSaveFilename.left = new FormAttachment(0, 0);
    m_fdlSaveFilename.top = new FormAttachment(m_wUpdateModel, margin);
    m_fdlSaveFilename.right = new FormAttachment(middle, -margin);
    m_wlSaveFilename.setLayoutData(m_fdlSaveFilename);

    // Save file browse button
    m_wbSaveFilename = new Button(wFileComp, SWT.PUSH | SWT.CENTER);
    props.setLook(m_wbSaveFilename);
    m_wbSaveFilename.setText(BaseMessages.getString(WekaScoringMeta.PKG, "System.Button.Browse")); //$NON-NLS-1$
    m_fdbSaveFilename = new FormData();
    m_fdbSaveFilename.right = new FormAttachment(100, 0);
    m_fdbSaveFilename.top = new FormAttachment(m_wUpdateModel, 0);
    m_wbSaveFilename.setLayoutData(m_fdbSaveFilename);
    m_wbSaveFilename.setEnabled(false);

    // combined text field and env variable widget
    m_wSaveFilename = new TextVar(transMeta, wFileComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(m_wSaveFilename);
    m_wSaveFilename.addModifyListener(lsMod);
    m_fdSaveFilename = new FormData();
    m_fdSaveFilename.left = new FormAttachment(middle, 0);
    m_fdSaveFilename.top = new FormAttachment(m_wUpdateModel, margin);
    m_fdSaveFilename.right = new FormAttachment(m_wbSaveFilename, -margin);
    m_wSaveFilename.setLayoutData(m_fdSaveFilename);
    m_wSaveFilename.setEnabled(false);

    m_fdFileComp = new FormData();
    m_fdFileComp.left = new FormAttachment(0, 0);
    m_fdFileComp.top = new FormAttachment(0, 0);
    m_fdFileComp.right = new FormAttachment(100, 0);
    m_fdFileComp.bottom = new FormAttachment(100, 0);
    wFileComp.setLayoutData(m_fdFileComp);

    wFileComp.layout();
    m_wFileTab.setControl(wFileComp);

    m_wAcceptFileNameFromFieldCheckLab = new Label(wFileComp, SWT.RIGHT);
    m_wAcceptFileNameFromFieldCheckLab.setText(BaseMessages.getString(WekaScoringMeta.PKG,
            "WekaScoringDialog.AcceptFileNamesFromFieldCheck.Label")); //$NON-NLS-1$
    props.setLook(m_wAcceptFileNameFromFieldCheckLab);
    FormData fdAcceptCheckLab = new FormData();
    fdAcceptCheckLab.left = new FormAttachment(0, 0);
    fdAcceptCheckLab.top = new FormAttachment(m_wSaveFilename, margin);
    fdAcceptCheckLab.right = new FormAttachment(middle, -margin);
    m_wAcceptFileNameFromFieldCheckLab.setLayoutData(fdAcceptCheckLab);
    m_wAcceptFileNameFromFieldCheckBox = new Button(wFileComp, SWT.CHECK);
    props.setLook(m_wAcceptFileNameFromFieldCheckBox);
    FormData fdAcceptCheckBox = new FormData();
    fdAcceptCheckBox.left = new FormAttachment(middle, 0);
    fdAcceptCheckBox.top = new FormAttachment(m_wSaveFilename, margin);
    fdAcceptCheckBox.right = new FormAttachment(100, 0);
    m_wAcceptFileNameFromFieldCheckBox.setLayoutData(fdAcceptCheckBox);

    m_wAcceptFileNameFromFieldCheckBox.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            m_currentMeta.setChanged();
            if (m_wAcceptFileNameFromFieldCheckBox.getSelection()) {
                m_wUpdateModel.setSelection(false);
                m_wUpdateModel.setEnabled(false);
                m_wSaveFilename.setText(""); //$NON-NLS-1$
                m_wlFilename.setText(
                        BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.Default.Label")); //$NON-NLS-1$
                if (!Const.isEmpty(m_wFilename.getText())) {
                    // load - loadModel() will take care of storing it in
                    // either the main or default model in the current meta
                    loadModel();
                } else {
                    // try and shift the main model (if non-null) over into the
                    // default model in current meta
                    m_currentMeta.setDefaultModel(m_currentMeta.getModel());
                    m_currentMeta.setModel(null);
                }

            } else {
                if (!Const.isEmpty(m_wFilename.getText())) {
                    // load - loadModel() will take care of storing it in
                    // either the main or default model in the current meta
                    loadModel();
                } else {
                    // try and shift the default model (if non-null) over into the
                    // main model in current meta
                    m_currentMeta.setModel(m_currentMeta.getDefaultModel());
                    m_currentMeta.setDefaultModel(null);
                }

                m_wCacheModelsCheckBox.setSelection(false);
                m_wlFilename.setText(
                        BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.Filename.Label")); //$NON-NLS-1$
            }

            m_wCacheModelsCheckBox.setEnabled(m_wAcceptFileNameFromFieldCheckBox.getSelection());
            m_wAcceptFileNameFromFieldText.setEnabled(m_wAcceptFileNameFromFieldCheckBox.getSelection());
            m_wbSaveFilename.setEnabled(
                    !m_wAcceptFileNameFromFieldCheckBox.getSelection() && m_wUpdateModel.getSelection());
            m_wSaveFilename.setEnabled(
                    !m_wAcceptFileNameFromFieldCheckBox.getSelection() && m_wUpdateModel.getSelection());
        }
    });

    //
    m_wAcceptFileNameFromFieldTextLab = new Label(wFileComp, SWT.RIGHT);
    m_wAcceptFileNameFromFieldTextLab.setText(
            BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.AcceptFileNamesFromField.Label")); //$NON-NLS-1$
    props.setLook(m_wAcceptFileNameFromFieldTextLab);
    FormData fdAcceptLab = new FormData();
    fdAcceptLab.left = new FormAttachment(0, 0);
    fdAcceptLab.top = new FormAttachment(m_wAcceptFileNameFromFieldCheckBox, margin);
    fdAcceptLab.right = new FormAttachment(middle, -margin);
    m_wAcceptFileNameFromFieldTextLab.setLayoutData(fdAcceptLab);
    m_wAcceptFileNameFromFieldText = new TextVar(transMeta, wFileComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(m_wAcceptFileNameFromFieldText);
    m_wAcceptFileNameFromFieldText.addModifyListener(lsMod);
    FormData fdAcceptText = new FormData();
    fdAcceptText.left = new FormAttachment(middle, 0);
    fdAcceptText.top = new FormAttachment(m_wAcceptFileNameFromFieldCheckBox, margin);
    fdAcceptText.right = new FormAttachment(100, 0);
    m_wAcceptFileNameFromFieldText.setLayoutData(fdAcceptText);
    m_wAcceptFileNameFromFieldText.setEnabled(false);

    m_wCacheModelsLab = new Label(wFileComp, SWT.RIGHT);
    m_wCacheModelsLab
            .setText(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.CacheModels.Label")); //$NON-NLS-1$
    props.setLook(m_wCacheModelsLab);
    FormData fdCacheLab = new FormData();
    fdCacheLab.left = new FormAttachment(0, 0);
    fdCacheLab.top = new FormAttachment(m_wAcceptFileNameFromFieldText, margin);
    fdCacheLab.right = new FormAttachment(middle, -margin);
    m_wCacheModelsLab.setLayoutData(fdCacheLab);
    //
    m_wCacheModelsCheckBox = new Button(wFileComp, SWT.CHECK);
    props.setLook(m_wCacheModelsCheckBox);
    FormData fdCacheCheckBox = new FormData();
    fdCacheCheckBox.left = new FormAttachment(middle, 0);
    fdCacheCheckBox.top = new FormAttachment(m_wAcceptFileNameFromFieldText, margin);
    fdCacheCheckBox.right = new FormAttachment(100, 0);
    m_wCacheModelsCheckBox.setLayoutData(fdCacheCheckBox);
    m_wCacheModelsCheckBox.setEnabled(false);

    m_wOutputProbsLab = new Label(wFileComp, SWT.RIGHT);
    m_wOutputProbsLab
            .setText(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.OutputProbs.Label")); //$NON-NLS-1$
    props.setLook(m_wOutputProbsLab);
    m_fdlOutputProbs = new FormData();
    m_fdlOutputProbs.left = new FormAttachment(0, 0);
    m_fdlOutputProbs.top = new FormAttachment(m_wCacheModelsCheckBox, margin);
    m_fdlOutputProbs.right = new FormAttachment(middle, -margin);
    m_wOutputProbsLab.setLayoutData(m_fdlOutputProbs);
    m_wOutputProbs = new Button(wFileComp, SWT.CHECK);
    props.setLook(m_wOutputProbs);
    m_fdOutputProbs = new FormData();
    m_fdOutputProbs.left = new FormAttachment(middle, 0);
    m_fdOutputProbs.top = new FormAttachment(m_wCacheModelsCheckBox, margin);
    m_fdOutputProbs.right = new FormAttachment(100, 0);
    m_wOutputProbs.setLayoutData(m_fdOutputProbs);

    // batch scoring size line
    Label batchLab = new Label(wFileComp, SWT.RIGHT);
    batchLab.setText("Batch scoring batch size"); //$NON-NLS-1$
    props.setLook(batchLab);
    FormData fdd = new FormData();
    fdd.left = new FormAttachment(0, 0);
    fdd.top = new FormAttachment(m_wOutputProbs, margin);
    fdd.right = new FormAttachment(middle, -margin);
    batchLab.setLayoutData(fdd);

    m_batchScoringBatchSizeText = new TextVar(transMeta, wFileComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(m_batchScoringBatchSizeText);
    m_batchScoringBatchSizeText.addModifyListener(lsMod);
    fdd = new FormData();
    fdd.left = new FormAttachment(middle, 0);
    fdd.top = new FormAttachment(m_wOutputProbs, margin);
    fdd.right = new FormAttachment(100, 0);
    m_batchScoringBatchSizeText.setLayoutData(fdd);
    m_batchScoringBatchSizeText.setEnabled(false);

    // Fields mapping tab
    m_wFieldsTab = new CTabItem(m_wTabFolder, SWT.NONE);
    m_wFieldsTab.setText(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.FieldsTab.TabTitle")); //$NON-NLS-1$

    FormLayout fieldsLayout = new FormLayout();
    fieldsLayout.marginWidth = 3;
    fieldsLayout.marginHeight = 3;

    Composite wFieldsComp = new Composite(m_wTabFolder, SWT.NONE);
    props.setLook(wFieldsComp);
    wFieldsComp.setLayout(fieldsLayout);

    // body of tab to be a scrolling text area
    // to display the mapping
    m_wMappingText = new Text(wFieldsComp, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    m_wMappingText.setEditable(false);
    FontData fontd = new FontData("Courier New", 12, SWT.NORMAL); //$NON-NLS-1$
    m_wMappingText.setFont(new Font(getParent().getDisplay(), fontd));

    props.setLook(m_wMappingText);
    // format the fields mapping text area
    m_fdMappingText = new FormData();
    m_fdMappingText.left = new FormAttachment(0, 0);
    m_fdMappingText.top = new FormAttachment(0, margin);
    m_fdMappingText.right = new FormAttachment(100, 0);
    m_fdMappingText.bottom = new FormAttachment(100, 0);
    m_wMappingText.setLayoutData(m_fdMappingText);

    m_fdFieldsComp = new FormData();
    m_fdFieldsComp.left = new FormAttachment(0, 0);
    m_fdFieldsComp.top = new FormAttachment(0, 0);
    m_fdFieldsComp.right = new FormAttachment(100, 0);
    m_fdFieldsComp.bottom = new FormAttachment(100, 0);
    wFieldsComp.setLayoutData(m_fdFieldsComp);

    wFieldsComp.layout();
    m_wFieldsTab.setControl(wFieldsComp);

    // Model display tab
    m_wModelTab = new CTabItem(m_wTabFolder, SWT.NONE);
    m_wModelTab.setText(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.ModelTab.TabTitle")); //$NON-NLS-1$

    FormLayout modelLayout = new FormLayout();
    modelLayout.marginWidth = 3;
    modelLayout.marginHeight = 3;

    Composite wModelComp = new Composite(m_wTabFolder, SWT.NONE);
    props.setLook(wModelComp);
    wModelComp.setLayout(modelLayout);

    // body of tab to be a scrolling text area
    // to display the pre-learned model

    m_wModelText = new Text(wModelComp, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    m_wModelText.setEditable(false);
    fontd = new FontData("Courier New", 12, SWT.NORMAL); //$NON-NLS-1$
    m_wModelText.setFont(new Font(getParent().getDisplay(), fontd));

    props.setLook(m_wModelText);
    // format the model text area
    m_fdModelText = new FormData();
    m_fdModelText.left = new FormAttachment(0, 0);
    m_fdModelText.top = new FormAttachment(0, margin);
    m_fdModelText.right = new FormAttachment(100, 0);
    m_fdModelText.bottom = new FormAttachment(100, 0);
    m_wModelText.setLayoutData(m_fdModelText);

    m_fdModelComp = new FormData();
    m_fdModelComp.left = new FormAttachment(0, 0);
    m_fdModelComp.top = new FormAttachment(0, 0);
    m_fdModelComp.right = new FormAttachment(100, 0);
    m_fdModelComp.bottom = new FormAttachment(100, 0);
    wModelComp.setLayoutData(m_fdModelComp);

    wModelComp.layout();
    m_wModelTab.setControl(wModelComp);

    m_fdTabFolder = new FormData();
    m_fdTabFolder.left = new FormAttachment(0, 0);
    m_fdTabFolder.top = new FormAttachment(m_wStepname, margin);
    m_fdTabFolder.right = new FormAttachment(100, 0);
    m_fdTabFolder.bottom = new FormAttachment(100, -50);
    m_wTabFolder.setLayoutData(m_fdTabFolder);

    // Buttons inherited from BaseStepDialog
    wOK = new Button(shell, SWT.PUSH);
    wOK.setText(BaseMessages.getString(WekaScoringMeta.PKG, "System.Button.OK")); //$NON-NLS-1$

    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(WekaScoringMeta.PKG, "System.Button.Cancel")); //$NON-NLS-1$

    setButtonPositions(new Button[] { wOK, wCancel }, margin, m_wTabFolder);

    // Add listeners
    lsCancel = new Listener() {
        public void handleEvent(Event e) {
            cancel();
        }
    };
    lsOK = new Listener() {
        public void handleEvent(Event e) {
            ok();
        }
    };

    wCancel.addListener(SWT.Selection, lsCancel);
    wOK.addListener(SWT.Selection, lsOK);

    lsDef = new SelectionAdapter() {
        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            ok();
        }
    };

    m_wStepname.addSelectionListener(lsDef);

    // Detect X or ALT-F4 or something that kills this window...
    shell.addShellListener(new ShellAdapter() {
        @Override
        public void shellClosed(ShellEvent e) {
            cancel();
        }
    });

    // Whenever something changes, set the tooltip to the expanded version:
    m_wFilename.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            m_wFilename.setToolTipText(transMeta.environmentSubstitute(m_wFilename.getText()));
        }
    });

    m_wSaveFilename.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            m_wSaveFilename.setToolTipText(transMeta.environmentSubstitute(m_wSaveFilename.getText()));
        }
    });

    // listen to the file name text box and try to load a model
    // if the user presses enter
    m_wFilename.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            if (!loadModel()) {
                log.logError(
                        BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.Log.FileLoadingError")); //$NON-NLS-1$
            }
        }
    });

    m_wbFilename.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            String[] extensions = null;
            String[] filterNames = null;
            if (XStream.isPresent()) {
                extensions = new String[4];
                filterNames = new String[4];
                extensions[0] = "*.model"; //$NON-NLS-1$
                filterNames[0] = BaseMessages.getString(WekaScoringMeta.PKG,
                        "WekaScoringDialog.FileType.ModelFileBinary"); //$NON-NLS-1$
                extensions[1] = "*.xstreammodel"; //$NON-NLS-1$
                filterNames[1] = BaseMessages.getString(WekaScoringMeta.PKG,
                        "WekaScoringDialog.FileType.ModelFileXML"); //$NON-NLS-1$
                extensions[2] = "*.xml"; //$NON-NLS-1$
                filterNames[2] = BaseMessages.getString(WekaScoringMeta.PKG,
                        "WekaScoringDialog.FileType.ModelFilePMML"); //$NON-NLS-1$
                extensions[3] = "*"; //$NON-NLS-1$
                filterNames[3] = BaseMessages.getString(WekaScoringMeta.PKG, "System.FileType.AllFiles"); //$NON-NLS-1$
            } else {
                extensions = new String[3];
                filterNames = new String[3];
                extensions[0] = "*.model"; //$NON-NLS-1$
                filterNames[0] = BaseMessages.getString(WekaScoringMeta.PKG,
                        "WekaScoringDialog.FileType.ModelFileBinary"); //$NON-NLS-1$
                extensions[1] = "*.xml"; //$NON-NLS-1$
                filterNames[1] = BaseMessages.getString(WekaScoringMeta.PKG,
                        "WekaScoringDialog.FileType.ModelFilePMML"); //$NON-NLS-1$
                extensions[2] = "*"; //$NON-NLS-1$
                filterNames[2] = BaseMessages.getString(WekaScoringMeta.PKG, "System.FileType.AllFiles"); //$NON-NLS-1$
            }

            // get current file
            FileObject rootFile = null;
            FileObject initialFile = null;
            FileObject defaultInitialFile = null;

            try {
                if (m_wFilename.getText() != null) {
                    String fname = transMeta.environmentSubstitute(m_wFilename.getText());

                    if (!Const.isEmpty(fname)) {
                        initialFile = KettleVFS.getFileObject(fname);
                        rootFile = initialFile.getFileSystem().getRoot();
                    } else {
                        defaultInitialFile = KettleVFS.getFileObject(Spoon.getInstance().getLastFileOpened());
                    }
                } else {
                    defaultInitialFile = KettleVFS.getFileObject("file:///c:/"); //$NON-NLS-1$
                }

                if (rootFile == null) {
                    rootFile = defaultInitialFile.getFileSystem().getRoot();
                }

                VfsFileChooserDialog fileChooserDialog = Spoon.getInstance().getVfsFileChooserDialog(rootFile,
                        initialFile);
                fileChooserDialog.setRootFile(rootFile);
                fileChooserDialog.setInitialFile(initialFile);
                fileChooserDialog.defaultInitialFile = rootFile;

                String in = (!Const.isEmpty(m_wFilename.getText())) ? initialFile.getName().getPath() : null;
                FileObject selectedFile = fileChooserDialog.open(shell, null, "file", //$NON-NLS-1$
                        true, in, extensions, filterNames, VfsFileChooserDialog.VFS_DIALOG_OPEN_FILE);

                if (selectedFile != null) {
                    m_wFilename.setText(selectedFile.getURL().toString());
                }

                // try to load model file and display model
                if (!loadModel()) {
                    log.logError(BaseMessages.getString(WekaScoringMeta.PKG,
                            "WekaScoringDialog.Log.FileLoadingError")); //$NON-NLS-1$
                }
            } catch (Exception ex) {
                logError("A problem occurred", ex); //$NON-NLS-1$
            }
        }
    });

    m_wbSaveFilename.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog dialog = new FileDialog(shell, SWT.SAVE);
            String[] extensions = null;
            String[] filterNames = null;
            if (XStream.isPresent()) {
                extensions = new String[3];
                filterNames = new String[3];
                extensions[0] = "*.model"; //$NON-NLS-1$
                filterNames[0] = BaseMessages.getString(WekaScoringMeta.PKG,
                        "WekaScoringDialog.FileType.ModelFileBinary"); //$NON-NLS-1$
                extensions[1] = "*.xstreammodel"; //$NON-NLS-1$
                filterNames[1] = BaseMessages.getString(WekaScoringMeta.PKG,
                        "WekaScoringDialog.FileType.ModelFileXML"); //$NON-NLS-1$
                extensions[2] = "*"; //$NON-NLS-1$
                filterNames[2] = BaseMessages.getString(WekaScoringMeta.PKG, "System.FileType.AllFiles"); //$NON-NLS-1$
            } else {
                extensions = new String[2];
                filterNames = new String[2];
                extensions[0] = "*.model"; //$NON-NLS-1$
                filterNames[0] = BaseMessages.getString(WekaScoringMeta.PKG,
                        "WekaScoringDialog.FileType.ModelFileBinary"); //$NON-NLS-1$
                extensions[1] = "*"; //$NON-NLS-1$
                filterNames[1] = BaseMessages.getString(WekaScoringMeta.PKG, "System.FileType.AllFiles"); //$NON-NLS-1$
            }
            dialog.setFilterExtensions(extensions);
            if (m_wSaveFilename.getText() != null) {
                dialog.setFileName(transMeta.environmentSubstitute(m_wSaveFilename.getText()));
            }
            dialog.setFilterNames(filterNames);

            if (dialog.open() != null) {

                m_wSaveFilename.setText(
                        dialog.getFilterPath() + System.getProperty("file.separator") + dialog.getFileName()); //$NON-NLS-1$
            }
        }
    });

    m_wTabFolder.setSelection(0);

    // Set the shell size, based upon previous time...
    setSize();

    getData();

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }

    return stepname;
}

From source file:org.pentaho.di.trans.steps.accessoutput.AccessOutput.java

private boolean OpenFile() throws Exception {
    data.oneFileOpened = true;//  w  w w. j a  v  a  2  s . c o  m
    String realFilename = environmentSubstitute(meta.getFilename());
    if (log.isBasic()) {
        logBasic(BaseMessages.getString(PKG, "AccessOutput.log.WritingToFile", realFilename));
    }
    FileObject fileObject = KettleVFS.getFileObject(realFilename, getTransMeta());
    File file = FileUtils.toFile(fileObject.getURL());

    // First open or create the access file
    if (!file.exists()) {
        if (meta.isFileCreated()) {
            data.db = Database.create(file);
        } else {
            logError(BaseMessages.getString(PKG, "AccessOutput.InitError.FileDoesNotExist", realFilename));
            return false;
        }
    } else {
        data.db = Database.open(file);
    }

    // Add the filename to the result object...
    //
    if (meta.isAddToResultFiles()) {
        ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, fileObject,
                getTransMeta().getName(), toString());
        resultFile.setComment("This file was created with an access output step");
        addResultFile(resultFile);
    }

    return true;
}

From source file:org.pentaho.di.trans.steps.fixedinput.FixedInput.java

public boolean init(StepMetaInterface smi, StepDataInterface sdi) {
    meta = (FixedInputMeta) smi;/* ww  w.j a v a 2  s . c  o m*/
    data = (FixedInputData) sdi;

    if (super.init(smi, sdi)) {
        try {
            data.preferredBufferSize = Integer.parseInt(environmentSubstitute(meta.getBufferSize()));
            data.lineWidth = Integer.parseInt(environmentSubstitute(meta.getLineWidth()));
            data.filename = environmentSubstitute(meta.getFilename());

            if (Const.isEmpty(data.filename)) {
                logError(BaseMessages.getString(PKG, "FixedInput.MissingFilename.Message"));
                return false;
            }

            FileObject fileObject = KettleVFS.getFileObject(data.filename, getTransMeta());
            try {
                data.fis = getFileInputStream(fileObject.getURL());
                data.fc = data.fis.getChannel();
                data.bb = ByteBuffer.allocateDirect(data.preferredBufferSize);
            } catch (IOException e) {
                logError(e.toString());
                return false;
            }

            // Add filename to result filenames ?
            if (meta.isAddResultFile()) {
                ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, fileObject,
                        getTransMeta().getName(), toString());
                resultFile.setComment("File was read by a Fixed input step");
                addResultFile(resultFile);
            }

            logBasic("Opened file with name [" + data.filename + "]");

            data.stopReading = false;

            if (meta.isRunningInParallel()) {
                data.stepNumber = getUniqueStepNrAcrossSlaves();
                data.totalNumberOfSteps = getUniqueStepCountAcrossSlaves();
                data.fileSize = fileObject.getContent().getSize();
            }

            // OK, now we need to skip a number of bytes in case we're doing a parallel read.
            //
            if (meta.isRunningInParallel()) {

                int totalLineWidth = data.lineWidth + meta.getLineSeparatorLength(); // including line separator bytes
                long nrRows = data.fileSize / totalLineWidth; // 100.000 / 100 = 1000 rows
                long rowsToSkip = Math.round(data.stepNumber * nrRows / (double) data.totalNumberOfSteps); // 0, 333, 667
                // 333, 667, 1000
                long nextRowsToSkip = Math
                        .round((data.stepNumber + 1) * nrRows / (double) data.totalNumberOfSteps);
                data.rowsToRead = nextRowsToSkip - rowsToSkip;
                long bytesToSkip = rowsToSkip * totalLineWidth;

                logBasic("Step #" + data.stepNumber + " is skipping " + bytesToSkip
                        + " to position in file, then it's reading " + data.rowsToRead + " rows.");

                data.fc.position(bytesToSkip);
            }

            return true;
        } catch (Exception e) {
            logError("Error opening file '" + meta.getFilename() + "'", e);
        }
    }
    return false;
}

From source file:org.pentaho.di.trans.steps.gpload.GPLoad.java

/**
 * Returns the path to the pathToFile. It should be the same as what was passed but this method will check the file
 * system to see if the path is valid.//from www . j  av a 2  s  .  c o  m
 * 
 * @param pathToFile
 *          Path to the file to verify.
 * @param exceptionMessage
 *          The message to use when the path is not provided.
 * @param checkExistence
 *          When true the path's existence will be verified.
 * @return
 * @throws KettleException
 */
private String getPath(String pathToFile, String exceptionMessage, boolean checkExistenceOfFile)
        throws KettleException {

    // Make sure the path is not empty
    if (Const.isEmpty(pathToFile)) {
        throw new KettleException(exceptionMessage);
    }

    // make sure the variable substitution is not empty
    pathToFile = environmentSubstitute(pathToFile).trim();
    if (Const.isEmpty(pathToFile)) {
        throw new KettleException(exceptionMessage);
    }

    FileObject fileObject = KettleVFS.getFileObject(pathToFile, getTransMeta());
    try {
        // we either check the existence of the file
        if (checkExistenceOfFile) {
            if (!fileObject.exists()) {
                throw new KettleException(
                        BaseMessages.getString(PKG, "GPLoad.Execption.FileDoesNotExist", pathToFile));
            }
        } else { // if the file does not have to exist, the parent, or source folder, does.
            FileObject parentFolder = fileObject.getParent();
            if (parentFolder.exists()) {
                return KettleVFS.getFilename(fileObject);
            } else {
                throw new KettleException(BaseMessages.getString(PKG, "GPLoad.Exception.DirectoryDoesNotExist",
                        parentFolder.getURL().getPath()));
            }

        }

        // if Windows is the OS
        if (Const.getOS().startsWith("Windows")) {
            return addQuotes(pathToFile);
        } else {
            return KettleVFS.getFilename(fileObject);
        }
    } catch (FileSystemException fsex) {
        throw new KettleException(
                BaseMessages.getString(PKG, "GPLoad.Exception.GPLoadCommandBuild", fsex.getMessage()));
    }
}

From source file:org.pentaho.di.trans.steps.mail.Mail.java

public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
    meta = (MailMeta) smi;/*  w w  w . j  ava 2 s .  c  o  m*/
    data = (MailData) sdi;

    Object[] r = getRow(); // get row, set busy!
    if (r == null) { // no more input to be expected...

        setOutputDone();
        return false;
    }

    if (first) {
        first = false;

        // get the RowMeta
        data.previousRowMeta = getInputRowMeta().clone();

        // Check is filename field is provided
        if (Const.isEmpty(meta.getDestination())) {
            throw new KettleException(BaseMessages.getString(PKG, "Mail.Log.DestinationFieldEmpty"));
        }

        // Check is replyname field is provided
        if (Const.isEmpty(meta.getReplyAddress())) {
            throw new KettleException(BaseMessages.getString(PKG, "Mail.Log.ReplyFieldEmpty"));
        }

        // Check is SMTP server is provided
        if (Const.isEmpty(meta.getServer())) {
            throw new KettleException(BaseMessages.getString(PKG, "Mail.Log.ServerFieldEmpty"));
        }

        // Check Attached filenames when dynamic
        if (meta.isDynamicFilename() && Const.isEmpty(meta.getDynamicFieldname())) {
            throw new KettleException(BaseMessages.getString(PKG, "Mail.Log.DynamicFilenameFielddEmpty"));
        }

        // Check Attached zipfilename when dynamic
        if (meta.isZipFilenameDynamic() && Const.isEmpty(meta.getDynamicZipFilenameField())) {
            throw new KettleException(BaseMessages.getString(PKG, "Mail.Log.DynamicZipFilenameFieldEmpty"));
        }

        if (meta.isZipFiles() && Const.isEmpty(meta.getZipFilename())) {
            throw new KettleException(BaseMessages.getString(PKG, "Mail.Log.ZipFilenameEmpty"));
        }

        // check authentication
        if (meta.isUsingAuthentication()) {
            // check authentication user
            if (Const.isEmpty(meta.getAuthenticationUser())) {
                throw new KettleException(BaseMessages.getString(PKG, "Mail.Log.AuthenticationUserFieldEmpty"));
            }

            // check authentication pass
            if (Const.isEmpty(meta.getAuthenticationPassword())) {
                throw new KettleException(
                        BaseMessages.getString(PKG, "Mail.Log.AuthenticationPasswordFieldEmpty"));
            }
        }

        // cache the position of the destination field
        if (data.indexOfDestination < 0) {
            String realDestinationFieldname = meta.getDestination();
            data.indexOfDestination = data.previousRowMeta.indexOfValue(realDestinationFieldname);
            if (data.indexOfDestination < 0) {
                throw new KettleException(BaseMessages.getString(PKG,
                        "Mail.Exception.CouldnotFindDestinationField", realDestinationFieldname));
            }
        }

        // Cc
        if (!Const.isEmpty(meta.getDestinationCc())) {
            // cache the position of the Cc field
            if (data.indexOfDestinationCc < 0) {
                String realDestinationCcFieldname = meta.getDestinationCc();
                data.indexOfDestinationCc = data.previousRowMeta.indexOfValue(realDestinationCcFieldname);
                if (data.indexOfDestinationCc < 0) {
                    throw new KettleException(BaseMessages.getString(PKG,
                            "Mail.Exception.CouldnotFindDestinationCcField", realDestinationCcFieldname));
                }
            }
        }
        // BCc
        if (!Const.isEmpty(meta.getDestinationBCc())) {
            // cache the position of the BCc field
            if (data.indexOfDestinationBCc < 0) {
                String realDestinationBCcFieldname = meta.getDestinationBCc();
                data.indexOfDestinationBCc = data.previousRowMeta.indexOfValue(realDestinationBCcFieldname);
                if (data.indexOfDestinationBCc < 0) {
                    throw new KettleException(BaseMessages.getString(PKG,
                            "Mail.Exception.CouldnotFindDestinationBCcField", realDestinationBCcFieldname));
                }
            }
        }
        // Sender Name
        if (!Const.isEmpty(meta.getReplyName())) {
            // cache the position of the sender field
            if (data.indexOfSenderName < 0) {
                String realSenderName = meta.getReplyName();
                data.indexOfSenderName = data.previousRowMeta.indexOfValue(realSenderName);
                if (data.indexOfSenderName < 0) {
                    throw new KettleException(BaseMessages.getString(PKG,
                            "Mail.Exception.CouldnotFindReplyNameField", realSenderName));
                }
            }
        }
        // Sender address
        // cache the position of the sender field
        if (data.indexOfSenderAddress < 0) {
            String realSenderAddress = meta.getReplyAddress();
            data.indexOfSenderAddress = data.previousRowMeta.indexOfValue(realSenderAddress);
            if (data.indexOfSenderAddress < 0) {
                throw new KettleException(BaseMessages.getString(PKG,
                        "Mail.Exception.CouldnotFindReplyAddressField", realSenderAddress));
            }
        }

        // Reply to
        if (!Const.isEmpty(meta.getReplyToAddresses())) {
            // cache the position of the reply to field
            if (data.indexOfReplyToAddresses < 0) {
                String realReplyToAddresses = meta.getReplyToAddresses();
                data.indexOfReplyToAddresses = data.previousRowMeta.indexOfValue(realReplyToAddresses);
                if (data.indexOfReplyToAddresses < 0) {
                    throw new KettleException(BaseMessages.getString(PKG,
                            "Mail.Exception.CouldnotFindReplyToAddressesField", realReplyToAddresses));
                }
            }
        }

        // Contact Person
        if (!Const.isEmpty(meta.getContactPerson())) {
            // cache the position of the destination field
            if (data.indexOfContactPerson < 0) {
                String realContactPerson = meta.getContactPerson();
                data.indexOfContactPerson = data.previousRowMeta.indexOfValue(realContactPerson);
                if (data.indexOfContactPerson < 0) {
                    throw new KettleException(BaseMessages.getString(PKG,
                            "Mail.Exception.CouldnotFindContactPersonField", realContactPerson));
                }
            }
        }
        // Contact Phone
        if (!Const.isEmpty(meta.getContactPhone())) {
            // cache the position of the destination field
            if (data.indexOfContactPhone < 0) {
                String realContactPhone = meta.getContactPhone();
                data.indexOfContactPhone = data.previousRowMeta.indexOfValue(realContactPhone);
                if (data.indexOfContactPhone < 0) {
                    throw new KettleException(BaseMessages.getString(PKG,
                            "Mail.Exception.CouldnotFindContactPhoneField", realContactPhone));
                }
            }
        }
        // cache the position of the Server field
        if (data.indexOfServer < 0) {
            String realServer = meta.getServer();
            data.indexOfServer = data.previousRowMeta.indexOfValue(realServer);
            if (data.indexOfServer < 0) {
                throw new KettleException(
                        BaseMessages.getString(PKG, "Mail.Exception.CouldnotFindServerField", realServer));
            }
        }
        // Port
        if (!Const.isEmpty(meta.getPort())) {
            // cache the position of the port field
            if (data.indexOfPort < 0) {
                String realPort = meta.getPort();
                data.indexOfPort = data.previousRowMeta.indexOfValue(realPort);
                if (data.indexOfPort < 0) {
                    throw new KettleException(
                            BaseMessages.getString(PKG, "Mail.Exception.CouldnotFindPortField", realPort));
                }
            }
        }
        // Authentication
        if (meta.isUsingAuthentication()) {
            // cache the position of the Authentication user field
            if (data.indexOfAuthenticationUser < 0) {
                String realAuthenticationUser = meta.getAuthenticationUser();
                data.indexOfAuthenticationUser = data.previousRowMeta.indexOfValue(realAuthenticationUser);
                if (data.indexOfAuthenticationUser < 0) {
                    throw new KettleException(BaseMessages.getString(PKG,
                            "Mail.Exception.CouldnotFindAuthenticationUserField", realAuthenticationUser));
                }
            }

            // cache the position of the Authentication password field
            if (data.indexOfAuthenticationPass < 0) {
                String realAuthenticationPassword = meta.getAuthenticationPassword();
                data.indexOfAuthenticationPass = data.previousRowMeta.indexOfValue(realAuthenticationPassword);
                if (data.indexOfAuthenticationPass < 0) {
                    throw new KettleException(BaseMessages.getString(PKG,
                            "Mail.Exception.CouldnotFindAuthenticationPassField", realAuthenticationPassword));
                }
            }
        }
        // Mail Subject
        if (!Const.isEmpty(meta.getSubject())) {
            // cache the position of the subject field
            if (data.indexOfSubject < 0) {
                String realSubject = meta.getSubject();
                data.indexOfSubject = data.previousRowMeta.indexOfValue(realSubject);
                if (data.indexOfSubject < 0) {
                    throw new KettleException(BaseMessages.getString(PKG,
                            "Mail.Exception.CouldnotFindSubjectField", realSubject));
                }
            }
        }
        // Mail Comment
        if (!Const.isEmpty(meta.getComment())) {
            // cache the position of the comment field
            if (data.indexOfComment < 0) {
                String realComment = meta.getComment();
                data.indexOfComment = data.previousRowMeta.indexOfValue(realComment);
                if (data.indexOfComment < 0) {
                    throw new KettleException(BaseMessages.getString(PKG,
                            "Mail.Exception.CouldnotFindCommentField", realComment));
                }
            }
        }

        if (meta.isAttachContentFromField()) {
            // We are dealing with file content directly loaded from file
            // and not physical file
            String attachedContentField = meta.getAttachContentField();
            if (Const.isEmpty(attachedContentField)) {
                // Empty Field
                throw new KettleException(
                        BaseMessages.getString(PKG, "Mail.Exception.AttachedContentFieldEmpty"));
            }
            data.indexOfAttachedContent = data.previousRowMeta.indexOfValue(attachedContentField);
            if (data.indexOfComment < 0) {
                throw new KettleException(BaseMessages.getString(PKG,
                        "Mail.Exception.CouldnotFindAttachedContentField", attachedContentField));
            }
            // Attached content filename
            String attachedContentFileNameField = meta.getAttachContentFileNameField();
            if (Const.isEmpty(attachedContentFileNameField)) {
                // Empty Field
                throw new KettleException(
                        BaseMessages.getString(PKG, "Mail.Exception.AttachedContentFileNameFieldEmpty"));
            }
            data.IndexOfAttachedFilename = data.previousRowMeta.indexOfValue(attachedContentFileNameField);
            if (data.indexOfComment < 0) {
                throw new KettleException(
                        BaseMessages.getString(PKG, "Mail.Exception.CouldnotFindAttachedContentFileNameField",
                                attachedContentFileNameField));
            }

        } else {

            // Dynamic Zipfilename
            if (meta.isZipFilenameDynamic()) {
                // cache the position of the attached source filename field
                if (data.indexOfDynamicZipFilename < 0) {
                    String realZipFilename = meta.getDynamicZipFilenameField();
                    data.indexOfDynamicZipFilename = data.previousRowMeta.indexOfValue(realZipFilename);
                    if (data.indexOfDynamicZipFilename < 0) {
                        throw new KettleException(BaseMessages.getString(PKG,
                                "Mail.Exception.CouldnotSourceAttachedZipFilenameField", realZipFilename));
                    }
                }
            }
            data.zipFileLimit = Const.toLong(environmentSubstitute(meta.getZipLimitSize()), 0);
            if (data.zipFileLimit > 0) {
                data.zipFileLimit = data.zipFileLimit * 1048576; // Mo
            }

            if (!meta.isZipFilenameDynamic()) {
                data.ZipFilename = environmentSubstitute(meta.getZipFilename());
            }

            // Attached files
            if (meta.isDynamicFilename()) {
                // cache the position of the attached source filename field
                if (data.indexOfSourceFilename < 0) {
                    String realSourceattachedFilename = meta.getDynamicFieldname();
                    data.indexOfSourceFilename = data.previousRowMeta.indexOfValue(realSourceattachedFilename);
                    if (data.indexOfSourceFilename < 0) {
                        throw new KettleException(BaseMessages.getString(PKG,
                                "Mail.Exception.CouldnotSourceAttachedFilenameField",
                                realSourceattachedFilename));
                    }
                }

                // cache the position of the attached wildcard field
                if (!Const.isEmpty(meta.getSourceWildcard())) {
                    if (data.indexOfSourceWildcard < 0) {
                        String realSourceattachedWildcard = meta.getDynamicWildcard();
                        data.indexOfSourceWildcard = data.previousRowMeta
                                .indexOfValue(realSourceattachedWildcard);
                        if (data.indexOfSourceWildcard < 0) {
                            throw new KettleException(
                                    BaseMessages.getString(PKG, "Mail.Exception.CouldnotSourceAttachedWildcard",
                                            realSourceattachedWildcard));
                        }
                    }
                }
            } else {
                // static attached filenames
                data.realSourceFileFoldername = environmentSubstitute(meta.getSourceFileFoldername());
                data.realSourceWildcard = environmentSubstitute(meta.getSourceWildcard());
            }
        }

        // check embedded images
        if (meta.getEmbeddedImages() != null && meta.getEmbeddedImages().length > 0) {
            FileObject image = null;
            data.embeddedMimePart = new HashSet<MimeBodyPart>();
            try {
                for (int i = 0; i < meta.getEmbeddedImages().length; i++) {
                    String imageFile = environmentSubstitute(meta.getEmbeddedImages()[i]);
                    String contentID = environmentSubstitute(meta.getContentIds()[i]);
                    image = KettleVFS.getFileObject(imageFile);

                    if (image.exists() && image.getType() == FileType.FILE) {
                        // Create part for the image
                        MimeBodyPart imagePart = new MimeBodyPart();
                        // Load the image
                        URLDataSource fds = new URLDataSource(image.getURL());
                        imagePart.setDataHandler(new DataHandler(fds));
                        // Setting the header
                        imagePart.setHeader("Content-ID", "<" + contentID + ">");
                        // keep this part for further user
                        data.embeddedMimePart.add(imagePart);
                        logBasic(BaseMessages.getString(PKG, "Mail.Log.ImageAdded", imageFile));

                    } else {
                        logError(BaseMessages.getString(PKG, "Mail.Log.WrongImage", imageFile));
                    }
                }
            } catch (Exception e) {
                logError(BaseMessages.getString(PKG, "Mail.Error.AddingImage", e.getMessage()));
            } finally {
                if (image != null) {
                    try {
                        image.close();
                    } catch (Exception e) { /* Ignore */
                    }
                }
            }
        }

    } // end if first

    boolean sendToErrorRow = false;
    String errorMessage = null;

    try {
        // get values
        String maildestination = data.previousRowMeta.getString(r, data.indexOfDestination);
        if (Const.isEmpty(maildestination)) {
            throw new KettleException("Mail.Error.MailDestinationEmpty");
        }
        String maildestinationCc = null;
        if (data.indexOfDestinationCc > -1) {
            maildestinationCc = data.previousRowMeta.getString(r, data.indexOfDestinationCc);
        }
        String maildestinationBCc = null;
        if (data.indexOfDestinationBCc > -1) {
            maildestinationBCc = data.previousRowMeta.getString(r, data.indexOfDestinationBCc);
        }

        String mailsendername = null;
        if (data.indexOfSenderName > -1) {
            mailsendername = data.previousRowMeta.getString(r, data.indexOfSenderName);
        }
        String mailsenderaddress = data.previousRowMeta.getString(r, data.indexOfSenderAddress);

        // reply addresses
        String mailreplyToAddresses = null;
        if (data.indexOfReplyToAddresses > -1) {
            mailreplyToAddresses = data.previousRowMeta.getString(r, data.indexOfReplyToAddresses);
        }

        String contactperson = null;
        if (data.indexOfContactPerson > -1) {
            contactperson = data.previousRowMeta.getString(r, data.indexOfContactPerson);
        }
        String contactphone = null;
        if (data.indexOfContactPhone > -1) {
            contactphone = data.previousRowMeta.getString(r, data.indexOfContactPhone);
        }

        String servername = data.previousRowMeta.getString(r, data.indexOfServer);
        if (Const.isEmpty(servername)) {
            throw new KettleException("Mail.Error.MailServerEmpty");
        }
        int port = -1;
        if (data.indexOfPort > -1) {
            port = Const.toInt("" + data.previousRowMeta.getInteger(r, data.indexOfPort), -1);
        }

        String authuser = null;
        if (data.indexOfAuthenticationUser > -1) {
            authuser = data.previousRowMeta.getString(r, data.indexOfAuthenticationUser);
        }
        String authpass = null;
        if (data.indexOfAuthenticationPass > -1) {
            authpass = data.previousRowMeta.getString(r, data.indexOfAuthenticationPass);
        }

        String subject = null;
        if (data.indexOfSubject > -1) {
            subject = data.previousRowMeta.getString(r, data.indexOfSubject);
        }

        String comment = null;
        if (data.indexOfComment > -1) {
            comment = data.previousRowMeta.getString(r, data.indexOfComment);
        }

        // send email...
        sendMail(r, servername, port, mailsenderaddress, mailsendername, maildestination, maildestinationCc,
                maildestinationBCc, contactperson, contactphone, authuser, authpass, subject, comment,
                mailreplyToAddresses);

        putRow(getInputRowMeta(), r); // copy row to possible alternate rowset(s).); // copy row to output rowset(s);

        if (log.isRowLevel()) {
            logRowlevel(BaseMessages.getString(PKG, "Mail.Log.LineNumber",
                    getLinesRead() + " : " + getInputRowMeta().getString(r)));
        }

    } catch (Exception e) {
        if (getStepMeta().isDoingErrorHandling()) {
            sendToErrorRow = true;
            errorMessage = e.toString();
        } else {
            throw new KettleException(BaseMessages.getString(PKG, "Mail.Error.General"), e);
        }
        if (sendToErrorRow) {
            // Simply add this row to the error row
            putError(getInputRowMeta(), r, 1, errorMessage, null, "MAIL001");
        }
    }

    return true;
}