// Copyright (c) 2003-2012, Jodd Team (jodd.org). All Rights Reserved.

package jodd.io.findfile;


import jodd.io.FileNameUtil;
import jodd.util.Wildcard;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * Wildcard file scanner.
 */
public class WildcardFileScanner extends FileScanner {

	protected final String wildcard;
	protected boolean usePathWildcards;
	protected List<File> files;

	public WildcardFileScanner(String wildcard) {
		this(wildcard, false);
	}

	public WildcardFileScanner(String wildcard, boolean usePathWildcards) {
		files = new ArrayList<File>();
		this.wildcard = wildcard;
		this.usePathWildcards = usePathWildcards;
	}

	public boolean isUsePathWildcards() {
		return usePathWildcards;
	}

	/**
	 * Set path wildcard matching algorithm.
	 */
	public void setUsePathWildcards(boolean usePathWildcards) {
		this.usePathWildcards = usePathWildcards;
	}

	@Override
	protected void onFile(File file) {
		String path = file.getAbsolutePath();
		path = FileNameUtil.separatorsToUnix(path);

		boolean match = usePathWildcards ?
				Wildcard.matchPath(path, wildcard) :
				Wildcard.match(path, wildcard) ;


		if (match) {
			files.add(file);
		}
	}

	/**
	 * Returns matched files.
	 */
	public List<File> getMatchedFiles() {
		return files;
	}

	/**
	 * Lists all matched files.
	 */
	public List<File> list(File root) {
		files.clear();
		scan(root);
		return files;
	}

	/**
	 * Lists all matched files.
	 */
	public List<File> list(String root) {
		files.clear();
		scan(root);
		return files;
	}
}

@@ -252,16 +252,24 @@
 ildcard 
+pattern 
 file sca
@@ -366,54 +366,15 @@
 ing 
-wildcard;%0D%0A%09protected boolean usePathWildcards
+pattern
 ;%0D%0A%09
@@ -443,474 +443,78 @@
 ing 
-wildcard) %7B%0D%0A%09%09this(wildcard, false);%0D%0A%09%7D%0D%0A%0D%0A%09public WildcardFileScanner(String wildcard, boolean usePathWildcards) %7B%0D%0A%09%09files = new ArrayList%3CFile%3E();%0D%0A%09%09this.wildcard = wildcard;%0D%0A%09%09this.usePathWildcards = usePathWildcards;%0D%0A%09%7D%0D%0A%0D%0A%09public boolean isUsePathWildcards() %7B%0D%0A%09%09return usePathWildcards;%0D%0A%09%7D%0D%0A%0D%0A%09/**%0D%0A%09 * Set path wildcard matching algorithm.%0D%0A%09 */%0D%0A%09public void setUsePathWildcards(boolean usePathWildcards) %7B%0D%0A%09%09this.usePathWildcards = usePathWildcards
+pattern) %7B%0D%0A%09%09files = new ArrayList%3CFile%3E();%0D%0A%09%09this.pattern = pattern
 ;%0D%0A%09
@@ -679,32 +679,8 @@
 h = 
-usePathWildcards ?%0D%0A%09%09%09%09
 Wild
@@ -704,59 +704,17 @@
 th, 
-wildcard) :%0D%0A%09%09%09%09Wildcard.match(path, wildcard) ;%0D%0A
+pattern);
 %0D%0A%0D%0A

use path-style for wildcard matching