header

Torsten Curdt’s weblog

Off to Europe

Today I am heading off for ApacheCon Dublin. Quite a way for a ApacheCon Europe – at least for me :) Of course I will stay a bit longer in Europe, visit my friends and family and (hopefully) enjoy the summer over there. For those interested here is my itinerary:

  • 25.6. Dublin
  • 1.7. Frankfurt
  • 3.7. Göttingen
  • 10.7. Frankfurt
  • 23.7. back to Melbourne

And probably somewhere in between: Hannover and Berlin.

Blog Content Migration

As you might have noticed suddenly a lot more posts appeared in the archives of my blog. I finally spend a few evenings to migrate the content of my old MovableType blog over into wordpress. Of course not by hand ;)

Wordpress has an importer that supports MT …but as soon as you have images and code inside your posts that’s not enough. E.g. I wanted to have my pictures getting served by flickr as this makes future blog migrations much easier. Preserving the keywords as tags also was a must. So I took the challange to play with a few new libraries to port everything across. Here is how…

The first idea was to improve my ruby knowdlege a bit while implementing this useful converter. Unfortunately the nice one of the ruby flickr apis did not support upload of pictures yet …and I was actually too lazy to look into that just to get this job done. Which brought me back to doing in it in java. The only available java flickr api, flickrj is not really nice but supports uploads and does the job.

So the first task was to parse the MT export file. Oh, boy! How can you come up with such a poor format! Anyway, I wrote a quick-and-dirty parser (really ugly!) for it that creates an object representation of the entries. Probably it would have been easier to extract these information the database …but anyway.

So next thing was to get the flickr upload working. First you have do get all the authentication right.


String apiKey = "...";
String sharedSecret = "...";

Transport transport = new REST();
transport.setHost("www.flickr.com");
Flickr f = new Flickr(apiKey, transport);
Flickr.debugStream = false;

RequestContext requestContext = RequestContext.getRequestContext();
requestContext.setSharedSecret(sharedSecret);
AuthInterface authInterface = f.getAuthInterface();
String frob = authInterface.getFrob();

URL url = authInterface.buildAuthenticationUrl(Permission.WRITE, frob);
System.out.println("Press return after you granted access at this URL:");
System.out.println(url.toExternalForm());

BrowserLauncher.openURL(url.toExternalForm());
BufferedReader infile = new BufferedReader ( new InputStreamReader (System.in) );
infile.readLine();

Auth auth = authInterface.getToken(frob);
requestContext.setAuth(auth);

Then you can do the upload the image. The tags I’ve extracted from the posts keyword.


Set tags = new HashSet(entry.getKeywords());
tags.add("imported");

Uploader u = new Uploader(f.getApiKey());
UploadMetaData meta = new UploadMetaData();
meta.setDescription(description);
meta.setPublicFlag(true);
meta.setTitle(title);
meta.setTags(tags);
String id = u.upload(new FileInputStream(photoFile), meta);

PhotosInterface photos = f.getPhotosInterface();
Photo photo = photos.getPhoto(id);

I then wanted to make sure the posts are all proper XHTML and passed them through TagSoup which does an excellent job of parsing HTML and creating a proper DOM representation. (Unfortunately it’s GPL)

So I was able to extract image links from the DOM download them, upload them to flickr and replace the links by the appropriate flickr links. It also created a sql script that can be run against the wordpress database to insert the entries and a htaccess file to redirect my old movabletype post to their new home.

Puh …done!

Gmail Import

Before I was using Gmail only for private emails – now I am using it for all my daily messages. Again I had to import some of my existing mails. Bertrand has already blogged some excellent instructions on how to do that. Some things I did differently though.

For one I wanted the subject line change to be as little disturbing as possible. (Gmail so needs an overhaul of its filter facilities!!) So I just added an “_” to then end of the subject and filtered on that.

sed s"/^Subject: \(.*\)$/Subject: \1 _/" < inbox.mbox > inbox.mbox.marked

I also modified the GML script to save the state of the import. So you can hit Ctrl-C at any stage of the import and continue later on. It now also writes out an error mbox file with message that could not be imported. (I had a few that the python library failed to parse). For the mail server to use check the Gmail MX record.

dig mx gmail.com

So I used…

python ngml.py mbox inbox.mbox.marked [email protected] gsmtp183.google.com.

You can get hold of the modified GML script here.

BCEL 5.2 released

After years of inactivity the long awaited release of BCEL 5.2 is finally out of the door. It includes many bug fixes and other small improvements. I know many people have been using snapshots or even forks for the time being …so please update to latest release now and give some feedback.

Unexpand Id keywords

While cleaning up my mails I found this tiny script that Sylvain once posted. I know I will need it if I just delete it so why not blog about it.


#!/bin/sh

# Unexpands all "$Id ....$" keywords from files having a certain prefix (i.e. replaces
# them by $Id$) The good thing with Subversion is that it doesn't consider as being
# modified a file where the keyword has changed

find . \( -name '*.java' -or -name '*.xml' \) -print | while read file
do
 echo $file
 sed -e 's/\$Id:.*\$/$Id$/' $file > ${file}.rmkw-tmp
 mv ${file}.rmkw-tmp $file
done