On 11/19/2009 07:24 PM, Lukasz Skowronski wrote:
Hi,
----- Original Message -----
From: "Vincent Massol">
I'm still wondering. When you do a view
source from an XE page, it's
not very nice and doesn't look very professional.
Just some thoughts...
What about creating an optional (configured in web.xml)
ResponseFormattingFilter which calls
chain.doFilter(request, new PrettyResponse(response));
PrettyResponse would be a wrapper for ServletResponse which would delegate
all method calls to original response but also wrap its OutputStream with
PrettyOutputStream.
PrettyOutputStream write() methods would have all necessary logic to
properly indent html tags on-the-fly and call its underlying (wrapped)
outputStream write() method whenever possible. This way we can process the
document in small chunks.
We could also buffer this way the whole document in the filter and pretty
print it at the end - it would be easier to implement but more memory
consuming.
Additional possibilities:
- we could use CompactResponse (the output doc would be a one-liner, all
unnecessary whitespaces removed) in order to lower bandwidth
- we can add the cache directives in response headers (so we won't need
Apache for doing this - this can be also done in separate filter, in fact I
already use such a filter)
This is a pretty dangerous zone. While I would also like to have neat
HTML responses, it's hard to come with a generic prettyprinter, since
some elements depend on having whitespace, others must explicitly have
no whitespace between similar elements to prevent broken layouts. True,
this means that the style is a bit fragile, but this the style we have,
and there's little we can do about it.
--
Sergiu Dumitriu
http://purl.org/net/sergiu/