indiWiz.com

Subhash's Tech Log

Archive for December, 2008

JEdit Macro for XML/HTML Special Character Conversion

without comments

One of the common requirement I face often when posting text to blog/forum/Wiki etc. is character conversion:

& &
< &lt;
> &gt;
" &quot;
' &apos;

I developed a small JEdit Macro for doing this. This macro can be executed from JEdit menu Macros > Run Other Macro..., or can be installed by copying to: ${user.home}/.jedit/macros/ (later executed from the menu Macros). This macro operates on selected text.

Written by Subhash Chandran

December 31st, 2008 at 2:03 pm

Posted in Scripting

Tagged with

Search for the perfect Ajax auto-complete library

without comments

Yesterday we (Krithika and myself) spent some time finding a perfect Ajax auto-complete solution for one of our internal projects. We wanted to have a tag search box with auto-complete functionality. We had created a front-end layer for our Java tagging API (developed by Arun) using RESTful interface. This exposed searched result in JSON. So our need was for a Ajax library which provided auto-complete feature which satisfied following parameters:

  1. The code we need to incorporate for enabling auto-complete should be minimal.
  2. Should not be flashy.
  3. Should consume JSON content.

This seemed to be a trivial task, but it took quite some time to find and finalize on AutoComplete 1.2 by Beau Scott. This script was simple to integrate, and did not require us to configure any sophisticated CSS. It allowed us to consume our RESTful service without any modification.

During our search, we were surprised to find how badly certain popular Ajax libraries implemented this oft-used functionality. The famous Scriptaculous library’s implementation has the implementation detailed here: http://github.com/madrobby/scriptaculous/wikis/ajax-autocompleter. If you go through this document, you will see that the script requires the server to return data in this format:

<ul>
    <li>your mom</li>
    <li>yodel</li>
</ul>

This is bad design. A server code returning data as HTML. This cannot be consumed effectively by other clients. The next one which we picked up was YUI Autocomplete. The amount of configuration effort needed from our side scared us. We didn’t plunge deeper!

Another one which we tried was DevBridge’s Auto Complete. This looked simple to implement, and the look and feel was simplistic. But it had an issue: the call to the server-side code was passed as a query string (query=). We were using RESTful URL and we cannot modify our backend-code to comply to the requirements of the UI layer. But I did a little hack and made this script compliant to our requirement. But finally, we decided against using this patched-script because it had additional dependencies like images and CSS styles to be specified.

As said earlier, the script which matched all our requirements was AutoComplete 1.2 by Beau Scott.

The only worry for me from this exercise was the divide between the front-end developers and backend developers. Such a common functionality was not being addressed by popular frameworks without sacrificing functionality and addressing usability–and, more importantly, complying to established enterprise patterns like consuming data (like JSON and XML instead of HTML snippet) and support for RESTful URLs.

Hope 2009 annihilates this divide ;-)

Written by Subhash Chandran

December 31st, 2008 at 12:17 pm

Posted in Scripting

Tagged with , ,

WebService Client in JAX-WS (Java 6 and above)

without comments

Given a WSDL URL, you may generate the Java client classes using the JDK provided tool wsimport. The basic usage:

$ wsimport <wsdl_url>

The common command-line parameters supported by this tool:

-p specifies the target package
-d folder where generated class files are placed

Written by Subhash Chandran

December 30th, 2008 at 6:10 pm

Posted in Java

Tagged with , ,

Ruby's two most popular Web Frameworks merge

without comments

Ruby on Rails and Merb, two of the most popular OpenSource web frameworks for Ruby merged. The merged version will be released as Ruby on Rails 3.0.

Written by Subhash Chandran

December 24th, 2008 at 12:32 pm

Posted in news

Tagged with , , ,

On Pairing: By John De

without comments

John De, President of N-Brain, has to say this about pairing:

… I discovered that two heads really are better than one. Developers have different ways of interpreting code, and different ways of solving problems. Combining this rich diversity creates a strength unequaled by any single developer. Put me in a room with a junior programmer, and turn us loose on some task, and I guarantee you that I will gain new insight into the problem from this developer, and that our resulting solution will be stronger than anything I could have come up with alone.

Read full interview here: http://java.dzone.com/news/interview-john-de-goes-free-un.

Written by Subhash Chandran

December 22nd, 2008 at 2:30 pm

Posted in Software Dev

Tagged with ,

JFXBuilder: JavaFX Visual Design Tool

without comments

The first design tool for JavaFX is available here: http://www.reportmill.com/jfx/. The product page does not discuss any licensing or pricing detail. The current version is available as WebStart application for free use.

Written by Subhash Chandran

December 19th, 2008 at 3:37 pm

Posted in news

Tagged with , ,

JEdit, powerful search and replace using BeanShell

with 2 comments

JEdit is my favorite text editor. And today I was pleased to find some powerful scripting capability in its search and replace functionality. Basically I wanted to enclose a RegularExpression pattern with:

<a href="">PATTERN</a>

The Search and Replace dialog provided an option Return value of a BeanShell snippet. So whatever RegularExpression pattern grouping I provided, I was able to access them using the BeanShell variable _1 to _9. So my final replace statement became:

