List<JsonDirIndex> subDirs = new ArrayList<JsonDirIndex>();
File currDir = new File(cfg.imageRootPath + currPath);
if (currDir.isDirectory()) {
File[] subDirFiles = currDir.listFiles(new DirFilter());
Arrays.sort(subDirFiles);
JsonDirIndex dirData;
String subDirPath;
Hashtable<String, JsonDirIndex> dirMap = new Hashtable<String, JsonDirIndex>();
// Create the json list of subdirectories
for (File subDir: subDirFiles) {
dirData = new JsonDirIndex();
dirData.setTitle(subDir.getName());
subDirPath = (currPath.endsWith(Configuration.sep)? currPath: currPath + Configuration.sep) + subDir.getName();
dirData.setKey(subDirPath);
// compute image number
File[] images = subDir.listFiles(new FilesFilter(cfg.imgExtensions));
dirData.setImageNbr(images.length);
dirMap.put(subDirPath, dirData);
// default value
dirData.setExtraClasses(JsonDirIndex.NOT_INDEXED_CLASS);
subDirs.add(dirData);
}
// Check whether sub-directories are already indexed in database
for (Directory dir: indexedDirectories) {
dirData = dirMap.get(dir.getPath());
if ((dirData != null) && (dir.isIndexingAllowedBoolean())) {
dirData.setExtraClasses(JsonDirIndex.INDEXED_CLASS);
}
}
}
return subDirs;