ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric Jain" <Eric.J...@isb-sib.ch>
Subject Re: HTML validation
Date Tue, 07 Jan 2003 13:40:39 GMT
> It would be pretty easy to take what I've done and make it into a
> general purpose <htmlvalidate> task and even have it fail the build if
> errors are detected if thats what you want.

Thanks, very simple indeed. Unfortunately Tidy isn't quite as strict as the
CSE HTML Validator, but hey, it's free...


import java.io.*;
import java.net.*;
import org.apache.tools.ant.*;
import org.w3c.tidy.Tidy;


public class TidyTask
 extends Task
{
 private String url;


 public void setUrl(String url)
 {
  this.url = url;
 }


 public void execute()
  throws BuildException
 {
  try
  {
   log("Validating: " + url);
   Tidy tidy = new Tidy();
   tidy.setQuiet(true);
   InputStream in = open();
   tidy.parse(in, null);
   in.close();
  }

  catch (IOException e)
  {
   throw new BuildException(e);
  }
 }


 private InputStream open()
  throws IOException
 {
  HttpURLConnection connection =
    (HttpURLConnection) new URL(url).openConnection();
  if (connection.getResponseCode() != HttpURLConnection.HTTP_OK)
   throw new BuildException("Couldn't retrieve '" + url + "': "
    + connection.getResponseMessage());
  return connection.getInputStream();
 }
}


--
Eric Jain


--
To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>


Mime
View raw message