"<a href\"\">" + _1 + "</a>"

Cool solution to a simple problem.

jedit_search_replace

Written by Subhash Chandran

December 17th, 2008 at 2:27 pm

Posted in OpenSource,Scripting

Tagged with

Implementing a DI Framework for WizTools.org RESTClient

with 2 comments

I wanted very basic DI functionality for RESTClient. Just wanted a mock implementation to execute when doing a mvn test, and real implementation when executed otherwise. So the functionality was simple. My immediate requirement did not require constructor injection or setter injection. And all the beans instantiated had to be singletons. No other fancy requirement. So for this limited functionality, I was able to design a small framework in two classes: DIFramework.java and DIException.java. For mapping the implementation to the interface, it is managed using a simple property file with content:

org.wiztools.restclient.IGlobalOptions = org.wiztools.restclient.GlobalOptions

The mock implementation in the test execution would be:

org.wiztools.restclient.IGlobalOptions = org.wiztools.restclient.MockGlobalOptions

org.wiztools.restclient.IGlobalOptions is the interface, and org.wiztools.restclient.GlobalOptions and org.wiztools.restclient.MockGlobalOptions are the implementation. To get instance of implementation bean:

IGlobalOptions obj = DIFramework.getInstance(IGlobalOptions.class);

This would return two different beans in different execution environments based on the property control.

Written by Subhash Chandran

December 15th, 2008 at 10:04 pm

Posted in Java,OpenSource

Tagged with , , ,

DI: Annotation or XML Configuration

with one comment

Recently I have been looking at couple of DI containers in Java. These are: Google Guice and Spring Framework. I did not like Guice in the first look itself. It involved annotating my beans with Guice specific annotations. I felt this was defeating the purpose of POJO. XML configuration using Spring was more natural for me.

Written by Subhash Chandran

December 15th, 2008 at 9:11 pm

Posted in Java

Tagged with , ,

JavaDoc: Avoid Manually Escaping HTML Special Characters

without comments

I discovered this new tip: when writing JavaDoc comments, we do not need to escape HTML characters. The magic happens when we enclose such content inside {@literal ...}. So typically, a comment would look like:

{@literal x < y}

There is another JavaDoc quickie in this line. It is {@code ...}. This is also like {@literal ...}, but displays the code in a different mono-spaced font.

Written by Subhash Chandran

December 14th, 2008 at 5:10 am

Posted in Uncategorized

Tagged with

James A Gosling's Cool Projects

without comments

Gosling, father of Java, contributes to some cool projects too. I found the following two:

  1. Huckster: This is a simple Swing application to build presentations.
  2. Bloged: This again, is a Swing application to post blogs without launching your browser.

Written by Subhash Chandran

December 12th, 2008 at 7:43 am

Posted in Uncategorized

Google Native Client: ActiveX replacement

without comments

If there is one web-technology that I hate, it should be ActiveX. Google engineers seem to have faced the same issue. They developed Native Client. Now it is easier, more secure to develop and run native code in any browser in any platform. Thanks guys :-)

Written by Subhash Chandran

December 12th, 2008 at 7:26 am

Posted in Innovation

Tagged with ,

Google Chrome comes out of Beta!

without comments

It is really surprising how fast it has come out of beta (compared to other Google products). View the official blog announcing it. For people using Windows XP and Vista (the only supported platforms of Google Chrome), the download is available here: http://www.google.com/chrome/.

Written by Subhash Chandran

December 12th, 2008 at 4:34 am

Posted in news,OpenSource

Tagged with

JavaScript: Dynamically Creating and Manipulating DOM Elements

without comments

I was pleasantly surprised to see that JavaScript now supports XML-DOM methods for manipulating JavaScript DOM trees. A quick look at the features:

Init

Before we proceed with the examples, the setup part. All the examples that follow assume the existence of this in the HTML page:

<div id="placeholderId"/>

Creating new element

Let us assume the requirement of placing <br/> element inside the placeholder. The code:

var e = document.getElementById('placeholderId');
var eBr = document.createElement('br');
e.appendChild(eBr);

Adding attribute

Suppose we want to add the attribute id="brId", we would write:

eBr.setAttribute('id', 'brId');

Deleting attribute

eBr.removeAttribute('id');

Deleting element

var e = document.getElementById('brId');
var eParent = e.parentNode;
eParent.removeChild(e);

Creating elements with text element

Consider that we want to have the following paragraph element inside the placeholderId <div>:

<p align="right">Hello World!</p>

It can be achieved thus:

var e = document.getElementById('placeholderId');
var ePara = document.createElement('p');
ePara.setAttribute('align', 'right');
var eTxt = document.createTextNode('Hello World!');
ePara.appendChild(eTxt);
e.appendChild(ePara);

Happy hacking with this info ;-)

Written by Subhash Chandran

December 10th, 2008 at 9:24 am

Posted in Scripting

Tagged with

JBoss Application Server 5.0.0 GA Released

without comments

Download it from here: http://www.jboss.org/jbossas/downloads/. If I remember correctly, the first beta was released more than two years back.

Written by Subhash Chandran

December 9th, 2008 at 5:30 am

Posted in Java,news

Tagged with , ,