0
我有一個應用程序,根據一些規則(存在一些關鍵字或正則表達式)過濾消息。這些規則將被存儲在.properties文件中(因爲它們必須是持久的)。我已經想出瞭如何從這個文件中讀取數據。這裏是代碼的一部分:如何使用apache.commons.configuration更改.properties文件
public class Config {
private static final Config ourInstance = new Config();
private static final CompositeConfiguration prop = new CompositeConfiguration();
public static Config getInstance() {
return ourInstance;
}
public Config(){
}
public synchronized void load() {
try {
prop.addConfiguration(new SystemConfiguration());
System.out.println("Loading /rules.properties");
final PropertiesConfiguration p = new PropertiesConfiguration();
p.setPath("/home/mikhail/bzrrep/DLP/DLPServer/src/main/resources/rules.properties");
p.load();
prop.addConfiguration(p);
} catch (ConfigurationException e) {
e.printStackTrace();
}
final int processors = prop.getInt("server.processors", 1);
// If you don't see this line - likely config name is wrong
System.out.println("Using processors:" + processors);
}
public void setKeyword(String customerId, String keyword){
}
public void setRegexp(String customerId, String regexp)
{}
}
正如你所看到的,我將爲某些屬性添加值。這裏的.properties文件本身:
users = admin, root, guest
users.admin.keywords = admin
users.admin.regexps = test-5, test-7
users.root.keywords = root
users.root.regexps = *
users.guest.keywords = guest
users.guest.regexps =
我有一個用戶界面,以關鍵字和正則表達式添加到該配置。那麼,如何實現setKeyword和setRegexp方法?