KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > core > util > FileExtensionFilter


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: FileExtensionFilter.java,v 1.4 2007/01/07 06:14:00 bastafidli Exp $
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21
22 package org.opensubsystems.core.util;
23
24 import java.io.File JavaDoc;
25 import java.io.FileFilter JavaDoc;
26
27 import org.opensubsystems.core.www.WebCommonConstants;
28
29 /**
30  * Description: Class to filter web supported images (.JPG).
31  *
32  * @version $Id: FileExtensionFilter.java,v 1.4 2007/01/07 06:14:00 bastafidli Exp $
33  * @author Miro Halas
34  * @code.reviewer Miro Halas
35  * @code.reviewed 1.2 2004/12/18 06:18:25 bastafidli
36  */

37 public class FileExtensionFilter implements FileFilter JavaDoc
38 {
39    // Cached values ////////////////////////////////////////////////////////////
40

41    /**
42     * Shared file filter instance.
43     */

44    public static final FileFilter JavaDoc JPEG_IMAGE_FILTER
45                                        = new FileExtensionFilter(
46                                                  WebCommonConstants.JPEG_IMAGE_EXTENSION);
47
48    // Attributes ///////////////////////////////////////////////////////////////
49

50    /**
51     * File extension to filter on.
52     */

53    protected String JavaDoc m_strExtension;
54
55    // Constructors /////////////////////////////////////////////////////////////
56

57    /**
58     * Create new FileExtensionFilter
59     *
60     * @param strExtension - extenstion to filter on
61     */

62    public FileExtensionFilter(
63       String JavaDoc strExtension
64    )
65    {
66       assert strExtension != null : "Extension cannot be null";
67       m_strExtension = strExtension;
68    }
69
70    // Public methods ///////////////////////////////////////////////////////////
71

72    /**
73     * Test if the found file matches the filter.
74     *
75     * @param flPathName - file to test
76     * @return true - if file matches the filter
77     */

78    public boolean accept(
79       File JavaDoc flPathName
80    )
81    {
82       return flPathName.isFile()
83              && flPathName.getName().toLowerCase().endsWith(m_strExtension);
84    }
85 }
86
Popular Tags