Author: niclas
Date: Wed May 26 03:08:37 2004
New Revision: 20456

Added:
   
avalon/trunk/tools/magic/engine/src/java/org/apache/avalon/magic/RegexpFilter.java
Log:
Forgot to add a file.

Added: 
avalon/trunk/tools/magic/engine/src/java/org/apache/avalon/magic/RegexpFilter.java
==============================================================================
--- (empty file)
+++ 
avalon/trunk/tools/magic/engine/src/java/org/apache/avalon/magic/RegexpFilter.java
  Wed May 26 03:08:37 2004
@@ -0,0 +1,59 @@
+/*
+Copyright 2004 The Apache Software Foundation
+Licensed  under the  Apache License,  Version 2.0  (the "License");
+you may not use  this file  except in  compliance with the License.
+You may obtain a copy of the License at 
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed  under the  License is distributed on an "AS IS" BASIS,
+WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
+implied.
+
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package org.apache.avalon.magic;
+
+import java.io.File;
+import java.io.FileFilter;
+
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
+
+public class RegexpFilter
+    implements FileFilter
+{
+    private Pattern m_Includes;
+    private Pattern m_Excludes;
+    
+    public RegexpFilter( String includes, String excludes )
+    {
+        m_Includes = Pattern.compile( includes );
+        m_Excludes = Pattern.compile( excludes );
+    }
+    
+    public boolean accept( File file )
+    {
+        String basename = file.getName();
+        
+        if( basename.equals( ".svn" ) )
+            return false;
+        
+        if( basename.equals( "CVS" ) )
+            return false;
+        
+        if( file.isDirectory() )
+            return true;
+        
+        String fullpath = file.getAbsolutePath();
+        Matcher m = m_Includes.matcher( fullpath );
+        if( ! m.matches() )
+            return false;
+        
+        m = m_Excludes.matcher( fullpath );
+        return ! m.matches() ;
+    }
+} 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to