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

RegexFTPFileEntryParserImpl

public abstract class RegexFTPFileEntryParserImpl extends org.apache.commons.net.ftp.FTPFileEntryParserImpl
This abstract class implements both the older FTPFileListParser and newer FTPFileEntryParser interfaces with default functionality. All the classes in the parser subpackage inherit from this. This is the base for all regular based FTPFileEntryParser
author
Steve Cohen

Fields Summary
private org.apache.oro.text.regex.Pattern
pattern
internal pattern the matcher tries to match, representing a file entry
private org.apache.oro.text.regex.MatchResult
result
internal match result used by the parser
protected org.apache.oro.text.regex.PatternMatcher
_matcher_
Internal PatternMatcher object used by the parser. It has protected scope in case subclasses want to make use of it for their own purposes.
Constructors Summary
public RegexFTPFileEntryParserImpl(String regex)
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.


                                                                                             

      
    
        super();
        try
        {
            _matcher_ = new Perl5Matcher();
            pattern   = new Perl5Compiler().compile(regex);
        }
        catch (MalformedPatternException e)
        {
            throw new IllegalArgumentException (
               "Unparseable regex supplied:  " + regex);
        }
    
Methods Summary
public intgetGroupCnt()
Convenience method delegates to the internal MatchResult's groups() method.

return
the number of groups() in the internal MatchResult.

        if (this.result == null)
        {
            return 0;
        }
        return this.result.groups();
    
public java.lang.StringgetGroupsAsString()
For debugging purposes - returns a string shows each match group by number.

return
a string shows each match group by number.

        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();
    
public java.lang.Stringgroup(int matchnum)
Convenience method delegates to the internal MatchResult's group() method.

param
matchnum match group number to be retrieved
return
the content of the matchnum'th group of the internal match or null if this method is called without a match having been made.

        if (this.result == null)
        {
            return null;
        }
        return this.result.group(matchnum);
    
public booleanmatches(java.lang.String s)
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.

        this.result = null;
        if (_matcher_.matches(s.trim(), this.pattern))
        {
            this.result = _matcher_.getMatch();
        }
        return null != this.result;