/*
 * Created on Apr 10, 2005 by Brian Schoudel
 * Part of CLCA project
 */
package edu.uiuc.webcoord;


import java.io.IOException;
import java.io.FileOutputStream;
import java.io.FileInputStream;
import java.io.PrintWriter;
import java.io.FileWriter;
import org.w3c.tidy.Tidy;


/**
 * This program shows how HTML could be tidied directly from
 * a URL stream, and running on separate threads.  Note the use
 * of the 'parse' method to parse from an InputStream, and send
 * the pretty-printed result to an OutputStream.
 * In this example thread th1 outputs XML, and thread th2 outputs
 * HTML.  This shows that properties are per instance of Tidy.
 */

public class HTMLValidate {

    private String inFileName;
    private String outFileName;
    private String errOutFileName;
    private boolean xmlOut;

    public HTMLValidate(String inFileName, String outFileName,
                  String errOutFileName, boolean xmlOut)
    {
        this.inFileName = inFileName;
        this.outFileName = outFileName;
        this.errOutFileName = errOutFileName;
        this.xmlOut = xmlOut;
    }

    public void run()
    {
        FileInputStream in;
        FileOutputStream out;
        Tidy tidy = new Tidy();

        tidy.setXmlOut(xmlOut);
        try {
            tidy.setErrout(new PrintWriter(new FileWriter(errOutFileName), true));
            in = new FileInputStream(inFileName);
            out = new FileOutputStream(outFileName);
            tidy.parse(in, out);
            in.close();
            out.close();
        }
        catch ( IOException e ) {
            System.out.println( this.toString() + e.toString() );
        }
    }

    public static void main( String[] args ) {
	String url1 = "https://sandbox.aits.uillinois.edu/brian/banking.html";
	String file1 = "c:\\temp\\banking.html";
	String file2 = "c:\\temp\\HTMLValidateError.log";
	HTMLValidate hv = new HTMLValidate(url1, file1, file2, false);
        
        hv.run();
    }

}

