| hawat.thufir@gmail.com 2005-06-10, 4:02 pm |
| In ControlTidy I want to create an instance of Test16, but of BasicTidy
type, like:
BasicTidy aTidy = new Test16();
and then just work with the aTidy object.
someone's suggested to me that "It might be a better design if you
moved that run() function from Test16 to a Test16Runner that uses a
Test16," but I'm not sure what that means.
package atreides.tidyXhtml;
public interface BasicTidy{
public void setUrl(String url);
public void setOutFileName(String outFileName);
public void setErrOutFileName(String errOutFileName);
public void setXmlOut(boolean xmlOut);
}//BasicTidy
public class ControlTidy{
public static void main (String[] args) {
Test16 aTidy = new Test16();
String yahooUrl = "http://www.yahoo.com/";
String googleUrl = "http://www.google.com/";
String out = "out.txt";
String err = "err.txt";
boolean xml = true;
aTidy.setUrl (yahooUrl);
aTidy.setOutFileName (out);
aTidy.setErrOutFileName (err);
aTidy.setXmlOut(xml);
Thread aTidyThread = new Thread(aTidy);
aTidyThread.start();
}//main
}//ControlTidy
package atreides.tidyXhtml;
//"inspired" from source at jtidy on sourceforge.net
import java.io.IOException;
import java.net.URL;
import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.io.FileWriter;
import org.w3c.tidy.Tidy;
public class Test16 implements Runnable, BasicTidy{
private String url;
private String outFileName;
private String errOutFileName;
private boolean xmlOut;
public Test16(){
this.url = "http://www.google.com/";
this.outFileName = "out.txt";
this.errOutFileName = "err.txt";
this.xmlOut = true;
}//Test16
public void run() {
URL u;
BufferedInputStream in;
FileOutputStream out;
Tidy tidy = new Tidy();
tidy.setXmlOut(xmlOut);
try {
tidy.setErrout(new PrintWriter(new FileWriter(errOutFileName),
true));
u = new URL(url);
in = new BufferedInputStream(u.openStream());
out = new FileOutputStream(outFileName);
tidy.parse(in, out);
}//try
catch ( IOException e ) {
System.out.println( this.toString() + e.toString() );
}//catch
}//run
public void setUrl (String url){
this.url = url;
}//setUrl
public void setOutFileName (String outFileName){
this.outFileName = outFileName;
}//setOutFileName
public void setErrOutFileName (String errOutFileName){
this.errOutFileName = errOutFileName;
}//setErrOutFileName
public void setXmlOut (boolean xmlOut) {
this.xmlOut = xmlOut;
}//setXmlOut
public static void main( String[] args ) {
}//main
}//Test16
thanks,
Thufir
|