01: /*
02:
03: This software is OSI Certified Open Source Software.
04: OSI Certified is a certification mark of the Open Source Initiative.
05:
06: The license (Mozilla version 1.0) can be read at the MMBase site.
07: See http://www.MMBase.org/license
08:
09: */
10:
11: package org.mmbase.util;
12:
13: import java.io.File;
14: import java.io.FilenameFilter;
15:
16: /**
17: * Support utility for MMObjectBuilder.getSMartPath
18: * This filter filters files with the specified
19: * number in its name.
20: *
21: * @todo move this code to a SmartPathFunction class?
22: * @author Wilbert Hengst
23: * @version $Id: SPartFileFilter.java,v 1.6 2004/09/30 17:19:49 pierre Exp $
24: */
25: public class SPartFileFilter implements FilenameFilter {
26:
27: /**
28: * The number to check on.
29: * Note: Should be a number, but this is not enforced.
30: */
31: private String nodeNumber;
32:
33: /**
34: * Creates the file filter.
35: * @param nodeNumber the number to filter on.
36: */
37: public SPartFileFilter(String nodeNumber) {
38: this .nodeNumber = nodeNumber;
39: }
40:
41: /**
42: * Checks whether a file has the node number in its file path.
43: * This checks on the exact number - so if the number to search on is '100',
44: * If the path contains a number such as '1001' or '1100' it will return <code>false</code>.
45: * @param dir The directory as a File (unused in this filter)
46: * @param name The file name to check
47: * @return <code>true</code> if the number is in the path, <code>false</code> otherwise.
48: */
49: public boolean accept(File dir, String name) {
50: int pos = name.indexOf(nodeNumber);
51: if (pos < 0)
52: return false;
53: // Check char before found number, if digit return false
54: int c;
55: if (pos > 0) {
56: c = name.charAt(pos - 1);
57: if ((c >= '0') && (c <= '9'))
58: return false;
59: }
60: // Check char after found number, if digit return false
61: pos += nodeNumber.length();
62: if (pos < name.length()) {
63: c = name.charAt(pos);
64: if ((c >= '0') && (c <= '9'))
65: return false;
66: }
67: return true;
68: }
69: }
|