commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bre...@apache.org
Subject cvs commit: jakarta-commons-sandbox/net/src/java/org/apache/commons/net/ftp/ftp2/parser MatchApparatus.java NTFTPEntryParser.java OS2FTPEntryParser.java UnixFTPEntryParser.java VMSFTPEntryParser.java
Date Tue, 30 Apr 2002 13:59:42 GMT
brekke      02/04/30 06:59:42

  Modified:    net/src/java/org/apache/commons/net/ftp/ftp2 FTPClient2.java
                        FTPFileEntryParser.java FTPFileIterator.java
                        FTPFileList.java
               net/src/java/org/apache/commons/net/ftp/ftp2/parser
                        MatchApparatus.java NTFTPEntryParser.java
                        OS2FTPEntryParser.java UnixFTPEntryParser.java
                        VMSFTPEntryParser.java
  Log:
  Patch from Steve Cohen:
  
  This is a series of mostly cosmetic changes in response to the CheckStyle
  suggestions and a couple of howling pieces of debugging junk that should not
  have made it through - System.out.println() and the like.  A little more
  significantly, two instances where exceptions were eaten were fixed -
  in FTPFileList and MatchApparatus.
  
  Revision  Changes    Path
  1.2       +9 -5      jakarta-commons-sandbox/net/src/java/org/apache/commons/net/ftp/ftp2/FTPClient2.java
  
  Index: FTPClient2.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/net/src/java/org/apache/commons/net/ftp/ftp2/FTPClient2.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FTPClient2.java	29 Apr 2002 03:55:31 -0000	1.1
  +++ FTPClient2.java	30 Apr 2002 13:59:42 -0000	1.2
  @@ -59,7 +59,6 @@
   import org.apache.commons.net.ftp.FTPClient;
   import org.apache.commons.net.ftp.FTPCommand;
   import org.apache.commons.net.ftp.FTPFile;
  -import org.apache.commons.net.ftp.ftp2.FTPFileEntryParser;
   import org.apache.commons.net.ftp.ftp2.parser.UnixFTPEntryParser;
   
   /**
  @@ -74,11 +73,14 @@
    * way.
    *
    * @author <a href="mailto:stevecoh1@attbi.com">Steve Cohen</a>
  - * @version $Id: FTPClient2.java,v 1.1 2002/04/29 03:55:31 brekke Exp $
  + * @version $Id: FTPClient2.java,v 1.2 2002/04/30 13:59:42 brekke Exp $
    */
   public class FTPClient2 extends FTPClient
   {
       private FTPFileEntryParser __fileEntryParser;
  +    /**
  +     * The only constructor for this class.
  +     */
       public FTPClient2()
       {
           super();
  @@ -187,8 +189,8 @@
        * capable of providing parsed FTPFile objects, one for each file containing
        * information contained in the given path in the format determined by the 
        * <code> parser </code> parameter.   Null will be returned if a 
  -     * data connection cannot be opened.  If the current working directory contains
  -     * no files, an empty array will be the return.
  +     * data connection cannot be opened.  If the current working directory
  +     * contains no files, an empty array will be the return.
        * @exception FTPConnectionClosedException
        *      If the FTP server prematurely closes the connection as a result
        *      of the client being idle or some other reason causing the server
  @@ -214,7 +216,7 @@
        * using glob expressions because the return format for glob listings
        * differs from server to server and will likely cause this method to fail.
        * <p>
  -     * @param pathname  The file or directory to list.
  +     * @param basedir The file or directory to list.
        * @return An iteratable object that holds the raw information and is 
        * capable of providing parsed FTPFile objects, one for each file containing
        * information contained in the given path in the format determined by the 
  @@ -306,7 +308,9 @@
           FTPFile[] results;
   
           if ((socket = __openDataConnection(FTPCommand.LIST, pathname)) == null)
  +        {
               return null;
  +        }
   
           FTPFileList list =
               FTPFileList.create(socket.getInputStream(), parser);
  
  
  
  1.2       +3 -2      jakarta-commons-sandbox/net/src/java/org/apache/commons/net/ftp/ftp2/FTPFileEntryParser.java
  
  Index: FTPFileEntryParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/net/src/java/org/apache/commons/net/ftp/ftp2/FTPFileEntryParser.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FTPFileEntryParser.java	29 Apr 2002 03:55:31 -0000	1.1
  +++ FTPFileEntryParser.java	30 Apr 2002 13:59:42 -0000	1.2
  @@ -58,13 +58,14 @@
   
   /**
    * FTPFileEntryParser defines the interface for parsing a single FTP file
  - * listing and converting that information into an <a href="org.apache.commons.net.ftp.FTPFile.html">
FTPFile </a> instance.
  + * listing and converting that information into an 
  + * <a href="org.apache.commons.net.ftp.FTPFile.html"> FTPFile </a> instance.
    * Sometimes you will want to parse unusual listing formats, in which
    * case you would create your own implementation of FTPFileEntryParser and
    * if necessary, subclass FTPFile.
    *
    * @author <a href="mailto:stevecoh1@attbi.com">Steve Cohen</a>
  - * @version $Id: FTPFileEntryParser.java,v 1.1 2002/04/29 03:55:31 brekke Exp $
  + * @version $Id: FTPFileEntryParser.java,v 1.2 2002/04/30 13:59:42 brekke Exp $
    * @see org.apache.commons.net.ftp.FTPFile
    * @see FTPClient2#listFiles
    */
  
  
  
  1.2       +9 -9      jakarta-commons-sandbox/net/src/java/org/apache/commons/net/ftp/ftp2/FTPFileIterator.java
  
  Index: FTPFileIterator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/net/src/java/org/apache/commons/net/ftp/ftp2/FTPFileIterator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FTPFileIterator.java	29 Apr 2002 03:55:31 -0000	1.1
  +++ FTPFileIterator.java	30 Apr 2002 13:59:42 -0000	1.2
  @@ -65,7 +65,7 @@
    * be receieved as an array of any requested number of entries or all of them.
    *
    * @author <a href="mailto:stevecoh1@attbi.com">Steve Cohen</a>
  - * @version $Id: FTPFileIterator.java,v 1.1 2002/04/29 03:55:31 brekke Exp $
  + * @version $Id: FTPFileIterator.java,v 1.2 2002/04/30 13:59:42 brekke Exp $
    * @see org.apache.commons.net.ftp.ftp2.FTPFileList
    */
   public class FTPFileIterator
  @@ -114,7 +114,7 @@
           FTPFile entry = null;
           for (int iter = 0; iter < this.rawlines.size(); iter++)
           {
  -            String line = (String)this.rawlines.elementAt(iter);
  +            String line = (String) this.rawlines.elementAt(iter);
               entry = parseFTPEntry(line);
               if (null != entry)
               {
  @@ -194,7 +194,7 @@
           for (int i = 0, e = this.firstGoodEntry + this.itemptr ;
                   i < _howMany; i++, e++)
           {
  -            output[i] = parseFTPEntry((String)this.rawlines.elementAt(e));
  +            output[i] = parseFTPEntry((String) this.rawlines.elementAt(e));
               this.itemptr++;
   
           }
  @@ -269,16 +269,16 @@
        */
       public FTPFile[] getPrevious(int howMany)
       {
  -        int _howMany = howMany;
  +        int how_many = howMany;
           // can't retreat further than we've come.
  -        if (_howMany > this.itemptr)
  +        if (how_many > this.itemptr)
           {
  -            _howMany = this.itemptr;
  +            how_many = this.itemptr;
           }
  -        FTPFile[] output = new FTPFile[_howMany];
  -        for (int i = _howMany, e = this.firstGoodEntry + this.itemptr; i > 0;)
  +        FTPFile[] output = new FTPFile[how_many];
  +        for (int i = how_many, e = this.firstGoodEntry + this.itemptr; i > 0; )
           {
  -            output[--i] = parseFTPEntry((String)this.rawlines.elementAt(--e));
  +            output[--i] = parseFTPEntry((String) this.rawlines.elementAt(--e));
               this.itemptr--;
           }
           return output;
  
  
  
  1.2       +47 -23    jakarta-commons-sandbox/net/src/java/org/apache/commons/net/ftp/ftp2/FTPFileList.java
  
  Index: FTPFileList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/net/src/java/org/apache/commons/net/ftp/ftp2/FTPFileList.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FTPFileList.java	29 Apr 2002 03:55:32 -0000	1.1
  +++ FTPFileList.java	30 Apr 2002 13:59:42 -0000	1.2
  @@ -58,10 +58,8 @@
   import java.io.IOException;
   import java.io.InputStream;
   import java.io.InputStreamReader;
  -import java.util.Enumeration;
   import java.util.Vector;
   import org.apache.commons.net.ftp.FTPFile;
  -import org.apache.commons.net.ftp.ftp2.FTPFileEntryParser;
   
   /**
    * FTPFileList.java
  @@ -79,14 +77,23 @@
    * which required a bigger memory hit.
    *
    * @author <a href="mailto:stevecoh1@attbi.com">Steve Cohen</a>
  - * @version $Id: FTPFileList.java,v 1.1 2002/04/29 03:55:32 brekke Exp $
  + * @version $Id: FTPFileList.java,v 1.2 2002/04/30 13:59:42 brekke Exp $
    * @see FTPClient2#listFiles
    * @see FTPClient2#createFileList
    */
   public class FTPFileList
   {
  +    /**
  +     * storage for the raw lines of input read from the FTP server
  +     */
       private Vector lines = null;
  +    /**
  +     * the FTPFileEntryParser assigned to be used with this lister
  +     */
       private FTPFileEntryParser parser;
  +    /**
  +     * private status code for an empty directory
  +     */
       private static final int EMPTY_DIR = -2;
   
       /**
  @@ -103,7 +110,7 @@
       }
   
       /**
  -     * The only way to create an <code> FTPFileList</code> object.  Invokes

  +     * The only way to create an <code>FTPFileList</code> object.  Invokes
        * the private constructor and then reads the stream  supplied stream to
        * build the intermediate array of "lines" which will later be parsed
        * into <code>FTPFile</code> object.
  @@ -112,29 +119,29 @@
        * the output of the LIST command was returned
        * @param parser the default <code>FTPFileEntryParser</code> to be used
        * by this object.  This may later be changed using the init() method.
  -     * @param sleepInterval - amount of time in milliseconds to sleep
  -     *                        between lines read.
  +     * 
        * @return the <code>FTPFileList</code> created, with an initialized
        * of unparsed lines of output.  Will be null if the listing cannot
        * be read from the stream.
  +     * @exception IOException
  +     *                   Thrown on any failure to read from the socket.
        */
       public static FTPFileList create( InputStream stream,
                                         FTPFileEntryParser parser)
  +            throws IOException
       {
  -        try
  -        {
  -            FTPFileList list = new FTPFileList(parser);
  -            list.readStream(stream);
  -            return list;
  -
  -        }
  -        catch (IOException e)
  -        {
  -            System.out.println("IOException " + e.getMessage());
  -            return null;
  -        }
  -    }
  +        FTPFileList list = new FTPFileList(parser);
  +        list.readStream(stream);
  +        return list;
  +    } 
   
  +    /**
  +     * internal method for reading the input into the <code>lines</code> vector.
  +     * 
  +     * @param stream The socket stream on which the input will be read.
  +     * 
  +     * @exception IOException
  +     */
       private void readStream(InputStream stream) throws IOException
       {
           BufferedReader reader =
  @@ -150,29 +157,46 @@
           reader.close();
       }
   
  +    /**
  +     * Accessor for this object's default parser.
  +     * 
  +     * @return this object's default parser.
  +     */
       FTPFileEntryParser getParser()
       {
           return this.parser;
       }
   
  +    /**
  +     * Package private accessor for the collection of raw input lines.
  +     * 
  +     * @return vector containing all the raw input lines returned from the FTP server
  +     */
       Vector getLines()
       {
           return this.lines;
       }
   
  +    /**
  +     * create an iterator over this list using the parser with which this list was
  +     * initally created
  +     * 
  +     * @return an iterator over this list using the list's default parser.
  +     */
       public FTPFileIterator iterator()
       {
           return new FTPFileIterator(this);
       }
  +    /**
  +     * create an iterator over this list using the supplied parser 
  +     * 
  +     * @return an iterator over this list using the supplied parser.
  +     */
       public FTPFileIterator iterator(FTPFileEntryParser parser)
       {
           return new FTPFileIterator(this, parser);
       }
   
  -    private FTPFile parseFTPEntry(String entry)
  -    {
  -        return this.parser.parseFTPEntry(entry);
  -    }
   
       /**
        * returns an array of FTPFile objects for all the files in the directory 
  
  
  
  1.2       +31 -43    jakarta-commons-sandbox/net/src/java/org/apache/commons/net/ftp/ftp2/parser/MatchApparatus.java
  
  Index: MatchApparatus.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/net/src/java/org/apache/commons/net/ftp/ftp2/parser/MatchApparatus.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MatchApparatus.java	29 Apr 2002 03:55:32 -0000	1.1
  +++ MatchApparatus.java	30 Apr 2002 13:59:42 -0000	1.2
  @@ -55,11 +55,10 @@
    */
   
   import org.apache.oro.text.regex.Pattern;
  +import org.apache.oro.text.regex.MalformedPatternException;
   import org.apache.oro.text.regex.Perl5Matcher;
   import org.apache.oro.text.regex.Perl5Compiler;
   import org.apache.oro.text.regex.MatchResult;
  -import org.apache.commons.net.ftp.FTPFileListParser;
  -import org.apache.commons.net.ftp.FTPFile;
   
   /**
    * This class is based on the logic of Winston Ojeda's ListParser.  It uses
  @@ -68,42 +67,39 @@
    * It is also designed to encapsulate access to the oro.text.regex
    * classes in one place.
    * @author <a href="mailto:scohen@ignitesports.com">Steve Cohen</a>
  - * @version $Id: MatchApparatus.java,v 1.1 2002/04/29 03:55:32 brekke Exp $
  + * @version $Id: MatchApparatus.java,v 1.2 2002/04/30 13:59:42 brekke Exp $
    */
   abstract class MatchApparatus
   {
  -    MatchApparatus()
  -    {
  -        this.prefix = "[" + getClass().getName() + "] ";
  -    }
  -
       private String prefix;
  -    private boolean initialized = false;
  -    private Perl5Compiler compiler = null;
       private Pattern pattern = null;
       private Perl5Matcher matcher = null;
       private MatchResult result = null;
  -
  -    private void initialize()
  +    
  +    /**
  +     * The constructor for a MatchApparatus object.
  +     * 
  +     * @param regex  The regular expression with which this object is initialized.
  +     * 
  +     * @exception IllegalArgumentException
  +     * Thrown if the regular expression is unparseable.  Should not be seen in normal
  +     * conditions.  It it is seen, this is a sign that a subclass has been created with
  +     * a bad regular expression.   Since the parser must be created before use, this 
  +     * means that any bad parser subclasses created from this will bomb very quickly,
  +     * leading to easy detection.  
  +     */
  +    MatchApparatus(String regex) 
       {
  -        if (!initialized)
  -        {
  -            compiler = new Perl5Compiler();
  -            matcher = new Perl5Matcher();
  -            String regex = getRegEx();
  -            try
  -            {
  -                pattern = compiler.compile(regex);
  -                initialized = true;
  -            }
  -            catch (Exception e)
  -            {
  -                System.out.println(prefix +
  -                                   "Unable to compile regular expression: [" + regex +
"]" );
  -            }
  +        try {
  +            this.prefix = "[" + getClass().getName() + "] ";
  +            this.matcher = new Perl5Matcher();
  +            this.pattern = new Perl5Compiler().compile(regex);
  +        }  catch (MalformedPatternException e) {
  +            throw new IllegalArgumentException ("Unparseable regex supplied:  " + regex);
           }
       }
   
  +
       /**
        * Convenience method delegates to the internal MatchResult's matches()
        * method.
  @@ -113,7 +109,6 @@
        */
       public boolean matches(String s)
       {
  -        initialize();
           if (matcher.matches(s.trim(), this.pattern))
           {
               this.result = matcher.getMatch();
  @@ -152,27 +147,20 @@
           return this.result.group(matchnum);
       }
   
  -
  -    /**
  -     * Each derived class must define this function so that it returns a 
  -     * properly formatted regular expression string which will be used to do
  -     * the pattern matching.
  -     *
  -     * @return the string to be used to build the regular expression pattern
  -     * for matching
  -     */
  -    protected abstract String getRegEx();
  -
  -
       /**
  -     * For debugging purposes - shows each match group by number.
  +     * For debugging purposes - returns a string shows each match group by number.
  +     * 
  +     * @return a string shows each match group by number.
        */
  -    public void showGroups()
  +    public String getGroupsAsString()
       {
  +        StringBuffer b = new StringBuffer();
           for (int i = 1; i <= this.result.groups(); i++)
           {
  -            System.out.println("" + i + ") " + this.result.group(i));
  +            b.append(i).append(") ").append(this.result.group(i))
  +                .append(System.getProperty("line.separator"));
           }
  +        return b.toString() ;
   
       }
   }
  
  
  
  1.2       +27 -5     jakarta-commons-sandbox/net/src/java/org/apache/commons/net/ftp/ftp2/parser/NTFTPEntryParser.java
  
  Index: NTFTPEntryParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/net/src/java/org/apache/commons/net/ftp/ftp2/parser/NTFTPEntryParser.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- NTFTPEntryParser.java	29 Apr 2002 03:55:32 -0000	1.1
  +++ NTFTPEntryParser.java	30 Apr 2002 13:59:42 -0000	1.2
  @@ -78,7 +78,8 @@
    * <LI>You might want to check if you are truly in a NT System</LI>
    *   <dd><B>String am_I_NT =  FTPClientObj.getSystemName()</B>
    *    <dd>parse am_I_NT to find out
  - * <LI>Call listFiles passing the newly created parser and a filename or a mask to
look for </LI>
  + * <LI>Call listFiles passing the newly created parser and a filename or a 
  + * mask to look for </LI>
    *   <dd>FTPClientObj.listFiles(parser,filename);
    * <LI>You'll get back the list as an array of FTPFiles like this
    *   <dd>FTPFile[] myNTFiles = FTPClientObj.listFiles(parser,filename);  (or)
  @@ -98,13 +99,13 @@
    *
    * @author  <a href="Winston.Ojeda@qg.com">Winston Ojeda</a>
    * @author <a href="mailto:stevecoh1@attbi.com">Steve Cohen</a>
  - * @version $Id: NTFTPEntryParser.java,v 1.1 2002/04/29 03:55:32 brekke Exp $
  + * @version $Id: NTFTPEntryParser.java,v 1.2 2002/04/30 13:59:42 brekke Exp $
    * @see org.apache.commons.net.ftp.FTPFileListParser
    */
   public class NTFTPEntryParser
               extends MatchApparatus implements FTPFileEntryParser
   {
  -    private static final String regEx =
  +    private static final String REGEX =
           "((?:0[1-9])|(?:1[0-2]))-" +
           "((?:0[1-9])|(?:[1-2]\\d)|(?:3[0-1]))-" +
           "(\\d\\d)\\s*" +
  @@ -115,11 +116,30 @@
           "([0-9]+)?\\s*" +
           "(\\S.*)";
   
  -    protected String getRegEx()
  +    /**
  +     * 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 <code>REGEX</code>
is 
  +     * not a valid regular expression.
  +     */
  +    public NTFTPEntryParser() 
       {
  -        return (regEx);
  +        super(REGEX);
       }
   
  +
  +    /**
  +     * Parses a line of an NT FTP server file listing and converts it into a
  +     * usable format in the form of an <code> FTPFile </code> instance.  If
the
  +     * file listing line doesn't describe a file, <code> null </code> is
  +     * returned, otherwise a <code> FTPFile </code> instance representing the
  +     * files in the directory is returned.
  +     * <p>
  +     * @param listEntry A line of text from the file listing
  +     * @return An FTPFile instance corresponding to the supplied entry
  +     */
       public FTPFile parseFTPEntry(String entry)
       {
           FTPFile f = new FTPFile();
  @@ -154,7 +174,9 @@
               // be sooooo dead anyways who cares.
               // SMC - IS NT's directory date REALLY still not Y2K-compliant?
               if (year > 2080)
  +            {
                   year -= 100;
  +            }
   
               Calendar cal = Calendar.getInstance();
               //set the calendar
  
  
  
  1.2       +44 -12    jakarta-commons-sandbox/net/src/java/org/apache/commons/net/ftp/ftp2/parser/OS2FTPEntryParser.java
  
  Index: OS2FTPEntryParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/net/src/java/org/apache/commons/net/ftp/ftp2/parser/OS2FTPEntryParser.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- OS2FTPEntryParser.java	29 Apr 2002 03:55:32 -0000	1.1
  +++ OS2FTPEntryParser.java	30 Apr 2002 13:59:42 -0000	1.2
  @@ -78,7 +78,8 @@
    * <LI>You might want to check if you are truly in a OS2 System</LI>
    *   <dd><B>String am_I_OS2 =  FTPClientObj.getSystemName()</B>
    *    <dd>parse am_I_OS2 to find out
  - * <LI>Call listFiles passing the newly created parser and a filename or a mask to
look for </LI>
  + * <LI>Call listFiles passing the newly created parser and a filename or a mask 
  + * to look for </LI>
    *   <dd>FTPClientObj.listFiles(parser,filename);
    * <LI>You'll get back the list as an array of FTPFiles like this
    *   <dd>FTPFile[] myOS2Files = FTPClientObj.listFiles(parser,filename);  (or)
  @@ -90,23 +91,21 @@
    * object. The only thing not implemented at this time is the file
    * permissions, but I can do it if there is a real need for it.
    * <P>
  - * !NOTE/WARNING!:Before you pass the parser to listFiles, make sure you are in the
  - * directory that you need to be. This parser will return the filtered
  + * !NOTE/WARNING!:Before you pass the parser to listFiles, make sure you are 
  + * in the directory that you need to be. This parser will return the filtered
    * files from the directory it is in. This becomes specially crucial if your
    * goal is to delete the output of the parser.
    * <P>
    * @author  <a href="Winston.Ojeda@qg.com">Winston Ojeda</a>
    * @author <a href="mailto:stevecoh1@attbi.com">Steve Cohen</a>
  - * @version $Id: OS2FTPEntryParser.java,v 1.1 2002/04/29 03:55:32 brekke Exp $
  + * @version $Id: OS2FTPEntryParser.java,v 1.2 2002/04/30 13:59:42 brekke Exp $
    * @see org.apache.commons.net.ftp.FTPFileListParser
    */
   public class OS2FTPEntryParser
               extends MatchApparatus implements FTPFileEntryParser
   
   {
  -    private String prefix = "[" + getClass().getName() + "] ";
  -
  -    private static final String regEx =
  +    private static final String REGEX =
           "(\\s+|[0-9]+)\\s*" +
           "(\\s+|[A-Z]+)\\s*" +
           "(DIR|\\s+)\\s*" +
  @@ -116,17 +115,44 @@
           "(?:([0-1]\\d)|(?:2[0-3])):" +
           "([0-5]\\d)\\s*" +
           "(\\S.*)";
  -
  -    public OS2FTPEntryParser()
  -    {}
  +    
  +    /**
  +     * The sole constructor for a OS2FTPEntryParser 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 <code>REGEX</code>
is 
  +     * not a valid regular * expression.
  +     */
  +    public OS2FTPEntryParser() 
  +    {
  +        super(REGEX);
  +    }
   
   
  +    /**
  +     * Returns the properly formatted regular expression string used to do
  +     * the pattern matching for an OS2 FTP system.
  +     *
  +     * @return the string used to build the regular expression pattern
  +     * for matching
  +     */
       protected String getRegEx()
       {
  -        return (regEx);
  +        return REGEX;
       }
   
   
  +    /**
  +     * Parses a line of an OS2 FTP server file listing and converts it into a
  +     * usable format in the form of an <code> FTPFile </code> instance.  If
the
  +     * file listing line doesn't describe a file, <code> null </code> is
  +     * returned, otherwise a <code> FTPFile </code> instance representing the
  +     * files in the directory is returned.
  +     * <p>
  +     * @param listEntry A line of text from the file listing
  +     * @return An FTPFile instance corresponding to the supplied entry
  +     */
       public FTPFile parseFTPEntry(String entry)
       {
   
  @@ -145,9 +171,13 @@
   
               //is it a DIR or a file
               if (dirString.trim().equals("DIR") || attrib.trim().equals("DIR"))
  +            {
                   f.setType(FTPFile.DIRECTORY_TYPE);
  +            }
               else
  +            {
                   f.setType(FTPFile.FILE_TYPE);
  +            }
   
               Calendar cal = Calendar.getInstance();
   
  @@ -162,8 +192,10 @@
               // Y2K stuff? this will break again in 2080 but I will
               // be sooooo dead anyways who cares.
               // SMC - IS OS2's directory date REALLY still not Y2K-compliant?
  -            if (year > 2080)
  +            if (year > 2080) 
  +            {
                   year -= 100;
  +            }
   
               //set the calendar
               cal.set(Calendar.SECOND, 0);
  
  
  
  1.2       +27 -7     jakarta-commons-sandbox/net/src/java/org/apache/commons/net/ftp/ftp2/parser/UnixFTPEntryParser.java
  
  Index: UnixFTPEntryParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/net/src/java/org/apache/commons/net/ftp/ftp2/parser/UnixFTPEntryParser.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- UnixFTPEntryParser.java	29 Apr 2002 03:55:32 -0000	1.1
  +++ UnixFTPEntryParser.java	30 Apr 2002 13:59:42 -0000	1.2
  @@ -63,29 +63,49 @@
    * DefaultFTPListParser, but adapted to use regular expressions and to fit the
    * new FTPFileEntryParser interface.
    * @author <a href="mailto:scohen@ignitesports.com">Steve Cohen</a>
  - * @version $Id: UnixFTPEntryParser.java,v 1.1 2002/04/29 03:55:32 brekke Exp $
  + * @version $Id: UnixFTPEntryParser.java,v 1.2 2002/04/30 13:59:42 brekke Exp $
    */
   public class UnixFTPEntryParser
               extends MatchApparatus implements FTPFileEntryParser
   {
  -    private static final String months =
  +    private static final String MONTHS =
           "(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)";
  -    private static final String regEx =
  +    private static final String REGEX =
           "([bcdlf])"
           + "(((r|-)(w|-)(x|-))((r|-)(w|-)(x|-))((r|-)(w|-)(x|-)))\\s*"
           + "(\\d*)\\s*"
           + "(\\S*)\\s*"
           + "(\\S*)\\s*"
           + "(\\d*)\\s*"
  -        + months + "\\s*"
  +        + MONTHS + "\\s*"
           + "((?:[012]\\d*)|(?:3[01]))\\s*"
           + "((\\d\\d\\d\\d)|((?:[01]\\d)|(?:2[0123])):([012345]\\d))\\s"
           + "(\\S*)(\\s*.*)";
  -    public String getRegEx()
  +
  +    
  +    /**
  +     * The sole constructor for a UnixFTPEntryParser 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 <code>REGEX</code>
is 
  +     * not a valid regular expression.
  +     */
  +    public UnixFTPEntryParser() 
       {
  -        return this.regEx;
  +        super(REGEX);
       }
   
  +    /**
  +     * Parses a line of a unix (standard) FTP server file listing and converts 
  +     * it into a usable format in the form of an <code> FTPFile </code> 
  +     * instance.  If the file listing line doesn't describe a file, 
  +     * <code> null </code> is returned, otherwise a <code> FTPFile </code>

  +     * instance representing the files in the directory is returned.
  +     * <p>
  +     * @param listEntry A line of text from the file listing
  +     * @return An FTPFile instance corresponding to the supplied entry
  +     */
       public FTPFile parseFTPEntry(String entry)
       {
   
  @@ -168,7 +188,7 @@
   
               try
               {
  -                int pos = months.indexOf(mo);
  +                int pos = MONTHS.indexOf(mo);
                   int month = pos / 4;
   
                   if (null != yr)
  
  
  
  1.2       +71 -28    jakarta-commons-sandbox/net/src/java/org/apache/commons/net/ftp/ftp2/parser/VMSFTPEntryParser.java
  
  Index: VMSFTPEntryParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/net/src/java/org/apache/commons/net/ftp/ftp2/parser/VMSFTPEntryParser.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- VMSFTPEntryParser.java	29 Apr 2002 03:55:32 -0000	1.1
  +++ VMSFTPEntryParser.java	30 Apr 2002 13:59:42 -0000	1.2
  @@ -67,7 +67,8 @@
    * <P><B>USAGE:</B></P>
    * <LI>Create an instance of VMSFTPEntryParser</LI>
    *   <dd>VMSFTPEntryParser parser = new VMSFTPEntryParser(boolean);
  - *  <dd><code>True</code>  = returns all versions of a file with the
respective ;#
  + *  <dd><code>True</code>  = returns all versions of a file with the
respective 
  + * ;#
    *  <dd><code>False</code> = only the last version will return <B>(Default)</B>
    * <LI>Create an instance of FTPClient</LI>
    *   <dd>FTPClient FTPClientObj = new FTPClient();
  @@ -78,16 +79,16 @@
    * <LI>Switch directories if you have to</LI>
    *   <dd>FTPClientObj.changeWorkingDirectory(thePath);
    * <LI>You might want to check if you are truly in a VMS System</LI>
  - *   <dd>And how do I do that you ask? easy...  VMS is such a wonderful OS that when
we do
  - *   <dd><B>String am_I_VMS =  FTPClientObj.getSystemName()</B>
  + *   <dd>And how do I do that you ask? easy...  VMS is such a wonderful OS 
  + * that when we do   <dd><B>String am_I_VMS =  FTPClientObj.getSystemName()</B>
    *   <dd>it returns NULL, while everyone else returns the FTP servername
  - * <LI>Call listFiles passing the newly created parser and a filename or a mask to
look for </LI>
  - *   <dd>FTPClientObj.listFiles(parser,filename);
  + * <LI>Call listFiles passing the newly created parser and a filename or a mask
  + *  to look for </LI> <dd>FTPClientObj.listFiles(parser,filename);
    * <LI>You'll get back the list as an array of FTPFile objects like this
    *   <dd>FTPFile[] myVMSFiles = FTPClientObj.listFiles(parser,filename);  (or)
    *    <dd>FTPFile[] myVMSFiles = FTPClientObj.listFiles(parser);
  - *    <dd>If <code>filename</code> is a filename and versioning is OFF,
the version
  - *    <dd>you requested will come back without the ;#
  + *    <dd>If <code>filename</code> is a filename and versioning is OFF,
the 
  + * version <dd>you requested will come back without the ;#
    * <P>
    * That's all there is to it.
    * <P>
  @@ -95,14 +96,14 @@
    * object. The only thing not implemented at this time is the file
    * permissions, but I can do it if there is a real need for it.
    * <P>
  - * !NOTE/WARNING!:Before you pass the parser to listFiles, make sure you are in the
  - * directory that you need to be. This parser will return the filtered
  + * !NOTE/WARNING!:Before you pass the parser to listFiles, make sure you are
  + * in the directory that you need to be. This parser will return the filtered
    * files from the directory it is in. This becomes crucial specialy if your
    * goal is to delete the output of the parser.
    * <P>
    * @author  <a href="Winston.Ojeda@qg.com">Winston Ojeda</a>
    * @author <a href="mailto:stevecoh1@attbi.com">Steve Cohen</a>
  - * @version $Id: VMSFTPEntryParser.java,v 1.1 2002/04/29 03:55:32 brekke Exp $
  + * @version $Id: VMSFTPEntryParser.java,v 1.2 2002/04/30 13:59:42 brekke Exp $
    * @see org.apache.commons.net.ftp.FTPFileFTPEntryParser
    */
   public class VMSFTPEntryParser
  @@ -117,36 +118,76 @@
             "1-JUN.LIS;2              9/9           2-JUN-1998 07:32:04  [GROUP,OWNER]  
 (RWED,RWED,RWED,RE)",
             "DATA.DIR;1               1/9           2-JUN-1998 07:32:04  [GROUP,OWNER]  
 (RWED,RWED,RWED,RE)",
       */
  -    private static final String months =
  +    private static final String MONTHS =
           "(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)";
   
  -    private static final String regEx =
  +    private static final String REGEX =
           "(.*;[0-9]+)\\s*" +
           "(\\d+)/\\d+\\s*" +
           "(\\d{1,2})-" +
  -        months +
  +        MONTHS +
           "-([0-9]{4})\\s*" +
           "((?:[01]\\d)|(?:2[0-3])):([012345]\\d):([012345]\\d)\\s*" +
           "(\\[[0-9$A-Za-z_]+),([0-9$a-zA-Z_]+)\\]\\s*" +
           "(\\([a-zA-Z]*,[a-zA-Z]*,[a-zA-Z]*,[a-zA-Z]*\\))";
   
   
  +    /**
  +     * Convenience Constructor for a VMSFTPEntryParser object.  Sets the 
  +     * <code>versioning</code> member false
  +     * 
  +     * @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 <code>REGEX</code>
is
  +     * not a valid regular expression.
  +     */
  +    public VMSFTPEntryParser()
  +    {
  +        this(false);
  +    }
  +    
  +    /**
  +     * Constructor for a VMSFTPEntryParser object.  Sets the versioning member 
  +     * to the supplied value.
  +     *  
  +     * @param versioning Value to which versioning is to be set.
  +     * 
  +     * @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 <code>REGEX</code>
is
  +     * not a valid regular expression.
  +     */
       public VMSFTPEntryParser(boolean versioning)
       {
  +        super(REGEX);
           this.versioning = versioning;
       }
   
  -    public VMSFTPEntryParser()
  -    {
  -        this(false);
  -    }
   
   
  +    /**
  +     * Returns the properly formatted regular expression string used to do
  +     * the pattern matching for a VMS FTP system.
  +     *
  +     * @return the string used to build the regular expression pattern
  +     * for matching
  +     */
       protected String getRegEx()
       {
  -        return (regEx);
  +        return REGEX;
       }
   
  +    
  +    /**
  +     * Parses a line of a VMS FTP server file listing and converts it into a
  +     * usable format in the form of an <code> FTPFile </code> instance.  If
the
  +     * file listing line doesn't describe a file, <code> null </code> is
  +     * returned, otherwise a <code> FTPFile </code> instance representing the
  +     * files in the directory is returned.
  +     * <p>
  +     * @param listEntry A line of text from the file listing
  +     * @return An FTPFile instance corresponding to the supplied entry
  +     */
       public FTPFile parseFTPEntry(String entry)
       {
           //one block in VMS equals 512 bytes
  @@ -170,16 +211,18 @@
               String grp = group(9);
               String owner = group(10);
   
  -            if (name.lastIndexOf(".DIR") != -1)
  +            if (name.lastIndexOf(".DIR") != -1) 
  +            {
                   f.setType(FTPFile.DIRECTORY_TYPE);
  -            else
  +            } else {
                   f.setType(FTPFile.FILE_TYPE);
  +            }
               //set FTPFile name
               //Check also for versions to be returned or not
  -            if (versioning)
  -                f.setName(name);
  -            else
  +            if (versioning) 
               {
  +                f.setName(name);
  +            } else {
                   name = name.substring(0, name.lastIndexOf(";"));
                   f.setName(name);
               }
  @@ -195,7 +238,7 @@
               cal.clear();
   
               cal.set(Calendar.DATE, new Integer(day).intValue());
  -            cal.set(Calendar.MONTH, months.indexOf(mo) / 4);
  +            cal.set(Calendar.MONTH, MONTHS.indexOf(mo) / 4);
               cal.set(Calendar.YEAR, new Integer(yr).intValue());
               cal.set(Calendar.HOUR_OF_DAY, new Integer(hr).intValue());
               cal.set(Calendar.MINUTE, new Integer(min).intValue());
  @@ -205,10 +248,10 @@
               f.setGroup(grp);
               f.setUser(owner);
               //set group and owner
  -            //Since I don't need the persmissions on this file (RWED), I'll leave that
  -            //for further development. 'Cause it will be a bit elaborate to do it
  -            //right with VMSes World, Global and so forth.
  -            return (f);
  +            //Since I don't need the persmissions on this file (RWED), I'll 
  +            //leave that for further development. 'Cause it will be a bit 
  +            //elaborate to do it right with VMSes World, Global and so forth.
  +            return f;
           }
           return null;
       }
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message