package journal.reader; import java.io.PrintStream; import java.util.HashMap; import java.util.Map; import journal.exception.UnknownOptionException; /* * Simple helper class to transport all options together in one block */ public class Options { public interface OptionSetter { public void set(String key, String value); } private boolean compressed; private boolean verbose; private boolean caseInsensitive; private boolean unicode; private PrintStream outputStream = System.out; private PrintStream errorStream = System.err; private Map<String, String> opts = new HashMap<String, String>(); private Map<String, OptionSetter> setters = new HashMap<String, OptionSetter>(); private String generateKey(String section, String optionName) { StringBuffer buf = new StringBuffer(section); buf.append('.'); buf.append(optionName); return buf.toString(); } public void setOptionName(String section, String optionName, String defaultValue, OptionSetter callback) { String key = generateKey(section, optionName); opts.put(key, defaultValue); setters.put(key, callback); } public void setOption(String section, String optionName, String value) throws UnknownOptionException { String key = generateKey(section, optionName); if( opts.containsKey(key) ) { opts.put(key, value); setters.get(key).set(key, value); } else { throw new UnknownOptionException(key); } } public String getOption(String section, String optionName) throws UnknownOptionException { String key = generateKey(section, optionName); if( opts.containsKey(key) ) { return opts.get(key); } else { throw new UnknownOptionException(key); } } public Options() { setOptionName("reader", "compressed", Boolean.FALSE.toString(), new OptionSetter() { public void set(String key, String value) { setCompressed(Boolean.parseBoolean(value)); } }); setOptionName("reader", "verbose", Boolean.FALSE.toString(), new OptionSetter() { public void set(String key, String value) { setVerbose(Boolean.parseBoolean(value)); } }); setOptionName("reader", "caseinsensitive", Boolean.FALSE.toString(), new OptionSetter() { public void set(String key, String value) { setCaseInsensitive(Boolean.parseBoolean(value)); } }); } public boolean isCompressed() { return compressed; } public void setCompressed(boolean compressed) { this.compressed = compressed; } public boolean isVerbose() { return verbose; } public void setVerbose(boolean verbose) { this.verbose = verbose; } public boolean isCaseInsensitive() { return caseInsensitive; } public void setCaseInsensitive(boolean caseInsensitive) { this.caseInsensitive = caseInsensitive; } public boolean isUnicode() { return unicode; } public void setUnicode(boolean unicode) { this.unicode = unicode; } public PrintStream getOutputStream() { return outputStream; } public void setOutputStream(PrintStream outputStream) { this.outputStream = outputStream; } public PrintStream getErrorStream() { return errorStream; } public void setErrorStream(PrintStream errorStream) { this.errorStream = errorStream; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#5 | 8027 | Sven Erik Knop |
Moved exceptions to their own package. Enabled new Action FilepathRenamer (not fully tested yet). |
||
#4 | 8023 | Sven Erik Knop |
Complete rewrite of the configuration file, now based on an ini-file format. The ini file has a general [reader] section for settings like verbose, outputFile, case-sensitivity and so on. It also allows to set up a range of Actions and Filters. The section name here is the fully classified class name, followed by settings for the particular actions. An example will make this clearer: ================================================================ [reader] verbose=true [journal.action.UserRenamer] fileName=user.txt patch=True outputFile=user.out [journal.action.ClientRenamer] fileName=client.txt outputFile=client.out patch=true ================================================================ I will provide more example set-ups in the near future. Filters are classes implementing journal.action.Filter (soon to be journal.filter.Filter) which can be chained together and are all executed before the actions. Actions are applied in order that they are given in the config file. |
||
#3 | 8020 | Sven Erik Knop | Replace public Option attributes with setters and getters. | ||
#2 | 8019 | Sven Erik Knop | Safety checks for case-sensitivity and Unicode, now provided in the checkpoint. | ||
#1 | 7527 | Sven Erik Knop |
JournalReader, now in its proper place. Documentation to follow. |