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

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

Introduction

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

Prototype

public void close() throws FileSystemException;

Source Link

Document

Closes this file, and its content.

Usage

From source file:org.pentaho.di.trans.steps.dom.xslt.DOMXslt.java

public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
    meta = (DOMXsltMeta) smi;//from w ww .j  a v  a2 s.c om
    data = (DOMXsltData) sdi;

    Object[] row = getRow();

    if (row == null) { // no more input to be expected...
        setOutputDone();
        return false;
    }
    if (first) {
        first = false;
        data.outputRowMeta = getInputRowMeta().clone();
        meta.getFields(data.outputRowMeta, getStepname(), null, null, this, repository, metaStore);

        // Check if The result field is given
        if (Const.isEmpty(meta.getResultfieldname())) {
            // Result Field is missing !
            logError(BaseMessages.getString(PKG, "Xslt.Log.ErrorResultFieldMissing"));
            throw new KettleStepException(
                    BaseMessages.getString(PKG, "Xslt.Exception.ErrorResultFieldMissing"));
        }

        // Check if The XML field is given
        if (Const.isEmpty(meta.getFieldname())) {
            // Result Field is missing !
            logError(BaseMessages.getString(PKG, "Xslt.Exception.ErrorXMLFieldMissing"));
            throw new KettleStepException(BaseMessages.getString(PKG, "Xslt.Exception.ErrorXMLFieldMissing"));
        }

        // Try to get XML Field index
        data.fieldposition = getInputRowMeta().indexOfValue(meta.getFieldname());
        // Let's check the Field
        if (data.fieldposition < 0) {
            // The field is unreachable !
            logError(BaseMessages.getString(PKG, "Xslt.Log.ErrorFindingField") + "[" + meta.getFieldname()
                    + "]");
            throw new KettleStepException(
                    BaseMessages.getString(PKG, "Xslt.Exception.CouldnotFindField", meta.getFieldname()));
        }

        // Check if the XSL Filename is contained in a column
        if (meta.useXSLField()) {
            if (Const.isEmpty(meta.getXSLFileField())) {
                // The field is missing
                // Result field is missing !
                logError(BaseMessages.getString(PKG, "Xslt.Log.ErrorXSLFileFieldMissing"));
                throw new KettleStepException(
                        BaseMessages.getString(PKG, "Xslt.Exception.ErrorXSLFileFieldMissing"));
            }

            // Try to get Field index
            data.fielxslfiledposition = getInputRowMeta().indexOfValue(meta.getXSLFileField());

            // Let's check the Field
            if (data.fielxslfiledposition < 0) {
                // The field is unreachable !
                logError(BaseMessages.getString(PKG, "Xslt.Log.ErrorXSLFileFieldFinding") + "["
                        + meta.getXSLFileField() + "]");
                throw new KettleStepException(BaseMessages.getString(PKG,
                        "Xslt.Exception.ErrorXSLFileFieldFinding", meta.getXSLFileField()));
            }

        } else {
            if (Const.isEmpty(meta.getXslFilename())) {
                logError(BaseMessages.getString(PKG, "Xslt.Log.ErrorXSLFile"));
                throw new KettleStepException(BaseMessages.getString(PKG, "Xslt.Exception.ErrorXSLFile"));
            }

            // Check if XSL File exists!
            data.xslfilename = environmentSubstitute(meta.getXslFilename());
            FileObject file = null;
            try {
                file = KettleVFS.getFileObject(data.xslfilename);
                if (!file.exists()) {
                    logError(BaseMessages.getString(PKG, "Xslt.Log.ErrorXSLFileNotExists", data.xslfilename));
                    throw new KettleStepException(BaseMessages.getString(PKG,
                            "Xslt.Exception.ErrorXSLFileNotExists", data.xslfilename));
                }
                if (file.getType() != FileType.FILE) {
                    logError(BaseMessages.getString(PKG, "Xslt.Log.ErrorXSLNotAFile", data.xslfilename));
                    throw new KettleStepException(
                            BaseMessages.getString(PKG, "Xslt.Exception.ErrorXSLNotAFile", data.xslfilename));
                }
            } catch (Exception e) {
                throw new KettleStepException(e);
            } finally {
                try {
                    if (file != null) {
                        file.close();
                    }
                } catch (Exception e) { /* Ignore */
                }
            }
        }

        // Check output parameters
        int nrOutputProps = meta.getOutputPropertyName() == null ? 0 : meta.getOutputPropertyName().length;
        if (nrOutputProps > 0) {
            data.outputProperties = new Properties();
            for (int i = 0; i < nrOutputProps; i++) {
                data.outputProperties.put(meta.getOutputPropertyName()[i],
                        environmentSubstitute(meta.getOutputPropertyValue()[i]));
            }
            data.setOutputProperties = true;
        }

        // Check parameters
        data.nrParams = meta.getParameterField() == null ? 0 : meta.getParameterField().length;
        if (data.nrParams > 0) {
            data.indexOfParams = new int[data.nrParams];
            data.nameOfParams = new String[data.nrParams];
            for (int i = 0; i < data.nrParams; i++) {
                String name = environmentSubstitute(meta.getParameterName()[i]);
                String field = environmentSubstitute(meta.getParameterField()[i]);
                if (Const.isEmpty(field)) {
                    throw new KettleStepException(
                            BaseMessages.getString(PKG, "Xslt.Exception.ParameterFieldMissing", name, i));
                }
                data.indexOfParams[i] = getInputRowMeta().indexOfValue(field);
                if (data.indexOfParams[i] < 0) {
                    throw new KettleStepException(
                            BaseMessages.getString(PKG, "Xslt.Exception.ParameterFieldNotFound", name));
                }
                data.nameOfParams[i] = name;
            }
            data.useParameters = true;
        }

        data.factory = TransformerFactory.newInstance();

        if (meta.getXSLFactory().equals("SAXON")) {
            // Set the TransformerFactory to the SAXON implementation.
            data.factory = new net.sf.saxon.TransformerFactoryImpl();
        }

        try {
            data.builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
            throw new KettleStepException(e);
        }

    } // end if first

    // Get the field value
    Document xmlValue = (Document) row[data.fieldposition];
    if (meta.useXSLField()) {
        // Get the value
        data.xslfilename = getInputRowMeta().getString(row, data.fielxslfiledposition);
        if (log.isDetailed()) {
            logDetailed(BaseMessages.getString(PKG, "Xslt.Log.XslfileNameFromFied", data.xslfilename,
                    meta.getXSLFileField()));
        }
    }

    try {

        if (log.isDetailed()) {
            if (meta.isXSLFieldIsAFile()) {
                logDetailed(BaseMessages.getString(PKG, "Xslt.Log.Filexsl") + data.xslfilename);
            } else {
                logDetailed(BaseMessages.getString(PKG, "Xslt.Log.XslStream", data.xslfilename));
            }
        }

        // Get the template from the cache
        Transformer transformer = data.getTemplate(data.xslfilename, data.xslIsAfile);

        // Do we need to set output properties?
        if (data.setOutputProperties) {
            transformer.setOutputProperties(data.outputProperties);
        }

        // Do we need to pass parameters?
        if (data.useParameters) {
            for (int i = 0; i < data.nrParams; i++) {
                transformer.setParameter(data.nameOfParams[i], row[data.indexOfParams[i]]);
            }
        }

        Source source = new DOMSource(xmlValue);
        // Prepare output stream

        Document doc = data.builder.newDocument();

        // transform xml source
        DOMResult result = new DOMResult(doc);

        transformer.transform(source, result);

        //By default the DOMResult object creates a Document node to hold the output:
        Document outputDocument = (Document) result.getNode();

        if (log.isDetailed()) {
            logDetailed(BaseMessages.getString(PKG, "Xslt.Log.FileResult"));
            //logDetailed( xmlString );
        }
        Object[] outputRowData = RowDataUtil.addValueData(row, getInputRowMeta().size(), outputDocument);

        if (log.isRowLevel()) {
            logRowlevel(
                    BaseMessages.getString(PKG, "Xslt.Log.ReadRow") + " " + getInputRowMeta().getString(row));
        }

        // add new values to the row.
        putRow(data.outputRowMeta, outputRowData); // copy row to output rowset(s);

    } catch (Exception e) {
        String errorMessage = e.getMessage();
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        DefaultErrorHandler.printLocation(pw, e);
        pw.close();
        errorMessage = sw.toString() + "\n" + errorMessage;

        if (getStepMeta().isDoingErrorHandling()) {
            // Simply add this row to the error row
            putError(getInputRowMeta(), row, 1, errorMessage, meta.getResultfieldname(), "XSLT01");
        } else {
            logError(BaseMessages.getString(PKG, "Xslt.ErrorProcesing" + " : " + errorMessage));
            throw new KettleStepException(BaseMessages.getString(PKG, "Xslt.ErrorProcesing"), e);
        }
    }

    return true;
}

