diff options
author | David A. Madore <david+git@madore.org> | 2011-08-31 22:26:55 +0200 |
---|---|---|
committer | David A. Madore <david+git@madore.org> | 2011-08-31 22:26:55 +0200 |
commit | 057a46982292c765e664f886097fdaf33ed22a62 (patch) | |
tree | f9ba446ae36f4e13f4b579b293ace2004a0dbf29 /org/madore/damlengine/DamlEngine.java | |
parent | 3d44424a1738ce3f70c82780f4441e077c1194a3 (diff) | |
download | damlengine-057a46982292c765e664f886097fdaf33ed22a62.tar.gz damlengine-057a46982292c765e664f886097fdaf33ed22a62.tar.bz2 damlengine-057a46982292c765e664f886097fdaf33ed22a62.zip |
Wrap it all in a single command handler.
Diffstat (limited to 'org/madore/damlengine/DamlEngine.java')
-rw-r--r-- | org/madore/damlengine/DamlEngine.java | 70 |
1 files changed, 64 insertions, 6 deletions
diff --git a/org/madore/damlengine/DamlEngine.java b/org/madore/damlengine/DamlEngine.java index e54ee86..874a220 100644 --- a/org/madore/damlengine/DamlEngine.java +++ b/org/madore/damlengine/DamlEngine.java @@ -1,9 +1,14 @@ package org.madore.damlengine; +import java.util.regex.Pattern; +import java.util.regex.Matcher; import java.io.InputStream; import java.io.FileInputStream; +import java.io.InputStreamReader; import java.io.OutputStream; +import java.io.FileOutputStream; import java.io.OutputStreamWriter; +import java.io.BufferedReader; import javax.xml.XMLConstants; import javax.xml.namespace.NamespaceContext; import javax.xml.parsers.DocumentBuilderFactory; @@ -117,12 +122,65 @@ public final class DamlEngine { public static void main(String[] args) throws Exception { - if ( args.length == 0 ) { - System.err.println("expecting filename as argument"); - } - - for (String fname : args) { - fullProcess (new FileInputStream(fname), System.out); + BufferedReader buf = new BufferedReader(new InputStreamReader(System.in, "UTF-8")); + String line; + Matcher matcher; + + while ( ( line = buf.readLine() ) != null ) { + if ( Pattern.matches("^\\s+$", line) ) + continue; + else if ( (matcher=Pattern.compile("process\\s+(\\S+)(?:\\s+\\>\\s*(\\S+))?\\s*").matcher(line)).matches() ) { + String inf = matcher.group(1); + String outf = matcher.group(2); + InputStream in = new FileInputStream(inf); + OutputStream out = (outf != null) + ? new FileOutputStream(outf) + : System.out; + fullProcess(in, out); + } 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); + String outf = matcher.group(3); + OutputStream out = (outf != null) + ? new FileOutputStream(outf) + : System.out; + WeblogSelect.fullProcess(new Context.WeblogMonthSelectionContext(year,month), + out); + } 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); + OutputStream out = (outf != null) + ? new FileOutputStream(outf) + : System.out; + WeblogSelect.fullProcess(new Context.WeblogCategorySelectionContext(code), + out); + } 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); + OutputStream out = (outf != null) + ? new FileOutputStream(outf) + : System.out; + WeblogSelect.fullProcess(new Context.WeblogRecentSelectionContext(count), + out); + } else if ( (matcher=Pattern.compile("process-weblog-index(?:\\s+\\>\\s*(\\S+))?\\s*").matcher(line)).matches() ) { + String outf = matcher.group(1); + OutputStream out = (outf != null) + ? new FileOutputStream(outf) + : System.out; + WeblogIndexSelect.fullProcess(out); + } 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); + } 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 { + throw new IllegalArgumentException("couldn't understand command"); + } } } |