Major cleanup of Utils class.
[trakem2.git] / ini / trakem2 / io / XMLFileFilter.java
blob5e309ebce1c060041419c484f718fe8d8fc134df
1 /**
3 TrakEM2 plugin for ImageJ(C).
4 Copyright (C) 2005 Albert Cardona and Rodney Douglas.
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation (http://www.gnu.org/licenses/gpl.txt )
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 You may contact Albert Cardona at acardona at ini.phys.ethz.ch
20 Institute of Neuroinformatics, University of Zurich / ETH, Switzerland.
21 **/
22 package ini.trakem2.io;
24 import java.io.FilenameFilter;
25 import java.io.File;
27 /** Accepts .dtd and/or .xml extensions. */
28 public class XMLFileFilter implements FilenameFilter {
30 static public final int DTD = 0;
31 static public final int XML = 1;
32 static public final int BOTH = 2;
33 private int ext = -1;
35 public XMLFileFilter(int ext) {
36 this.ext = ext;
38 public boolean accept(File dir, String name) {
39 File file = new File(dir + "/" + name);
40 if (file.isDirectory()) {
41 return true;
43 name = name.toLowerCase();
44 switch (ext) {
45 case DTD:
46 if (name.length() -4 == name.lastIndexOf(".dtd")) return true;
47 break;
48 case XML:
49 if (name.length() -4 == name.lastIndexOf(".xml")) return true;
50 break;
51 case BOTH:
52 if (name.length() -4 == name.lastIndexOf(".xml")
53 || name.length() -4 == name.lastIndexOf(".dtd")
54 ) {
55 return true;
57 break;
59 return false;