Search in sources :

Example 1 with MVSFileParser

use of org.pentaho.di.job.entries.ftp.MVSFileParser 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)1 FTPFileFactory (com.enterprisedt.net.ftp.FTPFileFactory)1 FTPFileParser (com.enterprisedt.net.ftp.FTPFileParser)1 IOException (java.io.IOException)1 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)1 KettleException (org.pentaho.di.core.exception.KettleException)1 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)1 VariableSpace (org.pentaho.di.core.variables.VariableSpace)1 MVSFileParser (org.pentaho.di.job.entries.ftp.MVSFileParser)1