cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r737809 - /cocoon/cocoon3/trunk/cocoon-sitemap/src/main/java/org/apache/cocoon/sitemap/util/WildcardMatcherHelper.java
Date Mon, 26 Jan 2009 20:12:55 GMT
Author: cziegeler
Date: Mon Jan 26 20:12:55 2009
New Revision: 737809

URL: http://svn.apache.org/viewvc?rev=737809&view=rev
Log:
COCOON3-15 : Replace use of internal Sun classes with java.util.regex

Modified:
    cocoon/cocoon3/trunk/cocoon-sitemap/src/main/java/org/apache/cocoon/sitemap/util/WildcardMatcherHelper.java

Modified: cocoon/cocoon3/trunk/cocoon-sitemap/src/main/java/org/apache/cocoon/sitemap/util/WildcardMatcherHelper.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sitemap/src/main/java/org/apache/cocoon/sitemap/util/WildcardMatcherHelper.java?rev=737809&r1=737808&r2=737809&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sitemap/src/main/java/org/apache/cocoon/sitemap/util/WildcardMatcherHelper.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-sitemap/src/main/java/org/apache/cocoon/sitemap/util/WildcardMatcherHelper.java
Mon Jan 26 20:12:55 2009
@@ -18,14 +18,11 @@
 
 import java.util.HashMap;
 import java.util.Map;
-
-import com.sun.org.apache.regexp.internal.RE;
-import com.sun.org.apache.regexp.internal.RECompiler;
-import com.sun.org.apache.regexp.internal.REProgram;
+import java.util.regex.Pattern;
 
 /**
  * This class is an utility class that perform wildcard-patterns matching and isolation.
- * 
+ *
  * @version $Id$
  */
 public class WildcardMatcherHelper {
@@ -45,7 +42,7 @@
     /**
      * Match a pattern agains a string and isolates wildcard replacement into a <code>Map</code>.
<br>
      * Here is how the matching algorithm works:
-     * 
+     *
      * <ul>
      * <li> The '*' character, meaning that zero or more characters (excluding the
path separator '/') are to be
      * matched. </li>
@@ -64,10 +61,10 @@
      * <dd>foo/bar/baz/bug</dt>
      * </dl>
      * The first '**' in the pattern will suck up as much as possible without making the
match fail.
-     * 
+     *
      * @param pat The pattern string.
      * @param str The string to math agains the pattern
-     * 
+     *
      * @return a <code>Map</code> containing the representation of the extracted
pattern. The extracted patterns are
      *         keys in the <code>Map</code> from left to right beginning with
"1" for te left most, "2" for the next,
      *         a.s.o. The key "0" is the string itself. If the return value is null, string
does not match to the
@@ -108,13 +105,13 @@
     private static class Matcher {
 
         /** Regexp to split constant parts from front and back leaving wildcards in the middle.
*/
-        private static final REProgram splitter;
+        private static final Pattern splitter;
 
         static {
             final String fixedRE = "([^*\\\\]*)";
             final String wcardRE = "(.*[*\\\\])";
             final String splitRE = "^" + fixedRE + wcardRE + fixedRE + "$";
-            splitter = new RECompiler().compile(splitRE);
+            splitter = Pattern.compile(splitRE);
         }
 
         /** Wildcard types to short-cut simple '*' and "**' matches. */
@@ -140,26 +137,26 @@
         private final int wctype;
 
         /** Compiled regexp equivalent to wildcard pattern between prefix and suffix. */
-        private final REProgram regexp;
+        private final Pattern regexp;
 
         // ~ Constructors ---------------------------------------------------------------------------
 
         /**
          * Creates a new Matcher object.
-         * 
+         *
          * @param pat The pattern
          * @param str The string
          */
         Matcher(final String pat) {
-            RE re = new RE(splitter);
+            java.util.regex.Matcher re = splitter.matcher(pat);
 
-            if (re.match(pat)) {
+            if (re.matches()) {
 
                 // Split pattern into (foo/)(*)(/bar).
 
-                this.prefix = re.getParen(1);
-                String wildcard = re.getParen(2);
-                String tail = re.getParen(3);
+                this.prefix = re.group(1);
+                String wildcard = re.group(2);
+                String tail = re.group(3);
 
                 // If wildcard ends with \ then add the first char of postfix to wildcard.
                 if (tail.length() != 0 && wildcard.charAt(wildcard.length() - 1)
== ESC) {
@@ -196,7 +193,7 @@
 
         /**
          * Match string against pattern.
-         * 
+         *
          * @param str The string
          * @return list of wildcard matches, null if match failed
          */
@@ -218,16 +215,16 @@
             String infix = str.substring(this.prefix.length(), str.length() - this.suffix.length());
 
             if (this.wctype == WC_REGEXP) {
-                RE re = new RE(this.regexp);
-                if (!re.match(infix)) {
+                java.util.regex.Matcher re = this.regexp.matcher(infix);
+                if (!re.matches()) {
                     return null;
                 }
 
-                int n = re.getParenCount();
-                String[] list = new String[n];
+                int n = re.groupCount();
+                String[] list = new String[n+1];
                 list[0] = str;
-                for (int i = 1; i < n; i++) {
-                    list[i] = re.getParen(i);
+                for (int i = 1; i <= n; i++) {
+                    list[i] = re.group(i);
                 }
                 return list;
             }
@@ -251,11 +248,11 @@
 
     /**
      * Compile wildcard pattern into regexp pattern.
-     * 
+     *
      * @param pat The wildcard pattern
      * @return compiled regexp program.
      */
-    private static REProgram compileRegexp(String pat) {
+    private static Pattern compileRegexp(String pat) {
         StringBuffer repat = new StringBuffer(pat.length() * 6);
         repat.append('^');
 
@@ -299,6 +296,6 @@
         }
         repat.append('$');
 
-        return new RECompiler().compile(repat.toString());
+        return Pattern.compile(repat.toString());
     }
 }



Mime
View raw message