public static void main(String[] argv) throws Exception {
if (argv.length == 0) {
printUsage();
System.exit(1);
}
XMLParserConfiguration parser = new HTMLConfiguration();
parser.setFeature(NOTIFY_CHAR_REFS, true);
parser.setFeature(NOTIFY_HTML_BUILTIN_REFS, true);
String encoding = "Windows-1252";
boolean identity = false;
boolean purify = false;
for (int i = 0; i < argv.length; i++) {
String arg = argv[i];
if (arg.equals("-e")) {
encoding = argv[++i];
continue;
}
if (arg.equals("-i")) {
identity = true;
continue;
}
if (arg.equals("-p")) {
purify = true;
continue;
}
if (arg.equals("-h")) {
printUsage();
System.exit(1);
}
java.util.Vector filtersVector = new java.util.Vector(2);
if (identity) {
filtersVector.addElement(new Identity());
}
else if (purify) {
filtersVector.addElement(new Purifier());
}
filtersVector.addElement(new Writer(System.out, encoding));
XMLDocumentFilter[] filters =
new XMLDocumentFilter[filtersVector.size()];
filtersVector.copyInto(filters);
parser.setProperty(FILTERS, filters);
parser.parse(new XMLInputSource(null, arg, null));
}
} // main(String[])