Wednesday, May 25, 2011

One of the best features of jEdit

Macros. The beanshell macro integration in jEdit is simply awesome. Here's an excellent example. Recently, a number of us at work are writing components for Day CQ5 (www.day.com), which is a high-end content management system. Most of the components are written as jsps. We are running local instance of CQ, but everything is packaged into jars, so it's not a simple matter of saving a changed jsp to the server with a regular save command. Fortunately, the server will reload a jsp that is sent to it with curl:

curl -T localfile destinationUrl

The Eclipse people run this from the command line, changing the filename and url by hand each time they move to a different file. I wrote a simple macro:


// macro to save and send a jsp file to a local Day instance
String filename = buffer.getPath();

// save the buffer and upload it to crx.
if (!buffer.isReadOnly()) {
    buffer.save(view, null);
}
//String filepath = filename.substring(filename.indexOf("WebContent") +"WebContent".length());
String filepath = filename.substring(filename.indexOf("jcr_root") + "jcr_root".length());
String destination = "http://admin:admin@localhost:4502" + filepath;
String cmd = "curl -T " + filename + " " + destination;
exec(cmd);

Then I mapped a keyboard shortcut to Alt+S. Now whenever I want to save an edited jsp to the server, it is a simple keyboard command, no typing long paths in the command line. The Eclipse guys are somewhat jealous and I am saving quite a bit of time.

No comments: