commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwins...@apache.org
Subject svn commit: r436947 - in /jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/java/org/apache/commons/net/ftp/parser: RegexFTPFileEntryParserImpl.java VMSVersioningFTPEntryParser.java
Date Fri, 25 Aug 2006 21:03:11 GMT
Author: rwinston
Date: Fri Aug 25 14:03:10 2006
New Revision: 436947

URL: http://svn.apache.org/viewvc?rev=436947&view=rev
Log:
Use JDK 5 regex facilities (including MatchResult)

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

Modified: jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/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/java/org/apache/commons/net/ftp/parser/RegexFTPFileEntryParserImpl.java?rev=436947&r1=436946&r2=436947&view=diff
==============================================================================
--- jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/java/org/apache/commons/net/ftp/parser/RegexFTPFileEntryParserImpl.java
(original)
+++ jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/java/org/apache/commons/net/ftp/parser/RegexFTPFileEntryParserImpl.java
Fri Aug 25 14:03:10 2006
@@ -15,13 +15,13 @@
  */
 
 package org.apache.commons.net.ftp.parser;
+import java.util.regex.MatchResult;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
 import org.apache.commons.net.ftp.FTPFileEntryParserImpl;
-import org.apache.oro.text.regex.MalformedPatternException;
-import org.apache.oro.text.regex.MatchResult;
-import org.apache.oro.text.regex.Pattern;
-import org.apache.oro.text.regex.PatternMatcher;
-import org.apache.oro.text.regex.Perl5Compiler;
-import org.apache.oro.text.regex.Perl5Matcher;
+
 
 
 
@@ -51,7 +51,7 @@
      * 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;
+    protected Matcher _matcher_ = null;
 
     /**
      * The constructor for a RegexFTPFileEntryParserImpl object.
@@ -72,10 +72,10 @@
         super();
         try
         {
-            _matcher_ = new Perl5Matcher();
-            pattern   = new Perl5Compiler().compile(regex);
+            //matcher_ = new Perl5Matcher();
+            pattern   = Pattern.compile(regex);
         }
-        catch (MalformedPatternException e)
+        catch (PatternSyntaxException e)
         {
             throw new IllegalArgumentException (
                "Unparseable regex supplied:  " + regex);
@@ -93,18 +93,17 @@
     public boolean matches(String s)
     {
         this.result = null;
-        if (_matcher_.matches(s.trim(), this.pattern))
+        _matcher_ = pattern.matcher(s);
+        if (_matcher_.matches())
         {
-            this.result = _matcher_.getMatch();
+            this.result = _matcher_.toMatchResult();
         }
         return null != this.result;
     }
-
-
+    
 
     /**
-     * Convenience method delegates to the internal MatchResult's groups()
-     * method.
+     * Convenience method 
      *
      * @return the number of groups() in the internal MatchResult.
      */
@@ -115,7 +114,7 @@
         {
             return 0;
         }
-        return this.result.groups();
+        return this.result.groupCount();
     }
 
 
@@ -149,7 +148,7 @@
     public String getGroupsAsString()
     {
         StringBuffer b = new StringBuffer();
-        for (int i = 1; i <= this.result.groups(); i++)
+        for (int i = 1; i <= this.result.groupCount(); i++)
         {
             b.append(i).append(") ").append(this.result.group(i))
                 .append(System.getProperty("line.separator"));

Modified: jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/java/org/apache/commons/net/ftp/parser/VMSVersioningFTPEntryParser.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/java/org/apache/commons/net/ftp/parser/VMSVersioningFTPEntryParser.java?rev=436947&r1=436946&r2=436947&view=diff
==============================================================================
--- jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/java/org/apache/commons/net/ftp/parser/VMSVersioningFTPEntryParser.java
(original)
+++ jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/java/org/apache/commons/net/ftp/parser/VMSVersioningFTPEntryParser.java
Fri Aug 25 14:03:10 2006
@@ -18,13 +18,12 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.ListIterator;
+import java.util.regex.MatchResult;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
 
 import org.apache.commons.net.ftp.FTPClientConfig;
-import org.apache.oro.text.regex.MalformedPatternException;
-import org.apache.oro.text.regex.MatchResult;
-import org.apache.oro.text.regex.Pattern;
-import org.apache.oro.text.regex.Perl5Compiler;
-import org.apache.oro.text.regex.Perl5Matcher;
 
 /**
  * Special implementation VMSFTPEntryParser with versioning turned on.
@@ -47,7 +46,7 @@
 public class VMSVersioningFTPEntryParser extends VMSFTPEntryParser
 {
 
-    private Perl5Matcher _preparse_matcher_;
+    private Matcher _preparse_matcher_;
     private Pattern _preparse_pattern_;
     private static final String PRE_PARSE_REGEX =
         "(.*);([0-9]+)\\s*.*";
@@ -84,10 +83,10 @@
         configure(config);
         try
         {
-            _preparse_matcher_ = new Perl5Matcher();
-            _preparse_pattern_ = new Perl5Compiler().compile(PRE_PARSE_REGEX);
+            //_preparse_matcher_ = new Perl5Matcher();
+            _preparse_pattern_ = Pattern.compile(PRE_PARSE_REGEX);
         }
-        catch (MalformedPatternException e)
+        catch (PatternSyntaxException pse)
         {
             throw new IllegalArgumentException (
                 "Unparseable regex supplied:  " + PRE_PARSE_REGEX);
@@ -122,8 +121,9 @@
         while (iter.hasNext()) {
             String entry = ((String)iter.next()).trim();
             MatchResult result = null;
-            if (_preparse_matcher_.matches(entry, _preparse_pattern_)) {
-                result = _preparse_matcher_.getMatch();
+            _preparse_matcher_ = _preparse_pattern_.matcher(entry);
+            if (_preparse_matcher_.matches()) {
+                result = _preparse_matcher_.toMatchResult();
                 String name = result.group(1);
                 String version = result.group(2);
                 NameVersion nv = new NameVersion(name, version);
@@ -145,8 +145,9 @@
         while (iter.hasPrevious()) {
             String entry = ((String)iter.previous()).trim();
             MatchResult result = null;
-            if (_preparse_matcher_.matches(entry, _preparse_pattern_)) {
-                result = _preparse_matcher_.getMatch();
+            _preparse_matcher_ = _preparse_pattern_.matcher(entry);
+            if (_preparse_matcher_.matches()) {
+                result = _preparse_matcher_.toMatchResult();
                 String name = result.group(1);
                 String version = result.group(2);
                 NameVersion nv = new NameVersion(name, version);
@@ -161,6 +162,7 @@
         }
         return original;
     }
+
 
     protected boolean isVersioning() {
         return true;



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