Notification Wrapper

In a few of my projects I need to provide feedback using notifications, configurable by the user. What I need is a lightweight framework that allows a user to subscribe to notifications via various channels, e.g. growl, taskbar notification, email, sms, instant message, etc. Varying levels of severity, perhaps 5.

I’ve not researched this a huge amount, so there is likely something out there that can provide most of my requirements. Initial searches show up web service solutions, but I need this to be local to the client machine or network for some channels of notification.


  • Subscribe to notifications from various channels with various levels of severity (thinking logging conifgurations)
  • Fire notification events and let the framework handle distributing them to the subscribers


  • Configure new plugin wrapper via a configuration file – probably go down the Spring route for this
  • OSX growl implementation using a native libgrowl library
  • Windows growl implementation, libgrowl, using the java library that supports GNTP (Growl Network Transport Protocol)
  • Java 6 system tray integration for taskbar notifications – looks crap on OSX


Initial concept developed and working, but not a reusable library

Cue Sport Diagrams

If you’re creating diagrams of ball positions on a pool table it would be much easier if there was a dedicated tool rather than trying to use a paint package all the time. Whether you’re trying to show your friends a position from a recent frame or describing a practice routine, you’d need the same tools.

I came across a tool that does most of what you’d need, but it is based around US 9 ball tables. The tool is called Cue Table, although it is a bit buried within the forum section of the site.


  • Select a cue sport table to show the correct background (7×4 uk 8 ball, 6×3 uk 8 ball, etc)
  • Drag and drop balls into position on the backgrond image
  • Create line paths if ball movement needs to be displayed
  • Create multiple scenes within a diagram if the scenario is better illustrated with multiple steps


Draft version created and functional, below is a rough idea of the save format.

<diagram name="Yesterday" width="800" height="450">
  <scene name="Default">
    <background image="7x4_uk8ball.jpeg">
      <coord x="0" y="0"/>
    <icon name="red1" image="50mmRedBall.png">
      <coord x="100" y="150"/>
    <icon name="white1" image="50mmWhiteBall.png">
      <coord x="190" y="150"/>
    <path colour="red" arrowhead="end">
      <coord x="100" y="150"/>
      <coord x="790" y="155"/>
      <coord x="650" y="160"/>

Backup Tool

Backup tools are not in short supply, but simplicity isn’t always a word I’d use to describe some solutions. I make extensive use of rsync, but without a simple equivalent on windows (although DeltaCopy looks promising) it’s hard to backup consistently across many platforms. Having the backup storage mirror the files so you can easily navigate and restore a lost file is also important.

This tool isn’t very high on my list these days due to suitable alternatives.


  • Backup files to a local disk
  • Backup files to a remote disk over FTP
  • Backup files to a remote disk over SFTP
  • Backup files allowing individual file transformations, i.e. zip, encryption


Initial version developed, but poorly designed file wrapper class means rewrite is necessary

Dropbox Clone

Dropbox is a great idea with nice GUIs for multiple platforms, as well as a web interface. The problem is, if you’re a business you have to pay for a decent amount of storage – even 100GB isn’t enough sometimes. Plus, if your data is client confidential, the last thing you want to do is store it on a server out of your control. You could put it in a truecrypt vault, but backing up a binary blob isn’t great considering it will need an update for each slight change (this may be negated somewhat by Dropbox using rsync style technology for only transfering binary differences, not the whole file).

There is a project in it’s early stages, as I write this (Oct 2010), that can solve some of the problems – SparkleShare. It allows you to use your own server to store the files, removing the problems of insufficient storage space and using untrusted servers to store your confidential data.

That’s it right? Just wait for SparkleShare to reach a production level product? Well maybe … but I have more requirements for the environment I work in. We use a very large amount of disk space as we deal with video files, amongst other things. Employees tend to syncronise the parts of the remote storage they require to their local machine. Changes are re-synchronised on a ‘updated files only’ basis, but this is hardly full proof and only works at the moment due to the small number of employees with access. There is also no ability to backtrack changes, apart from resorting to the nightly backups. So, what would I like from a dropbox clone?


  • Dropbox style folder on local machine that automatically stays in sync with the server
  • File versioning with the ability to backtrack changes (binary blob only, no subversion style change tracking)
  • Web interface for remote file access
  • File/folder filtering to allow the local directory to only synchronise part of the remote storage, while keeping the folder structure (remember it may be huge!)
  • Remote storage accessed over common file transfer protocols, such as FTP, or more likely SFTP


  • Local file system change monitoring using JNotify
  • Hand crafted flat file DB system on remote storage to remove the need for a DB or server software. The clients will understand how to interpret the meta files stored alongside the actual data files/folders.


Planning – not started

JasperReports Tips

JasperReports is a java based open source reporting framework with similar, if not more, functionality to that of Crystal Reports. There is a visual report designer called iReport, but my experience of using it for anything but the simplest report has been a waste. It is useful for dragging and dropping report layouts around, but once you get the hang of it, it’s far easier to do it directly in XML.

