Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Getting Tidy with Eclipse

Eclipse's extensibility makes it the perfect collaborator. Learn how to build custom views in Eclipse that integrate with other useful public libraries. For example, in this article, you'll learn how to create a split pane view in Eclipse that cleans malformed HTML files using JTidy.


advertisement
n my last article, "Extending Eclipse with Helpful Views," I explained how easy it was to create new functionality in Eclipse. This article continues in the same vein by also creating a new view. However, instead of focusing on the mechanics of writing a view, the focus of this article is on integration. The Java world is rich with freely available libraries that provide all sorts of useful functions. Coupling those libraries with Eclipse can provide a very powerful combination indeed.

In this article, I will show how to make use of JTidy with Eclipse to help clean up HTML files automatically. The JTidy site describes the library as follows.

"JTidy is a Java port of HTML Tidy, a HTML syntax checker and pretty printer. Like its non-Java cousin, JTidy can be used as a tool for cleaning up malformed and faulty HTML."
The combination of JTidy and Eclipse isn't a new idea and in fact, an open source project named EclipseTidy already exists to provide just that. I would highly recommend checking out that project if you are in need of JTidy's functionality in Eclipse. The result of this article—an Eclipse plugin—will provide similar functionality in that both plugins can clean up HTML, but it is not the result that matters; it is getting there.

Figure 1. Tidy Up: The split pane view created in this article will allow you to read in an HTML on the left, to execute JTidy against it in the background, and have the result show up on the right. It's just one example of innovative ideas for creating views in Eclipse.
I've used JTidy quite a bit and I've often been faced with the same problem: How do you know that the changes JTidy makes to the HTML won't affect the way it renders? We'd all like to believe that fixing malformed HTML will result in more standardized code that will render more consistently in browsers. However, that is far from the case. Thus, when dealing with existing HTML you need to be concerned not only with reforming your code but in retaining the original look and feel.



If I wanted to compare my starting HTML with the result of JTidy I might use a diff utility, but that would only show me the differences in the HTML; not the differences in how it will render. Sure I could take each of the HTML files and load them in a browser to compare the result, but all that takes time. What I want is a plugin that can do it for me. In order to produce such a plugin I need two things: the ability to execute JTidy against an HTML file and the ability to render the HTML as a browser would.

To begin I'll show how to execute JTidy against an HTML file. Next, I'll show how to render HTML inside an Eclipse view. Finally, I'll put the two together, creating a split-pane view with one side showing how the HTML renders before and the other side showing the code after JTidy is applied (see Figure 1).



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date