From source file:org.pentaho.di.trans.steps.exceloutput.ExcelOutput.java

private boolean createParentFolder(FileObject file) {
    boolean retval = true;
    // Check for parent folder
    FileObject parentfolder = null;
    try {//from w  w  w.  j av  a2  s . c o m
        // Get parent folder
        parentfolder = file.getParent();
        if (parentfolder.exists()) {
            if (isDetailed()) {
                logDetailed(BaseMessages.getString(PKG, "ExcelOutput.Log.ParentFolderExist",
                        parentfolder.getName().toString()));
            }
        } else {
            if (isDetailed()) {
                logDetailed(BaseMessages.getString(PKG, "ExcelOutput.Log.ParentFolderNotExist",
                        parentfolder.getName().toString()));
            }
            if (meta.isCreateParentFolder()) {
                parentfolder.createFolder();
                if (isDetailed()) {
                    logDetailed(BaseMessages.getString(PKG, "ExcelOutput.Log.ParentFolderCreated",
                            parentfolder.getName().toString()));
                }
            } else {
                retval = false;
                logError(BaseMessages.getString(PKG, "ExcelOutput.Error.CanNotFoundParentFolder",
                        parentfolder.getName().toString(), file.getName().toString()));
            }
        }
    } catch (Exception e) {
        retval = false;
        logError(BaseMessages.getString(PKG, "ExcelOutput.Log.CouldNotCreateParentFolder",
                parentfolder.getName().toString()));
    } finally {
        if (parentfolder != null) {
            try {
                parentfolder.close();
            } catch (Exception ex) {
                // Ignore
            }
        }
    }
    return retval;
}

