scohen      2004/04/21 20:27:19

  Modified:    net/src/java/org/apache/commons/net/ftp/parser
                        UnixFTPEntryParser.java
                        RegexFTPFileEntryParserImpl.java
  Log:
  make checkstyle happy by converting tabs to spaces.
  
  Revision  Changes    Path
  1.16      +220 -220  
jakarta-commons/net/src/java/org/apache/commons/net/ftp/parser/UnixFTPEntryParser.java
  
  Index: UnixFTPEntryParser.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/net/src/java/org/apache/commons/net/ftp/parser/UnixFTPEntryParser.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- UnixFTPEntryParser.java   22 Apr 2004 00:48:07 -0000      1.15
  +++ UnixFTPEntryParser.java   22 Apr 2004 03:27:19 -0000      1.16
  @@ -30,223 +30,223 @@
    */
   public class UnixFTPEntryParser extends RegexFTPFileEntryParserImpl
   {
  -     /**
  -      * months abbreviations looked for by this parser.  Also used
  -      * to determine which month is matched by the parser
  -      */
  -     private static final String MONTHS =
  -             "(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)";
  -
  -     /**
  -      * this is the regular expression used by this parser.
  -      *
  -      * Permissions:
  -      *        r   the file is readable
  -      *    w   the file is writable
  -      *    x   the file is executable
  -      *    -   the indicated permission is not granted
  -      *    L   mandatory     locking occurs during access (the set-group-ID bit is
  -      *        on and the group execution bit is off)
  -      *    s   the set-user-ID or set-group-ID bit is on, and the corresponding
  -      *        user or group execution bit is also on
  -      *    S   undefined     bit-state (the set-user-ID bit is on and the user
  -      *        execution     bit is off)
  -      *    t   the 1000 (octal) bit, or sticky bit, is on [see chmod(1)], and
  -      *        execution     is on
  -      *    T   the 1000 bit is turned on, and execution is off (undefined bit-
  -      *        state)
  -      */
  -     private static final String REGEX =
  -             "([bcdlf-])"
  -             + 
"(((r|-)(w|-)([xsStTL-]))((r|-)(w|-)([xsStTL-]))((r|-)(w|-)([xsStTL-])))\\s+"
  -             + "(\\d+)\\s+"
  -             + "(\\S+)\\s+"
  -             + "(?:(\\S+)\\s+)?"
  -             + "(\\d+)\\s+"
  -             + MONTHS + "\\s+"
  -             + "((?:[0-9])|(?:[0-2][0-9])|(?:3[0-1]))\\s+"
  -             + 
"((\\d\\d\\d\\d)|((?:[01]\\d)|(?:2[0123])|(?:[1-9])):([012345]\\d))\\s+"
  -             + "(\\S+)(\\s*.*)";
  -
  -
  -     /**
  -      * 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()
  -     {
  -             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 entry A line of text from the file listing
  -      * @return An FTPFile instance corresponding to the supplied entry
  -      */
  -     public FTPFile parseFTPEntry(String entry)
  -     {
  -
  -             FTPFile file = new FTPFile();
  -             file.setRawListing(entry);
  -             int type;
  -             boolean isDevice = false;
  -
  -             if (matches(entry))
  -             {
  -                     String typeStr = group(1);
  -                     String hardLinkCount = group(15);
  -                     String usr = group(16);
  -                     String grp = group(17);
  -                     String filesize = group(18);
  -                     String mo = group(19);
  -                     String da = group(20);
  -                     String yr = group(22);
  -                     String hr = group(23);
  -                     String min = group(24);
  -                     String name = group(25);
  -                     String endtoken = group(26);
  -
  -                     switch (typeStr.charAt(0))
  -                     {
  -                     case 'd':
  -                             type = FTPFile.DIRECTORY_TYPE;
  -                             break;
  -                     case 'l':
  -                             type = FTPFile.SYMBOLIC_LINK_TYPE;
  -                             break;
  -                     case 'b':
  -                     case 'c':
  -                             isDevice = true;
  -                             // break; - fall through
  -                     default:
  -                             type = FTPFile.FILE_TYPE;
  -                     }
  -
  -                     file.setType(type);
  -
  -                     int g = 4;
  -                     for (int access = 0; access < 3; access++, g += 4)
  -                     {
  -                             // Use != '-' to avoid having to check for suid and 
sticky bits
  -                             file.setPermission(access, FTPFile.READ_PERMISSION,
  -                                                                
(!group(g).equals("-")));
  -                             file.setPermission(access, FTPFile.WRITE_PERMISSION,
  -                                                                (!group(g + 
1).equals("-")));
  -
  -                             String execPerm = group(g + 2);
  -                             if (!execPerm.equals("-") && 
!Character.isUpperCase(execPerm.charAt(0)))
  -                             {
  -                                     file.setPermission(access, 
FTPFile.EXECUTE_PERMISSION, true);
  -                             }
  -                             else
  -                             {
  -                                     file.setPermission(access, 
FTPFile.EXECUTE_PERMISSION, false);
  -                             }
  -                     }
  -
  -                     if (!isDevice)
  -                     {
  -                             try
  -                             {
  -                                     
file.setHardLinkCount(Integer.parseInt(hardLinkCount));
  -                             }
  -                             catch (NumberFormatException e)
  -                             {
  -                                     // intentionally do nothing
  -                             }
  -                     }
  -
  -                     file.setUser(usr);
  -                     file.setGroup(grp);
  -
  -                     try
  -                     {
  -                             file.setSize(Integer.parseInt(filesize));
  -                     }
  -                     catch (NumberFormatException e)
  -                     {
  -                             // intentionally do nothing
  -                     }
  -
  -                     Calendar cal = Calendar.getInstance();
  -                     cal.set(Calendar.SECOND, 0);
  -                     cal.set(Calendar.MINUTE, 0);
  -                     cal.set(Calendar.HOUR_OF_DAY, 0);
  -
  -                     try
  -                     {
  -                             int pos = MONTHS.indexOf(mo);
  -                             int month = pos / 4;
  -
  -                             if (null != yr)
  -                             {
  -                                     // it's a year
  -                                     cal.set(Calendar.YEAR, Integer.parseInt(yr));
  -                             }
  -                             else
  -                             {
  -                                     // it must be  hour/minute or we wouldn't have 
matched
  -                                     int year = cal.get(Calendar.YEAR);
  -                                     // if the month we're reading is greater than 
now, it must
  -                                     // be last year
  -                                     if (cal.get(Calendar.MONTH) < month)
  -                                     {
  -                                             year--;
  -                                     }
  -                                     cal.set(Calendar.YEAR, year);
  -                                     cal.set(Calendar.HOUR_OF_DAY, 
Integer.parseInt(hr));
  -                                     cal.set(Calendar.MINUTE, 
Integer.parseInt(min));
  -                             }
  -                             cal.set(Calendar.MONTH, month);
  -
  -                             cal.set(Calendar.DATE, Integer.parseInt(da));
  -                             file.setTimestamp(cal);
  -                     }
  -                     catch (NumberFormatException e)
  -                     {
  -                             // do nothing, date will be uninitialized
  -                     }
  -                     if (null == endtoken)
  -                     {
  -                             file.setName(name);
  -                     }
  -                     else
  -                     {
  -                             // oddball cases like symbolic links, file names
  -                             // with spaces in them.
  -                             name += endtoken;
  -                             if (type == FTPFile.SYMBOLIC_LINK_TYPE)
  -                             {
  -
  -                                     int end = name.indexOf(" -> ");
  -                                     // Give up if no link indicator is present
  -                                     if (end == -1)
  -                                     {
  -                                             file.setName(name);
  -                                     }
  -                                     else
  -                                     {
  -                                             file.setName(name.substring(0, end));
  -                                             file.setLink(name.substring(end + 4));
  -                                     }
  -
  -                             }
  -                             else
  -                             {
  -                                     file.setName(name);
  -                             }
  -                     }
  -                     return file;
  -             }
  -             return null;
  -     }
  +    /**
  +     * months abbreviations looked for by this parser.  Also used
  +     * to determine which month is matched by the parser
  +     */
  +    private static final String MONTHS =
  +        "(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)";
  +
  +    /**
  +     * this is the regular expression used by this parser.
  +     *
  +     * Permissions:
  +     *    r   the file is readable
  +     *    w   the file is writable
  +     *    x   the file is executable
  +     *    -   the indicated permission is not granted
  +     *    L   mandatory locking occurs during access (the set-group-ID bit is
  +     *        on and the group execution bit is off)
  +     *    s   the set-user-ID or set-group-ID bit is on, and the corresponding
  +     *        user or group execution bit is also on
  +     *    S   undefined bit-state (the set-user-ID bit is on and the user
  +     *        execution bit is off)
  +     *    t   the 1000 (octal) bit, or sticky bit, is on [see chmod(1)], and
  +     *        execution is on
  +     *    T   the 1000 bit is turned on, and execution is off (undefined bit-
  +     *        state)
  +     */
  +    private static final String REGEX =
  +        "([bcdlf-])"
  +        + 
"(((r|-)(w|-)([xsStTL-]))((r|-)(w|-)([xsStTL-]))((r|-)(w|-)([xsStTL-])))\\s+"
  +        + "(\\d+)\\s+"
  +        + "(\\S+)\\s+"
  +        + "(?:(\\S+)\\s+)?"
  +        + "(\\d+)\\s+"
  +        + MONTHS + "\\s+"
  +        + "((?:[0-9])|(?:[0-2][0-9])|(?:3[0-1]))\\s+"
  +        + "((\\d\\d\\d\\d)|((?:[01]\\d)|(?:2[0123])|(?:[1-9])):([012345]\\d))\\s+"
  +        + "(\\S+)(\\s*.*)";
  +
  +
  +    /**
  +     * 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()
  +    {
  +        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 entry A line of text from the file listing
  +     * @return An FTPFile instance corresponding to the supplied entry
  +     */
  +    public FTPFile parseFTPEntry(String entry)
  +    {
  +
  +        FTPFile file = new FTPFile();
  +        file.setRawListing(entry);
  +        int type;
  +        boolean isDevice = false;
  +
  +        if (matches(entry))
  +        {
  +            String typeStr = group(1);
  +            String hardLinkCount = group(15);
  +            String usr = group(16);
  +            String grp = group(17);
  +            String filesize = group(18);
  +            String mo = group(19);
  +            String da = group(20);
  +            String yr = group(22);
  +            String hr = group(23);
  +            String min = group(24);
  +            String name = group(25);
  +            String endtoken = group(26);
  +
  +            switch (typeStr.charAt(0))
  +            {
  +            case 'd':
  +                type = FTPFile.DIRECTORY_TYPE;
  +                break;
  +            case 'l':
  +                type = FTPFile.SYMBOLIC_LINK_TYPE;
  +                break;
  +            case 'b':
  +            case 'c':
  +                isDevice = true;
  +                // break; - fall through
  +            default:
  +                type = FTPFile.FILE_TYPE;
  +            }
  +
  +            file.setType(type);
  +
  +            int g = 4;
  +            for (int access = 0; access < 3; access++, g += 4)
  +            {
  +                // Use != '-' to avoid having to check for suid and sticky bits
  +                file.setPermission(access, FTPFile.READ_PERMISSION,
  +                                   (!group(g).equals("-")));
  +                file.setPermission(access, FTPFile.WRITE_PERMISSION,
  +                                   (!group(g + 1).equals("-")));
  +
  +                String execPerm = group(g + 2);
  +                if (!execPerm.equals("-") && 
!Character.isUpperCase(execPerm.charAt(0)))
  +                {
  +                    file.setPermission(access, FTPFile.EXECUTE_PERMISSION, true);
  +                }
  +                else
  +                {
  +                    file.setPermission(access, FTPFile.EXECUTE_PERMISSION, false);
  +                }
  +            }
  +
  +            if (!isDevice)
  +            {
  +                try
  +                {
  +                    file.setHardLinkCount(Integer.parseInt(hardLinkCount));
  +                }
  +                catch (NumberFormatException e)
  +                {
  +                    // intentionally do nothing
  +                }
  +            }
  +
  +            file.setUser(usr);
  +            file.setGroup(grp);
  +
  +            try
  +            {
  +                file.setSize(Integer.parseInt(filesize));
  +            }
  +            catch (NumberFormatException e)
  +            {
  +                // intentionally do nothing
  +            }
  +
  +            Calendar cal = Calendar.getInstance();
  +            cal.set(Calendar.SECOND, 0);
  +            cal.set(Calendar.MINUTE, 0);
  +            cal.set(Calendar.HOUR_OF_DAY, 0);
  +
  +            try
  +            {
  +                int pos = MONTHS.indexOf(mo);
  +                int month = pos / 4;
  +
  +                if (null != yr)
  +                {
  +                    // it's a year
  +                    cal.set(Calendar.YEAR, Integer.parseInt(yr));
  +                }
  +                else
  +                {
  +                    // it must be  hour/minute or we wouldn't have matched
  +                    int year = cal.get(Calendar.YEAR);
  +                    // if the month we're reading is greater than now, it must
  +                    // be last year
  +                    if (cal.get(Calendar.MONTH) < month)
  +                    {
  +                        year--;
  +                    }
  +                    cal.set(Calendar.YEAR, year);
  +                    cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(hr));
  +                    cal.set(Calendar.MINUTE, Integer.parseInt(min));
  +                }
  +                cal.set(Calendar.MONTH, month);
  +
  +                cal.set(Calendar.DATE, Integer.parseInt(da));
  +                file.setTimestamp(cal);
  +            }
  +            catch (NumberFormatException e)
  +            {
  +                // do nothing, date will be uninitialized
  +            }
  +            if (null == endtoken)
  +            {
  +                file.setName(name);
  +            }
  +            else
  +            {
  +                // oddball cases like symbolic links, file names
  +                // with spaces in them.
  +                name += endtoken;
  +                if (type == FTPFile.SYMBOLIC_LINK_TYPE)
  +                {
  +
  +                    int end = name.indexOf(" -> ");
  +                    // Give up if no link indicator is present
  +                    if (end == -1)
  +                    {
  +                        file.setName(name);
  +                    }
  +                    else
  +                    {
  +                        file.setName(name.substring(0, end));
  +                        file.setLink(name.substring(end + 4));
  +                    }
  +
  +                }
  +                else
  +                {
  +                    file.setName(name);
  +                }
  +            }
  +            return file;
  +        }
  +        return null;
  +    }
   }
  
  
  
  1.5       +115 -115  
