Posts

Showing posts from August, 2007

Comfortable XPath accessor

Three weeks ago I blogged about a "Groovy way" to create XML documents in Java. This article now is about a convenient way to access XML without requiring more than a single class (downloadable here) on top of the JRE's own XML library functions.In fact I wrote this class before I even looked for an easy way to create XML myself, because at the time I just had to parse some XML and extract the values in an easy to use fashion.I believe it is easiest to show an example of how to use the class. Consider the following very simple Java class: import java.math.BigDecimal;

/**
 * Simple value object for a contact.
*/
public class Contact {
public String firstname;
public String lastname;
public boolean withAccount;
public Integer numberOfCalls;
public BigDecimal amountDue;
} Usually the fields would not be public of course, but for the sake of the example, just imagine the getters and setters being there ;-)Now consider getting an XML string back from an external sy…

How the Vulcan greeting came about

Ever gave a thought on how the Vulcan greeting (you know, the V shaped hand gesture) came about in Star Trek? Turns out this is really a fun and interesting story, not just some script writer conceiving it out of thin air. Have a look at this very funny video in which Leonard Nimoy, Mr. Spock, explains how it entered the show.

Windows Date Created Timestamp strangeness

I have been using Windows since version 3.0 and thought  I had seen most of its subtleties. However today I found a new "gem" I had not encountered before.We use two Perl scripts to do some FTP transfers regularly, scheduled by the Windows "Scheduled Tasks" to run several times a day. The scripts both use a common function to append to their respective daily log file. In case a file is older than 5 days, judging by its age in days based on the "Date Created" timestamp, it will be deleted and a new one created under the same name. This is intended to not have the files grow indefinitely.
While one of the jobs worked just fine, appending to its log files and rotating after 5 days, the other seemed to overwrite its log file on each run. Strangely enough  - as said before - they both used the same log function, just with different file names.After some poking around in the scripts source we decided to make a more low level test to see whether this had anything…

Gnome Nautilus SSH fails when hostkey changed

Today I tried to upload some files to my server via Nautilus. Months ago I created an SSH connection to my home folder via the "Places - Connect to Server" option on the main menu. It allows you transparently use SSH via the graphical user interface.However for some reason trying to double click the desktop connection just did not do anything at all. Selecting the entry in an open file manager windows led to a confusing error message: Nautilus cannot display "ssh://shipdown.de".
Please select another viewer and try again.Another connection, set up via WebDAV worked without problems. It occurred to me that this might have something to do with the recent crash of the server which made it necessary to set it up freshly. This of course included the generation of a new SSH host key. Trying to connect via the command line confirmed this:ds@yavin:~$ ssh ds@shipdown.de
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
WARNING: REMOTE HOST IDENTIFICATION HAS C…

GMail advanced search operators

Several rules in my GMail account apply various labels to mails and mostly archive them right away. This is handy for newsletters, mailing lists and the like. However over time - if you do not read them all - there are unread mails, scattered around several labels which are too old to show on the first 50 items.Up to now I sometimes went through the following pages, using the "Select unread" and "Mark as read" functions. Today I stumbled across a page that mentions a search term to show only unread mails. I had suspected something like this must exist, but there is no GUI feature I know of to use it.So in addition to any other search criteria you might have (e. g. "label:newsletter") you can just add "is:unread" and only get those mails that you haven't looked at before. Other things I just tried out and found to work:is:starred - applies to messages with stars.is:unread - applies to unread messagesis:read - applies to read messagesOnly afte…

Building XML the Groovy way in Java

When working with XML - i. e. creating XML documents - the Java DOM API is a little cumbersome. You have to ask all sorts of factories for instances of themselves, those instances for documents, elements and so forth. It is usually a lot code to write, even if all you want is a little XML fragment with only a few elements, e. g. to be sent over the network to some server. One way to make your life easier is to resign to StringBuilder/StringBuffer and building the XML "by hand". However this is error-prone and not always easy to read.Recently I had to implement a service that responded with XML over the net, building the document by collecting data from several sources and combining them together. The first version I wrote used the DOM API and once finished was hard to read even for me. I would have liked to use Groovy's MarkupBuilder for this, however company policy does not allow this (yet).So I looked around for a similarly easy to read solution in plain Java. I found