From source file:org.pentaho.di.trans.steps.exceloutput.ExcelOutput.java

public boolean openNewFile() {
    boolean retval = false;

    try {/*  w  w  w.ja  v  a 2  s  .c  o  m*/
        // Static filename
        data.realFilename = buildFilename();
        data.file = KettleVFS.getFileObject(data.realFilename, getTransMeta());
        if (meta.isCreateParentFolder()) {
            if (!createParentFolder(data.file)) {
                return retval;
            }
        }
        data.realFilename = KettleVFS.getFilename(data.file);

        addFilenameToResult();

        if (log.isDebug()) {
            logDebug(BaseMessages.getString(PKG, "ExcelOutput.Log.OpeningFile", data.realFilename));
        }

        // Create the workbook
        if (!meta.isTemplateEnabled()) {
            File fle = new File(KettleVFS.getFilename(data.file));
            if (meta.isAppend() && fle.exists()) {
                Workbook workbook = Workbook.getWorkbook(fle);
                data.workbook = Workbook.createWorkbook(fle, workbook);

                if (data.workbook.getSheet(data.realSheetname) != null) {
                    // get available sheets
                    String[] listSheets = data.workbook.getSheetNames();

                    // Let's see if this sheet already exist...
                    for (int i = 0; i < listSheets.length; i++) {
                        if (listSheets[i].equals(data.realSheetname)) {
                            // let's remove sheet
                            data.workbook.removeSheet(i);
                        }
                    }
                }
                // and now .. we create the sheet
                data.sheet = data.workbook.createSheet(data.realSheetname, data.workbook.getNumberOfSheets());
            } else {
                // Create a new Workbook
                data.outputStream = KettleVFS.getOutputStream(data.file, false);
                data.workbook = Workbook.createWorkbook(data.outputStream, data.ws);

                // Create a sheet?
                String sheetname = "Sheet1";
                data.sheet = data.workbook.getSheet(sheetname);
                if (data.sheet == null) {
                    data.sheet = data.workbook.createSheet(sheetname, 0);
                }
            }
        } else {
            FileObject fo = KettleVFS.getFileObject(environmentSubstitute(meta.getTemplateFileName()),
                    getTransMeta());
            // create the openFile from the template

            Workbook tmpWorkbook = Workbook.getWorkbook(KettleVFS.getInputStream(fo), data.ws);
            data.outputStream = KettleVFS.getOutputStream(data.file, false);
            data.workbook = Workbook.createWorkbook(data.outputStream, tmpWorkbook);

            fo.close();
            // use only the first sheet as template
            data.sheet = data.workbook.getSheet(0);
            // save initial number of columns
            data.templateColumns = data.sheet.getColumns();
        }

        // Rename Sheet
        if (!Const.isEmpty(data.realSheetname)) {
            data.sheet.setName(data.realSheetname);
        }

        if (meta.isSheetProtected()) {
            // Protect Sheet by setting password
            data.sheet.getSettings().setProtected(true);
            data.sheet.getSettings().setPassword(environmentSubstitute(meta.getPassword()));
        }

        // Set the initial position...

        data.positionX = 0;
        if (meta.isTemplateEnabled() && meta.isTemplateAppend()) {
            data.positionY = data.sheet.getRows();
        } else {
            data.positionY = 0;
        }

        if (data.headerImage != null) {
            // Put an image (LEFT TOP Corner)
            data.sheet.addImage(data.headerImage);
            data.positionY += Math.round(data.headerImageHeight);
        }

        // Sets the height of the specified row, as well as its collapse status
        // height the row height in characters
        if (data.Headerrowheight > 0 && data.Headerrowheight != ExcelOutputMeta.DEFAULT_ROW_HEIGHT) {
            data.sheet.setRowView(data.positionY, data.Headerrowheight);
        }

        data.headerWrote = false;
        data.splitnr++;
        data.oneFileOpened = true;
        if (log.isDebug()) {
            logDebug(BaseMessages.getString(PKG, "ExcelOutput.Log.FileOpened", data.file.toString()));
        }
        retval = true;
    } catch (Exception e) {
        logError("Error opening new file", e);
        setErrors(1);
    }

    return retval;
}

