Friday, August 29, 2008

Java Classpath issues

The most difficult problem to solve from a distance... But if we look closely its a piece of cake.
Many developers spend so much time in fixing this issue. Lot of frustration and anger. What they dont spend time on is finding how the classpath and class loading is done in java. Once you know it, you are done.

I herewith try to log a list of java classpath issues:

1. Junit cannot load classpath resource:
The ideal solution as I know is to put the resource along with the junit class(unless it is not reused across). Then load the resource using MyClassTest.class.getResourceAsStream("articles.xml");

This is a simple and elegant solution rather than hardcoding or putting a relative path , which are bound to fail in different environments.

Sunday, August 10, 2008

AJAX - What javascript can do..

AJAX is asynchronous javascript and XML. AJAX in it raw form is difficult to build rich applications. Many frameworks are developed hence. As javascript is object oriented, building a framework on it is easy. Something like a JDK with packages can be built and maintained easily.. Though AJAX was for XML, HTTP responses and JSON(kind of protocol) are supported. The following are in the market:
  1. GWT -by google. Java to javascript compiler makes it easy for java developer.
  2. Zk -very powerful and simple.
  3. DWR -simple
  4. Dojo - Excellent.
  5. Yahoo kit - dont know
  6. Ext JS
  7. Jquery
  8. More.....
Setting up the environment for these AJAX development is always a pain. Will write more in future on this. Links: Excellent gwt components here : http://www.gwt-ext.com/demo Jquery slider for select boxes : http://www.filamentgroup.com/lab/progressive_enhancement_convert_select_box_to_accessible_jquery_ui_slider/
This guy is 12 yr old.. and he knows so much of  jquery :
http://uk.youtube.com/watch?v=8mwKq7_JlS8

jquery with jsp
http://www.infoq.com/articles/First-Cup-Web-2.0-Joel-Confino

Automatic form post jquery plugin:

http://malsup.com/jquery/form/

Yes it is infact simple (include a javascript into ur existing page and
you start playing with Jquery), light weight(core is just 20KB),
pluggable/ extensible(thousands of plugins) and easy to use (implicit
event handling, expression evaluation and function chaining).





Also its jquery-form plugin( http://malsup.com/jquery/form/ )  makes
things much more easier. This takes care of marshalling the HTML input
fields automatically at the browser end.



There is some work done already on (spring MVC  + jquery) http://www.infoq.com/articles/First-Cup-Web-2.0-Joel-Confino

Tried a prototype using this and actually it works well with Xstream and Jettison mapped driver .

Also converting the existing spring MVC controller to have AJAX
capability is just a matter of setting a custom Json View instead of
Velocity view.



Data can be transferred from browser to server in either of the format:

JSON(Java script object notation) or XML.

   JSON is simple as it gives you a java like object graph and is more popular in open source community.      

   However it lacks XML flexibility (like having attributes,etc)



Obviously, having an IDE for jQuery would make development easier
especially with code completion  and debugging capabilities. There are
few of them to evaluate - Aptana and Spket IDE.

Jquery Editor:
http://spket.com/jquery.html

Tuesday, August 5, 2008

Oracle tips

A sneeky tool in oracle SQL developer to help u visually generate sql query is here


Printing a tree hierarchy using SQL connect by:

select
lpad('-', (level)*2,' ' ) || HIERARCHY_cat_short_name as padded_name, HIERARCHY_cat_id, HIERARCHY_cat_parent_id, level
from HIERARCHY_category
connect by prior HIERARCHY_cat_id =HIERARCHY_cat_parent_id
start with
HIERARCHY_cat_id in (select HIERARCHY_cat_id from HIERARCHY_category where
HIERARCHY_cat_parent_id is null)

quick reference here :http://philip.greenspun.com/sql/trees.html

Oracle CONTAINS function for XML based search
select count(*) from ATABLE where contains(xml_COLUMN, 'HASPATH(//filed="12568") ') >0

Extractvalue from xml column
SELECT distinct EXTRACTVALUE( xmltype(column_meta_xml), '//field',    'xmlns:ora="http://xmlns.oracle.com/xdb"') from atable





Friday, August 1, 2008

Textpad tricks

Textpad tricks

Find and replace 

Input : 66 Urology & Nephrology 737 Spermatogenesis
Replace : the bold text in the above input

Find Pattern : ^\([0-9]+\)\(.*[a-z \t]+\)\([0-9]+\)
Replace pattern: \1 \3

output: 66 737 Spermatogenesis


Gotcha's

Always escape group by characters ( or ) with \ [backslash] like this \( \)

^ is the beginning of the line

$ is the end of the line

\n is new line.