Developer's Daily Java Education - Test Projects
  front page | java | perl | unix | DevDirectory
   
Front Page
Java
Education
   
 



// core Java stuff.
import java.io.*;
import java.text.*;
import java.util.*;
import java.net.*;

// JTidy stuff.
import org.w3c.tidy.Tidy;

public class Main
{
  public static void main(String args[])
  {
    if (args.length != 1)
    {
      System.out.println("Usage TidyURL url");
      System.out.println("Full example: \n"
        +"java -cp .:Tidy.jar TidyURL http://www.esperanto.net");
      return;
    }

    String url = args[0];

    try
    {
      URL u = new URL(url);

      Reader reader;

      BufferedInputStream sourceIn = new BufferedInputStream(u.openStream());
      ByteArrayOutputStream tidyOutStream = new ByteArrayOutputStream();

      // Create the Tidy bean
      Tidy tidy = new Tidy();

      // Set bean properties
      tidy.setQuiet(false);
      tidy.setShowWarnings(true);
      tidy.setIndentContent(true);
      tidy.setSmartIndent(true);
      tidy.setIndentAttributes(false);
      tidy.setWraplen(1024);
      //tidy.setXHTML(true);
      //tidy.setXmlOut(true);

      tidy.setMakeClean(true);
      tidy.setErrout(new PrintWriter(System.out));

      tidy.parse(sourceIn, tidyOutStream);
      System.out.println(tidyOutStream.toString());

    }
    catch (Exception ex)
    {
      ex.printStackTrace();
    }
  }
}

Copyright © 1998-2003 DevDaily Interactive, Inc.
All Rights Reserved.