Author Archive

Kataweb News

My latest effort in web development is now online, its name is Kataweb News. It’s an italian news aggregator. Incoming news content from the main italian media is analyzed and keywords (Web 2.0 fanboys would say tags) are automatically extracted. Other features include user comments, a usable and standard-compliant design, so called tag clouds and contextualized RSS feeds.

Another main feature is decontextualized advertising (also known as spam), but Adblock can help with this kind of features.

Obviously the site makes heavy use of Gomba, Juseppe, the patched JSTL and the HTTP Headers Filter.

This is mainly a one-man project starting from the MySQL schema, to the application logic, up to the CSS style. I hope the site will be useful to real people and that it brings innovation to the italian web, which is rather depressing these days.

UPDATE: Here’s a list of reviews and comments about the site:

Multimedia and usability on the Web

Multimedia content on the Web is plagued by usability problems. I created this simple prototype for the company I work for, trying to demonstrate that browser plugins are not the way to go. The most seamless user experience is not the embedded (Windows) media player.

Let people choose or at least let the OS choose. Many users are able to configure a browser in order to use their favorite player. Operating systems provide carefully chosen defaults for the majority of people who are unable to tweak their system, a website can’t do better than that.

There’s no pragmatical or economical explanation for the crippled presentation of multimedia content, it’s just due to plain ignorance. Marketing people are scared of letting people directly access the streams because of advertising. Many had the brilliant idea to put banners aside the embedded player. Ads can be served much more nicely in the stream without even recurring to client-side scripting: ASX e RAM files are basically playlists, just put the ad in there. Then again this is almost always a problem due to the very advertising systems that were supposed to ease the work of marketers.

UPDATE: the prototype eventually became a real site called Kataweb Multimedia. Obviously the marketing people forced us to drop the use-your-own-player approach. Nevertheless I’m really happy since this is the first Kataweb site and probably the first site in any italian portal that validates. Wow! I’m turning into a web designer.

Copyleft wallpaper

A wallpaper I made with Inkscape is currently a Top rated on the Gnome Art website and has been downloaded by thousands of people. Wow! I’m turning into a graphic artist.

Here’s the SVG file, use it directly or open it with Inkscape and export it to the resolution you need.

HTTP Headers Filter

A Java Servlet Filter that sets HTTP headers.
Implementation of javax.servlet.Filter used to set HTTP headers. The filter parameters are treated as HTTP headers. The parameter name becomes the header name, while the parameter value becomes the header value. The parameter value may contain EL expressions. If the expression evaluates to a java.util.Date or a java.lang.Long object the header is considered to be a Date header and formatted according to the HTTP spec.

These are the implicit objects available to the EL context:

now
A java.util.Date object the represents the current time.

Init-params:

negativeMapping
A regular expression matching request URIs to be ignored. The URI is obtained using HttpServletRequest.getRequestURI(). See also the regular expression documentation

This is a typical usage example:

<filter>
  <filter-name>httpHeaders</filter-name>
  <filter-class>
    org.ft.servlet.filters.httpheaders.HTTPHeadersFilter
  </filter-class>
  <init-param>
    <param-name>Expires</param-name>
    <param-value>${now.time + 1000 * 60}</param-value>
  </init-param>
  <init-param>
    <param-name>Last-Modified</param-name>
    <param-value>${now}</param-value>
  </init-param>
</filter>
<filter-mapping>
  <filter-name>httpHeaders</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

Requirements

Download

Legal

This is Open Source software distributed under the Apache License Version 2.0.

Csound syntax highlight for Kate

I wrote a Csound Highlight Definition XML file for Kate. It only supports the CSD format. Just copy the XML file to ~/.kde/share/apps/katepart/syntax/. Kate is a great text editor, if you use Csound on Linux, give it a try.

UPDATE: Added support for ORC and SCO!

How to access a remote machine at work from home using SSH

I just found out how to mount the home directory of my work PC at home, bypassing the company firewall.

First of all password authentication is tedious and won’t work in batch scripts so we need to create a RSA key on the work pc:

ssh-keygen
scp ~/.ssh/id_rsa.pub [myhomeuser]@[homehost]

Now log at home and add the work pc public key to your authorized keys:

cat id_rsa.pub >> .ssh/authorized_keys2

Now let’s connect to the home pc from the machine at work using ssh.

ssh  -f -C -o BatchMode=yes -R [anyport]:localhost:22 -l [myhomeuser] -N [homehost]

The -R argument does the trick by forwarding to the work pc (port 22) all traffic on the loopback interface (on a given port) of your home computer. Refer to the SSH man for info.
-o BatchMode=yes makes the ssh client at work try to contact the remote server at home every 300 seconds in order to prevent the firewall from closing the connection. If you get a “Connection reset by peer” after a period of inactivity, try -o ServerAliveInterval=[seconds].

Let’s move to the home pc. In order to mount the remote pc on the filesystem you’ll need SSHFS, if you’re using Ubuntu follow this great How-to.

First let’s create a directory for the mount point:
mkdir /home/[myhomeuser]/workpc

Make sure the FUSE kernel module has been loaded:

sudo modprobe fuse

Now mount the work pc home directory:

sshfs -C -p [anyport] localhost:/home/[myworkuser] /home/[myhomeuser]/workpc

Make sure that the port number is the same specified in the ssh command at work.

If you need to unmount just type:

sudo umount /home/[myhomeuser]/workpc

Done. Now cd to ~/workpc and type one of the most satisfactory ls of your life.

UPDATE: What happens if any of the two machines reboots or the network goes down? The tunnel dies.
You may use this simple Bash script as a cronjob installed on the work pc. Thanks to Fabrizio for pointing this out!

#!/bin/bash

