A Blog Uploading Tool for java.net

In this blog, I address my grief with blog uploading, following Paul Graham's advice about choosing technology.

Someone just complained on the java.net bloggers list about the wretched online blogging tool. Indeed, I couldn't imagine actually authoring in that thing. Instead, I paste in my HTML code, upload the images, and curse when I have to adjust the image URLs. Clearly, this is not the right way of doing it either. I looked at offline blogging tools such as Thingamablog, or ScribeFire. But I quickly realized that this was still a step in the wrong direction. Each of those tools has its own half-baked environment for authoring that may be fine for Aunt Tilly's recipe blog, but it just doesn't cut it if you write about coding.

A blog post contains HTML. I have an HTML editor, thank you very much, since I author just about everything in XHTML: web pages, slide presentations, blog articles, and even entire books.

As an aside, this often surprises my students. Why don't I use Word and PowerPoint, like everyone else? Well, as this classic article states: “When you choose technology, you have to ignore what other people are doing, and consider only what will work the best.” Wise words indeed.

In my line of business, character markup matters a great deal. When I write: “Consider a variable var of an type T1…”, I really care about the fact that var is written in monospace but that the two blank spaces to its left and right are not in monospace, and that T  is in italics and not monospace, and 1 is a subscript and not in italics.

In Word, this requires lots and lots of repetitive mouse clicks and trial and error. For example, click between the T and the 1 and type a character. Will it be in italics? A subscript? Neither? Trying to design Word macros that reliably switch fonts on and off is an exercise in frustration—Word seems to think that font boundary locations are some kind of no-man's land.

Of course, in HTML, it is always clear where one font ends and another one starts. That's why I use HTML. It's not what other people are doing, but it's what works best. Why not some fancier XML dialect such as DocBook? Nothing wrong with that, but for me, HTML + a microformat is good enough. In fact, it's better since I have a wider choice of editors. For making PDF files, there is Prince, and for slides, there is Slidy. Since I am careful to produce XHTML, I can transform into DocBook, or SafariML, or PearsonML, or whatever.

Back to the blogs. I needed a tool that takes an XHTML file, uploads the images and the files using this wild and wooly XML RPC API, and munges the image source attributes in the process. I found almost what I needed in the AsciiDoc project—a Python program that uploads AsciiDoc or XHTML files to WordPress. Unfortunately, WordPress uses  a different XML RPC API than java.net.

I looked at the source of the AsciiDoc tool, and it uses regular expressions to manipulate XML, which isn't really my thing. I knew I could do better with Scala.

It was an easy matter reimplementing the tool in Scala. Except, I realized that, in order to share my creation with the world, I needed some configurability since I couldn't just bake my blogging password into the source. Ugh, that meant processing command-line arguments. But fortunately, the Scala infrastructure is getting better all the time. I googled for “getopts Scala” and found several  packages, a couple of which are in repos that sbt/Ivy/Maven can find. I picked one of those, added the repo to my sbt configuration, looked at the sample code, and tried it out in the Scala REPL. 30 minutes later, I was done with my command line processing.

The source for the blog upload tool is here. You need Scala and sbt to build it (see the README.html). Let me know if you are interested in a pre-built binary.