26 package org.nexusformat.nxvalidate;
29 import java.util.ArrayList;
30 import java.util.logging.Level;
31 import java.util.logging.Logger;
35 static final String VERSION =
"0.1 alpha";
36 private ArrayList<File> files;
37 private File schematronFile;
38 private boolean keepTemp;
39 private boolean convertNxs;
41 private ArrayList<Report> reports;
42 private File reduced = null;
45 files =
new ArrayList<File>();
46 this.schematronFile = null;
47 this.keepTemp =
false;
48 this.convertNxs =
true;
50 this.reports =
new ArrayList<Report>();
70 return schematronFile;
74 this.schematronFile = schematronFile;
82 this.keepTemp = keepTemp;
90 this.convertNxs = convertNxs;
98 this.verbose = verbose;
110 return this.reduced = reduced;
113 void parseArgs(
final String[] args) {
115 for (
int i = 0; i < args.length; i++) {
116 if (args[i].equals(
"-h") || args[i].equals(
"--help")) {
120 if (args[i].equals(
"--version")) {
127 for (
int i = 0; i < args.length; i++) {
128 if (args[i].equals(
"-v") || args[i].equals(
"--verbose")) {
130 }
else if (args[i].equals(
"-k") || args[i].equals(
"--keep")) {
131 this.keepTemp =
true;
132 }
else if (args[i].equals(
"-d") || args[i].equals(
"--dfn")) {
133 schematronFile =
new File(args[i + 1]);
135 }
else if (args[i].equals(
"--noconvert")) {
136 this.convertNxs =
false;
138 files.add(
new File(args[i]));
144 if (this.files.size() <= 0) {
145 System.out.println(
"Must specify at least one nexus file");
149 if (!schematronFile.exists()) {
150 System.out.println(
"Must specify a schematron file");
159 if (this.verbose > 0) {
160 System.out.println(
"Running NXvalidate (version:" + VERSION +
")");
162 int size = this.files.size();
163 for (
int i = 0; i < size; i++) {
164 this.process(this.files.get(i));
168 private static File toAbsFile(
final String filename) {
169 File file =
new File(filename);
173 private File process(
final File file)
throws Error {
179 NXconvert converter =
new NXconvert(file, keepTemp,null);
180 reduced = converter.convert();
181 }
catch (Exception e) {
182 Logger.getLogger(NXvalidate.class.getName()).log(Level.SEVERE,
183 "While converting \"" + file +
184 "\" to reduced xml format",e);
185 throw new Error(
"While converting \"" + file +
186 "\" to reduced xml format", e);
190 if (reduced != null && schematronFile !=null) {
193 NXschematron schematron =
new NXschematron(file,reduced,
194 schematronFile, keepTemp);
197 result = schematron.validate();
198 }
catch (Exception e) {
199 Logger.getLogger(NXvalidate.class.getName()).log(Level.SEVERE,
200 "While creating validation report",e);
201 throw new Error(
"While creating validation report", e);
205 Report report = null;
207 report =
new Report(reduced, result);
208 }
catch (Exception e) {
209 Logger.getLogger(NXvalidate.class.getName()).log(Level.SEVERE,
210 "While generating the report object",e);
211 throw new Error(
"While generating the report object", e);
218 int numErrors = report.numErrors();
220 report.printReport();
227 private void printVersion() {
228 System.out.println(
"NXvalidate version " + VERSION);
231 private void printHelp(
final int level) {
232 System.out.println(
"usage: nxvalidate [options] <nxsfile>");
237 System.out.println();
238 System.out.println(
"Validate nexus files against the nexus definitions");
244 System.out.println();
245 System.out.println(
"-h, --help print this help information");
246 System.out.println(
"-v, --verbose increase verbose printing");
247 System.out.println(
"-d, --dfn specify the definition file");
248 System.out.println(
"-k, --keep keep temporary files");
249 System.out.println(
"--noconvert do not reduce the nexus file");
252 public static void main(String[] args) {
254 validate.parseArgs(args);