KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > vfs > FileFilterSelector


1 /*
2  * Copyright 2002-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.vfs;
17
18 import org.apache.commons.vfs.util.Messages;
19
20 /**
21  * A {@link org.apache.commons.vfs.FileSelector} that selects all children of the given fileObject.<br />
22  * This is to mimic the {@link java.io.FileFilter} interface
23  *
24  * @author <a HREF="mailto:imario@apache.org">Mario Ivankovits</a>
25  */

26 public class FileFilterSelector extends FileDepthSelector
27 {
28     private FileFilter fileFilter;
29
30     public FileFilterSelector()
31     {
32         super(1, 1);
33     }
34
35     public FileFilterSelector(FileFilter fileFilter)
36     {
37         this();
38         this.fileFilter = fileFilter;
39     }
40
41     /**
42      * Determines if a file or folder should be selected.
43      */

44     public boolean includeFile(final FileSelectInfo fileInfo)
45     {
46         if (!super.includeFile(fileInfo))
47         {
48             return false;
49         }
50
51         return accept(fileInfo);
52     }
53
54     public boolean accept(final FileSelectInfo fileInfo)
55     {
56         if (fileFilter != null)
57         {
58             return fileFilter.accept(fileInfo);
59         }
60
61         throw new IllegalArgumentException JavaDoc(Messages.getString("vfs.selectors/filefilter.missing.error"));
62     }
63 }
64
Popular Tags