KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > james > mailrepository > filepair > NumberedRepositoryFileFilter


1 /***********************************************************************
2  * Copyright (c) 2000-2004 The Apache Software Foundation. *
3  * All rights reserved. *
4  * ------------------------------------------------------------------- *
5  * Licensed under the Apache License, Version 2.0 (the "License"); you *
6  * may not use this file except in compliance with the License. You *
7  * may obtain a copy of the License at: *
8  * *
9  * http://www.apache.org/licenses/LICENSE-2.0 *
10  * *
11  * Unless required by applicable law or agreed to in writing, software *
12  * distributed under the License is distributed on an "AS IS" BASIS, *
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or *
14  * implied. See the License for the specific language governing *
15  * permissions and limitations under the License. *
16  ***********************************************************************/

17
18 package org.apache.james.mailrepository.filepair;
19
20 import java.io.File JavaDoc;
21 import java.io.FilenameFilter JavaDoc;
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 JavaDoc {
29     private String JavaDoc postfix;
30     private String JavaDoc prefix;
31
32     public NumberedRepositoryFileFilter(final String JavaDoc extension) {
33         postfix = extension;
34         prefix = "." + RepositoryManager.getName();
35     }
36
37     public boolean accept(final File JavaDoc file, final String JavaDoc 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 }
59
60
61
Popular Tags