Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BB938CF3C for ; Wed, 16 May 2012 16:07:26 +0000 (UTC) Received: (qmail 31865 invoked by uid 500); 16 May 2012 16:07:26 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 31775 invoked by uid 500); 16 May 2012 16:07:26 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 31766 invoked by uid 99); 16 May 2012 16:07:26 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 16 May 2012 16:07:26 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 16 May 2012 16:07:23 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id 5A10580EE for ; Wed, 16 May 2012 16:07:02 +0000 (UTC) Date: Wed, 16 May 2012 16:07:02 +0000 (UTC) From: "Gary D. Gregory (JIRA)" To: issues@commons.apache.org Message-ID: <1472494469.4490.1337184422370.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <24137679.1526.1328520839516.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Resolved] (VFS-400) Add a FileSelector based on regular expressions MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/VFS-400?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Gary D. Gregory resolved VFS-400. --------------------------------- Resolution: Fixed Fix Version/s: 2.1 Implemented as org.apache.commons.vfs2.PatternFileSelector. > Add a FileSelector based on regular expressions > ----------------------------------------------- > > Key: VFS-400 > URL: https://issues.apache.org/jira/browse/VFS-400 > Project: Commons VFS > Issue Type: New Feature > Affects Versions: 2.1 > Reporter: Rikard Oxenstrand > Priority: Minor > Fix For: 2.1 > > Attachments: FileRegexSelector.java.patch > > > In the long todo list there was a post about adding a file selector based on regular expressions. I had need for that for a specific project so I built a simple class that seems to work. I'm kind of new to open source contribution though so I'm not sure if i should just commit it to trunk. Here is the code: > {code:title=FileRegexSelector.java|borderStyle=solid} > /* > * Licensed to the Apache Software Foundation (ASF) under one or more > * contributor license agreements. See the NOTICE file distributed with > * this work for additional information regarding copyright ownership. > * The ASF licenses this file to You 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.commons.vfs2; > import java.util.regex.Matcher; > import java.util.regex.Pattern; > /** > * A {@link FileSelector} that selects based on regular expressions matched against base filename. > * > * @since 2.1 > */ > public class FileRegexSelector implements FileSelector > { > /** > * The extensions to select. > */ > private Pattern pattern = null; > /** > * Creates a new selector for the given extensions. > * > * @param extensions > * The extensions to be included by this selector. > */ > public FileRegexSelector(String regex) > { > this.pattern = Pattern.compile(regex); > } > /** > * Determines if a file or folder should be selected. > * @param fileInfo > * The file selection information. > * @return true if the file should be selected, false otherwise. > */ > public boolean includeFile(final FileSelectInfo fileInfo) > { > if (this.pattern == null) > { > return false; > } > Matcher matcher = this.pattern.matcher(fileInfo.getFile().getName().getBaseName()); > return matcher.matches(); > } > /** > * Determines whether a folder should be traversed. > * > * @param fileInfo > * The file selection information. > * @return true if descendents should be traversed, fase otherwise. > */ > public boolean traverseDescendents(final FileSelectInfo fileInfo) > { > return true; > } > } > {code} -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa For more information on JIRA, see: http://www.atlassian.com/software/jira