Documentation is available, but it’s quite often difficult to get simple answers via a google search – as is possible for most open source software. The current books also lack good examples when they explain some of the more powerful features. Simple things like, I don’t want my report to have nulls printed on it, what are my options are suprisingly awkward to locate! My own, FAQs …

  • Null values in reports, what can I do?

    If you want to replace the null value with a blank entry this is easy to achieve with the isBlankWhenNull attribute of textField

    <textField isBlankWhenNull="true"> ... </textField>

    If you need to replace the null value with something else, you can do this directly in the report as shown below. Using the ternary operator the GROUP_NAME field is checked for a null, if it is null the text None is used instead.

    <textFieldExpression>(($F{GROUP_NAME} != null) ? $F{GROUP_NAME} : "None")</textFieldExpression>
  • How to add a row count?

    If you need a row count and don’t want to add unnecessary fields into the SQL statement you can use a variable. Straight after your field definitions include the following, assuming you have a field named USER_NAME in your fied definitions!

    <variable name="row_count" class="java.lang.Integer" calculation="Count">
        <initialValueExpression><![CDATA[new java.lang.Integer(0)]]></initialValueExpression>

    This can be used in the report as follow

        <reportElement x="0" y="0" width="30" height="20"/>
        <textFieldExpression class="java.lang.Integer"><![CDATA[$V{row_count}]]></textFieldExpression>
  • Highlight certain rows depending on the value of other data?

    If you need to highlight some text, the trick is to create two versions of the textField that displays it and use the <printWhenExpression> tag to determine which one displays the text. The below example highlight in red if the PASS_DATE field is null.

    <!-- main textField -->
        <reportElement x="466" y="0" width="228" height="20">
            <printWhenExpression>new Boolean($F{PASS_DATE} != null)</printWhenExpression>
        <textFieldExpression class="java.lang.String"><![CDATA[$F{USER_NAME}]]></textFieldExpression>
    <!-- highlight textField -->
        <reportElement x="466" y="0" width="228" height="20" forecolor="red">
            <printWhenExpression>new Boolean($F{PASS_DATE} == null)</printWhenExpression>
        <textFieldExpression class="java.lang.String"><![CDATA[$F{USER_NAME}]]></textFieldExpression>

JSTL Internationalisation

Some notes on how to get JSTL pages ready.


Inside a JSP page included on every other, for example a header jsp file.

<fmt:setLocale value="${param.locale}" scope="request" />
<fmt:setTimeZone value="${param.timeZone}" scope="request" />
<fmt:setBundle basename="Messages"/>

At your classpath root create a fallback localised file called in which to store key/value pairs. Files for other languages take the form of,, etc.

page.text.title=Page Title
page.text.message=Page Message
page.text.welcomeMessage=Welcome {0}
page.text.returnLink=<a href="{0}" title="Return">Return</a>


<h1>Page Title</h1>
<h1><fmt:message value="page.text.title"/></h1>

<h1>Welcome <c:out value="${}"/></h1>
<h1><fmt:message value="page.text.welcomeMessage"><fmt:param value="${fn:escapeXml("}/></fmt:message></h1>

Pull phpBB2 forum posts (basically a simple CMS)

phpBB2 is currently one of the most popular bulletin boards on the internet (yes, this statement is old, but the post is a repost of old content from my previous website).

Forum Powered Website

A forum is the most popular section of many websites so I was looking for a way to drive the website content from the forum. In the end I decided to write the following code to get topics from a forum which I could then display on other pages.

 * PHPBB2 extension to get posts from a forum.  This allows you to power a news sections of
 * a website by posting in the forum.  Any posts in reply to the topic are classed as
 * comments.
 * $Id$

define('IN_PHPBB', true);

$phpbb_root_path = 'forum/';
$phpEx = 'php';

include($phpbb_root_path . 'config.' . $phpEx);
include($phpbb_root_path . 'includes/constants.' . $phpEx);
include($phpbb_root_path . 'includes/db.' . $phpEx);
include($phpbb_root_path . 'includes/template.' . $phpEx);
include($phpbb_root_path . 'includes/functions.' . $phpEx);
include($phpbb_root_path . 'includes/bbcode.' . $phpEx);

// need template defined as the bbcode uses it
$template = new Template($phpbb_root_path . 'templates/Saphic');

function &getForumPosts($forum_id) {
  global $db;

  $posts_array = array();

  // get list of topics
  $topic_sql = 'SELECT t.topic_id, t.topic_first_post_id, t.topic_replies FROM ' . TOPICS_TABLE . ' t WHERE t.forum_id = ' . $forum_id . ' ORDER BY t.topic_time DESC';
  if (!($topic_result = $db->sql_query($topic_sql))) { 
    return $posts_text;
  if ($topics = $db->sql_fetchrowset($topic_result)) {
  foreach($topics as $topic_row) {
    // get post for topic
    $post_sql = 'SELECT p.post_time, pt.post_subject, pt.post_text, pt.bbcode_uid FROM ' . POSTS_TABLE . ' p, ' . POSTS_TEXT_TABLE . ' pt WHERE p.post_id = ' . $topic_row['topic_first_post_id'] . ' AND p.post_id = pt.post_id';
    if (!($post_result = $db->sql_query($post_sql))) {
    if ($posts = $db->sql_fetchrowset($post_result)) { 
    $post_row = $posts[0];  // should always have a result
    $text = bbencode_second_pass($post_row['post_text'], $post_row['bbcode_uid']);

    array_push($posts_array, array('topic_id' => $topic_row['topic_id'],
                                   'topic_replies' => $topic_row['topic_replies'],
                                   'post_time' => $post_row['post_time'],
                                   'post_subject' => $post_row['post_subject'],
                                   'post_text' => $text));

  return $posts_array;

In the pages for your actual website, you can include the file above and then do the following.

foreach(getForumPosts(13) as $post) {
  echo('<dt>' . date("jS F, Y", $post['post_time']) . '</dt>' . "n");
  echo('<dd>' . nl2br($post['post_text']) . '<br/>');
  echo($post['topic_replies'] . ' comment/s (<a href="forum/viewtopic.php?t=' . $post['topic_id'] . '">view</a>, <a href="' . $post['topic_id'] . '">add</a>)</dd>' . "n");