Search in sources :

Example 1 with FTPFileFactory

use of com.enterprisedt.net.ftp.FTPFileFactory in project pentaho-kettle by pentaho.

the class JobEntryFTP method hookInOtherParsers.

/**
 * Hook in known parsers, and then those that have been specified in the variable ftp.file.parser.class.names
 *
 * @param ftpClient
 * @throws FTPException
 * @throws IOException
 */
protected void hookInOtherParsers(FTPClient ftpClient) throws FTPException, IOException {
    if (log.isDebug()) {
        logDebug(BaseMessages.getString(PKG, "JobEntryFTP.DEBUG.Hooking.Parsers"));
    }
    String system = ftpClient.system();
    MVSFileParser parser = new MVSFileParser(log);
    if (log.isDebug()) {
        logDebug(BaseMessages.getString(PKG, "JobEntryFTP.DEBUG.Created.MVS.Parser"));
    }
    FTPFileFactory factory = new FTPFileFactory(system);
    if (log.isDebug()) {
        logDebug(BaseMessages.getString(PKG, "JobEntryFTP.DEBUG.Created.Factory"));
    }
    factory.addParser(parser);
    ftpClient.setFTPFileFactory(factory);
    if (log.isDebug()) {
        logDebug(BaseMessages.getString(PKG, "JobEntryFTP.DEBUG.Get.Variable.Space"));
    }
    VariableSpace vs = this.getVariables();
    if (vs != null) {
        if (log.isDebug()) {
            logDebug(BaseMessages.getString(PKG, "JobEntryFTP.DEBUG.Getting.Other.Parsers"));
        }
        String otherParserNames = vs.getVariable("ftp.file.parser.class.names");
        if (otherParserNames != null) {
            if (log.isDebug()) {
                logDebug(BaseMessages.getString(PKG, "JobEntryFTP.DEBUG.Creating.Parsers"));
            }
            String[] parserClasses = otherParserNames.split("|");
            String cName = null;
            Class<?> clazz = null;
            Object parserInstance = null;
            for (int i = 0; i < parserClasses.length; i++) {
                cName = parserClasses[i].trim();
                if (cName.length() > 0) {
                    try {
                        clazz = Class.forName(cName);
                        parserInstance = clazz.newInstance();
                        if (parserInstance instanceof FTPFileParser) {
                            if (log.isDetailed()) {
                                logDetailed(BaseMessages.getString(PKG, "JobEntryFTP.DEBUG.Created.Other.Parser", cName));
                            }
                            factory.addParser((FTPFileParser) parserInstance);
                        }
                    } catch (Exception ignored) {
                        if (log.isDebug()) {
                            ignored.printStackTrace();
                            logError(BaseMessages.getString(PKG, "JobEntryFTP.ERROR.Creating.Parser", cName));
                        }
                    }
                }
            }
        }
    }
}
Also used : FTPFileFactory(com.enterprisedt.net.ftp.FTPFileFactory) VariableSpace(org.pentaho.di.core.variables.VariableSpace) FileObject(org.apache.commons.vfs2.FileObject) FTPFileParser(com.enterprisedt.net.ftp.FTPFileParser) FTPException(com.enterprisedt.net.ftp.FTPException) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 2 with FTPFileFactory

use of com.enterprisedt.net.ftp.FTPFileFactory in project pentaho-kettle by pentaho.

the class JobEntryFTPPUT method hookInOtherParsers.

/**
 * Hook in known parsers, and then those that have been specified in the variable ftp.file.parser.class.names
 *
 * @param ftpClient
 * @throws FTPException
 * @throws IOException
 */
protected void hookInOtherParsers(FTPClient ftpClient) throws FTPException, IOException {
    if (log.isDebug()) {
        logDebug(BaseMessages.getString(PKG, "JobEntryFTP.DEBUG.Hooking.Parsers"));
    }
    String system = ftpClient.system();
    MVSFileParser parser = new MVSFileParser(log);
    if (log.isDebug()) {
        logDebug(BaseMessages.getString(PKG, "JobEntryFTP.DEBUG.Created.MVS.Parser"));
    }
    FTPFileFactory factory = new FTPFileFactory(system);
    if (log.isDebug()) {
        logDebug(BaseMessages.getString(PKG, "JobEntryFTP.DEBUG.Created.Factory"));
    }
    factory.addParser(parser);
    ftpClient.setFTPFileFactory(factory);
    if (log.isDebug()) {
        logDebug(BaseMessages.getString(PKG, "JobEntryFTP.DEBUG.Get.Variable.Space"));
    }
    VariableSpace vs = this.getVariables();
    if (vs != null) {
        if (log.isDebug()) {
            logDebug(BaseMessages.getString(PKG, "JobEntryFTP.DEBUG.Getting.Other.Parsers"));
        }
        String otherParserNames = vs.getVariable("ftp.file.parser.class.names");
        if (otherParserNames != null) {
            if (log.isDebug()) {
                logDebug(BaseMessages.getString(PKG, "JobEntryFTP.DEBUG.Creating.Parsers"));
            }
            String[] parserClasses = otherParserNames.split("|");
            String cName = null;
            Class<?> clazz = null;
            Object parserInstance = null;
            for (int i = 0; i < parserClasses.length; i++) {
                cName = parserClasses[i].trim();
                if (cName.length() > 0) {
                    try {
                        clazz = Class.forName(cName);
                        parserInstance = clazz.newInstance();
                        if (parserInstance instanceof FTPFileParser) {
                            if (log.isDetailed()) {
                                logDetailed(BaseMessages.getString(PKG, "JobEntryFTP.DEBUG.Created.Other.Parser", cName));
                            }
                            factory.addParser((FTPFileParser) parserInstance);
                        }
                    } catch (Exception ignored) {
                        if (log.isDebug()) {
                            ignored.printStackTrace();
                            logError(BaseMessages.getString(PKG, "JobEntryFTP.ERROR.Creating.Parser", cName));
                        }
                    }
                }
            }
        }
    }
}
Also used : MVSFileParser(org.pentaho.di.job.entries.ftp.MVSFileParser) FTPFileFactory(com.enterprisedt.net.ftp.FTPFileFactory) VariableSpace(org.pentaho.di.core.variables.VariableSpace) FTPFileParser(com.enterprisedt.net.ftp.FTPFileParser) FTPException(com.enterprisedt.net.ftp.FTPException) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) IOException(java.io.IOException)

Aggregations

FTPException (com.enterprisedt.net.ftp.FTPException)2 FTPFileFactory (com.enterprisedt.net.ftp.FTPFileFactory)2 FTPFileParser (com.enterprisedt.net.ftp.FTPFileParser)2 IOException (java.io.IOException)2 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)2 KettleException (org.pentaho.di.core.exception.KettleException)2 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)2 VariableSpace (org.pentaho.di.core.variables.VariableSpace)2 UnknownHostException (java.net.UnknownHostException)1 FileObject (org.apache.commons.vfs2.FileObject)1 MVSFileParser (org.pentaho.di.job.entries.ftp.MVSFileParser)1