[jboss-cvs] JBossAS SVN: r101660 - projects/vfs/trunk/src/main/java/org/jboss/vfs/util.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Mar 1 10:25:49 EST 2010


Author: johnbailey
Date: 2010-03-01 10:25:47 -0500 (Mon, 01 Mar 2010)
New Revision: 101660

Added:
   projects/vfs/trunk/src/main/java/org/jboss/vfs/util/AbstractPatternVirtualFileFilter.java
   projects/vfs/trunk/src/main/java/org/jboss/vfs/util/FileNameVirtualFileFilter.java
   projects/vfs/trunk/src/main/java/org/jboss/vfs/util/IncludeFileNameVirtualFileFilter.java
   projects/vfs/trunk/src/main/java/org/jboss/vfs/util/IncludePatternVirtualFileFilter.java
Log:
[JBVFS-140] - Recovered IncludeExcludeVisitorAttributes FileNameVirtualFileFilter

Copied: projects/vfs/trunk/src/main/java/org/jboss/vfs/util/AbstractPatternVirtualFileFilter.java (from rev 100703, projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/vfs/helpers/AbstractPatternVirtualFileFilter.java)
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/vfs/util/AbstractPatternVirtualFileFilter.java	                        (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/vfs/util/AbstractPatternVirtualFileFilter.java	2010-03-01 15:25:47 UTC (rev 101660)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.vfs.util;
+
+import java.util.regex.Pattern;
+
+import org.jboss.vfs.VirtualFileFilter;
+import org.jboss.vfs.VirtualFile;
+
+/**
+ * Regexp patter filter.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class AbstractPatternVirtualFileFilter implements VirtualFileFilter
+{
+   private Pattern pattern;
+
+   public AbstractPatternVirtualFileFilter(String regexp)
+   {
+      if (regexp == null)
+         throw new IllegalArgumentException("Null regexp");
+
+      pattern = Pattern.compile(regexp);
+   }
+
+   /**
+    * Extract match string from file.
+    *
+    * @param file the file
+    * @return extracted match string
+    */
+   protected abstract String getMatchString(VirtualFile file);
+
+   /**
+    * Should we match the pattern.
+    *
+    * @return the match flag
+    */
+   protected abstract boolean doMatch();
+
+   public boolean accepts(VirtualFile file)
+   {
+      String string = getMatchString(file);
+      return pattern.matcher(string).matches() == doMatch();
+   }
+}

Copied: projects/vfs/trunk/src/main/java/org/jboss/vfs/util/FileNameVirtualFileFilter.java (from rev 100703, projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/vfs/helpers/FileNameVirtualFileFilter.java)
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/vfs/util/FileNameVirtualFileFilter.java	                        (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/vfs/util/FileNameVirtualFileFilter.java	2010-03-01 15:25:47 UTC (rev 101660)
@@ -0,0 +1,100 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.vfs.util;
+
+import java.util.Set;
+import java.util.Map;
+
+import org.jboss.vfs.VirtualFileFilter;
+import org.jboss.vfs.VirtualFile;
+import org.jboss.logging.Logger;
+
+/**
+ * Exclude virtual file by file name and path.
+ *
+ * @author ales.justin at jboss.org
+ */
+public class FileNameVirtualFileFilter implements VirtualFileFilter
+{
+   protected Logger log = Logger.getLogger(getClass());
+   private Map<String, Set<String>> excludes;
+
+   public FileNameVirtualFileFilter(Map<String, Set<String>> excludes)
+   {
+      if (excludes == null || excludes.isEmpty())
+         throw new IllegalArgumentException("Null or empty excludes.");
+
+      this.excludes = excludes;
+   }
+
+   /**
+    * Do we accept file.
+    *
+    * If pathName contains any of the keys,
+    *   * if the value is null - then do exclude
+    *   * if value is not null - only exclude if it value contains simple name
+    *
+    * @param file the virtual file
+    * @return false if file is excluded by excludes map, true other wise
+    */
+   public boolean accepts(VirtualFile file)
+   {
+      String pathName = getPathName(file);
+      for (Map.Entry<String, Set<String>> entry : excludes.entrySet())
+      {
+         String key = entry.getKey();
+         if (pathName.contains(key))
+         {
+            String simpleName = file.getName();
+            Set<String> value = entry.getValue();
+            if (value == null || value.contains(simpleName))
+            {
+               if (log.isTraceEnabled())
+                  log.trace("Excluding " + pathName);
+
+               return false;
+            }
+         }
+      }
+      return true;
+   }
+
+   /**
+    * Get the path name for the VirtualFile.
+    *
+    * @param file the virtual file
+    * @return the path name
+    */
+   protected String getPathName(VirtualFile file)
+   {
+      try
+      {
+         // prefer the URI, as the pathName might
+         // return an empty string for temp virtual files
+         return file.toURI().toString();
+      }
+      catch(Exception e)
+      {
+         return file.getPathName();
+      }
+   }
+}
\ No newline at end of file

Copied: projects/vfs/trunk/src/main/java/org/jboss/vfs/util/IncludeFileNameVirtualFileFilter.java (from rev 100703, projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/vfs/helpers/IncludeFileNameVirtualFileFilter.java)
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/vfs/util/IncludeFileNameVirtualFileFilter.java	                        (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/vfs/util/IncludeFileNameVirtualFileFilter.java	2010-03-01 15:25:47 UTC (rev 101660)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.vfs.util;
+
+import org.jboss.vfs.VirtualFile;
+
+/**
+ * Include file name filter.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class IncludeFileNameVirtualFileFilter extends IncludePatternVirtualFileFilter
+{
+   public IncludeFileNameVirtualFileFilter(String regexp)
+   {
+      super(regexp);
+   }
+
+   protected String getMatchString(VirtualFile file)
+   {
+      return file.getName();
+   }
+}
\ No newline at end of file

Copied: projects/vfs/trunk/src/main/java/org/jboss/vfs/util/IncludePatternVirtualFileFilter.java (from rev 100703, projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/vfs/helpers/IncludePatternVirtualFileFilter.java)
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/vfs/util/IncludePatternVirtualFileFilter.java	                        (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/vfs/util/IncludePatternVirtualFileFilter.java	2010-03-01 15:25:47 UTC (rev 101660)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.vfs.util;
+
+/**
+ * Include pattern filter.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class IncludePatternVirtualFileFilter extends AbstractPatternVirtualFileFilter
+{
+   public IncludePatternVirtualFileFilter(String regexp)
+   {
+      super(regexp);
+   }
+
+   protected boolean doMatch()
+   {
+      return true;
+   }
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list