Saturday, October 4, 2008

Groovy as extension for Netbeans editor

As you know I work a lot with xml files (see my Xml/Xsl posts). Xml files are perfect for storing informations in structured way. Sometimes there is need for refactoring those informations. By refactoring I mean nodes/attributes renaming, changing value or place of those. If file is too big, that task may be very-very boring doing it by hand. Of course you can use your favorite text editor's search-replace feature but for complex tasks you will end writing utility for processing xml.
I played a little bit with Groovy and GroovyShell and noticed that you can easily pass your (java) variables to it. It means that you can pass your editor's document and process it with Groovy.
I created simple module for processing xml files. It is based on XPathEvaluator module. It adds a new window to Netbeans where you can write Groovy scripts.


Code for "Run Script" button looks like this:
Binding binding = new Binding();
binding.setVariable("doc", xmlDoc);
binding.setVariable("output", jTextArea1);
GroovyShell shell = new GroovyShell(binding);
shell.evaluate(jEditorPane1.getText());

It binds xmlDoc, which is EditorCookie.getDocument(), to doc variable and evaluates the script which is in jEditorArea.

Maybe a Groovy could be a new way for extending Netbeans? Tell me what you think.

Saturday, August 23, 2008

SubnetCalculator JM2E

I just found this little utility on my computer and decided to share it. It is a j2me subnet calculator midlet for the mobile phone. I made it when I was attending a Cisco courses (2 years ago). I tested it on Samsung D500 (CLDC1.0 and MIDP 2.0) at that time. If jar is not working you can recompile it with Netbeans 6.5 and Sun Java Wireless Toolkit 2.5.2 for CLDC.



Download: jar and source code

I also found some interesting stuff: my antivirus (Avira AntiVir) software is reporting that Java Wireless Toolkit is infected by "BDS/Backdoor.Gen" back-door program when I try to run emulator.exe.