-
Fixing HTML code with jTidy
Hi everybody,
I´m new in this forum. I were very thankfull if somebody could lend me a hand with the Jtidy library.
I've installed a WYSIWYG editor for my customers in a CMS, for publishing pretty documents in their portal. The issue is the usual with that kind of HTML editors, the final code that they provide doesn't validate for the most grammars published by the w3c, specificilly we are looking for a XHTML Strict validation.
I have heared about the Tidy project, in fact I am interesting in the Jtidy library.I need to develop a .java class for cleaning my code, more or less like the Guid for Jtidy do (http://www.paehl.de/tidy/). This tool works very well, it fix a lot of bugs in your code.
I´ve do only a couple of test with the jTidy, next I post the code:
package es.pa.common.tidy;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import org.w3c.dom.Document;
import org.w3c.tidy.Configuration;
import org.w3c.tidy.Tidy;
public class CleanHtmlCode {
public CleanHtmlCode() {
super();
// TODO Auto-generated constructor stub
}
public String clean(String input){
ByteArrayInputStream bais = new ByteArrayInputStream(input.getBytes());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Tidy tidy = new Tidy();
tidy.setXHTML(true);
tidy.setDocType("strict");
tidy.setMakeClean(true);
tidy.setQuiet(false);
tidy.setIndentContent(true);
tidy.setSmartIndent(true);
tidy.setIndentAttributes(true);
tidy.setWord2000(true);
tidy.parse(bais,baos);
return baos.toString();
}
}
package es.pa.test;
import es.pa.common.tidy.CleanHtmlCode;
public class TestCleanHtmlCode {
/**
* @param args
*/
public static void main(String[] args) {
CleanHtmlCode chc = new CleanHtmlCode();
System.out.println(chc.clean("<p>OTROS SUPUESTOS AUTORIZABLES</p> <p>Podrá solicitarse la realización de quemas no contempladas en la Resolución de 14 de agosto de 2002, <strong>Otras quemas</strong>, <u>quemas para otras finalidades diferentes a la eliminación de rastrojos agrícolas (pueden tener finalidad educativa, cultural...)</u> así como la solicitud de trabajos que, de forma puntual, se realicen en los montes y exijan el empleo de equipos o herramientas susceptibles de propagar el fuego. El Jefe del Servicio de Montes y Producción Forestal de la Consejería de Medio Rural y Pesca podrá, previo informe, autorizar estos trabajos imponiendo las normas que se consideren oportunas en cada caso y por un plazo no superior a 15 días.</p>"));
}
}
In this piece of code you can find the tag <u>, that is not allowed in XHTML Strict. In this case the GUITIDY generates a XHTML Transitional page.
What I´m looking for is a .java class for fixing these pieces of code, I´d call this class in a <xsl:variable> element of a XSL transformation page.
Thanks in advance,
Luis
Similar Threads
-
By keystoneclimber in forum VB Classic
Replies: 1
Last Post: 09-27-2006, 08:33 PM
-
Replies: 2
Last Post: 06-16-2006, 05:58 AM
-
By clean in forum ASP.NET
Replies: 1
Last Post: 03-14-2006, 08:01 AM
-
Replies: 90
Last Post: 04-17-2001, 12:45 AM
-
By james chung in forum Web
Replies: 0
Last Post: 09-16-2000, 02:41 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks