001package dk.netarkivet.harvester.tools; 002 003import java.io.BufferedReader; 004 005import java.io.File; 006import java.io.FileReader; 007import java.io.IOException; 008 009import org.apache.commons.io.IOUtils; 010import dk.netarkivet.harvester.utils.CrawlertrapsUtils; 011 012/** 013 * Test all strings in the file argument for XML-wellformedness. 014 */ 015public class CheckTrapsInFile { 016 017 public static void main(String[] args) throws IOException { 018 if (args.length != 1) { 019 System.err.println("Missing trapsfile argument"); 020 System.exit(1); 021 } 022 File trapsFile = new File(args[0]); 023 if (!trapsFile.isFile()) { 024 System.err.println("trapsfile argument '" + trapsFile + "' does not exist"); 025 System.exit(1); 026 } 027 028 BufferedReader fr = null; 029 String line=null; 030 String trimmedLine=null; 031 032 try { 033 fr = new BufferedReader(new FileReader(trapsFile)); 034 while ((line = fr.readLine()) != null) { 035 trimmedLine = line.trim(); 036 if (trimmedLine.isEmpty()) { 037 continue; 038 } 039 if (CrawlertrapsUtils.isCrawlertrapsWellformedXML(trimmedLine)) { 040 System.out.println("OK: crawlertrap '" + trimmedLine + "' is wellformed"); 041 } else { 042 System.out.println("BAD: crawlertrap '" + trimmedLine + "' is not wellformed"); 043 } 044 } 045 } finally { 046 IOUtils.closeQuietly(fr); 047 } 048 } 049 050}