Example usage for org.apache.commons.net.ftp.parser ParserInitializationException ParserInitializationException

List of usage examples for org.apache.commons.net.ftp.parser ParserInitializationException ParserInitializationException

Introduction

In this page you can find the example usage for org.apache.commons.net.ftp.parser ParserInitializationException ParserInitializationException.

Prototype

public ParserInitializationException(String message) 

Source Link

Document

Constucts a ParserInitializationException with just a message

Usage

From source file:ch.cyberduck.core.ftp.FTPParserFactory.java

public CompositeFileEntryParser createFileEntryParser(final String system, final TimeZone timezone)
        throws ParserInitializationException {
    if (null != system) {
        String ukey = system.toUpperCase(Locale.ROOT);
        if (ukey.contains(FTPClientConfig.SYST_UNIX)) {
            return this.createUnixFTPEntryParser(timezone);
        } else if (ukey.contains(FTPClientConfig.SYST_VMS)) {
            throw new ParserInitializationException(
                    String.format("\"%s\" is not currently a supported system.", system));
        } else if (ukey.contains(FTPClientConfig.SYST_NETWARE)) {
            return this.createNetwareFTPEntryParser(timezone);
        } else if (ukey.contains(FTPClientConfig.SYST_NT)) {
            return this.createNTFTPEntryParser(timezone);
        } else if (ukey.contains(FTPClientConfig.SYST_OS2)) {
            return this.createOS2FTPEntryParser(timezone);
        } else if (ukey.contains(FTPClientConfig.SYST_OS400)) {
            return this.createOS400FTPEntryParser(timezone);
        } else if (ukey.contains(FTPClientConfig.SYST_MVS)) {
            return this.createUnixFTPEntryParser(timezone);
        }//from w w  w  .  j a va  2 s . c o  m
    }
    // Defaulting to UNIX parser
    return this.createUnixFTPEntryParser(timezone);
}

From source file:org.openo.nfvo.emsdriver.commons.ftp.ExtendsDefaultFTPFileEntryParserFactory.java

/**
* This default implementation of the FTPFileEntryParserFactory
* interface works according to the following logic:
* First it attempts to interpret the supplied key as a fully
* qualified classname of a class implementing the
* FTPFileEntryParser interface.  If that succeeds, a parser
* object of this class is instantiated and is returned; 
* otherwise it attempts to interpret the key as an identirier
* commonly used by the FTP SYST command to identify systems.
* <p/>//w  w  w.  ja va  2  s .  c om
* If <code>key</code> is not recognized as a fully qualified
* classname known to the system, this method will then attempt
* to see whether it <b>contains</b> a string identifying one of
* the known parsers.  This comparison is <b>case-insensitive</b>.
* The intent here is where possible, to select as keys strings
* which are returned by the SYST command on the systems which
* the corresponding parser successfully parses.  This enables
* this factory to be used in the auto-detection system.
* <p/>
*
* @param key    should be a fully qualified classname corresponding to
*               a class implementing the FTPFileEntryParser interface<br/>
*               OR<br/>
*               a string containing (case-insensitively) one of the
*               following keywords:
*               <ul>
*               <li>{@link FTPClientConfig#SYST_UNIX UNIX}</li>
*               <li>{@link FTPClientConfig#SYST_NT WINDOWS}</li>
*               <li>{@link FTPClientConfig#SYST_OS2 OS/2}</li>
*               <li>{@link FTPClientConfig#SYST_OS400 OS/400}</li>
*               <li>{@link FTPClientConfig#SYST_VMS VMS}</li>
*               <li>{@link FTPClientConfig#SYST_MVS MVS}</li>
*               </ul>
* @return the FTPFileEntryParser corresponding to the supplied key.
* @throws ParserInitializationException thrown if for any reason the factory cannot resolve
*                   the supplied key into an FTPFileEntryParser.
* @see FTPFileEntryParser
*/
public FTPFileEntryParser createFileEntryParser(String key) {
    @SuppressWarnings("rawtypes")
    Class parserClass = null;
    FTPFileEntryParser parser = null;
    try {
        parserClass = Class.forName(key);
        parser = (FTPFileEntryParser) parserClass.newInstance();
    } catch (ClassNotFoundException e) {
        String ukey = null;
        if (null != key) {
            ukey = key.toUpperCase();
        }
        if (ukey.indexOf(FTPClientConfig.SYST_UNIX) >= 0) {
            parser = createUnixFTPEntryParser();
        } else if (ukey.indexOf(FTPClientConfig.SYST_VMS) >= 0) {
            parser = createVMSVersioningFTPEntryParser();
        } else if (ukey.indexOf(FTPClientConfig.SYST_NT) >= 0 || ukey.indexOf("DOPRA") >= 0
                || ukey.indexOf("MSDOS") >= 0) {
            parser = createNTFTPEntryParser();
        } else if (ukey.indexOf(FTPClientConfig.SYST_OS2) >= 0) {
            parser = createOS2FTPEntryParser();
        } else if (ukey.indexOf(FTPClientConfig.SYST_OS400) >= 0) {
            parser = createOS400FTPEntryParser();
        } else if (ukey.indexOf(FTPClientConfig.SYST_MVS) >= 0) {
            parser = createMVSEntryParser();
        } else {
            throw new ParserInitializationException("Unknown parser type: " + key);
        }
    } catch (ClassCastException e) {
        throw new ParserInitializationException(parserClass.getName() + " does not implement the interface "
                + "org.apache.commons.net.ftp.FTPFileEntryParser.", e);
    } catch (Throwable e) {
        throw new ParserInitializationException("Error initializing parser", e);
    }

    if (parser instanceof Configurable) {
        ((Configurable) parser).configure(this.config);
    }
    return parser;
}