Good news, everyone! No, Futurama isn’t on the air, yet. But soon. Anyway, I’m still here, albeit a little busy. However, in one of those few late night things I do, I was able to finish up a little project. If you didn’t know, there’s a site that stores your icons and lets weblogs put icons on the comments, based on the author’s email. Gravatar.com provides your site with icons for all the people who comment on your weblog. This works by locally (on your site) generating an MD5 hash of the comment author’s email, and then creating an img tag with a source URL that points to gravatar.com and uses the hash to identify the author, and if the author has previously registered that email with gravatar, it will give back an 80×80 picture that was previously loaded by the author. The MD5 hash avoids the need for someone’s email address to leave your site, which I think it’s good.
I found this concept very interesting, and when I looked at the implementation page, I found out there’s very few java support, other than some code on how to create the MD5 and I realized this was a good opportunity to create a taglib. So here it is. jAvatar is a tag library that lets you include a gravatar icon for each of the comments on your weblog. To use it, you just need to add the javatar.jar to your webapp, and the taglib to your comment page. Here’s an example on how you can do it on your comments JSP page:
<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@taglib uri="http://javageek.org/files/taglib/javatar" prefix="javatar"%></span>
String email = "email@example.com";
<head><title>My JSP 'index.jsp' starting page</title></head>
This is a gravatar:
<javatar:image mail="<%= email %>" imgSize="100" styleClass="gravatar" rating="R" defaultImgUrl="http://mysite.com/img/defIcon.gif" borderColor="F0F"/>
Of course, the email should be the comment author’s email, and the tag should be put in whatever loop you have for showing your comments. I hope you like it.