commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mario Ivankovits <ma...@ops.co.at>
Subject Re: [net] NT FTP Server & DIRSTYLE (was Re: [net] [vote] Release Commons-Net 1.2)
Date Thu, 01 Apr 2004 06:47:51 GMT
Steve Cohen wrote:

>Wow, that's nasty.  Or maybe not.
>  
>
I think using DIRSTYLE to toggle the output isnt that nice.
Another idea could be to change the DefaultFTPEntryParserFactory to 
allow easier derivation..

---snip---
    public FTPFileEntryParser createFileEntryParser(String key)
    {
        Class parserClass = null;
        try {
            parserClass = Class.forName(key);
            return (FTPFileEntryParser) parserClass.newInstance();
        } catch (ClassNotFoundException e) {
            String ukey = null;
            if (null != key) {
                ukey = key.toUpperCase();
            }
            if (ukey.indexOf("UNIX") >= 0) {
                return createUnixFTPEntryParser();
            } else if (ukey.indexOf("VMS") >= 0) {
                return createVMSVersioningFTPEntryParser();
            } else if (ukey.indexOf("WINDOWS") >= 0) {
                return createNTFTPEntryParser();
            } else if (ukey.indexOf("OS/2") >= 0) {
                return createOS2FTPEntryParser();
            } else if (ukey.indexOf("OS/400") >= 0) {
                return createOS400FTPEntryParser();
            } 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);
        }
    }

    public FTPFileEntryParser createUnixFTPEntryParser()
    {
        return new UnixFTPEntryParser();
    }

    public FTPFileEntryParser createVMSVersioningFTPEntryParser()
    {
        return new VMSVersioningFTPEntryParser();
    }

    public FTPFileEntryParser createNTFTPEntryParser()
    {
        return new NTFTPEntryParser();
    }

    public FTPFileEntryParser createOS2FTPEntryParser()
    {
        return new OS2FTPEntryParser();
    }

    public FTPFileEntryParser createOS400FTPEntryParser()
    {
        return new OS400FTPEntryParser();
    }
---snip---

That way, you still have the current behaviour, and one could easily 
override the function "createNTFTPEntryParser()" to return an 
UnixFTPEntryParser.
People (including me) deriving from DefaultFTPEntryParserFactory also 
benefit from later added parsers.


Ciao,
Mario


Mime
View raw message