commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwins...@apache.org
Subject svn commit: r437149 - /jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/ftp/parser/RegexFTPFileEntryParserImpl.java
Date Sat, 26 Aug 2006 11:56:50 GMT
Author: rwinston
Date: Sat Aug 26 04:56:49 2006
New Revision: 437149

URL: http://svn.apache.org/viewvc?rev=437149&view=rev
Log: (empty)

Modified:
    jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/ftp/parser/RegexFTPFileEntryParserImpl.java

Modified: jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/ftp/parser/RegexFTPFileEntryParserImpl.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/ftp/parser/RegexFTPFileEntryParserImpl.java?rev=437149&r1=437148&r2=437149&view=diff
==============================================================================
--- jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/ftp/parser/RegexFTPFileEntryParserImpl.java
(original)
+++ jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/ftp/parser/RegexFTPFileEntryParserImpl.java
Sat Aug 26 04:56:49 2006
@@ -15,6 +15,7 @@
  */
 
 package org.apache.commons.net.ftp.parser;
+
 import java.util.regex.MatchResult;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -22,9 +23,6 @@
 
 import org.apache.commons.net.ftp.FTPFileEntryParserImpl;
 
-
-
-
 /**
  * This abstract class implements both the older FTPFileListParser and
  * newer FTPFileEntryParser interfaces with default functionality.
@@ -34,128 +32,121 @@
  *
  * @author Steve Cohen <scohen@apache.org>
  */
-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 Matcher _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   = Pattern.compile(regex);
-        }
-        catch (PatternSyntaxException 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;
-        _matcher_ = pattern.matcher(s);
-        if (_matcher_.matches())
-        {
-            this.result = _matcher_.toMatchResult();
-        }
-        return null != this.result;
-    }
-    
-
-    /**
-     * Convenience method 
-     *
-     * @return the number of groups() in the internal MatchResult.
-     */
-
-    public int getGroupCnt()
-    {
-        if (this.result == null)
-        {
-            return 0;
-        }
-        return this.result.groupCount();
-    }
-
-
-
-    /**
-     * 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.groupCount(); i++)
-        {
-            b.append(i).append(") ").append(this.result.group(i))
-                .append(System.getProperty("line.separator"));
-        }
-        return b.toString();
-    }
-    
-}
-
+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 Matcher _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();
+		changeRegex(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;
+		_matcher_ = pattern.matcher(s);
+		if (_matcher_.matches()) {
+			this.result = _matcher_.toMatchResult();
+		}
+		return null != this.result;
+	}
+
+	/**
+	 * Convenience method 
+	 *
+	 * @return the number of groups() in the internal MatchResult.
+	 */
+
+	public int getGroupCnt() {
+		if (this.result == null) {
+			return 0;
+		}
+		return this.result.groupCount();
+	}
+
+	/**
+	 * 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.groupCount(); i++) {
+			b.append(i).append(") ").append(this.result.group(i)).append(
+					System.getProperty("line.separator"));
+		}
+		return b.toString();
+	}
+
+	/**
+	 * Alter the current regular expression being utilised for entry parsing 
+	 * and create a new {@link Pattern} instance.
+	 * @param regex The new regular expression
+	 * @return 
+	 */
+	public boolean changeRegex(String regex) {
+		try {
+			pattern = Pattern.compile(regex);
+		} catch (PatternSyntaxException pse) {
+			throw new IllegalArgumentException("Unparseable regex supplied: "
+					+ regex);
+		}
+		return (pattern != null);
+	}
 
+}



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


Mime
View raw message