| 1 |
package com.thaiopensource.xml.dtd.app; |
| 2 |
|
| 3 |
import com.thaiopensource.util.Localizer; |
| 4 |
import com.thaiopensource.util.UriOrFile; |
| 5 |
import com.thaiopensource.util.Version; |
| 6 |
import com.thaiopensource.xml.dtd.om.Dtd; |
| 7 |
import com.thaiopensource.xml.dtd.parse.DtdParserImpl; |
| 8 |
import com.thaiopensource.xml.out.XmlWriter; |
| 9 |
import com.thaiopensource.xml.em.UriEntityManager; |
| 10 |
|
| 11 |
import java.io.IOException; |
| 12 |
|
| 13 |
public class Driver { |
| 14 |
private static final int FAILURE_EXIT_CODE = 1; |
| 15 |
private static final Localizer localizer = new Localizer(Driver.class); |
| 16 |
|
| 17 |
public static void main(String[] args) { |
| 18 |
try { |
| 19 |
if (doMain(args)) |
| 20 |
return; |
| 21 |
} |
| 22 |
catch (IOException e) { |
| 23 |
error(e.getMessage()); |
| 24 |
} |
| 25 |
System.exit(FAILURE_EXIT_CODE); |
| 26 |
} |
| 27 |
|
| 28 |
public static boolean doMain(String args[]) throws IOException { |
| 29 |
if (args.length == 0) { |
| 30 |
error(localizer.message("MISSING_ARGUMENT")); |
| 31 |
usage(); |
| 32 |
return false; |
| 33 |
} |
| 34 |
if (args.length > 1) { |
| 35 |
error(localizer.message("TOO_MANY_ARGUMENTS")); |
| 36 |
usage(); |
| 37 |
return false; |
| 38 |
} |
| 39 |
String uri = UriOrFile.toUri(args[0]); |
| 40 |
Dtd dtd = new DtdParserImpl().parse(uri, new UriEntityManager()); |
| 41 |
XmlWriter w = new XmlOutputStreamWriter(System.out, dtd.getEncoding()); |
| 42 |
new SchemaWriter(w).writeDtd(dtd); |
| 43 |
w.close(); |
| 44 |
return true; |
| 45 |
} |
| 46 |
|
| 47 |
private static void usage() { |
| 48 |
print(localizer.message("USAGE", Version.getVersion(Driver.class))); |
| 49 |
} |
| 50 |
|
| 51 |
private static void error(String str) { |
| 52 |
print(localizer.message("ERROR", str)); |
| 53 |
} |
| 54 |
|
| 55 |
private static void warning(String str) { |
| 56 |
print(localizer.message("WARNING", str)); |
| 57 |
} |
| 58 |
|
| 59 |
private static void print(String str) { |
| 60 |
System.err.println(str); |
| 61 |
} |
| 62 |
|
| 63 |
} |