From source file:org.pentaho.di.trans.steps.exceloutput.ExcelOutput.java

private void setFonts() throws Exception {
    // --- Set Header font
    int headerFontSize = Const.toInt(environmentSubstitute(meta.getHeaderFontSize()),
            ExcelOutputMeta.DEFAULT_FONT_SIZE);
    // Set font name
    FontName headerFontName = ExcelFontMap.getFontName(meta.getHeaderFontName());
    // Set UnderlineStyle
    UnderlineStyle underline = ExcelFontMap.getUnderlineStyle(meta.getHeaderFontUnderline());

    WritableFont writableHeaderFont = null;
    if (meta.isHeaderFontBold()) {
        writableHeaderFont = new WritableFont(headerFontName, headerFontSize, WritableFont.BOLD,
                meta.isHeaderFontItalic(), underline);
    } else {/*from ww  w.  j a v a 2 s.  co m*/
        writableHeaderFont = new WritableFont(headerFontName, headerFontSize, WritableFont.NO_BOLD,
                meta.isHeaderFontItalic(), underline);
    }

    // Header font color
    Colour fontHeaderColour = ExcelFontMap.getColour(meta.getHeaderFontColor(), Colour.BLACK);
    if (!fontHeaderColour.equals(Colour.BLACK)) {
        writableHeaderFont.setColour(fontHeaderColour);
    }
    data.headerCellFormat = new WritableCellFormat(writableHeaderFont);

    // Header background color
    if (meta.getHeaderBackGroundColor() != ExcelOutputMeta.FONT_COLOR_NONE) {
        data.headerCellFormat.setBackground(ExcelFontMap.getColour(meta.getHeaderBackGroundColor(), null));
    }

    // Set alignment
    data.headerCellFormat = ExcelFontMap.getAlignment(meta.getHeaderAlignment(), data.headerCellFormat);
    data.headerCellFormat = ExcelFontMap.getOrientation(meta.getHeaderFontOrientation(), data.headerCellFormat);

    // Do we need to put a image on the header
    if (!Const.isEmpty(data.realHeaderImage)) {
        FileObject imageFile = null;
        try {
            imageFile = KettleVFS.getFileObject(data.realHeaderImage);
            if (!imageFile.exists()) {
                throw new KettleException(
                        BaseMessages.getString(PKG, "ExcelInputLog.ImageFileNotExists", data.realHeaderImage));
            }
            data.realHeaderImage = KettleVFS.getFilename(imageFile);
            // Put an image
            Dimension m = ExcelFontMap.getImageDimension(data.realHeaderImage);
            data.headerImageWidth = m.getWidth() * 0.016;
            data.headerImageHeight = m.getHeight() * 0.0625;

            byte[] imageData = new byte[(int) imageFile.getContent().getSize()];
            KettleVFS.getInputStream(imageFile).read(imageData);

            data.headerImage = new WritableImage(0, 0, data.headerImageWidth, data.headerImageHeight,
                    imageData);
        } catch (Exception e) {
            throw new KettleException(e);
        } finally {
            if (imageFile != null) {
                try {
                    imageFile.close();
                } catch (Exception e) {
                    // Ignore;
                }
            }
        }
    }

    // --- Set rows font
    // Set font size
    int rowFontSize = Const.toInt(environmentSubstitute(meta.getRowFontSize()),
            ExcelOutputMeta.DEFAULT_FONT_SIZE);
    // Set font name
    FontName rowFontName = ExcelFontMap.getFontName(meta.getRowFontName());

    data.writableFont = new WritableFont(rowFontName, rowFontSize, WritableFont.NO_BOLD, false,
            UnderlineStyle.NO_UNDERLINE);

    // Row font color
    Colour rowFontColour = ExcelFontMap.getColour(meta.getRowFontColor(), Colour.BLACK);
    if (!fontHeaderColour.equals(Colour.BLACK)) {
        data.writableFont.setColour(rowFontColour);
    }

    // Set rows background color if needed
    if (meta.getRowBackGroundColor() != ExcelOutputMeta.FONT_COLOR_NONE) {
        data.rowFontBackgoundColour = ExcelFontMap.getColour(meta.getRowBackGroundColor(), null);
    }
}