HOMEPC=[homehost]
HOMEUSER=[homeuser]
HOMEPORT=[homeport]
# Path of a file used to test the connection
HOMEFILE=[homefile]

ssh $HOMEUSER@$HOMEPC scp -P $HOMEPORT $HOMEFILE localhost:/tmp/
if [ $? != 0 ]; then
  echo Starting SSH tunnel at `date`
  ssh -f -C -N -o BatchMode=yes -R $HOMEPORT:localhost:22 -l $HOMEUSER $HOMEPC
fi

Type crontab -e and add something like this:

0,20,40 * * * * /home/[user]/tunnel.sh

Turning Blogger into a RESTful data source

I wrote a Blogger template that generates machine-readable XML.
This is great if you need to integrate a Blogger-based blog with the rest of your site.
I’m using XSLT to process the generated XML, but any programming or scripting language will do.

Here’s the Blogger template. I suggest you disable the “Enable float alignment” option in the “Formatting” tab to get cleaner data. Enjoy!

Juseppe, a simple JSP framework

Juseppe is a simple framework for JSP development. I wrote it to speed up my (and my colleagues’) work, but you can use it too. Juseppe is implemented as a Java Servlet Filter and meant to be used in a JSP 2.0 + JSTL environment.

Goals

Clean URIs

With Juseppe, your URIs will not reveal the underlying technology. This is both a security advantage and a wise naming design: when you’ll reimplement your site with a new technology chances are you’ll be able to preserve the old URIs and break no links. Your URIs will look like:

http://www.dumbnews.com/politics
http://www.dumbnews.com/article/4321

and not:

http://www.dumbnews.com/politics.jsp
http://www.dumbnews.com/article.jsp?id=4321

Site structure

Juseppe simplifies JSP development and mantainance by providing a navigation system among web application resources. Instead of hardcoding links and site sections inside JSPs, Juseppe puts the website structure in a freeform XML file. URIs are then mapped to XML nodes and to JSPs using XPath expressions. This makes adding and removing sections much easier than delving inside spaghetti JSP code.

This is a typical XML configuration:

<page name="." resource="/home.jsp" display="Homepage">
<page name="politics" resource="/politics.jsp" display="Politics"/>
<page name="technology" resource="/technology.jsp" display="Technology"/>
<page name="article" resource="/article.jsp"/>
</page>

Take a look to the demo!

The quickest way to grasp the concept behind this project is trying the sample webapp included in the distribution.

Starting a new web application from scratch

  1. Drop juseppe-x.x.x.war found in the binary distribution in your servlet container web application directory.

Using Juseppe in an existing web application

  1. Extract juseppe-x.x.x.war using the jar utility (or any other zip utility).
  2. Copy the libraries found in WEB-INF/lib to your application WEB-INF/lib directory.
  3. Copy WEB-INF/juseppe.xml to your application WEB-INF directory.
  4. Open WEB-INF/web.xml, then cut’n’paste the Juseppe Filter definition and mapping to your web.xml.
  5. Customize WEB-INF/juseppe.xml according to your website structure.
  6. Possibly customize Juseppe Filter init-params in WEB-INF/web.xml.

For reference documentation see the Javadocs included in the distribution.

Status

Juseppe is production ready. It is currently used on the following (italian) sites:

Legal

Juseppe is Open Source software distributed under the Apache License Version 2.0.

Requirements

Download

JSTL patch

This is a patched version of the Jakarta Standard Tag Library
which implements the JSTL 1.1 specification. This patch makes the XML tags run 100 times faster. I wrote almost no code, I just reverted the XPathUtil class to a previous version and managed to compile the whole thing.

Originally the Standard Taglib used the Jaxen XPath processor. With version 1.1 the project switched to Xalan, decreasing performance by a factor of 100. At my company we chose to use JSTL and we’re really happy about it. But our sites must work now, so I put together this patched version. I hope to be able to use the official version very soon. In the meanwhile, if you’re using JSTL in a production environment give this version a try.

I submitted this patch to the Standard Taglib developers but it was refused because it implies a dependency on Jaxen. Here’s the original thread on the taglibs-dev at jakarta.apache.org mailing list.

To install over an existing webapp just drop in the standard-*.*.*-patched.jar and remove standard.jar.
You also need jaxen-*.*.jar from the Jaxen project.

Requirements

Download

XSLT Servlet

This servlet transforms an XML document using an XSLT stylesheet. Probably there are other Servlet implementations of this kind, but I couldn’t find one with the features I need available under an Open Source license, so I wrote this one.

Features

  • the XML document and the stylesheet can be retrieved from the local webapp or from the network (using java.net).
  • Stylesheet is preloaded at startup and then periodically reloaded in the background in order to optimize performance.
  • JSP EL expressions can be used in the Servlet init params.
  • Parameters can be passed to the stylesheet.
  • XSLT output properties can be controlled by the Servlet.
  • Not tied to a specific XML parser or XSLT processor.
    This Servlet uses javax.xml.transform (aka TrAX) for XSLT processing.

This is a sample web.xml configuration:

<servlet>
  <servlet-name>myTransformation</servlet-name>
  <servlet-class>it.kataweb.xslt.servlet.XSLTServlet</servlet-class>
  <init-param>
    <param-name>xml</param-name>
    <param-value>http://domain.org/service?param=${param.myParam}</param-value>
  </init-param>
  <init-param>
    <param-name>xslt</param-name>
    <param-value>/WEB-INF/xslt/myStylesheet.xslt</param-value>
  </init-param>
  <init-param>
    <param-name>xsltReloadInterval</param-name>
    <param-value>60</param-value>
  </init-param>
</servlet>

    

For reference documentation see the Javadocs included in the distribution.

Legal

This Servlet is Open Source software distributed under the Apache License Version 2.0.

Requirements

Download