KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sape > carbon > core > config > node > file > FileNodeFilter


1 /*
2  * The contents of this file are subject to the Sapient Public License
3  * Version 1.0 (the "License"); you may not use this file except in compliance
4  * with the License. You may obtain a copy of the License at
5  * http://carbon.sf.net/License.html.
6  *
7  * Software distributed under the License is distributed on an "AS IS" basis,
8  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9  * the specific language governing rights and limitations under the License.
10  *
11  * The Original Code is The Carbon Component Framework.
12  *
13  * The Initial Developer of the Original Code is Sapient Corporation
14  *
15  * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.
16  */

17
18 package org.sape.carbon.core.config.node.file;
19
20 import java.io.File JavaDoc;
21 import java.io.FilenameFilter JavaDoc;
22
23 /**
24  * Used to filter files from the file system that fit the
25  * naming criteria for files that may be represented by
26  * a <code>FileConfigurationDocument</code>. Currently, valid files
27  * must end in '<code>.xml</code>'.
28  *
29  * Copyright 2002 Sapient
30  * @see org.sape.carbon.core.config.node.file.FileConfigurationDocument
31  * @since carbon 1.0
32  * @author Mike Redd, February 2001
33  * @version $Revision: 1.9 $($Author: dvoet $ / $Date: 2003/05/05 21:21:19 $)
34  */

35 public class FileNodeFilter implements FilenameFilter JavaDoc {
36
37     /**
38      * The extension for files than may be represented by a
39      * <code>FileConfigurationDocument</code>, currently '<code>.xml</code>'.
40      */

41     public static final String JavaDoc CONFIG_DOC_NODE_EXTENSION = ".xml";
42
43     /** Extension of a link node. **/
44     public static final String JavaDoc LINK_NODE_EXTENSION = ".link";
45
46     /** Name of a CVS directory. */
47     public static final String JavaDoc CVS_DIR_NAME = "CVS";
48
49     /**
50      * Returns <code>true</code> if <code>name</code> is the name
51      * of a file that is a valid <code>FileConfigurationDocument</code> file.
52      * These files must end with '<code>.xml</code>' in their names, and
53      * must be a physical file.
54      *
55      * @param dir directory for file
56      * @param name the name of the file
57      * @return if this file is acceptabled as a FileNode
58      */

59     public boolean accept(File JavaDoc dir, String JavaDoc name) {
60         File JavaDoc file = new File JavaDoc(dir, name);
61
62         if (file.isDirectory()) {
63             if (name.equals(CVS_DIR_NAME)) {
64                 return false;
65             } else {
66                 return true;
67             }
68         } else if (name.endsWith(CONFIG_DOC_NODE_EXTENSION)
69                   || name.endsWith(LINK_NODE_EXTENSION)) {
70             return true;
71         } else {
72             return false;
73         }
74     }
75 }
Popular Tags