From source file:org.pentaho.di.trans.steps.getxmldata.GetXMLData.java

private boolean ReadNextString() {

    try {//w  ww .  j a va2  s. c o  m
        // Grab another row ...
        data.readrow = getRow();

        if (data.readrow == null) {
            // finished processing!

            if (log.isDetailed()) {
                logDetailed(BaseMessages.getString(PKG, "GetXMLData.Log.FinishedProcessing"));
            }
            return false;
        }

        if (first) {
            first = false;

            data.nrReadRow = getInputRowMeta().size();
            data.inputRowMeta = getInputRowMeta();
            data.outputRowMeta = data.inputRowMeta.clone();
            meta.getFields(data.outputRowMeta, getStepname(), null, null, this, repository, metaStore);

            // Get total previous fields
            data.totalpreviousfields = data.inputRowMeta.size();

            // Create convert meta-data objects that will contain Date & Number formatters
            data.convertRowMeta = new RowMeta();
            for (ValueMetaInterface valueMeta : data.convertRowMeta.getValueMetaList()) {
                data.convertRowMeta.addValueMeta(
                        ValueMetaFactory.cloneValueMeta(valueMeta, ValueMetaInterface.TYPE_STRING));
            }

            // For String to <type> conversions, we allocate a conversion meta data row as well...
            //
            data.convertRowMeta = data.outputRowMeta.cloneToType(ValueMetaInterface.TYPE_STRING);

            // Check is XML field is provided
            if (Const.isEmpty(meta.getXMLField())) {
                logError(BaseMessages.getString(PKG, "GetXMLData.Log.NoField"));
                throw new KettleException(BaseMessages.getString(PKG, "GetXMLData.Log.NoField"));
            }

            // cache the position of the field
            if (data.indexOfXmlField < 0) {
                data.indexOfXmlField = getInputRowMeta().indexOfValue(meta.getXMLField());
                if (data.indexOfXmlField < 0) {
                    // The field is unreachable !
                    logError(BaseMessages.getString(PKG, "GetXMLData.Log.ErrorFindingField",
                            meta.getXMLField()));
                    throw new KettleException(BaseMessages.getString(PKG,
                            "GetXMLData.Exception.CouldnotFindField", meta.getXMLField()));
                }
            }
        }

        if (meta.isInFields()) {
            // get XML field value
            String Fieldvalue = getInputRowMeta().getString(data.readrow, data.indexOfXmlField);

            if (log.isDetailed()) {
                logDetailed(BaseMessages.getString(PKG, "GetXMLData.Log.XMLStream", meta.getXMLField(),
                        Fieldvalue));
            }

            if (meta.getIsAFile()) {
                FileObject file = null;
                try {
                    // XML source is a file.
                    file = KettleVFS.getFileObject(Fieldvalue, getTransMeta());
                    // Open the XML document
                    if (!setDocument(null, file, false, false)) {
                        throw new KettleException(
                                BaseMessages.getString(PKG, "GetXMLData.Log.UnableCreateDocument"));
                    }

                    if (!applyXPath()) {
                        throw new KettleException(
                                BaseMessages.getString(PKG, "GetXMLData.Log.UnableApplyXPath"));
                    }

                    addFileToResultFilesname(file);

                    if (log.isDetailed()) {
                        logDetailed(BaseMessages.getString(PKG, "GetXMLData.Log.LoopFileOccurences",
                                "" + data.nodesize, file.getName().getBaseName()));
                    }

                } catch (Exception e) {
                    throw new KettleException(e);
                } finally {
                    try {
                        if (file != null) {
                            file.close();
                        }
                    } catch (Exception e) {
                        // Ignore close errors
                    }
                }
            } else {
                boolean url = false;
                boolean xmltring = true;
                if (meta.isReadUrl()) {
                    url = true;
                    xmltring = false;
                }

                // Open the XML document
                if (!setDocument(Fieldvalue, null, xmltring, url)) {
                    throw new KettleException(
                            BaseMessages.getString(PKG, "GetXMLData.Log.UnableCreateDocument"));
                }

                // Apply XPath and set node list
                if (!applyXPath()) {
                    throw new KettleException(BaseMessages.getString(PKG, "GetXMLData.Log.UnableApplyXPath"));
                }
                if (log.isDetailed()) {
                    logDetailed(BaseMessages.getString(PKG, "GetXMLData.Log.LoopFileOccurences",
                            "" + data.nodesize));
                }
            }
        }
    } catch (Exception e) {
        logError(BaseMessages.getString(PKG, "GetXMLData.Log.UnexpectedError", e.toString()));
        stopAll();
        logError(Const.getStackTracker(e));
        setErrors(1);
        return false;
    }
    return true;

}

