my recent reads..

Free Nelson Mandela - The Special AKA

For no reason in particular, I get The Specials' Free Nelson Mandela spinning in my head every so often. It's wierd, since I guess the last time I actually heard the song was in the late 80's. This time I googled it, and happily YouTube comes to the rescue!

read more and comment..

Optimism

Winston Churchill had quite a bit to say about optimism.

A pessimist sees the difficulty in every opportunity; an optimist sees the opportunity in every difficulty.
For myself I am an optimist. It does not seem to be much use being anything else.
But Havelock Ellis would rather lock him up..
The place where optimism most flourishes is the lunatic asylum.

read more and comment..

JDeveloper Filter Add-in

I hinted at a project to develop a simple filter add-in in my last post on Code Generation with JDeveloper. So that turned into my latest weekend project;-)

I'm registering the project on sourceforge, but in the meantime you can get the full source kit here, or if you prefer just the add-in jar here (which just needs to be dropped into your ${jdev.home}/jdev/extensions folder). [30-Jan-2008: the project is now available on sourceforge]

What does it do?
It is a simple idea. Allow you to invoke an external program to filter any text you have selected in the JDeveloper Editor. Of course, it is up to you to define what filter means - limited by your imagination only. And by externalizing the filter process, it means you can use the tool or scripting language of your choice to implement and make on-the-fly changes to your filter.

To be precise, the filter operates like operating system pipes:

  • Selected text is sent to the standard-input of the filter process.
  • The standard-output of the filter process is written back to replace the selected text.

Configuring the Filter
Configuration is done via the JDeveloper Tools | Preferences menu, and is very simple at present. It only supports a single filter process definition. As you can see in the screenshot, you just need to enter a valid command line to invoke the filter. A nice enhancement would be the support for multiple filter definitions.


This is where the flexibility comes in. As an example, I've provided a rot13 encoder written in ruby [samples/myrot13filter.rb in the source kit].
puts $stdin.readlines.to_s.tr("A-Za-z", "N-ZA-Mn-za-m")

Ruby, Perl, php, vbscript/WSH, bash ... use whatever you prefer. Rather than needing to develop and deploy an add-in in Java, you can just script the filter.

Applying the filter is simply a matter of selecting some text in the IDE, and choose the Custom Text Filter item from the right-click pop-up menu

The Development View
The truth is that I developed this add-in as more an investigation of the Extensions SDK, and the filter idea appeared to be unexplored territory.

As Brian Duff writes, there are some major improvements in the support for JDeveloper Extensions in 11g. Since it is still in preview, I decided to stick with Extension SDK 10.1.3 however.

There are four classes of significance. since this was an educational exercise, I spent a bit of time to make sure I really understood how it all worked, and tried to reflect that with liberal comments in the source.
  • CodePaneAddin - implements the pop-up menu hook and applies the filter
  • ExecShell - wraps the invocation of the filter process iwth stdin/out handling. It is independent of the extension API and may be of interest in its own right
  • ConfigPanelData - handles preferences panel configuration
  • ConfigData - bean to wrap the configuration data


The source kit comes with a JDeveloper project and also ant build file. If you want to build and deploy the add-in to JDeveloper, simplest is to first check the environment-specific settings in build.properties and then simply run
C:\MyDocs\MyDev2\JDevFilter>ant deploy
Buildfile: build.xml

init:

prepare:

compile:

jar:

deploy:
[copy] Copying 1 file to C:\oracle\jdevstudio10131\jdev\extensions

BUILD SUCCESSFUL
Total time: 0 seconds

Interested? Head on over to sourceforge to download the kit.
read more and comment..

Mickey the Assistant Manager


..from Hobtopia/lol cats
read more and comment..