01: //** Copyright Statement ***************************************************
02: //The Salmon Open Framework for Internet Applications (SOFIA)
03: // Copyright (C) 1999 - 2002, Salmon LLC
04: //
05: // This program is free software; you can redistribute it and/or
06: // modify it under the terms of the GNU General Public License version 2
07: // as published by the Free Software Foundation;
08: //
09: // This program is distributed in the hope that it will be useful,
10: // but WITHOUT ANY WARRANTY; without even the implied warranty of
11: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: // GNU General Public License for more details.
13: //
14: // You should have received a copy of the GNU General Public License
15: // along with this program; if not, write to the Free Software
16: // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17: //
18: // For more information please visit http://www.salmonllc.com
19: //** End Copyright Statement ***************************************************
20: package com.salmonllc.util;
21:
22: /**
23: * Implements a file filter to test whether a file ends with a particular suffix
24: */
25: public class FilterFile implements java.io.FilenameFilter {
26: private String _suffix;
27: private boolean _bCaseInsensitive;
28:
29: /**
30: * FileFilter constructor comment.
31: */
32: public FilterFile(String suffix) {
33: this (suffix, false);
34: }
35:
36: /**
37: * FileFilter constructor comment.
38: */
39: public FilterFile(String suffix, boolean bCaseInsensitive) {
40: super ();
41:
42: _bCaseInsensitive = bCaseInsensitive;
43: _suffix = suffix;
44: }
45:
46: /**
47: * Tests if a specified file should be included in a file list.
48: *
49: * @param dir the directory in which the file was found.
50: * @param name the name of the file.
51: * @return <code>true</code> if and only if the name should be
52: * included in the file list; <code>false</code> otherwise.
53: */
54: public boolean accept(java.io.File dir, String name) {
55: if (_bCaseInsensitive) {
56: if (name.toUpperCase().endsWith(_suffix.toUpperCase()))
57: return true;
58: } else {
59: if (name.endsWith(_suffix))
60: return true;
61: }
62:
63: return false;
64: }
65: }
|