From source file:org.pentaho.di.trans.steps.gpbulkloader.GPBulkLoader.java

public void dispose(StepMetaInterface smi, StepDataInterface sdi) {
    meta = (GPBulkLoaderMeta) smi;/*from w w w.  j  av a 2s .  c  om*/
    data = (GPBulkLoaderData) sdi;

    super.dispose(smi, sdi);

    if (!preview && meta.isEraseFiles()) {
        // Erase the created cfg/dat files if requested. We don't erase
        // the rest of the files because it would be "stupid" to erase them
        // right after creation. If you don't want them, don't fill them in.
        FileObject fileObject = null;

        String method = meta.getLoadMethod();

        // GPBulkLoaderMeta.METHOD_AUTO_CONCURRENT.equals(method) ||
        if (GPBulkLoaderMeta.METHOD_AUTO_END.equals(method)) {

            if (meta.getControlFile() != null) {
                try {
                    fileObject = KettleVFS.getFileObject(environmentSubstitute(meta.getControlFile()),
                            getTransMeta());
                    fileObject.delete();
                    fileObject.close();
                } catch (Exception ex) {
                    logError("Error deleting control file \'" + KettleVFS.getFilename(fileObject) + "\': "
                            + ex.getMessage());
                }
            }
        }

        if (GPBulkLoaderMeta.METHOD_AUTO_END.equals(method)) {
            // In concurrent mode the data is written to the control file.
            if (meta.getDataFile() != null) {
                try {
                    fileObject = KettleVFS.getFileObject(environmentSubstitute(meta.getDataFile()),
                            getTransMeta());
                    fileObject.delete();
                    fileObject.close();
                } catch (Exception ex) {
                    logError("Error deleting data file \'" + KettleVFS.getFilename(fileObject) + "\': "
                            + ex.getMessage(), ex);
                }
            }
        }

        if (GPBulkLoaderMeta.METHOD_MANUAL.equals(method)) {
            logBasic("Deletion of files is not compatible with \'manual load method\'");
        }
    }
}

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

