De Tout Et De Rien

To content | To menu | To search

Tuesday, March 27 2007

Choix du type d'exception : Checked ou Unchecked

Petite règle qui peut aider au choix du type d'exception entre Checked et Unchecked :

Si l'appelant d'une méthode ne peut rien faire pour résoudre le problème quand une exception est levée, alors rendez cette exception Unchecked [Via]

Pour rappel, une exception est dite Checked quand elle est déclaré dans une clause throws d'une méthode, ce qui permet au compilateur d'effectuer la vérification du traitement des exceptions lors de la compilation. Les exception dites Unchecked, héritent de RuntimeException et servent surtout à signaler des erreurs pour lesquelles la poursuite de l'exécution est difficile, voire impossible.

PS : Un peu de lecture pour les puristes.

Monday, June 5 2006

Babies in Eclipse

When browsing the Eclipse SWT website, you can be a bit surprised... Here is what you can see if you read the SWT 3.2 Plan carrefully :

Eclipse SWT R3.2 Plan

Needless to say, that these babies won't be part of the download...

Tuesday, May 16 2006

JDK 1.5 source code under Eclipse on MacOS X

There is one thing pretty annoying with the Apple Java Development Kit : you don't have access to the source code under . Why ? Simply because doesn't ship it with the JDK and therefore Eclipse cannot discover it. So, what can I do if I want to have the source code linked to the JRE library as it is done automatically under Windows ?

Update 2006-05-20 : Thanks to Cedrik Lime (see the first comment), here is a very simple solution :

  • Go to the Apple Developer Connection, in the downloads page.
  • Download the J2SE 5.0 Release 4 Developer Documentation package. You may have to log on the ADC. Registration is free if you don't have an account.
  • Once downloaded, install it.
  • In Eclipse, go to Window menu and open the Preferences... dialog.
  • Go to Java/Installed JRE panel. You should see a list of the currently detected MacOS X JVMs.
  • Click on the Add... button to add a new JRE definition.
  • Type JDK 1.5.0 in the JRE name field (or whatever you want).
  • Click on the Browse... button and selec the /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home folder.
  • A list a jars must show up. A part of them should have them source attachement filed.
  • Click on the Ok button.
  • Click on the Ok button.

That's it. You have an Eclipse that can show you the JDK source code when you need it. Of course, you don't have access to all the source because, doesn't ship all the JDK source code.

Friday, March 24 2006

Easy search with Javamail

When dealing with message folder, the temptation is strong to re-invent the wheel when it comes to make a search through its messages. One evident solution is to grab all the messages, test against the criteria, and if the message matches, store it for further need.

Since JavaMail 1.1, a search facility has been provided. It is located in the jaxax.mail.search package. To make a complex search, you just create the needed search terms and compose them with a AND or OR operator. The next step is to call the magic method on the message folder : Folder.search(SearchTerm term) that returns an array of Message instance.

It may be look weird to add such complexity to a simple search in a mail folder, but when it comes to term composition, this solution is the most flexible and above all, when you look at your code, the nicest one.

Friday, January 13 2006

Skype buttons for Confluence : the sequel

In a , I have described how to create a simple macro to have a SkypeMe button in Wiki.

To go a step further, here is a more complete macro that covers all the cases offered by : this Confluence macros is based on the documentation.

Here is the skype macro. It takes two parameter :

  1. action : the skype action to perform (mandatory). Valid values are : "call", "add", "chat", "userinfo", "voicemail" and "sendfile".
  2. color : the color of button (optional). Valid values are : "blue" and "green". When omitted, the color is "blue".
#if($param1)
  #set($imagecolor=$param1)
#else
  #set($imagecolor="blue")
#end
<a href="skype:$generalUtil.escapeXml($body)?$param0">
#if($param0 == "call")
  #set($imagefile="http://download.skype.com/share/skypebuttons/buttons/call_${imagecolor}_transparent_70x23.png")
#end
#if($param0 == "add")
  #set($imagefile="http://download.skype.com/share/skypebuttons/buttons/add_${imagecolor}_transparent_118x23.png")
#end
#if($param0 == "chat")
  #set($imagefile="http://download.skype.com/share/skypebuttons/buttons/chat_${imagecolor}_transparent_97x23.png")
#end
#if($param0 == "userinfo")
  #set($imagefile="http://download.skype.com/share/skypebuttons/buttons/userinfo_${imagecolor}_transparent_108x23.png")
#end
#if($param0 == "voicemail")
  #set($imagefile="http://download.skype.com/share/skypebuttons/buttons/voicemail_${imagecolor}_transparent_129x23.png")
#end
#if($param0 == "sendfile")
  #set($imagefile="http://download.skype.com/share/skypebuttons/buttons/sendfile_${imagecolor}_transparent_98x23.png")
#end
<img src="$imagefile" alt="$param0" border="0"/>
</a>

Here is the macro in action

Use in Confluence Overview
{skype:call}steve.jobs{skype} call
{skype:add|green}steve.jobs{skype} add
{skype:chat}steve.jobs{skype} chat
{skype:userinfo|green}steve.jobs{skype} userinfo
{skype:voicemail}steve.jobs{skype} voicemail
{skype:sendfile|green}steve.jobs{skype} Send File

