Brain Flush

May 19, 2009

The Force Unleashed: XML+XPath on Android using dom4j and Jaxen

Filed under: Linux & Open Source, Mobile Devices, Software Development & Programming — Tags: , , , — Matthias @ 1:15 pm

*UPDATE* This post has become obsolete. Google has bundled the Java XPath APIs with the release of FroYo (Android 2.2 / level 8).

*UPDATE* The source code is now on GitHub. Feel free to fork ‘n fix. Here’s the JAR: http://github.com/kaeppler/dom4j-1.6.1-harmony/downloads

I have been very disappointed with Android’s XML parsing support from day one, it’s simply too low level, inconvenient to use, and is lacking important features (I was especially disappointed with the decision to exclude the JAXP XPath support from Android, which has become an integral part of the JSE).

This is not only about cosmetics. Parsing XML documents of only medium complexity already turned out to be error prone and very tedious on Android (white space normalization problems, broken Unicode entity ref expansion, etc.) and we would’ve had to rewrite stuff which existing Java XML libraries already do in a graceful and stable manner.

Since I have always been a big fan of dom4j, I fixed an issue with the latest source tree that prevented dom4j’s QNAME caching to work with Android’s Java implementation (or more precisely, with Apache Harmony’s SAX implementation — the Android Java implementation is based on a pre-release version of Apache Harmony).

I haven’t committed that change back to dom4j yet, because development seems to have stalled on that project, but if anyone is interested, I can host the source code and a working JAR somewhere (please drop a short line in the comments section, otherwise I won’t bother sharing it).

dom4j also works very well in conjunction with Jaxen (a free XPath implementation)!

Some example code to wet your mouth:

SAXReader reader = new SAXReader(); // dom4j SAXReader
Document document = reader.read(xmlInputStream); // dom4j Document

// select all link nodes with href "http://example.com"
List linkNodes = document.selectNodes("//link[@href='http://example.com']");

// select an attribute value
String val = linkNodes.get(0).attributeValue("href");

// select element text and trim it
String value = document.elementTextTrim("childNode");

etc. pp.

Simple, powerful, straight forward — and performance is also decent (it’s pretty slow in debug mode, but reasonably fast otherwise).

Advertisements

April 29, 2008

Ubuntu 8.04 “Hardy Heron” In The Wild

Filed under: Linux & Open Source — Tags: , , — Matthias @ 11:21 am

The Bleeding Edge

I have to admit, when it comes to software, I am always grinding the bleeding edge. So what can I say, of course I was eager to take the new Long Term Support release of the wonderful Ubuntu Linux distribution for a test ride (in fact, I installed the RC on my laptop, which is my production machine… risky, but the idea of having 3D desktop effects out of the box was just too tempting).

The Grumpy Gibbon

First things first though. I have to say that I was quite disappointed with the last Ubuntu release — Gutsy Gibbon. I installed it on my desktop machine 6 months ago and I had nothing but trouble. Took me almost two weeks to fix the system so I could run my ordinary desktop tasks (don’t want to go into detail here, but how about not being able to boot into your newly installed system… makes you lose your faith rather quickly). In other words, I was rather anxious whether Hardy would follow Gutsy’s path of doom, or get back on the righteous path of a solid Dapper.

The Heron can fly — but does its feathering impress?

To break the tension: I am fairly satisfied.

I wrote a guide for Linux on Laptops and Tuxmobil once covering hardware compatibility (and how to fix it…) for Ubuntu Edgy and this very same notebook. For Hardy, I wouldn’t even know what to put into that guide. Every piece of hardware worked out of the box, from Wi-Fi to sound to 3D graphics. So, no complaints here. Installation was also a breeze, I still can’t understand why people claim that Linux would be much more difficult to install than Windows. Fedora, Ubuntu, SUSE, … they all manage to deliver a simple and straightforward installation procedure.

Now that I have run Hardy for over a week, I dug deep enough into the system to find some flaws though. I will list them below; for most of them I am not yet aware of a fix. I will post fix proposals (or links to them) as soon as I find them.

Stability problems

