X-Git-Url: http://sraa.de/git/?a=blobdiff_plain;f=dol%2Ftest%2Fsrc%2Ftest%2Ftest%2FTreeValidator.java;fp=dol%2Ftest%2Fsrc%2Ftest%2Ftest%2FTreeValidator.java;h=4deede8f443f0242c56f289c855dccaff8425e5e;hb=8c411cf24ed0eb889191aaeafd8fa1e69081df42;hp=0000000000000000000000000000000000000000;hpb=dea7a4fb1ed110d3ce6e6d9255103d724bd66c0e;p=jump.git diff --git a/dol/test/src/test/test/TreeValidator.java b/dol/test/src/test/test/TreeValidator.java new file mode 100644 index 0000000..4deede8 --- /dev/null +++ b/dol/test/src/test/test/TreeValidator.java @@ -0,0 +1,78 @@ +package test.test; + +import java.io.File; + +import test.util.XMLValidator; + +/** + * Class to check well-formedness and validity of XML documents. + */ +public class TreeValidator { + + /** + * Check the well-formedness and validity of XML files. + * + * @param args Specifies the XML file to be checked or the + * directory (including subdirectories) where XML + * and XSD files are checked. Multiple files or + * directories can be specified. + */ + public static void main(String args[]) throws Exception { + System.out.println("Run TreeValidator."); + if (args.length == 0) + browseDirectoryTree("./"); + else { + for (int k = 0; k < args.length; k++) + browseDirectoryTree(args[k]); + } + System.out.println("Finished."); + } + + /** + * Method which defines what is done for each file found in the + * directory tree: When the file is an XML or XSD file, it is + * validated using + * {@link test.util.XMLValidator#isValid(java.lang.String)}. + * + * @param filename file to process + */ + protected static void processFile(String filename) throws Exception { + if (filename.endsWith("xml") || filename.endsWith("xsd")) { + System.out.println("Checking " + filename + "..."); + if (!XMLValidator.isValid(filename)) + throw new Exception("File not valid."); + } + } + + /** + * Iterate through the given directory tree. For each file found in + * the file, the method {@link #processFile(java.lang.String)} is + * called. + * + * @param path the path of the directory to be browsed + */ + protected static void browseDirectoryTree(String path) throws Exception { + File file = new File(path); + + if (!file.exists()) return; + if (!file.isDirectory()) return; + + String filepath = file.getPath(); + String filename = file.getName(); + + //loop through files in directory + String[] files = file.list(); + + for (int k = 0; k < files.length; k++) { + File newfile = new File(file.getPath(), files[k]); + if (newfile.isFile()) + processFile(path + System.getProperty("file.separator") + + files[k]); + else if (newfile.isDirectory()) { + browseDirectoryTree(file.getPath() + + System.getProperty("file.separator") + + files[k]); + } + } + } +}