Wednesday, December 7 2005

Tapestry without specification files ?

In , a page or a component development usally involves three elements : a template file, a specification file and Java class. It is the most common case (even if there are some cases where one or two of theses elements are not used).

What I find annoying in the Tapestry specification files is :

  • Inheritance : pages or components class can inherit but not their specifications. It leads to duplication of informations.
  • Composition : pages or components class can be composed but not specifications. It leads to duplication of informations.
In short, it really bugs me not to be able to apply Java concepts to both class and specification files.

As I am exploring the and its annotations, I wonder if 4.0 could handle components and pages definitions without specification files (the .page or .jwc files), only by using Java annotations. The basic idea behing is to move the content of the specification file into Java class by using annotations. Let's take an example :

The following specification part :

<component id="select" type="DirectLink">
    <binding name="listener" value="listener:makeGuess"/>
    <binding name="parameters" value="letterForGuessIndex"/>
    <binding name="disabled" value="letterGuessed"/>
</component>
will become the following annotations :
@Component(type = "DirectLink", bindings = { "listener=listener:makeGuess", "parameters=letterForGuessIndex", "disabled=letterGuessed" })
public abstract DirectLink getSelect();
and so on. At the end, all the content of the specification file will be translated into annotations.

To go further and to illustrate the general concept on a sample application, I took application and convert all the pages and components using the method described above. It is available for download (please note that a JDK 5.0 is required to run this application), source code is included (under public domain of course). In short, I am using an ISpecificationDelegate implementation that can handles specification-less pages and components.

As a conclusion, I will said that without specification files, the development under Tapestry can benefit from :

  • True inheritance. Annotations are inherited by sub-classes so pages or components are clearer and simpler.
  • True composition. As most annotations are put on abstract methods, they can be gathered in interfaces. Creating a page can be as simple as compositing interfaces on top of abstract class.
  • Less error-prone. The specification file can be a source of error as it must be in sync with the template and the class.

This development method as also its drawbacks :

  • Class have more lines and mostly reference components through abstract getters. This can be addressed by factorisation and use of inheritance and composition.
  • Annotation syntax is hardier to read than its XML counterpart.
  • JDK 5.0 is required to support this feature.

I am requesting feedback from the community about this approach. Is it a way to reduce the development cycle in the KISS philosophy or is it just a overuse of the Java annotations ?

Monday, December 5 2005

Hyperlink without link in Confluence

If you are a user, here is a trick to display hyperlinks without generating links within Confluence pages. It is a simple macro that takes the hyperlink and skip the link creation. The result is an hyperlink that is not clickable. It is very useful to avoid unwanted click on the hyperlink.

To define the macro, log into Confluence as an administrator and select the "User Macro" menu on the left. Select "Create Macro" and type the following :

Name nolink
Macro Has Body yes
Template
$body

Use the macro as following :

Wiki Source
Go to visit {nolink}http://www.atlassian.com/{nolink} and enjoy !!!
Result
Instead of
Visit http://www.atlassian.com/ and enjoy !!!
you will see
Visit http://www.atlassian.com/ and enjoy !!!

Hangman Application for Tapestry 4.0

I have updated the Hangman application for Tapestry 4.0. It is now running with Tapestry 4.0b13 and Hivemind 1.1. Of course, source code is included, released in the public domain et feedback is welcomed.

For those who are insterested, my initial port is here.

Tuesday, November 22 2005

Conluence 2.0 is out

Atlassian has released the version 2.0 of Confluence, a profressional Wiki software. The upgrade from the version 1.4.4 is done smoothly and the only configuration needed is the setup of the data repository path.

Once logged-in, two things catch the eyes : the Favourite Pages list and the Feed Builder button. You can now mark your prefered pages and they are listed on your dashboard. The Feed Builder allows to select what your feed will be : space choice, type of content and feed format.

The best feature of Confluence 2.0 is the Wysiwyg editor used to edit pages. It is truly easy to use and very smooth. And of course, it works on Internet Explorer, Mozilla Firefox and Apple Safari without any glitch. Only macros and plugins are not rendered inside it. But for every day editing, it is faster than the Wiki syntax.

Confluence 2.0 is a truly profressional product and greatly simplify the administration : installation, upgrade, backup and restoration are mostly done through a Web interface. A must have Wiki software.

Thursday, September 8 2005

SkypeMe button in Confluence

If you are a Confluence user, here is a trick to display SkypeMe buttons within Confluence pages. It is a simple macro that takes the Skype pseudo and set up a button around it. The result is an inline image which starts a Skype call when clicked (of course you need Skype installed on your machine).

To define the macro, log into Confluence as an administrator and select the "User Macro" menu on the left. Select "Create Macro" and type the following :

Name skypeme
Macro Has Body yes
Template
<a href="callto://$generalUtil.escapeXml($body)">
<img src="http://goodies.skype.com/graphics/skypeme_btn_small_green.gif" border="0">
</a>

Use the macro as following :

Wiki Source Result
{skypeme}bill.gates{skypeme}

Update (2005-12-23) : Charles Miller has added this macro to the Confluence Site. I have modified the code to reflect his advice : using the $generalUtil.escapeXml() function to avoid cross-site scripting attacks. Thank to you Charles !

- page 1 of 2