I have to say right out front that in this week, Hardy dared to lock up on me completely — but only once. But still, this is something that has never happened to me with any Ubuntu release before. I just don’t expect Linux to hardlock on me, it just… doesn’t feel right. Only Windows does that right?! Sarcasm aside, it was not the only stability problem:

Glipper

The Glipper applet (yes, Glipper is a panel applet now) keeps crashing on me after logging in. I am not aware of any fix yet.

Evince

The Evince PDF reader keeps getting stuck on “Loading…” a PDF much too often for my taste. Exiting and reopening it resolves the problem though, but still, this is annoying and demands fixage.

Firefox

Despite Hardy being an LTS release, it was shipped with a beta version of Firefox 3 (Beta 5). As expected, this brings with it all the stability issues of a beta release. From plain crashes to Firefox completely messing up sound and video (I was once not able to properly play back video files as long as FF would be running; only after exiting FF video playback went back to normal). Since Ubuntu will constantly update FF as it matures however, this won’t be much of a problem anymore later this year.

NetworkManager

I sometimes had problems to connect to my wireless network (it would just stay in connect phase endlessly without actually connecting). To fix it, I had to re-create the network. On shutdown, I also get errors related to NetworkManager (see Bug #216908). Doesn’t feel very polished.

Suspend/Hibernate

Sigh. I am still waiting for the day when the Linux kernel will actually support hibernation and suspend (I mean seriosuly support it, not just saying it would). Because, it is still as broken in Hardy as in any other Linux distribution I have ever used. In 50% of the time, your laptop will not recover from suspension in a healthy way (either your screen keeps blank, or the network is broken). I remain faithful though.

Glitches and other problems

I observed glitches with several software components, in particular in conjunction with compiz and 3D desktop effects.

Compiz

The compiz glitches are visible, but not serious. From messed up color palettes on inactive window title bars to flickering buttons on window decorations to completely disappearing widgets on Java based applications. The latter can be fixed though by setting an environment variable:

AWT_TOOLKIT=MToolkit

VLC

With the change to Pulse Audio in Hardy, VLC media player by default does not play back audio streams. Read this thread for a solution.

But still!

Apart from these (rather small) annoyances, Hardy is an excellent Ubuntu. Ubuntu more and more is simply Doing Things Right (TM). From the ease of detecting and installing required (non-free) media codecs, to the easy activation of 3D desktop effects (and detection and installation of proper proprietary drivers), it really makes progress in overall ease of use. Although FF3 is still a bit unstable, I am glad they included it. The performance improvements over FF2 are significant. The new printing interface looks more complicated at first, but simply works better than ever before. It keeps configuration required by the user at a minimum.

Bottom line being, I am pretty happy with Hardy Heron. It seems to be a very solid foundation for the upcoming Intrepid Ibex.

Enter the next round!

February 29, 2008

Firefox 3 Claims Huge Performance Boost in JavaScript Runtime

As posted recently on Cybernet News, a profile-guided optimization build of the upcoming version 3 of the Firefox Web browser has appeared which performs the SunSpider JavaScript Benchmark in only one third of the time required by Firefox 2.0.0.12.

This sounds great at first, but if you take a closer look, you see that this benchmark for example does not take DOM operations into account. AJAX heavy websites however basically evolve around modifying a page’s DOM tree at runtime, which can quickly become the major bottle neck when requesting and re-rendering large amounts of data.

Instead of focusing on DOM operations, the benchmark runs exotic tests like 3D raytracing and cryptographic calculations which do not seem to be typical use cases for Web 2.0 content.

For my part, I remain skeptical, although I would of course welcome performance improvements in any part of Firefox in upcoming releases.

December 30, 2007

Ubuntu Linux on a Samsung R55 Notebook

Filed under: Hardware & Technology, Linux & Open Source — Tags: , , , — Matthias @ 1:24 pm

In an attempt of shameless self-promotion, I’d like to point out my website covering the installation and potential issues of running Ubuntu Linux on Samsung’s R55 notebook series.

http://www.infodump.de/samsung-r55-linux

It focuses on an older version of Ubuntu, but I will update it once the next LTS release of Ubuntu hits the server somewhere around April 2008.

Blog at WordPress.com.