KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > utils > DirFilter


1 /*
2  ************************************************************************************
3  * Copyright (C) 2001-2007 Openbravo S.L.
4  * Licensed under the Apache Software License version 2.0
5  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6  * Unless required by applicable law or agreed to in writing, software distributed
7  * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
8  * CONDITIONS OF ANY KIND, either express or implied. See the License for the
9  * specific language governing permissions and limitations under the License.
10  ************************************************************************************
11 */

12 package org.openbravo.utils;
13
14 import java.io.FilenameFilter JavaDoc;
15 import java.io.File JavaDoc;
16
17 public class DirFilter implements FilenameFilter JavaDoc {
18   String JavaDoc afn;
19   public DirFilter(String JavaDoc afn) {
20     this.afn = afn;
21   }
22
23   public boolean accept(File JavaDoc dir, String JavaDoc name) {
24     boolean boolReturn;
25     // the name is obtained only to compare it with the filename and not with all the names in all the path
26
String JavaDoc f = new File JavaDoc(name).getName();
27     // returns true if the filter agrees or if it is a directory
28
boolReturn = f.indexOf(afn, f.length() - afn.length()) != -1 || new File JavaDoc(dir,name).isDirectory();
29     return boolReturn;
30   }
31 }
32
Popular Tags