You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ba...@apache.org on 2006/08/10 07:29:06 UTC
svn commit: r430256 - in
/jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder:
FindingFilter.java filters/NameFilter.java filters/PathFilter.java
Author: bayard
Date: Wed Aug 9 22:29:06 2006
New Revision: 430256
URL: http://svn.apache.org/viewvc?rev=430256&view=rev
Log:
Switched Finder from using its own NameFilter to using IO's WildcardFileFilter. This involved some hackery in Finder's PathFilter as it extended NameFilter. It now extends WildcardFileFilter - which is not a class built for inheritence.
Removed:
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/NameFilter.java
Modified:
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/FindingFilter.java
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/PathFilter.java
Modified: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/FindingFilter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/FindingFilter.java?rev=430256&r1=430255&r2=430256&view=diff
==============================================================================
--- jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/FindingFilter.java (original)
+++ jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/FindingFilter.java Wed Aug 9 22:29:06 2006
@@ -19,12 +19,12 @@
import java.io.File;
import java.util.Map;
import java.util.Iterator;
-import org.apache.commons.finder.filters.NameFilter;
import org.apache.commons.finder.filters.PathFilter;
import org.apache.commons.finder.filters.RegexFilter;
import org.apache.commons.finder.filters.SizeFilter;
-// import org.apache.commons.io.filefilter.WildcardFileFilter; // todo switch to WildcardFileFilter
+import org.apache.commons.io.IOCase;
+import org.apache.commons.io.filefilter.WildcardFileFilter;
import org.apache.commons.io.filefilter.IOFileFilter;
import org.apache.commons.io.filefilter.AgeFileFilter;
import org.apache.commons.io.filefilter.NotFileFilter;
@@ -106,13 +106,11 @@
return (invert ? new NotFileFilter(filter) : filter);
}
if( option.equals(Finder.NAME) ) {
-// IOFileFilter filter = new WildcardFileFilter(argument.toString(), false);
- IOFileFilter filter = new NameFilter(argument.toString(), false);
+ IOFileFilter filter = new WildcardFileFilter(argument.toString(), IOCase.SENSITIVE);
return (invert ? new NotFileFilter(filter) : filter);
}
if( option.equals(Finder.INAME) ) {
-// WildcardFileFilter filter = new WildcardFileFilter(argument.toString(), true);
- IOFileFilter filter = new NameFilter(argument.toString(), true);
+ IOFileFilter filter = new WildcardFileFilter(argument.toString(), IOCase.INSENSITIVE);
return (invert ? new NotFileFilter(filter) : filter);
}
if( option.equals(Finder.PATH) ) {
Modified: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/PathFilter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/PathFilter.java?rev=430256&r1=430255&r2=430256&view=diff
==============================================================================
--- jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/PathFilter.java (original)
+++ jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/PathFilter.java Wed Aug 9 22:29:06 2006
@@ -16,6 +16,9 @@
package org.apache.commons.finder.filters;
import java.io.File;
+import org.apache.commons.io.filefilter.WildcardFileFilter;
+import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.io.IOCase;
/**
* <code>IOFileFilter</code> implementation that uses wildcard matching on the file's path.
@@ -23,7 +26,14 @@
* @version $Id$
* @since 0.1
*/
-public class PathFilter extends NameFilter {
+public class PathFilter extends WildcardFileFilter {
+
+ // Ideally this would just use the same variable in the parent, but it's
+ // not accessible
+ private IOCase caseSensitivity;
+
+ // Same here
+ private String wildcard;
/**
* Construct a new <code>IOFileFilter</code> specifying whether the
@@ -33,16 +43,39 @@
* @param ignoreCase whether to ignore the case
*/
public PathFilter(String wildcardmatcher, boolean ignoreCase) {
- super(wildcardmatcher, ignoreCase);
+ super(wildcardmatcher, ignoreCase ? IOCase.INSENSITIVE : IOCase.SENSITIVE);
+ this.caseSensitivity = ignoreCase ? IOCase.INSENSITIVE : IOCase.SENSITIVE;
+ this.wildcard = wildcardmatcher;
}
+
/**
- * Return the name of the path.
- *
- * @param file The {@link File} to test.
- * @return the name of the path
+ * Checks to see if the filename matches the wildcard.
+ *
+ * @param dir the file directory
+ * @param name the full filename
+ * @return true if the full filename matches the wildcard
*/
- protected String getName(File file) {
- return file.getPath();
+ public boolean accept(File dir, String name) {
+ String path = new File(dir, name).toString();
+ if (FilenameUtils.wildcardMatch(path, wildcard, caseSensitivity)) {
+ return true;
+ }
+ return false;
}
+
+ /**
+ * Checks to see if the full filename matches the wildcard.
+ *
+ * @param file the file to check
+ * @return true if the full filename matches the wildcard
+ */
+ public boolean accept(File file) {
+ String name = file.getPath();
+ if (FilenameUtils.wildcardMatch(name, wildcard, caseSensitivity)) {
+ return true;
+ }
+ return false;
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org