commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r424198 - in /jakarta/commons/sandbox/finder/trunk: project.xml src/java/org/apache/commons/finder/filters/NameFilter.java
Date Fri, 21 Jul 2006 06:39:59 GMT
Author: bayard
Date: Thu Jul 20 23:39:58 2006
New Revision: 424198

URL: http://svn.apache.org/viewvc?rev=424198&view=rev
Log:
Returned the IO dependency after chatting with Niall. Better to wait until we have are closer
to a release to decide how this should relate to IO. Also added Niall's name to project.xml

Modified:
    jakarta/commons/sandbox/finder/trunk/project.xml
    jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/NameFilter.java

Modified: jakarta/commons/sandbox/finder/trunk/project.xml
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/finder/trunk/project.xml?rev=424198&r1=424197&r2=424198&view=diff
==============================================================================
--- jakarta/commons/sandbox/finder/trunk/project.xml (original)
+++ jakarta/commons/sandbox/finder/trunk/project.xml Thu Jul 20 23:39:58 2006
@@ -59,11 +59,22 @@
     <developer>
       <name>Henri Yandell</name>
       <id>bayard</id>
-      <email>bayard@apache.org</email>
+      <email>bayard at apache dot org</email>
+    </developer>
+    <developer>
+      <name>Niall Pemberton</name>
+      <id>niallp</id>
+      <email>niallp at apache dot org</email>
     </developer>
   </developers>
     
   <dependencies>
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+      <version>1.2</version>
+      <url>http://jakarta.apache.org/commons/io/</url>
+    </dependency>
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>

Modified: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/NameFilter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/NameFilter.java?rev=424198&r1=424197&r2=424198&view=diff
==============================================================================
--- jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/NameFilter.java
(original)
+++ jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/NameFilter.java
Thu Jul 20 23:39:58 2006
@@ -19,6 +19,8 @@
 import java.util.Stack;
 import java.util.ArrayList;
 
+import org.apache.commons.io.FilenameUtils;
+
 /**
  * {@link java.io.FileFilter} implementation that uses wildcard matching on the file name.
  * 
@@ -93,7 +95,12 @@
      * <code>false</code> .
      */
     protected boolean test(File file) {
-        return wildcardMatch(getName(file), getWildcardmatcher(), isMatchOnSystem());
+        if( isMatchOnSystem() ) {
+            // TODO: Switch to using the IOCase API when IO 1.3 comes out
+            return FilenameUtils.wildcardMatch(getName(file).toLowerCase(), getWildcardmatcher().toLowerCase());
+        } else {
+            return FilenameUtils.wildcardMatch(getName(file), getWildcardmatcher());
+        }
     }
 
     /**
@@ -106,140 +113,4 @@
         return file.getName();
     }
 
-    // ****************************************************************************
-    // ********** FOLLOWING METHODS WERE COPIED FROM Commons IO *******************
-    // **********        FilenameUtils.wildcardMatch()          *******************
-    // **********        FilenameUtils.splitOnTokens()          *******************
-    // ****************************************************************************
-
-    /**
-     * Checks a filename to see if it matches the specified wildcard matcher.
-     * <p>
-     * The wildcard matcher uses the characters '?' and '*' to represent a
-     * single or multiple wildcard characters.
-     * 
-     * @param filename  the filename to match on
-     * @param wildcardMatcher  the wildcard string to match against
-     * @param system  whether to use the system (windows or unix)
-     * @return true if the filename matches the wilcard string
-     */
-    private static boolean wildcardMatch(String filename, String wildcardMatcher, boolean
system) {
-        if (filename == null && wildcardMatcher == null) {
-            return true;
-        }
-        if (filename == null || wildcardMatcher == null) {
-            return false;
-        }
-        if (system && (SYSTEM_SEPARATOR == WINDOWS_SEPARATOR)) {
-            filename = filename.toLowerCase();
-            wildcardMatcher = wildcardMatcher.toLowerCase();
-        }
-        String[] wcs = splitOnTokens(wildcardMatcher);
-        boolean anyChars = false;
-        int textIdx = 0;
-        int wcsIdx = 0;
-        Stack backtrack = new Stack();
-        
-        // loop around a backtrack stack, to handle complex * matching
-        do {
-            if (backtrack.size() > 0) {
-                int[] array = (int[]) backtrack.pop();
-                wcsIdx = array[0];
-                textIdx = array[1];
-                anyChars = true;
-            }
-            
-            // loop whilst tokens and text left to process
-            while (wcsIdx < wcs.length) {
-      
-                if (wcs[wcsIdx].equals("?")) {
-                    // ? so move to next text char
-                    textIdx++;
-                    anyChars = false;
-                    
-                } else if (wcs[wcsIdx].equals("*")) {
-                    // set any chars status
-                    anyChars = true;
-                    if (wcsIdx == wcs.length - 1) {
-                        textIdx = filename.length();
-                    }
-                    
-                } else {
-                    // matching text token
-                    if (anyChars) {
-                        // any chars then try to locate text token
-                        textIdx = filename.indexOf(wcs[wcsIdx], textIdx);
-                        if (textIdx == -1) {
-                            // token not found
-                            break;
-                        }
-                        int repeat = filename.indexOf(wcs[wcsIdx], textIdx + 1);
-                        if (repeat >= 0) {
-                            backtrack.push(new int[] {wcsIdx, repeat});
-                        }
-                    } else {
-                        // matching from current position
-                        if (!filename.startsWith(wcs[wcsIdx], textIdx)) {
-                            // couldnt match token
-                            break;
-                        }
-                    }
-      
-                    // matched text token, move text index to end of matched token
-                    textIdx += wcs[wcsIdx].length();
-                    anyChars = false;
-                }
-      
-                wcsIdx++;
-            }
-            
-            // full match
-            if (wcsIdx == wcs.length && textIdx == filename.length()) {
-                return true;
-            }
-            
-        } while (backtrack.size() > 0);
-  
-        return false;
-    }
-
-    /**
-     * Splits a string into a number of tokens.
-     * 
-     * @param text  the text to split
-     * @return the tokens, never null
-     */
-    static String[] splitOnTokens(String text) {
-        // used by wildcardMatch
-        // package level so a unit test may run on this
-        
-        if (text.indexOf("?") == -1 && text.indexOf("*") == -1) {
-            return new String[] { text };
-        }
-
-        char[] array = text.toCharArray();
-        ArrayList list = new ArrayList();
-        StringBuffer buffer = new StringBuffer();
-        for (int i = 0; i < array.length; i++) {
-            if (array[i] == '?' || array[i] == '*') {
-                if (buffer.length() != 0) {
-                    list.add(buffer.toString());
-                    buffer.setLength(0);
-                }
-                if (array[i] == '?') {
-                    list.add("?");
-                } else if (list.size() == 0 ||
-                        (i > 0 && list.get(list.size() - 1).equals("*") == false))
{
-                    list.add("*");
-                }
-            } else {
-                buffer.append(array[i]);
-            }
-        }
-        if (buffer.length() != 0) {
-            list.add(buffer.toString());
-        }
-
-        return (String[]) list.toArray(new String[0]);
-    }
 }



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