Skip to content

Commit

Permalink
Cleanup a class
Browse files Browse the repository at this point in the history
  • Loading branch information
joeha480 committed Jun 11, 2019
1 parent e051d1a commit dcc718a
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions src/org/daisy/dotify/cli/Dotify.java
Expand Up @@ -51,15 +51,15 @@ public class Dotify {
extensionBindings.put("txt", SystemKeys.FORMATTED_TEXT_FORMAT.getKey()); extensionBindings.put("txt", SystemKeys.FORMATTED_TEXT_FORMAT.getKey());
} }


private final boolean writeTempFiles; /**
private final boolean keepTempFilesOnSuccess; * Runs Dotify with the supplied parameters.
// hide default constructor to disable instantiation. * @param input the input file
private Dotify(Map<String, String> params) { * @param output the output file
// get parameters * @param locale the language/region context
writeTempFiles = "true".equals(params.get(SystemKeys.WRITE_TEMP_FILES.getKey())); * @param params additional parameters
keepTempFilesOnSuccess = !("false".equals(params.get(SystemKeys.KEEP_TEMP_FILES_ON_SUCCESS.getKey()))); * @throws IOException if there is an i/o error
} * @throws InternalTaskException if there is a problem with running the task system

*/
public static void run(File input, File output, String locale, Map<String, String> params) throws IOException, InternalTaskException { public static void run(File input, File output, String locale, Map<String, String> params) throws IOException, InternalTaskException {
run(input, output, FilterLocale.parse(locale), params); run(input, output, FilterLocale.parse(locale), params);
} }
Expand All @@ -74,8 +74,9 @@ public static void run(File input, File output, String locale, Map<String, Strin
* @throws InternalTaskException if there is a problem with running the task system * @throws InternalTaskException if there is a problem with running the task system
*/ */
public static void run(File inputFile, File output, FilterLocale context, Map<String, String> params) throws IOException, InternalTaskException { public static void run(File inputFile, File output, FilterLocale context, Map<String, String> params) throws IOException, InternalTaskException {
Dotify d = new Dotify(params); boolean writeTempFiles = "true".equals(params.get(SystemKeys.WRITE_TEMP_FILES.getKey()));

boolean keepTempFilesOnSuccess = !("false".equals(params.get(SystemKeys.KEEP_TEMP_FILES_ON_SUCCESS.getKey())));

String cols = params.get("cols"); String cols = params.get("cols");
if (cols==null || "".equals(cols)) { if (cols==null || "".equals(cols)) {
params.remove("cols"); params.remove("cols");
Expand Down Expand Up @@ -155,7 +156,7 @@ public static void run(File inputFile, File output, FilterLocale context, Map<St


// Load setup // Load setup
String setup = map.remove("preset"); String setup = map.remove("preset");
Map<String, Object> rp = d.loadSetup(map, setup); Map<String, Object> rp = loadSetup(map, setup);


boolean shouldPrintOptions = "true".equalsIgnoreCase(map.getOrDefault(SystemKeys.LIST_OPTIONS.getKey(), "false")); boolean shouldPrintOptions = "true".equalsIgnoreCase(map.getOrDefault(SystemKeys.LIST_OPTIONS.getKey(), "false"));
// Run tasks // Run tasks
Expand All @@ -165,8 +166,8 @@ public static void run(File inputFile, File output, FilterLocale context, Map<St
logger.info("About to run with parameters " + rp); logger.info("About to run with parameters " + rp);
CompiledTaskSystem tl = ts.compile(rp); CompiledTaskSystem tl = ts.compile(rp);
TaskRunner.Builder builder = TaskRunner.withName(ts.getName()) TaskRunner.Builder builder = TaskRunner.withName(ts.getName())
.writeTempFiles(d.writeTempFiles) .writeTempFiles(writeTempFiles)
.keepTempFiles(d.keepTempFilesOnSuccess) .keepTempFiles(keepTempFilesOnSuccess)
.tempFileWriter( .tempFileWriter(
new DefaultTempFileWriter.Builder() new DefaultTempFileWriter.Builder()
.prefix("Dotify") .prefix("Dotify")
Expand Down Expand Up @@ -205,7 +206,7 @@ private static boolean supportsOutputFormat(FormatIdentifier outputFormat, TaskS
return specs.listOutputs().stream().filter(v->v.equals(outputFormat)).findAny().isPresent(); return specs.listOutputs().stream().filter(v->v.equals(outputFormat)).findAny().isPresent();
} }


private Map<String, Object> loadSetup(Map<String, String> guiParams, String setup) { private static Map<String, Object> loadSetup(Map<String, String> guiParams, String setup) {
Map<String, Object> ret; Map<String, Object> ret;
if (setup==null) { if (setup==null) {
ret = new HashMap<>(); ret = new HashMap<>();
Expand All @@ -219,7 +220,7 @@ private Map<String, Object> loadSetup(Map<String, String> guiParams, String setu
return ret; return ret;
} }


private Map<String, Object> loadConfiguration(String setup) { private static Map<String, Object> loadConfiguration(String setup) {
try { try {
ConfigurationsCatalog cm = ConfigurationsCatalog.newInstance(); ConfigurationsCatalog cm = ConfigurationsCatalog.newInstance();
return cm.getConfiguration(setup); return cm.getConfiguration(setup);
Expand Down

0 comments on commit dcc718a

Please sign in to comment.