public void dispose(StepMetaInterface smi, StepDataInterface sdi) {
    meta = (GPLoadMeta) smi;//from www  .  ja v a2 s  . c  o m
    data = (GPLoadData) sdi;

    super.dispose(smi, sdi);

    if (!preview && meta.isEraseFiles()) {
        // Erase the created cfg/dat files if requested. We don't erase
        // the rest of the files because it would be "stupid" to erase them
        // right after creation. If you don't want them, don't fill them in.
        FileObject fileObject = null;

        String method = meta.getLoadMethod();
        if (GPLoadMeta.METHOD_AUTO_END.equals(method)) {
            if (meta.getControlFile() != null) {
                try {
                    fileObject = KettleVFS.getFileObject(environmentSubstitute(meta.getControlFile()),
                            getTransMeta());
                    fileObject.delete();
                    fileObject.close();
                } catch (Exception ex) {
                    logError("Error deleting control file \'" + KettleVFS.getFilename(fileObject) + "\': "
                            + ex.getMessage());
                }
            }
        }

        if (GPLoadMeta.METHOD_AUTO_END.equals(method)) {
            // In concurrent mode the data is written to the control file.
            if (meta.getDataFile() != null) {
                try {
                    fileObject = KettleVFS.getFileObject(environmentSubstitute(meta.getDataFile()),
                            getTransMeta());
                    fileObject.delete();
                    fileObject.close();
                } catch (Exception ex) {
                    logError("Error deleting data file \'" + KettleVFS.getFilename(fileObject) + "\': "
                            + ex.getMessage(), ex);
                }
            }
        }

        if (GPLoadMeta.METHOD_MANUAL.equals(method)) {
            logBasic("Deletion of files is not compatible with \'manual load method\'");
        }
    }
}

From source file:org.pentaho.di.trans.steps.jsonoutput.JsonOutput.java

private void createParentFolder(String filename) throws KettleStepException {
    if (!meta.isCreateParentFolder()) {
        return;/*from  w  w  w .ja va  2  s  . c  o  m*/
    }
    // Check for parent folder
    FileObject parentfolder = null;
    try {
        // Get parent folder
        parentfolder = KettleVFS.getFileObject(filename, getTransMeta()).getParent();
        if (!parentfolder.exists()) {
            if (log.isDebug()) {
                logDebug(BaseMessages.getString(PKG, "JsonOutput.Error.ParentFolderNotExist",
                        parentfolder.getName()));
            }
            parentfolder.createFolder();
            if (log.isDebug()) {
                logDebug(BaseMessages.getString(PKG, "JsonOutput.Log.ParentFolderCreated"));
            }
        }
    } catch (Exception e) {
        throw new KettleStepException(BaseMessages.getString(PKG, "JsonOutput.Error.ErrorCreatingParentFolder",
                parentfolder.getName()));
    } finally {
        if (parentfolder != null) {
            try {
                parentfolder.close();
            } catch (Exception ex) { /* Ignore */
            }
        }
    }
}

From source file:org.pentaho.di.trans.steps.loadfileinput.LoadFileInput.java

