[jboss-cvs] JBossAS SVN: r57647 - projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/vfs/helpers
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Oct 12 23:53:15 EDT 2006
Author: scott.stark at jboss.org
Date: 2006-10-12 23:53:14 -0400 (Thu, 12 Oct 2006)
New Revision: 57647
Modified:
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/vfs/helpers/SuffixMatchFilter.java
Log:
Update to support multiple suffixes.
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/vfs/helpers/SuffixMatchFilter.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/vfs/helpers/SuffixMatchFilter.java 2006-10-13 03:35:55 UTC (rev 57646)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/vfs/helpers/SuffixMatchFilter.java 2006-10-13 03:53:14 UTC (rev 57647)
@@ -1,31 +1,35 @@
/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt 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.
- */
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt 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.virtual.plugins.vfs.helpers;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
import org.jboss.virtual.VirtualFile;
import org.jboss.virtual.VisitorAttributes;
/**
- * Matches a suffix recursively
+ * Matches a file name against a list of suffixes.
*
* @author Scott.Stark at jboss.org
* @author adrian at jboss.org
@@ -33,8 +37,8 @@
*/
public class SuffixMatchFilter extends AbstractVirtualFileFilterWithAttributes
{
- /** The suffix */
- private String suffix;
+ /** The suffixes */
+ private List<String> suffixes;
/**
* Create a new SuffixMatchFilter,
@@ -57,15 +61,46 @@
*/
public SuffixMatchFilter(String suffix, VisitorAttributes attributes)
{
+ this(Collections.EMPTY_LIST, attributes);
+ suffixes.add(suffix);
+ }
+ /**
+ * Create a new SuffixMatchFilter.
+ * @param suffixes - the list of file suffixes to accept.
+ * @throws IllegalArgumentException for a null suffixes
+ */
+ public SuffixMatchFilter(List<String> suffixes)
+ {
+ this(suffixes, null);
+ }
+ /**
+ * Create a new SuffixMatchFilter.
+ * @param suffixes - the list of file suffixes to accept.
+ * @param attributes the attributes, pass null to use {@link VisitorAttributes#RECURSE_LEAVES_ONLY}
+ * @throws IllegalArgumentException for a null suffixes
+ */
+ public SuffixMatchFilter(List<String> suffixes, VisitorAttributes attributes)
+ {
super(attributes == null ? VisitorAttributes.RECURSE_LEAVES_ONLY : attributes);
- if (suffix == null)
- throw new IllegalArgumentException("Null suffix");
- this.suffix = suffix;
+ if (suffixes == null)
+ throw new IllegalArgumentException("Null suffixes");
+ this.suffixes = new ArrayList<String>();
+ this.suffixes.addAll(suffixes);
}
+ /**
+ * Accept any file that ends with one of the filter suffixes. This checks
+ * that the file.getName() endsWith a suffix.
+ * @return true if the file matches a suffix, false otherwise.
+ */
public boolean accepts(VirtualFile file)
{
String name = file.getName();
- return name.endsWith(suffix);
+ for (int i = 0; i < suffixes.size(); ++i)
+ {
+ if (name.endsWith(suffixes.get(0)))
+ return true;
+ }
+ return false;
}
}
More information about the jboss-cvs-commits
mailing list