14fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy/* 24fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * Licensed to the Apache Software Foundation (ASF) under one or more 34fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * contributor license agreements. See the NOTICE file distributed with 44fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * this work for additional information regarding copyright ownership. 54fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * The ASF licenses this file to You under the Apache License, Version 2.0 64fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * (the "License"); you may not use this file except in compliance with 74fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * the License. You may obtain a copy of the License at 84fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * 94fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * http://www.apache.org/licenses/LICENSE-2.0 104fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * 114fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * Unless required by applicable law or agreed to in writing, software 124fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * distributed under the License is distributed on an "AS IS" BASIS, 134fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 144fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * See the License for the specific language governing permissions and 154fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * limitations under the License. 164fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy */ 174fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedypackage org.apache.commons.io.filefilter; 184fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy 194fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedyimport java.io.File; 204fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy 214fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy/** 224fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * An abstract class which implements the Java FileFilter and FilenameFilter 234fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * interfaces via the IOFileFilter interface. 244fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * <p> 254fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * Note that a subclass <b>must</b> override one of the accept methods, 264fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * otherwise your class will infinitely loop. 274fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * 284fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * @since Commons IO 1.0 294fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * @version $Revision: 539231 $ $Date: 2007-05-18 04:10:33 +0100 (Fri, 18 May 2007) $ 304fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * 314fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * @author Stephen Colebourne 324fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy */ 334fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedypublic abstract class AbstractFileFilter implements IOFileFilter { 344fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy 354fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy /** 364fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * Checks to see if the File should be accepted by this filter. 374fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * 384fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * @param file the File to check 394fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * @return true if this file matches the test 404fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy */ 414fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy public boolean accept(File file) { 424fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy return accept(file.getParentFile(), file.getName()); 434fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy } 444fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy 454fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy /** 464fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * Checks to see if the File should be accepted by this filter. 474fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * 484fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * @param dir the directory File to check 494fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * @param name the filename within the directory to check 504fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * @return true if this file matches the test 514fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy */ 524fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy public boolean accept(File dir, String name) { 534fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy return accept(new File(dir, name)); 544fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy } 554fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy 564fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy /** 574fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * Provide a String representaion of this file filter. 584fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * 594fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * @return a String representaion 604fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy */ 614fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy public String toString() { 624fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy String name = getClass().getName(); 634fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy int period = name.lastIndexOf('.'); 644fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy return (period > 0 ? name.substring(period + 1) : name); 654fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy } 664fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy 674fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy} 68