private boolean openNextFile() {
    try {//from w w w. java2s  .c om
        if (meta.getIsInFields()) {
            data.readrow = getRow(); // Grab another row ...

            if (data.readrow == null) { // finished processing!

                if (isDetailed()) {
                    logDetailed(BaseMessages.getString(PKG, "LoadFileInput.Log.FinishedProcessing"));
                }
                return false;
            }

            if (first) {
                first = false;

                data.inputRowMeta = getInputRowMeta();
                data.outputRowMeta = data.inputRowMeta.clone();
                meta.getFields(data.outputRowMeta, getStepname(), null, null, this, repository, metaStore);

                // Create convert meta-data objects that will contain Date & Number formatters
                //
                data.convertRowMeta = data.outputRowMeta.cloneToType(ValueMetaInterface.TYPE_STRING);

                if (meta.getIsInFields()) {
                    // Check is filename field is provided
                    if (Const.isEmpty(meta.getDynamicFilenameField())) {
                        logError(BaseMessages.getString(PKG, "LoadFileInput.Log.NoField"));
                        throw new KettleException(BaseMessages.getString(PKG, "LoadFileInput.Log.NoField"));
                    }

                    // cache the position of the field
                    if (data.indexOfFilenameField < 0) {
                        data.indexOfFilenameField = data.inputRowMeta
                                .indexOfValue(meta.getDynamicFilenameField());
                        if (data.indexOfFilenameField < 0) {
                            // The field is unreachable !
                            logError(BaseMessages.getString(PKG, "LoadFileInput.Log.ErrorFindingField") + "["
                                    + meta.getDynamicFilenameField() + "]");
                            throw new KettleException(
                                    BaseMessages.getString(PKG, "LoadFileInput.Exception.CouldnotFindField",
                                            meta.getDynamicFilenameField()));
                        }
                    }
                    // Get the number of previous fields
                    data.totalpreviousfields = data.inputRowMeta.size();

                }
            } // end if first

            // get field value
            String Fieldvalue = data.inputRowMeta.getString(data.readrow, data.indexOfFilenameField);

            if (isDetailed()) {
                logDetailed(BaseMessages.getString(PKG, "LoadFileInput.Log.Stream",
                        meta.getDynamicFilenameField(), Fieldvalue));
            }

            FileObject file = null;
            try {
                // Source is a file.
                data.file = KettleVFS.getFileObject(Fieldvalue);
            } catch (Exception e) {
                throw new KettleException(e);
            } finally {
                try {
                    if (file != null) {
                        file.close();
                    }
                } catch (Exception e) {
                    // Ignore errors
                }
            }
        } else {
            if (data.filenr >= data.files.nrOfFiles()) {
                // finished processing!

                if (isDetailed()) {
                    logDetailed(BaseMessages.getString(PKG, "LoadFileInput.Log.FinishedProcessing"));
                }
                return false;
            }

            // Is this the last file?
            data.last_file = (data.filenr == data.files.nrOfFiles() - 1);
            data.file = data.files.getFile(data.filenr);
        }

        // Check if file is empty
        data.fileSize = data.file.getContent().getSize();
        // Move file pointer ahead!
        data.filenr++;

        if (meta.isIgnoreEmptyFile() && data.fileSize == 0) {
            logError(BaseMessages.getString(PKG, "LoadFileInput.Error.FileSizeZero", "" + data.file.getName()));
            openNextFile();

        } else {
            if (isDetailed()) {
                logDetailed(BaseMessages.getString(PKG, "LoadFileInput.Log.OpeningFile", data.file.toString()));
            }
            data.filename = KettleVFS.getFilename(data.file);
            // Add additional fields?
            if (meta.getShortFileNameField() != null && meta.getShortFileNameField().length() > 0) {
                data.shortFilename = data.file.getName().getBaseName();
            }
            if (meta.getPathField() != null && meta.getPathField().length() > 0) {
                data.path = KettleVFS.getFilename(data.file.getParent());
            }
            if (meta.isHiddenField() != null && meta.isHiddenField().length() > 0) {
                data.hidden = data.file.isHidden();
            }
            if (meta.getExtensionField() != null && meta.getExtensionField().length() > 0) {
                data.extension = data.file.getName().getExtension();
            }
            if (meta.getLastModificationDateField() != null
                    && meta.getLastModificationDateField().length() > 0) {
                data.lastModificationDateTime = new Date(data.file.getContent().getLastModifiedTime());
            }
            if (meta.getUriField() != null && meta.getUriField().length() > 0) {
                data.uriName = data.file.getName().getURI();
            }
            if (meta.getRootUriField() != null && meta.getRootUriField().length() > 0) {
                data.rootUriName = data.file.getName().getRootURI();
            }
            // get File content
            getFileContent();

            addFileToResultFilesname(data.file);

            if (isDetailed()) {
                logDetailed(BaseMessages.getString(PKG, "LoadFileInput.Log.FileOpened", data.file.toString()));
            }
        }

    } catch (Exception e) {
        logError(BaseMessages.getString(PKG, "LoadFileInput.Log.UnableToOpenFile", "" + data.filenr,
                data.file.toString(), e.toString()));
        stopAll();
        setErrors(1);
        return false;
    }
    return true;
}

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

public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
    meta = (MailMeta) smi;/*from   ww w . j  av  a 2  s . co  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;
}