From 97aabc8ab1def8bbc44166c50e045a488593bdaf Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Fri, 2 Sep 2011 18:10:30 +0200 Subject: Add an "echo" command for synchronization. Close output files. --- org/madore/damlengine/DamlEngine.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'org/madore') diff --git a/org/madore/damlengine/DamlEngine.java b/org/madore/damlengine/DamlEngine.java index 8b0b63d..c0010b6 100644 --- a/org/madore/damlengine/DamlEngine.java +++ b/org/madore/damlengine/DamlEngine.java @@ -9,6 +9,7 @@ import java.io.OutputStream; import java.io.FileOutputStream; import java.io.OutputStreamWriter; import java.io.BufferedReader; +import java.io.PrintStream; import javax.xml.XMLConstants; import javax.xml.namespace.NamespaceContext; import javax.xml.parsers.DocumentBuilderFactory; @@ -138,6 +139,8 @@ public final class DamlEngine { ? new FileOutputStream(outf) : System.out; fullProcess(in, out); + if ( out != System.out ) + out.close(); } else if ( (matcher=Pattern.compile("process-weblog-month\\s+(\\d{4})\\-(\\d{2})(?:\\s+\\>\\s*(\\S+))?\\s*").matcher(line)).matches() ) { String year = matcher.group(1); String month = matcher.group(2); @@ -147,6 +150,8 @@ public final class DamlEngine { : System.out; WeblogSelect.fullProcess(new Context.WeblogMonthSelectionContext(year,month), out); + if ( out != System.out ) + out.close(); } else if ( (matcher=Pattern.compile("process-weblog-cat\\s+([a-z0-9\\-]+)(?:\\s+\\>\\s*(\\S+))?\\s*").matcher(line)).matches() ) { String code = matcher.group(1); String outf = matcher.group(2); @@ -155,6 +160,8 @@ public final class DamlEngine { : System.out; WeblogSelect.fullProcess(new Context.WeblogCategorySelectionContext(code), out); + if ( out != System.out ) + out.close(); } else if ( (matcher=Pattern.compile("process-weblog-recent\\s+(\\d+)(?:\\s+\\>\\s*(\\S+))?\\s*").matcher(line)).matches() ) { int count = Integer.parseInt(matcher.group(1)); String outf = matcher.group(2); @@ -169,16 +176,29 @@ public final class DamlEngine { ? new FileOutputStream(outf) : System.out; WeblogIndexSelect.fullProcess(out); + if ( out != System.out ) + out.close(); } else if ( (matcher=Pattern.compile("process-weblog-rss(?:\\s+\\>\\s*(\\S+))?\\s*").matcher(line)).matches() ) { String outf = matcher.group(1); OutputStream out = (outf != null) ? new FileOutputStream(outf) : System.out; WeblogRSS.fullProcess(out); + if ( out != System.out ) + out.close(); } else if ( (matcher=Pattern.compile("populate-weblog\\s+(\\S+)\\s*").matcher(line)).matches() ) { String inf = matcher.group(1); InputStream in = new FileInputStream(inf); WeblogPopulate.populate(in); + } else if ( (matcher=Pattern.compile("echo\\s+(\\S+)(?:\\s+\\>\\s*(\\S+))?\\s*").matcher(line)).matches() ) { + String str = matcher.group(1); + String outf = matcher.group(2); + OutputStream out = (outf != null) + ? new FileOutputStream(outf) + : System.out; + new PrintStream(out, true).println(str); + if ( out != System.out ) + out.close(); } else { throw new IllegalArgumentException("couldn't understand command"); } -- cgit v1.2.3