Source Code Cross Referenced for WildcardFilter.java in  » Library » apache-common-IO » org » apache » commons » io » filefilter » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Library » apache common IO » org.apache.commons.io.filefilter 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.commons.io.filefilter;
018:
019:        import java.io.File;
020:        import java.util.List;
021:
022:        import org.apache.commons.io.FilenameUtils;
023:
024:        /**
025:         * Filters files using the supplied wildcards.
026:         * <p>
027:         * This filter selects files, but not directories, based on one or more wildcards
028:         * and using case-sensitive comparison.
029:         * <p>
030:         * The wildcard matcher uses the characters '?' and '*' to represent a
031:         * single or multiple wildcard characters.
032:         * This is the same as often found on Dos/Unix command lines.
033:         * The extension check is case-sensitive.
034:         * See {@link FilenameUtils#wildcardMatch} for more information.
035:         * <p>
036:         * For example:
037:         * <pre>
038:         * File dir = new File(".");
039:         * FileFilter fileFilter = new WildcardFilter("*test*.java~*~");
040:         * File[] files = dir.listFiles(fileFilter);
041:         * for (int i = 0; i < files.length; i++) {
042:         *   System.out.println(files[i]);
043:         * }
044:         * </pre>
045:         *
046:         * @author Jason Anderson
047:         * @version $Revision: 437680 $ $Date: 2006-08-28 13:57:00 +0200 (Mo, 28 Aug 2006) $
048:         * @since Commons IO 1.1
049:         * @deprecated Use WilcardFileFilter. Deprecated as this class performs directory
050:         * filtering which it shouldn't do, but that can't be removed due to compatability.
051:         */
052:        public class WildcardFilter extends AbstractFileFilter {
053:
054:            /** The wildcards that will be used to match filenames. */
055:            private String[] wildcards;
056:
057:            /**
058:             * Construct a new case-sensitive wildcard filter for a single wildcard.
059:             *
060:             * @param wildcard  the wildcard to match
061:             * @throws IllegalArgumentException if the pattern is null
062:             */
063:            public WildcardFilter(String wildcard) {
064:                if (wildcard == null) {
065:                    throw new IllegalArgumentException(
066:                            "The wildcard must not be null");
067:                }
068:                this .wildcards = new String[] { wildcard };
069:            }
070:
071:            /**
072:             * Construct a new case-sensitive wildcard filter for an array of wildcards.
073:             *
074:             * @param wildcards  the array of wildcards to match
075:             * @throws IllegalArgumentException if the pattern array is null
076:             */
077:            public WildcardFilter(String[] wildcards) {
078:                if (wildcards == null) {
079:                    throw new IllegalArgumentException(
080:                            "The wildcard array must not be null");
081:                }
082:                this .wildcards = wildcards;
083:            }
084:
085:            /**
086:             * Construct a new case-sensitive wildcard filter for a list of wildcards.
087:             *
088:             * @param wildcards  the list of wildcards to match
089:             * @throws IllegalArgumentException if the pattern list is null
090:             * @throws ClassCastException if the list does not contain Strings
091:             */
092:            public WildcardFilter(List wildcards) {
093:                if (wildcards == null) {
094:                    throw new IllegalArgumentException(
095:                            "The wildcard list must not be null");
096:                }
097:                this .wildcards = (String[]) wildcards
098:                        .toArray(new String[wildcards.size()]);
099:            }
100:
101:            //-----------------------------------------------------------------------
102:            /**
103:             * Checks to see if the filename matches one of the wildcards.
104:             *
105:             * @param dir  the file directory
106:             * @param name  the filename
107:             * @return true if the filename matches one of the wildcards
108:             */
109:            public boolean accept(File dir, String name) {
110:                if (dir != null && new File(dir, name).isDirectory()) {
111:                    return false;
112:                }
113:
114:                for (int i = 0; i < wildcards.length; i++) {
115:                    if (FilenameUtils.wildcardMatch(name, wildcards[i])) {
116:                        return true;
117:                    }
118:                }
119:
120:                return false;
121:            }
122:
123:            /**
124:             * Checks to see if the filename matches one of the wildcards.
125:             *
126:             * @param file the file to check
127:             * @return true if the filename matches one of the wildcards
128:             */
129:            public boolean accept(File file) {
130:                if (file.isDirectory()) {
131:                    return false;
132:                }
133:
134:                for (int i = 0; i < wildcards.length; i++) {
135:                    if (FilenameUtils.wildcardMatch(file.getName(),
136:                            wildcards[i])) {
137:                        return true;
138:                    }
139:                }
140:
141:                return false;
142:            }
143:
144:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.