FileDocCategorySizeDatePackage
NTFTPEntryParser.javaAPI DocApache Commons NET 1.4.1 API4732Sat Dec 03 10:05:48 GMT 2005org.apache.commons.net.ftp.parser

NTFTPEntryParser

public class NTFTPEntryParser extends ConfigurableFTPFileEntryParserImpl
Implementation of FTPFileEntryParser and FTPFileListParser for NT Systems.
author
Winston Ojeda
author
Steve Cohen
version
$Id: NTFTPEntryParser.java 155429 2005-02-26 13:13:04Z dirkv $
see
org.apache.commons.net.ftp.FTPFileEntryParser FTPFileEntryParser (for usage instructions)

Fields Summary
private static final String
DEFAULT_DATE_FORMAT
private static final String
REGEX
this is the regular expression used by this parser.
Constructors Summary
public NTFTPEntryParser()
The sole constructor for an NTFTPEntryParser object.

exception
IllegalArgumentException Thrown if the regular expression is unparseable. Should not be seen under normal conditions. It it is seen, this is a sign that REGEX is not a valid regular expression.


                                                   
     
    
        this(null);
    
public NTFTPEntryParser(org.apache.commons.net.ftp.FTPClientConfig config)
This constructor allows the creation of an NTFTPEntryParser object with something other than the default configuration.

param
config The {@link FTPClientConfig configuration} object used to configure this parser.
exception
IllegalArgumentException Thrown if the regular expression is unparseable. Should not be seen under normal conditions. It it is seen, this is a sign that REGEX is not a valid regular expression.
since
1.4

        super(REGEX);
        configure(config);
    
Methods Summary
public org.apache.commons.net.ftp.FTPClientConfiggetDefaultConfiguration()
Defines a default configuration to be used when this class is instantiated without a {@link FTPClientConfig FTPClientConfig} parameter being specified.

return
the default configuration for this parser.

        return new FTPClientConfig(
                FTPClientConfig.SYST_NT,
                DEFAULT_DATE_FORMAT,
                null, null, null, null);
    
public org.apache.commons.net.ftp.FTPFileparseFTPEntry(java.lang.String entry)
Parses a line of an NT FTP server file listing and converts it into a usable format in the form of an FTPFile instance. If the file listing line doesn't describe a file, null is returned, otherwise a FTPFile instance representing the files in the directory is returned.

param
entry A line of text from the file listing
return
An FTPFile instance corresponding to the supplied entry

        FTPFile f = new FTPFile();
        f.setRawListing(entry);

        if (matches(entry))
        {
        	String datestr = group(1)+" "+group(2);
            String dirString = group(3);
            String size = group(4);
            String name = group(5);
            try
            {
                f.setTimestamp(super.parseTimestamp(datestr));
            }
            catch (ParseException e)
            {
            	return null;  // this is a parsing failure too.
            }

            if (null == name || name.equals(".") || name.equals(".."))
            {
                return (null);
            }
            f.setName(name);


            if ("<DIR>".equals(dirString))
            {
                f.setType(FTPFile.DIRECTORY_TYPE);
                f.setSize(0);
            }
            else
            {
                f.setType(FTPFile.FILE_TYPE);
                if (null != size)
                {
                  f.setSize(Long.parseLong(size));
                }
            }
            return (f);
        }
        return null;