Agile Ajax

How to do Page Preview in Java with Embedded HTML Rendering

He who doesn't look ahead remains behind. -- Mexican Proverb

One Ajax technique you see quite a bit of lately is the page preview. This is where the html page is rendered as an image so that you can cast a skeptical eye on a tiny version instead of navigating to a lame page. The tech social bookmarking site dzone features an excellent version of this.

dzone.jpg


So, how do you get a screenshot of a web page from within a Java app using open source? Back in 2004, Joshua Marinacci wrote a very useful article on just this sort of technology, entitled Java Sketchbook: The HTML Renderer Shootout, Part 1. The article is a bit out of date, but at least one of the tools -- JRex -- is still around and kicking.

All of these tools are intended to be used as components for providing interactive HTML rendering and browsing for desktop applications, but just because it is intended for one thing does not mean you can't use it for another. In fact, you can use this technique of using Swing components to render images with some of the following XHTML/CSS rendering engines.

  • JRex - the oldest of the contenders. Not pure Java; uses the Mozilla Gecko Runtime Environment (GRE), a minimal HTML rendering engine.
  • Flying Saucer - pure Java renderer with support CSS 2.1, but not Javascript.
  • Cobra HTML Toolkit - A pure Java HTML 4 parser and renderer. Supports Javascript and CSS2. The Warrior HTML browser is based on this toolkit.

JRex with Gecko will give you the best and most robust results. For legacy HTML, you many want to use JTidy to clean it up into XHTML before passing it into the last two renderers.

The only thing that worries me is that with Javascript enabled, one could have the same sort of exploits we see in regular browsers, only now targeted at servers that use these embedded rendering engines. Since something like this would run unattended for days and weeks, there's a real concern that things could get out of control. There are ways of sandboxing and locking down, and that's something definitely worth considering.


Technorati : , , , , , ,

Comments: 1 so far

  1. If your title has “How To” in it, your “How To” should provide a code samples.

    Comment by Mark, Wednesday, December 20, 2006 @ 2:34 am

Leave a comment

Powered by WP Hashcash

About Pathfinder

  • We design and build extraordinary applications for companies looking to make the next great idea a reality.
  • learn more

Topics

WordPress

Comments about this site: info@pathf.com