Monday, February 13, 2006

Executing JavaScript code with a time delay

To execute a JavaScript code after a time interval use the setTimeOut function:

sayHello()', 1000);

function sayHello(){
alert("Hello :-)");

Handle special ASCII characters in PHP and HTML

I had today the following situation: A html site sends an httpRequest using Ajax to a php script that returns an html table representing the result set. Unfortunately, the mysql result set contains ASCII characters with a code between 0 and 32. Since I parse the responseText of the xmlHttpRequest as an xml document, the resulted xml is invalid because of the existence of those characters.
To solve this problem, I wrote the following php function that replaces any ASCII character that may affect the validation of the xml file with its identifier.
function convertSpecialAscii($str){
$tab = array('NUL','SOH','STX','ETX',
'EOT','ENQ','ACK', 'BEL',
'BS','HT (\t)','LF (\n)',
'VT','FF';'CR (\r)',
'SO', 'SI', 'DLE', 'DC1',
'DC2', 'DC3',
'DC4', 'NAK', 'SYN', 'ETB',
'CAN', 'EM', 'SUB', 'ESC',
'FS', 'GS', 'RSD', 'US');
$tempStr = '<font color="red"/>[' . $tab[$i]. ']</font>';
$str = str_replace(chr($i) ,$tempStr, $str);
return $str;

The code is based on an example from

Tuesday, December 13, 2005

Regexp for XML2TXT?

use this regular expression to replace all xml tags with a space in your editor (I use notepad++)


Monday, November 21, 2005

How to activate subsubsection numbering in LaTeX?


Monday, September 19, 2005

Using eclipse console view in RCP

In RCP it is possible to add the eclipse console as a view to a new RCP. Here is an example how to add the console view to your perspective and link all output messages to it:

public class MyPerspective implements IPerspectiveFactory {

public void createInitialLayout(IPageLayout layout) {
MessageConsole myConsole = new MessageConsole("Console", null); // declare console

ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[]{

MessageConsoleStream stream = myConsole.newMessageStream();

PrintStream myS = new PrintStream(stream);
System.setOut(myS); // link standard output stream to the console
System.setErr(myS); // link error output stream to the console

Now every System.out.println or log4j output will come out on the console. VoilĂ  :-)

PS: the code above MUST
come directly after createInitialLayout(IPageLayout layout) and before any other code!

Adding a JNDI Datasource to Tomcat 5.5.9

By using a JNDI data source to connect to a database from a web application running on tomcat, you do not have to care about connections building, closing, or pooling anymore.

Defining a JNDI data source

I assume that your web application is named 'myWebApp' and accesses a database named 'myDatabase' on a MySql server 'localhost'.
Create a new xml file named 'myWebApp.xml' in the directory {TOMCAT_HOME}/conf/Catalina/localhost and add the following content to it:
<context path="/myWebApp" docbase="myWebApp" debug="5" reloadable="true" crosscontext="true">

<logger classname="org.apache.catalina.logger.FileLogger" prefix="localhost_myWebApp_log." suffix=".txt" timestamp="true">

<!-- org.apache.commons.dbcp.BasicDataSourceFactory -->

<resource name="jdbc/myDatabase" auth="Container" type="javax.sql.DataSource" factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory" username="guru" password="secret" driverclassname="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/myDatabase?autoReconnect=true" maxwait="1000" removeabandoned="true" maxactive="30" maxidle="10" removeabandonedtimeout="60" logabandoned="true">

I use the DataSourceFactory org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory and not org.apache.commons.dbcp.BasicDataSourceFactory as it is recommended on the Jakarta project web page for the simple reason that it does not work.

Adding required libraries

Download the MySql jdbc connector mysql-connector-java-3.0.16-ga-bin.jar and move it to {TOMCA_HOME}/common/lib

Accessing the data source

From a jsp site you can now access the database using the following JSTL code:

<sql:query var="rs" dataSource="jdbc/myDatabse">



Welcome to my Blog!