XML In Java In XML Is Ugly

November 26th, 2004

I’ve been struggling with getting Cocoon and Exist to work together properly and allow me to insert an XML snippet into a document in the database.  Apart from the fact that the apparent assumption seems to be that no one would ever have an XML snippet being fed into an XML-based system and thus all the < and > characters should be converted to entities, plus the fact that Exists seems to only want to retrieve stuff from the database and not change stuff in the database, I’ve wound up with the following:

<?xml version="1.0" ?>
<xsp:page xmlns:xsp="http://apache.org/xsp"
    xmlns:xsp-request="http://apache.org/xsp/request/2.0"
    xmlns:xdb="http://exist-db.org/xmldb/1.0">
    <result>
    <xdb:driver class="org.exist.xmldb.DatabaseImpl" />
    <xdb:collection uri="xmldb:exist:///db/features" user="admin" password="password">
        <xsp:logic>
            String comment = <xsp-request:get-parameter name="comment" />;
            String author = <xsp-request:get-parameter name="author" />;
            String id = <xsp-request:get-parameter name="id" />;
            String xupdateQuery = "&lt;xupdate:modifications version='1.0' xmlns:        xupdate='http://www.xmldb.org/xupdate'&gt;&lt;xupdate:append select='/my:featureList/  my:feature[@id = " + id + "]/my:comments'&gt;&lt;xupdate:element name='my:comment'     namespace='http://www.ephox.com/featureManager'&gt;&lt;xupdate:attribute               name='author'&gt;" + author + "&lt;/xupdate:attribute&gt;" + comment + "&lt;/xupdate:  element&gt;&lt;/xupdate:append&gt;&lt;/xupdate:modifications&gt;";
            try {
                XUpdateQueryService service = (XUpdateQueryService)collection.           getService("XUpdateQueryService", "1.0");
                service.update(xupdateQuery);
            } catch (Exception e) {
                e.printStackTrace();
            }
        </xsp:logic>
        <xdb:execute>
            <xdb:xpath>
                "/my:featureList/my:feature[@id = <xsp-request:get-parameter             name="id" />]
            </xdb:xpath>
        </xdb:execute>
    </xdb:collection>
    <greeting>
    </greeting>
    </result>
</xsp:page>

Seriously ugly….  Surely there has to be a better way!  I know I can move all of the Java code into a logic sheet but my real concern is with the doubly escaped XUpdate template which is just completely unreadable.  If so wish I could just tell XQuery that the request parameter should be treated as an XML snippet instead of as a string.

Sigh.  Perhaps this would be easier if I actually knew something about Cocoon, Exist, XQuery, XUpdate and XML databases before I started this project….

So Much For Standards Compliant

November 23rd, 2004

Maybe I’m expecting too much but I would have thought that a browser that claimed to be standards compliant might actually implement the standard….  In particular I’m annoyed that Gecko doesn’t fully support HTML 4 tables (it ignores the align and valign attributes on colgroup and col elements).  IE gets it right.  To be fair, Safari also ignores them.  Oh and of course you can’t achieve the same thing via CSS since CSS styles don’t get applied either via a styles attribute or via embedded styles (rightfully so since the standard doesn’t say they should be applied).   You have to manually markup each cell in the column. Yuck..

The main reason I comment though isn’t because I terribly miss the align or valign attributes on colgroups but rather that I consider it a pretty sad state of affairs that noone can correctly implement the HTML standard and that people seem to consider it okay to claim that Mozilla is standards compliant when it can be shown that it isn’t (in more ways than just colgroups).  To their credit, the Mozilla organization don’t seem to claim this but most Mozilla advocates do.

Sigh.  What’s the point of the W3C if the stuff they come up with is practically impossible to implement?

Derby Is Cool

November 20th, 2004

I thought it was worth mentioning that I got to play with Derby as part of the Time Tracker mini-project I mentioned earlier.  Very cool.  I’ve not had a need to work with an embedded database before so it was really nice to have a small, efficient library that handled all my data storage needs.  The only complaint I’d have is that it needs to use a directory to store stuff in (it’s a little more flexible than that but a directory is always created and used).  It would be really nice to be able to just point it at a file and say "that’s my database, do your thing".

It probably would have also been useful to have a persistence tool that worked well with the embedded database. For instance, I was really storing a database representation of TimeEntry objects. It would have been nice to be able to have an API similar to:

store(TimeEntry entry);

find(TimeEntry entry);

update(TimeEntry entry)

 

The find method would have some magical way of detecting which data items within the TimeEntry I’d actually specified and form a search query for all entries that had those attributes with those values (but ignore attributes that I hadn’t explicitly specified).  Similarly the update method would have some magical way of knowing which entry I was talking about.

Of course, I wrote an interface along those lines but it would have been nice to avoid relearning SQL to do so.  An embedded database is going to be used in situations like this a lot where what’s really required is an embedded persistence mechanism.  I’m sure it’s possible to achieve this but it would be nice if there were a project dedicated to it that worked out-of-the-box so to speak.

JDIC

November 20th, 2004

Java Desktop Integration Components (JDIC) is a set of components aimed at making OS specific functionality available to Java programs and to allow Java programs to make better use of existing code within the OS.

