Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one or more
   * contributor license agreements.  See the NOTICE file distributed with
   * this work for additional information regarding copyright ownership.
   * The ASF licenses this file to You under the Apache License, Version 2.0
   * (the "License"); you may not use this file except in compliance with
   * the License.  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.apache.commons.net.ftp.parser;
 
 
This is the default implementation of the FTPFileEntryParserFactory interface. This is the implementation that will be used by org.apache.commons.net.ftp.FTPClient.listFiles() if no other implementation has been specified.

 
     implements FTPFileEntryParserFactory
 {
 
     // Match a plain Java Identifier
     private static final String JAVA_IDENTIFIER = "\\p{javaJavaIdentifierStart}(\\p{javaJavaIdentifierPart})*";
     // Match a qualified name, e.g. a.b.c.Name - but don't allow the default package as that would allow "VMS"/"UNIX" etc.
     private static final String JAVA_QUALIFIED_NAME  = "("++"\\.)+"+;
     // Create the pattern, as it will be reused many times
     private static final Pattern JAVA_QUALIFIED_NAME_PATTERN = Pattern.compile();

    
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 (default package is not allowed) 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.

If key is not recognized as a fully qualified classname known to the system, this method will then attempt to see whether it contains a string identifying one of the known parsers. This comparison is case-insensitive. 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.

Parameters:
key should be a fully qualified classname corresponding to a class implementing the FTPFileEntryParser interface
OR
a string containing (case-insensitively) one of the following keywords:
  • UNIX
  • WINDOWS
  • OS/2
  • OS/400
  • AS/400
  • VMS
  • MVS
  • NETWARE
  • TYPE:L8
Returns:
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 also:
org.apache.commons.net.ftp.FTPFileEntryParser
 
 //    @Override
     {
         if (key == null) {
             throw new ParserInitializationException("Parser key cannot be null");
         }
         return createFileEntryParser(keynull);
     }
 
     // Common method to process both key and config parameters.
     private FTPFileEntryParser createFileEntryParser(String keyFTPClientConfig config) {
        FTPFileEntryParser parser = null;
        // Is the key a possible class name?
        if (.matcher(key).matches()) {
            try
            {
                Class<?> parserClass = Class.forName(key);
                try {
                    parser = (FTPFileEntryParserparserClass.newInstance();
                } catch (ClassCastException e) {
                    throw new ParserInitializationException(parserClass.getName()
                        + " does not implement the interface "
                        + "org.apache.commons.net.ftp.FTPFileEntryParser."e);
                } catch (Exception e) {
                    throw new ParserInitializationException("Error initializing parser"e);
                } catch (ExceptionInInitializerError e) {
                    throw new ParserInitializationException("Error initializing parser"e);
                }
            } catch (ClassNotFoundException e) {
                // OK, assume it is an alias
            }
        }
        if (parser == null) { // Now try for aliases
            String ukey = key.toUpperCase(...);
            if (ukey.indexOf(.) >= 0)
            {
                parser = new UnixFTPEntryParser(config);
            }
            else if (ukey.indexOf(.) >= 0)
            {
                parser = new VMSVersioningFTPEntryParser(config);
            }
            else if (ukey.indexOf(.) >= 0)
            {
                parser = createNTFTPEntryParser(config);
            }
            else if (ukey.indexOf(.) >= 0)
            {
                parser = new OS2FTPEntryParser(config);
            }
            else if (ukey.indexOf(.) >= 0 ||
                    ukey.indexOf(.) >= 0)
            {
                parser = createOS400FTPEntryParser(config);
            }
            else if (ukey.indexOf(.) >= 0)
            {
                parser = new MVSFTPEntryParser(); // Does not currently support config parameter
            }
            else if (ukey.indexOf(.) >= 0)
            {
                parser = new NetwareFTPEntryParser(config);
            }
            else if (ukey.indexOf(.) >= 0)
            {
                parser = new MacOsPeterFTPEntryParser(config);
            }
            else if (ukey.indexOf(.) >= 0)
            {
                // L8 normally means Unix, but move it to the end for some L8 systems that aren't.
                // This check should be last!
                parser = new UnixFTPEntryParser(config);
            }
            else
            {
                throw new ParserInitializationException("Unknown parser type: " + key);
            }
        }
        if (parser instanceof Configurable) {
            ((Configurable)parser).configure(config);
        }
        return parser;
    }

    

Implementation extracts a key from the supplied org.apache.commons.net.ftp.FTPClientConfig parameter and creates an object implementing the interface FTPFileEntryParser and uses the supplied configuration to configure it.

Note that this method will generally not be called in scenarios that call for autodetection of parser type but rather, for situations where the user knows that the server uses a non-default configuration and knows what that configuration is.

Parameters:
config A org.apache.commons.net.ftp.FTPClientConfig used to configure the parser created
Returns:
the @link FTPFileEntryParser FTPFileEntryParser} so created.
Throws:
ParserInitializationException Thrown on any exception in instantiation
java.lang.NullPointerException if config is null
Since:
1.4
//    @Override
    throws ParserInitializationException
    {
        String key = config.getServerSystemKey();
        return createFileEntryParser(keyconfig);
    }
    {
        return new UnixFTPEntryParser();
    }
    {
        return new VMSVersioningFTPEntryParser();
    }
        return new NetwareFTPEntryParser();
    }
    {
        return createNTFTPEntryParser(null);
    }

    
Creates an NT FTP parser: if the config exists, and the system key equals FTPClientConfig.SYST_NT then a plain NTFTPEntryParser is used, otherwise a composite of NTFTPEntryParser and UnixFTPEntryParser is used.

Parameters:
config the config to use, may be null
Returns:
the parser
    {
        if (config != null && ..equals(
                config.getServerSystemKey()))
        {
            return new NTFTPEntryParser(config);
        } else {
            return new CompositeFileEntryParser(new FTPFileEntryParser[]
                   {
                       new NTFTPEntryParser(config),
                       new UnixFTPEntryParser(config)
                   });
        }
    }
    {
        return new OS2FTPEntryParser();
    }
    {
        return createOS400FTPEntryParser(null);
    }

    
Creates an OS400 FTP parser: if the config exists, and the system key equals FTPClientConfig.SYST_OS400 then a plain OS400FTPEntryParser is used, otherwise a composite of OS400FTPEntryParser and UnixFTPEntryParser is used.

Parameters:
config the config to use, may be null
Returns:
the parser
        {
        if (config != null &&
                ..equals(config.getServerSystemKey()))
        {
            return new OS400FTPEntryParser(config);
        } else {
            return new CompositeFileEntryParser(new FTPFileEntryParser[]
                {
                    new OS400FTPEntryParser(config),
                    new UnixFTPEntryParser(config)
                });
        }
    }
    {
        return new MVSFTPEntryParser();
    }
New to GrepCode? Check out our FAQ X