Saturday, May 23, 2009

Texter - An auto text expander

I just cant imagine how many times I would have typed the same sentence again and again...
Texter to the rescue.... thanks to Adam Pash!!
As the source is open for viewing, there is no nasty spyware in it I suppose!!
It is built using autohotkey for windows. Its scripting mode is excellent. Check this for syntax.

Thursday, May 21, 2009

XSLT caching Transformers

 The usage of cached transformer objects is recommended here

A sample implementation of CachingTransformerFactory is here

The above code abstracts the caching of Transformer objects using HashMap's.

In brief it says to override the TransformerFactoryImpl and cache the transformer objects. The xsl updates are dealt by checking the timestamp on the XSL file.
Hence no need of a web service to update XSL transformer cache!!

Using TransformerFactory.newInstance() ,
there will be absolutely no code change. The Services API will look for a classname in the file META-INF/services/javax.xml.transform.TransformerFactory in jars available to the runtime. More here...






Thursday, May 14, 2009

Cron jobs

Cron actually an UNIX tool.

Cron expressions:
* * * * * *
seconds minutes hours "day of month" month "day of week" year

Except year rest all are mandatory.
The details are here



Wednesday, May 13, 2009

JSP implicit objects printer

copy paste the below and include it using <%@ include file="jspPrinter.jsp" %>

<%@ page
errorPage="ErrorPage.jsp"
import="java.io.*"
import="java.util.*"
%>

<%
Enumeration enames;
Map map;
String title;

// Print the request headers

map = new TreeMap();
enames = request.getHeaderNames();
while (enames.hasMoreElements()) {
String name = (String) enames.nextElement();
String value = request.getHeader(name);
map.put(name, value);
}
out.println(createTable(map, "Request Headers"));

// Print the session attributes

map = new TreeMap();
enames = session.getAttributeNames();
while (enames.hasMoreElements()) {
String name = (String) enames.nextElement();
String value = "" + session.getAttribute(name);
map.put(name, value);
}
out.println(createTable(map, "Session Attributes"));

map = new TreeMap();
enames = request.getAttributeNames();
while (enames.hasMoreElements()) {
String name = (String) enames.nextElement();
String value = "" + session.getAttribute(name);
map.put(name, value);
}
out.println(createTable(map, "Request Attributes"));

%>



<%-- Define a method to create an HTML table --%>

<%!
private static String createTable(Map map, String title)
{
StringBuffer sb = new StringBuffer();

// Generate the header lines

sb.append("");
sb.append("");
sb.append("");
sb.append("");

// Generate the table rows

Iterator imap = map.entrySet().iterator();
while (imap.hasNext()) {
Map.Entry entry = (Map.Entry) imap.next();
String key = (String) entry.getKey();
String value = (String) entry.getValue();
sb.append("");
sb.append("");
sb.append("");
sb.append("");
}

// Generate the footer lines

sb.append("
");
sb.append(title);
sb.append("
");
sb.append(key);
sb.append("
");
sb.append(value);
sb.append("

");

// Return the generated HTML

return sb.toString();
}
%>