jakarta-commons/net/src/java/org/apache/commons/net/ftp/parser/RegexFTPFileEntryParserImpl.java
  
  Index: RegexFTPFileEntryParserImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/net/src/java/org/apache/commons/net/ftp/parser/RegexFTPFileEntryParserImpl.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- RegexFTPFileEntryParserImpl.java  22 Apr 2004 00:48:07 -0000      1.4
  +++ RegexFTPFileEntryParserImpl.java  22 Apr 2004 03:27:19 -0000      1.5
  @@ -34,122 +34,122 @@
    */

   public abstract class RegexFTPFileEntryParserImpl extends FTPFileEntryParserImpl

   {

  -     /**

  -      * internal pattern the matcher tries to match, representing a file

  -      * entry

  -      */

  -     private Pattern pattern = null;

  -

  -     /**

  -      * internal match result used by the parser

  -      */

  -     private MatchResult result = null;

  -

  -     /**

  -      * Internal PatternMatcher object used by the parser.  It has protected

  -      * scope in case subclasses want to make use of it for their own purposes.

  -      */

  -     protected PatternMatcher _matcher_ = null;

  -

  -

  -     /**

  -      * The constructor for a RegexFTPFileEntryParserImpl 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.

  -      */

  -     public RegexFTPFileEntryParserImpl(String regex)

  -     {

  -             super();

  -

  -             try

  -             {

  -                     _matcher_ = new Perl5Matcher();

  -                     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.

  -      *

  -      * @param s the String to be matched

  -      * @return true if s matches this object's regular expression.

  -      */

  -     public boolean matches(String s)

  -     {

  -             this.result = null;

  -             if (_matcher_.matches(s.trim(), this.pattern))

  -             {

  -                     this.result = _matcher_.getMatch();

  -             }

  -             return null != this.result;

  -     }

  -

  -     /**

  -      * Convenience method delegates to the internal MatchResult's groups()

  -      * method.

  -      *

  -      * @return the number of groups() in the internal MatchResult.

  -      */

  -     public int getGroupCnt()

  -     {

  -             if (this.result == null)

  -             {

  -                     return 0;

  -             }

  -             return this.result.groups();

  -     }

  -

  -     /**

  -      * Convenience method delegates to the internal MatchResult's group()

  -      * method.

  -      *

  -      * @param matchnum match group number to be retrieved

  -      *

  -      * @return the content of the <code>matchnum'th<code> group of the internal

  -      *         match or null if this method is called without a match having

  -      *         been made.

  -      */

  -     public String group(int matchnum)

  -     {

  -             if (this.result == null)

  -             {

  -                     return null;

  -             }

  -             return this.result.group(matchnum);

  -     }

  -

  -     /**

  -      * For debugging purposes - returns a string shows each match group by

  -      * number.

  -      *

  -      * @return a string shows each match group by number.

  -      */

  -     public String getGroupsAsString()

  -     {

  -             StringBuffer b = new StringBuffer();

  -             for (int i = 1; i <= this.result.groups(); i++)

  -             {

  -                     b.append(i).append(") ").append(this.result.group(i))

  -                             .append(System.getProperty("line.separator"));

  -             }

  -             return b.toString();

  +    /**

  +     * internal pattern the matcher tries to match, representing a file

  +     * entry

  +     */

  +    private Pattern pattern = null;

  +

  +    /**

  +     * internal match result used by the parser

  +     */

  +    private MatchResult result = null;

  +

  +    /**

  +     * Internal PatternMatcher object used by the parser.  It has protected

  +     * scope in case subclasses want to make use of it for their own purposes.

  +     */

  +    protected PatternMatcher _matcher_ = null;

  +

  +

  +    /**

  +     * The constructor for a RegexFTPFileEntryParserImpl 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.

  +     */

  +    public RegexFTPFileEntryParserImpl(String regex)

  +    {

  +        super();

  +

  +        try

  +        {

  +            _matcher_ = new Perl5Matcher();

  +            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.

  +     *

  +     * @param s the String to be matched

  +     * @return true if s matches this object's regular expression.

  +     */

  +    public boolean matches(String s)

  +    {

  +        this.result = null;

  +        if (_matcher_.matches(s.trim(), this.pattern))

  +        {

  +            this.result = _matcher_.getMatch();

  +        }

  +        return null != this.result;

  +    }

  +

  +    /**

  +     * Convenience method delegates to the internal MatchResult's groups()

  +     * method.

  +     *

  +     * @return the number of groups() in the internal MatchResult.

  +     */

  +    public int getGroupCnt()

  +    {

  +        if (this.result == null)

  +        {

  +            return 0;

  +        }

  +        return this.result.groups();

  +    }

  +

  +    /**

  +     * Convenience method delegates to the internal MatchResult's group()

  +     * method.

  +     *

  +     * @param matchnum match group number to be retrieved

  +     *

  +     * @return the content of the <code>matchnum'th<code> group of the internal

  +     *         match or null if this method is called without a match having

  +     *         been made.

  +     */

  +    public String group(int matchnum)

  +    {

  +        if (this.result == null)

  +        {

  +            return null;

  +        }

  +        return this.result.group(matchnum);

  +    }

  +

  +    /**

  +     * For debugging purposes - returns a string shows each match group by

  +     * number.

  +     *

  +     * @return a string shows each match group by number.

  +     */

  +    public String getGroupsAsString()

  +    {

  +        StringBuffer b = new StringBuffer();

  +        for (int i = 1; i <= this.result.groups(); i++)

  +        {

  +            b.append(i).append(") ").append(this.result.group(i))

  +                .append(System.getProperty("line.separator"));

  +        }

  +        return b.toString();

   

  -     }

  +    }

   }

   

   /* Emacs configuration

  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to