001package apps.jmrit;
002
003import java.awt.Component;
004import java.io.File;
005
006/**
007 * Make sure an XML file is readable, and validates OK against its schema and
008 * DTD.
009 * <p>
010 * Intended to be run from the command line with e.g. ./runtest.csh
011 * jmri/jmrit/XmlFileValidateRunner foo.xml in which case if there's a filename
012 * argument, it checks that directly, otherwise it pops a file selection dialog.
013 * (The dialog form has to be manually canceled when done)
014 *
015 * @author Bob Jacobsen Copyright (C) 2005, 2007
016 * @see jmri.jmrit.XmlFile
017 * @see jmri.jmrit.XmlFileCheckAction
018 */
019public class XmlFileValidateRunner extends jmri.jmrit.XmlFileValidateAction {
020
021    private XmlFileValidateRunner(String s, Component who) {
022        super(s, who);
023    }
024
025    // package protected for testing
026    XmlFileValidateRunner() {
027        super();
028    }
029
030    // Main entry point fires the action
031    static public void main(String[] args) {
032        // if a 1st argument provided, act
033        if (args.length == 0) {
034            new XmlFileValidateRunner("", (Component) null).actionPerformed(null);
035        } else {
036            apps.util.Log4JUtil.initLogging("default_lcf.xml");
037            new XmlFileValidateRunner("", (Component) null) {
038                @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value="SLF4J_SIGN_ONLY_FORMAT",
039                                                                    justification="I18N of log message")
040                @Override
041                protected void showFailResults(Component who, String fileName, String text) {
042                    log.error("{}: {}", Bundle.getMessage("ValidationErrorInFile", fileName), text);
043                }
044
045                @Override
046                protected void showOkResults(Component who, String text) {
047                    // silent if OK
048                }
049            }.processFile(new File(args[0]));
050        }
051    }
052
053    private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(XmlFileValidateRunner.class);
054
055}