Another Fluent API: jOOX. Porting jQuery to Java
Recently, in my every day programming madness, I really felt the urge to kill someone involved with the formal specification of DOM. The beloved Document Object Model. While everyone understands that this API is complete in functionality and scope and it’s a standard, and it’s almost the same in every language…. well it’s incredibly verbose. Manipulating XML is about as fun and exciting as cleaning the dishes of a 2000-people Indian wedding.
And then, suddenly, I remembered that this is how I felt with Java’s support for advanced SQL and how JPA/CriteriaQuery made me feel like that poor dishwasher, before. And I wondered whether someone had felt like me before. So I asked this question on Stack Overflow:
I had also found one project, that has a somewhat fluent approach:
It looks quite nice, actually, although it is a bit biased towards DOM creation, not navigation. And then, it struck me like lightning: “Why hasn’t anyone ported jQuery” to Java, yet?? jQuery is exactly how an XML API should be: Awesome. Fluent. Fun, and efficient to use. So I tried to hack something together that looks like jQuery and that’s the beginning of another product in the “jOO-Star suite”: jOOX with X for XML! I wanted this to be fluent, and fun and efficient to use. Like jOOQ. So jOOX will be an attempt for doing precisely that. Here’s an example of what jOOX code looks like:
// Find the order at index for and add an element "paid" joox(document).find("orders") .children() .eq(4) .append("<paid>true</paid>"); // Find those orders that are paid and flag them as "settled" joox(document).find("orders") .children() .find("paid") .after("<settled>true</settled>");
So in the future, I will also post one or two entries about jOOX on this blog. Looking forward to feedback!
Download jOOX from Google Code:
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)