KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > cms > ant > JavaFilenameFilter


1 /*
2  * Copyright 1999-2004 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  */

17
18 /* $Id: JavaFilenameFilter.java 106994 2004-11-30 10:53:10Z andreas $ */
19
20 package org.apache.lenya.cms.ant;
21
22 import java.io.File JavaDoc;
23 import java.io.FilenameFilter JavaDoc;
24 import java.util.Arrays JavaDoc;
25 import java.util.StringTokenizer JavaDoc;
26
27 public class JavaFilenameFilter implements FilenameFilter JavaDoc {
28     
29     protected static final String JavaDoc[] SUFFIXES = { "java", "properties", "xml", "xsl", "jdo", "dtd" };
30
31     /**
32      * (non-Javadoc)
33      * @see java.io.FilenameFilter#accept(java.io.File, java.lang.String)
34      */

35     public boolean accept(File JavaDoc dir, String JavaDoc name) {
36         boolean accept = true;
37         if (new File JavaDoc(dir, name).isFile()) {
38             String JavaDoc suffix = getExtension(name);
39             if (!Arrays.asList(SUFFIXES).contains(suffix)) {
40                 accept = false;
41             }
42         }
43         return accept;
44     }
45
46     /**
47      * Get the extension
48      *
49      * @param filename the file name from which the extension is extracted
50      * @return the extension
51      */

52     static public String JavaDoc getExtension(String JavaDoc filename) {
53         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(filename, ".");
54         st.nextToken();
55
56         String JavaDoc extension = "";
57
58         while (st.hasMoreTokens()) {
59             extension = st.nextToken();
60         }
61
62         return extension;
63     }
64 }
65
Popular Tags