Dashboard Widget for Posting Blog Entries to Confluence via XML-RPC

First of all, here’s a zip of the working widget (10.4.3+): Confluence Daily Log.zip. I also checked in the Dashcode project.

I had an old WordPress widget from a year or two back that I had written, so I thought this would be a simple port, but I forgot that I had written it w/ a set of Python proxies because 1) xmlrpclib is awesome and 2) the JavaScript XML-RPC libraries I had tried (at the time I believe the best was jsolait) were maddening.

I’ve moved onto jsxmlRPC, which is an improvement from the prior options, but still has some issues. I also gave JS-XMLRPC a try, but the lack of documentation, examples, and the verbose retardedness of it all quickly convinced me otherwise. And I looked at @tomic briefly, but just couldn’t justify 300+K of JS dependencies for it. If I continue to have problems w/ jsxmlRPC, I may switch. Mostly I went w/ jsxmlRPC because I approve of its interface and of its documentation (it’s not that hard, a reference implementation would cover most of it).

My preference would have been something that magically did its business, but I actually had to really dig into jsxmlRPC’s code to get things working. While the demo worked well enough, it was barfing when interacting with Confluence. Turns out this is because jsxmlRPC does not handle parsing of payloads according to the spec – param values can be returned without a nested type tag (defaults to a string data format). jsxmlRPC tried to find a nested value all the time, which as you might guess, caused all sorts of brokenness. This can be fixed by changing the following (swap the while with this if) at the top of the getResultFromValueNode() function (line 385ish):

if ("#text"==valueNode.nodeName){                                              
  return valueNode.textContent;                                                  
}

Note: I saw that jsxmlRPC was still barfing on empty values. That’s probably a simple fix, but my brain’s pretty fried and I’m tired of looking at the code.

I developed this widget in Dashcode, which is many sorts of awesome and very much simplified the process, however the debugger and stack frame was for some reason not quite as helpful as one would imagine it to be. (It was all sorts of unhelpful in tracking down the errors I was looking for even when stepping through). Once I ported the code to Firebug and added a few console.logs(), the problems became much clearer.

In terms of functionality, everything seems to work for me. It does whipped up a very dumb local autosave as well. Here’s what’s missing:

  • Confirm dialog when navigating away from edited entries – I track the editing, but when I found out that Dashboard doesn’t support confirm() I tabled that feature
  • Handling reauth: I have no idea how long tokens last (forever? it’s not specified in the Confluence RPC docs), but if they expire, I don’t have a good way of trying to reauth (this would just involve adding some extra timers and some exception handling so not that bad to implement) – Update: – looks like these expire pretty quickly. I’ve uploaded a new version that just reauths before every API call (getBlogEntries, getBlogEntry, and storeBlogEntry)
  • Help – Some notes for the settings might be useful. IE, the “Space Key” is the shortname for your Confluence Space and the “Endpoint” is http://yourconfluenceinstall/rpc/xmlrpc
  • Widget Icon

OK, it’s late. I’m going to bed.