velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brian W. Young" <byo...@decadesystems.com>
Subject Re: other options besides jtidy
Date Fri, 15 Aug 2003 15:59:32 GMT
Well, I'm all for giving JTidy a try, in testing it seems to work okay.

One question- what is the best way to pipe the output through Tidy when 
merging your templates?  It takes an InputStream and OutputStream. (My 
HTML output  is aways a file on disk.) Velocity's template.merge() takes 
a BufferedWriter.  It is almost like I'd want a gender changer (to lack 
a better term) to convert the BufferedWriter passed into 
template.merge() into an InputStream that could be passed into Tidy.

The only option I can think of involves a two stage process of writing 
Velocity's output to a string in memory or a temp file, neither of which 
I like.  I'd like to just hook the streams up together and let it go.  
Any ideas?

Thanks,
Brian

Serge Knystautas wrote:

> JTidy is not very *actively* maintained, but it's been around for some 
> time, and activity comes and goes like any project.  We use it in a 
> few places that wants cleansed HTML.  Our content management system 
> offers a Tidy error report on a page or site, but in the end we 
> usually end up just restricting what users can edit.
>
> If you really just want extra whitespace removed, I would think you 
> could just do this....
>
> String original = <what I started with>
> StringBuffer result = new StringBuffer(original.length());
> StringTokenizer tokenizer = new StringTokenizer(original, " \r\t\n", 
> false);
> while (tokenizer.hasMoreTokens()) {
>     result.append(tokenizer.nextToken()).append(' ');
> }
>
> This will strip all spots where you have more than one whitespace 
> elements.  It would screw up something in a <pre> tag, but that's 
> related to whatever whitespace removal approach you take.
>




Mime
View raw message