01: /****************************************************************
02: * Licensed to the Apache Software Foundation (ASF) under one *
03: * or more contributor license agreements. See the NOTICE file *
04: * distributed with this work for additional information *
05: * regarding copyright ownership. The ASF licenses this file *
06: * to you under the Apache License, Version 2.0 (the *
07: * "License"); you may not use this file except in compliance *
08: * with the License. You may obtain a copy of the License at *
09: * *
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: ****************************************************************/package org.apache.james.mailrepository.filepair;
19:
20: import java.io.File;
21: import java.io.FilenameFilter;
22:
23: /**
24: * This filters files based on the extension and is tailored to provide
25: * backwards compatibility of the numbered repositories that Avalon does.
26: *
27: */
28: public class NumberedRepositoryFileFilter implements FilenameFilter {
29: private String postfix;
30: private String prefix;
31:
32: public NumberedRepositoryFileFilter(final String extension) {
33: postfix = extension;
34: prefix = "." + RepositoryManager.getName();
35: }
36:
37: public boolean accept(final File file, final String name) {
38: //System.out.println("check: " + name);
39: //System.out.println("post: " + postfix);
40: if (!name.endsWith(postfix)) {
41: return false;
42: }
43: //Look for a couple of digits next
44: int pos = name.length() - postfix.length();
45: //We have to find at least one digit... if not then this isn't what we want
46: if (!Character.isDigit(name.charAt(pos - 1))) {
47: return false;
48: }
49: pos--;
50: while (pos >= 1 && Character.isDigit(name.charAt(pos - 1))) {
51: //System.out.println("back one");
52: pos--;
53: }
54: //System.out.println("sub: " + name.substring(0, pos));
55: //Now want to check that we match the rest
56: return name.substring(0, pos).endsWith(prefix);
57: }
58: }
|