The tray icon integration is an excellent example of this.  It’s quite common for a Windows application to make functionality available via a system tray icon and now via JDIC Java apps can do just that.  During some down time after our last release I had a chance to play with this while developing an internal time tracking application and it worked out really well.  The system tray icon acts as the main UI for the program so it’s neatly tucked out of the way so it doesn’t waste screen space but always quickly available so recording time spent on a task is highly efficient.  The downside is that it doesn’t seem to map to an OS X dock icon menu yet (the API doesn’t really fit that model particularly well anyway but it could be done).

The other interesting project for me in JDIC is the browser integration.  There are a lot of complaints about the current HTML support in the Swing Text package so a simple solution for rendering HTML is to provide a Java interface to integrate the user’s default browser instead of attempting to write a pure-Java solution.  Naturally this platform dependency restricts the number of systems that the program can run on but that’s probably not a bad tradeoff.  Sadly, again this component isn’t working on Mac at the moment.  The other massive limitation of this approach is that it doesn’t support HTML editing at all.  The current Swing Text code may not be the world’s best editor (though you can build the world’s best editor using them <grin>) but at least they provide some editing support.

It’s particularly sad to see that Mac support isn’t being worked on early in the process and that Sun (who is throwing the majority of resources behind the project) isn’t putting some time into Mac ports instead of expecting the community to do that.  The projects have a lot of potential but if they’re not available on the major OSs which Java is deployed to (Windows, Linux, Solaris and Mac) it makes them far less usable.  It’s great that it’s possible for Mac developers to add support themselves since the code is opensource, but that doesn’t help much when the target audience for the library are Java developers but the developers have to be native programmers (Obj-C or C on OS X, C pretty much everywhere else).

It will definitely be interesting to see how this project progresses.

Why So Anti-Sun?

November 19th, 2004

I really don’t understand why there’s so much anti-Sun sentiment around these days.  I mean, the opensource movement in general just seems to have it in for Sun no matter what they announce or plan it’s either never good enough of there’s some sinister plan behind it.  I don’t get it.  Sun is one of very few big companies who are seriously weighing up the prospects of opensource and seem to generally be finding that opensource can work for them and moving in that direction.  The opensource movement however, far from encouraging this is pulling out all stops in a smear campaign against Sun.

I don’t see how people can miss the fact that Sun is competing directly with RedHat for a lot of business and the fur is flying on both sides.  It’s not like RedHat hasn’t taken its fair share of cheap-shots at Sun and Sun have given as good as they got.  I honestly can’t remember a single time that Sun attacked Linux outside of either technical differences or RedHat.  The closest I can come is in the horrifically biases, predetermined agenda article from NewsForge:

I’ve already mentioned SUSE, but what about community-developed OSes? A skilled sysadmin can take a BSD variant like OpenBSD, or a community-developed GNU/Linux distribution such as Debian, Gentoo, or Slackware, and make it into a powerful server that can compete with Solaris 10. McNealy balked at that notion, saying, "And who will support that? Red Hat won’t support Debian,"

While NewsForge attempts to make out that McNealy’s statement is uninformed or outright FUD, I’d beg to differ.  McNealy understands the enterprise market.  He understands how conservative huge enterprise companies are.  He understands that a minor purchase involves a 9 month sales process and that the company goes through all kinds of checks to make sure that any business they are dealing with isn’t going to go out of business and leave them in the lurch.  All the independent support providers NewsForge pointed out would either have a hard time convincing a major fortune 500 company that they had the infrastructure to provide the support in the first place or convincing them that the company will still be in business in 5-10 years time.  The issue of core server infrastructure is of critical importance to big companies and it’s not taken lightly.  Anyone who thinks that a small unheard of startup is going to have much chance of securing the support contract for the core infrastructure of a fortune 500 company most likely hasn’t dealt with too many major companies.  McNealy is exactly right in his comment - major companies are not going to make their companies dependent on a community group with no support contract, a small company that hasn’t fully demonstrated it’s ability to uphold a major support contract and particularly not in a skilled sysadmin’s pieced together system which noone will understand once that sysadmin leaves.

From that same article is an excellent example of what I’m talking about:

…as though Red Hat only offered one product to fit all situations, and all other GNU/Linux distributions were insignificant.

This is simply putting words into Schwartz’ mouth.  Schwartz made comparisons between Solaris 10 and all it’s major competitors.  "all other GNU/Linux distributions" don’t compete with Solaris to any extent worthy of a mention in such a speech.  It doesn’t mean Schwartz doesn’t know they exist, it doesn’t mean he doesn’t think they’re any good.  It simply means that the marketing figures say they aren’t a threat.  I’ll guarantee that Sun has researched this and is monitoring marketing trends.  If SUSE or Debian suddenly look like they will take significant business away from Sun you can expect to hear about all the weak points in them too.

Perhaps if the opensource movement provided support and constructive comments about how Sun can better embrace the open source movement and why they should take that advice people might find that Sun is actually spending a lot of time listening to the community and really looking hard at the way they do business.  The Java team is definitely putting in a lot of effort in this area and all the indications I’ve seen are that it’s a company wide policy of evaluating how to get the most benefit out of an opensource strategy for the company.