*) added method to only get file names in directory listing which match a filter

*) only files which end with .black will be listed as blacklists
*) added a little bit of Javadoc

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5366 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
low012 16 years ago
parent 577b53aee6
commit e423fa9846

@ -69,6 +69,8 @@ public class BlacklistCleaner_p {
private static final int ERR_HOST_WRONG_CHARS = 4;
private static final int ERR_DOUBLE_OCCURANCE = 5;
private final static String BLACKLIST_FILENAME_FILTER = "^.*\\.black$";
public static final Class<?>[] supportedBLEngines = {
indexDefaultReferenceBlacklist.class
};
@ -87,7 +89,7 @@ public class BlacklistCleaner_p {
if (post == null) {
prop.put("results", "0");
putBlacklists(prop, listManager.getDirListing(listManager.listsPath), blacklistToUse);
putBlacklists(prop, listManager.getDirListing(listManager.listsPath, BLACKLIST_FILENAME_FILTER), blacklistToUse);
return prop;
}
@ -97,7 +99,7 @@ public class BlacklistCleaner_p {
prop.put("results", "2");
}
putBlacklists(prop, listManager.getDirListing(listManager.listsPath), blacklistToUse);
putBlacklists(prop, listManager.getDirListing(listManager.listsPath, BLACKLIST_FILENAME_FILTER), blacklistToUse);
if (blacklistToUse != null) {
prop.put("results", "1");

@ -54,6 +54,8 @@ public class Blacklist_p {
private final static String BLACKLIST = "blackLists_";
private final static String BLACKLIST_MOVE = "blackListsMove_";
private final static String BLACKLIST_SHARED = "BlackLists.Shared";
private final static String BLACKLIST_FILENAME_FILTER = "^.*\\.black$";
public static serverObjects respond(final httpRequestHeader header, final serverObjects post, final serverSwitch<?> env) {
@ -66,7 +68,7 @@ public class Blacklist_p {
final String[] supportedBlacklistTypes = supportedBlacklistTypesStr.split(",");
// loading all blacklist files located in the directory
List<String> dirlist = listManager.getDirListing(listManager.listsPath);
List<String> dirlist = listManager.getDirListing(listManager.listsPath, BLACKLIST_FILENAME_FILTER);
String blacklistToUse = null;
final serverObjects prop = new serverObjects();
@ -148,7 +150,7 @@ public class Blacklist_p {
}
// reload Blacklists
dirlist = listManager.getDirListing(listManager.listsPath);
dirlist = listManager.getDirListing(listManager.listsPath, BLACKLIST_FILENAME_FILTER);
}
} else if (post.containsKey("deleteList")) {
@ -176,7 +178,7 @@ public class Blacklist_p {
blacklistToUse = null;
// reload Blacklists
dirlist = listManager.getDirListing(listManager.listsPath);
dirlist = listManager.getDirListing(listManager.listsPath, BLACKLIST_FILENAME_FILTER);
} else if (post.containsKey("activateList")) {

@ -48,6 +48,7 @@ import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.server.serverCore;
// The Naming of the functions is a bit strange...
import java.io.FileFilter;
public class listManager {
public static plasmaSwitchboard switchboard = null;
@ -220,12 +221,29 @@ public class listManager {
return new String(temp);
}
// get a Directory Listing as a String Array
/**
* Read content of a directory into a String array of file names.
* @param dirname The directory to get the file listing from. If it doesn't exist yet,
* it will be created.
* @return array of file names
*/
public static List<String> getDirListing(final String dirname){
final File dir = new File(dirname);
return getDirListing(dir);
return getDirListing(dirname, null);
}
/**
* Read content of a directory into a String array of file names.
* @param dirname The directory to get the file listing from. If it doesn't exist yet,
* it will be created.
* @param filter String which contains a regular expression which has to be matched by
* file names in order to appear in returned array. All file names will be returned if
* filter is null.
* @return array of file names
*/
public static List<String> getDirListing(final String dirname, final String filter) {
return getDirListing(new File(dirname), filter);
}
/**
* Read content of a directory into a String array of file names.
*
@ -234,16 +252,30 @@ public class listManager {
* @return array of file names
*/
public static List<String> getDirListing(final File dir){
return getDirListing(dir, null);
}
/**
* Read content of a directory into a String array of file names.
* @param dir The directory to get the file listing from. If it doesn't exist yet,
* it will be created.
* @param filter String which contains a regular expression which has to be matched by
* file names in order to appear in returned array. All file names will be returned if
* filter is null.
* @return array of file names
*/
public static List<String> getDirListing(final File dir, final String filter){
List<String> ret = new LinkedList<String>();
File[] fileList;
if (dir != null ) {
if (!dir.exists()) {
dir.mkdir();
}
fileList = dir.listFiles();
for (int i=0; i<= fileList.length-1; i++) {
ret.add(fileList[i].getName());
if (filter == null || fileList[i].getName().matches(filter)) {
ret.add(fileList[i].getName());
}
}
return ret;
}

Loading…
Cancel
Save