KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > tool > archive > ClassFilter


1
2 /*
3  * Enhydra Java Application Server Project
4  *
5  * The contents of this file are subject to the Enhydra Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License on
8  * the Enhydra web site ( http://www.enhydra.org/ ).
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific terms governing rights and limitations
13  * under the License.
14  *
15  * The Initial Developer of the Enhydra Application Server is Lutris
16  * Technologies, Inc. The Enhydra Application Server and portions created
17  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
18  * All Rights Reserved.
19  *
20  * Contributor(s):
21  * Paul Mahar
22  *
23  */

24 package org.enhydra.tool.archive;
25
26 //
27
import org.enhydra.tool.common.PathHandle;
28
29 //
30
import java.io.File JavaDoc;
31 import java.io.FileFilter JavaDoc;
32
33 //
34
public class ClassFilter implements FileFilter JavaDoc {
35     // NFS
36
protected static final String JavaDoc TEMP_NFS = ".nfs"; // nores
37

38     //
39
private final String JavaDoc MANIFEST = "MANIFEST.MF"; // nores
40

41     // JBuilder/JDevelper
42
private final String JavaDoc GEN_SOURCE = "Generated Source"; // nores
43
private final String JavaDoc DEP_CACHE = "dependency cache"; // nores
44

45     // Forte
46
private final String JavaDoc TYPE_JAVA = ".java"; // nores
47
private final String JavaDoc TYPE_JSP = ".jsp"; // nores
48

49     //
50
private PathHandle root = null;
51
52
53     //
54
public ClassFilter() {}
55
56     ;
57     public ClassFilter(String JavaDoc r) {
58         setRoot(r);
59     }
60
61     public void setRoot(String JavaDoc r) {
62         root = PathHandle.createPathHandle(r);
63     }
64
65     public String JavaDoc getRoot() {
66         return root.getPath();
67     }
68
69     public boolean accept(File JavaDoc file) {
70         boolean include = false;
71         PathHandle filePath = null;
72
73         filePath = PathHandle.createPathHandle(file);
74         if (root.parentOf(filePath)) {
75             if (filePath.isDirectory()) {
76                 include = true;
77             } else {
78                 String JavaDoc relative = null;
79
80                 relative =
81                     file.getAbsolutePath().substring(root.getPath().length()
82                                                      + 1);
83                 if (relative.startsWith(GEN_SOURCE)) {
84
85                     // exclude JB/JDev Generated Source
86
} else if (relative.startsWith(DEP_CACHE)) {
87
88                     // exclude JBuilder dependancy cache
89
} else if (relative.toUpperCase().endsWith(MANIFEST)) {
90
91                     // exclude Manifest
92
} else if (relative.toLowerCase().endsWith(TYPE_JAVA)) {
93
94                     // exclude Java source
95
} else if (relative.toLowerCase().endsWith(TYPE_JSP)) {
96
97                     // exclude JSP
98
} else if (file.getName().toLowerCase().startsWith(ClassFilter.TEMP_NFS)) {
99
100                     // exclude nfs temp files
101
} else {
102                     include = true;
103                 }
104             }
105         }
106         return include;
107     }
108
109 }
110
Popular Tags