You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Eric Jain <Er...@isb-sib.ch> on 2003/01/07 09:14:14 UTC
HTML validation
Is there an Ant task for retrieving and validating HTML from a server?
Something like a combination of HttpUnit and JTidy...
--
Eric Jain
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: HTML validation
Posted by Eric Jain <Er...@isb-sib.ch>.
> 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: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: HTML validation
Posted by Erik Hatcher <ja...@ehatchersolutions.com>.
On Tuesday, January 7, 2003, at 04:26 AM, Eric Jain wrote:
>> <http://jakarta.apache.org/ant/external.html#Anteater>
>> <http://jakarta.apache.org/commons/latka/index.html>
>> <http://webtest.canoo.com/webtest/manual/WebTestHome.html>
>
> Thanks. What I was looking for was a task to do validation in the
> sense of
> checking the syntax for conformance to the official W3C standards
> (something
> like http://validator.w3.org/), doesn't seem to be supported directly
> by any
> of those tools.
I created a Lucene <index> task to parse HTML using JTidy and index the
contents. I ran it on Ant's documentation and Javadocs many times and
corrected a lot of the errors it kicked out (and there were a lot of
them!).
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.
Have a look at the lucene-sandbox repository for contributions/ant:
http://cvs.apache.org/viewcvs/jakarta-lucene-sandbox/contributions/ant/
The HtmlDocument class is the one you're looking for.
Erik
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: HTML validation
Posted by Eric Jain <Er...@isb-sib.ch>.
> <http://jakarta.apache.org/ant/external.html#Anteater>
> <http://jakarta.apache.org/commons/latka/index.html>
> <http://webtest.canoo.com/webtest/manual/WebTestHome.html>
Thanks. What I was looking for was a task to do validation in the sense of
checking the syntax for conformance to the official W3C standards (something
like http://validator.w3.org/), doesn't seem to be supported directly by any
of those tools.
--
Eric Jain
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: HTML validation
Posted by Stefan Bodewig <bo...@apache.org>.
On Tue, 7 Jan 2003, Eric Jain <Er...@isb-sib.ch> wrote:
> Is there an Ant task for retrieving and validating HTML from a
> server? Something like a combination of HttpUnit and JTidy...
<http://jakarta.apache.org/ant/external.html#Anteater>
<http://jakarta.apache.org/commons/latka/index.html>
<http://webtest.canoo.com/webtest/manual/WebTestHome.html>
look interesting, I haven't used one of them, though.
Stefan
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>