La API oficial en
permite llamar a un inspector local o remoto W3C través de la API de servicios Web de marcado Validador desde 2007.
tiene una sola solución Java Class que usa Jersey y moxy-Jaxb para leer en la respuesta SOAP.
esta es la dependencia Maven para utilizarlo:
<dependency>
<groupId>com.bitplan</groupId>
<artifactId>w3cValidator</artifactId>
<version>0.0.2</version>
</dependency>
Aquí está una prueba unitaria para probarlo:
/**
* the URL of the official W3C Markup Validation service
* if you'd like to run the tests against your own installation you might want to modify this
*/
public static final String url="http://validator.w3.org/check";
/**
* test the w3cValidator interface with some html code
* @throws Exception
*/
@Test
public void testW3CValidator() throws Exception {
String preamble="<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" +
" \"http://www.w3.org/TR/html4/loose.dtd\">\n"+
"<html>\n"+
" <head>\n"+
" <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n"+
" <title>test</title>\n"+
" </head>\n"+
" <body>\n";
String footer=" </body>\n"+
"</html>\n";
String[] htmls = {
preamble+
" <div>\n"+
footer,
"<!DOCTYPE html><html><head><title>test W3CChecker</title></head><body><div></body></html>"
};
int[] expectedErrs={1,2};
int[] expectedWarnings={1,2};
int index=0;
System.out.println("Testing "+htmls.length+" html messages via "+url);
for (String html : htmls) {
W3CValidator checkResult = W3CValidator.check(url, html);
List<ValidationError> errlist = checkResult.body.response.errors.errorlist;
List<ValidationWarning> warnlist = checkResult.body.response.warnings.warninglist;
Object first = errlist.get(0);
assertTrue("if first is a string, than moxy is not activated",first instanceof ValidationError);
//System.out.println(first.getClass().getName());
//System.out.println(first);
System.out.println("Validation result for test "+(index+1)+":");
for (ValidationError err:errlist) {
System.out.println("\t"+err.toString());
}
for (ValidationWarning warn:warnlist) {
System.out.println("\t"+warn.toString());
}
System.out.println();
assertTrue(errlist.size()>=expectedErrs[index]);
assertTrue(warnlist.size()>=expectedWarnings[index]);
index++;
}
} // testW3CValidator
muestra cómo ejecutar su en el validador w3c en un sistema Ubuntu Linux.
Me sorprende que no haya API para Java. Aparte de eso, realmente no quiero modificar mi código fuente para agregar las API. Todo lo que quiero hacer es cambiar el archivo de configuración en mi proyecto J2EE para poder activarlo en el momento del desarrollo y desactivarlo cuando no lo haga. necesito. – newguy
ver soluciones Java en otras respuestas –