1 /*****************************************************************
2 * Licensed to the Apache Software Foundation (ASF) under one *
3 * or more contributor license agreements. See the NOTICE file *
4 * distributed with this work for additional information *
5 * regarding copyright ownership. The ASF licenses this file *
6 * to you under the Apache License, Version 2.0 (the *
7 * "License"); you may not use this file except in compliance *
8 * with the License. You may obtain a copy of the License at *
9 * *
10 * http://www.apache.org/licenses/LICENSE-2.0 *
11 * *
12 * Unless required by applicable law or agreed to in writing, *
13 * software distributed under the License is distributed on an *
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15 * KIND, either express or implied. See the License for the *
16 * specific language governing permissions and limitations *
17 * under the License. *
18 ****************************************************************/
19
20 package org.apache.james.mailrepository.filepair;
21
22 import java.io.File;
23 import java.io.FilenameFilter;
24
25 /***
26 * This filters files based on the extension and is tailored to provide
27 * backwards compatibility of the numbered repositories that Avalon does.
28 *
29 */
30 public class NumberedRepositoryFileFilter implements FilenameFilter {
31 private String postfix;
32 private String prefix;
33
34 public NumberedRepositoryFileFilter(final String extension) {
35 postfix = extension;
36 prefix = "." + RepositoryManager.getName();
37 }
38
39 public boolean accept(final File file, final String name) {
40
41
42 if (!name.endsWith(postfix)) {
43 return false;
44 }
45
46 int pos = name.length() - postfix.length();
47
48 if (!Character.isDigit(name.charAt(pos - 1))) {
49 return false;
50 }
51 pos--;
52 while (pos >= 1 && Character.isDigit(name.charAt(pos - 1))) {
53
54 pos--;
55 }
56
57
58 return name.substring(0, pos).endsWith(prefix);
59 }
60 }
61
62