01: package com.canoo.ant.table;
02:
03: import org.apache.log4j.Logger;
04:
05: import java.io.File;
06: import java.io.FileInputStream;
07: import java.io.FilenameFilter;
08: import java.io.IOException;
09: import java.util.LinkedList;
10: import java.util.List;
11: import java.util.Properties;
12:
13: public class DirectoryPropertyTable extends APropertyTable {
14:
15: private static final Logger LOG = Logger
16: .getLogger(DirectoryPropertyTable.class);
17: private static final String PROP_FILE_SUFFIX = ".properties";
18:
19: public DirectoryPropertyTable() {
20: }
21:
22: protected List read(final String subdir) throws IOException {
23: List result = new LinkedList();
24: File containerDir = new File(getContainer() + File.separator
25: + subdir);
26: if (!containerDir.isDirectory()) {
27: if (subdir.equals(KEY_JOIN)) {
28: LOG
29: .debug("no meta info available in "
30: + getContainer());
31: } else {
32: LOG.error(containerDir.getCanonicalPath()
33: + " is not a directory");
34: }
35: return result;
36: }
37: File[] files = containerDir.listFiles(new FilenameFilter() {
38: public boolean accept(File dir, String name) {
39: return name.endsWith(PROP_FILE_SUFFIX);
40: }
41: });
42: for (int i = 0; i < files.length; i++) {
43: File file = files[i];
44: Properties props = new Properties();
45: props.load(new FileInputStream(file));
46: props.setProperty(subdir + ".file.name", simpleName(file));
47: LOG.debug("loaded " + file.getCanonicalPath()
48: + " with values " + props.toString());
49: result.add(props);
50: }
51: return result;
52: }
53:
54: private String simpleName(File file) {
55: String name = file.getName();
56: return name.substring(0, name.length()
57: - PROP_FILE_SUFFIX.length());
58: }
59: }
|