Java

The Java language

JSP Quoting rules

The Eclipse WTP project contains a JSP editor which has trouble with the JSP quote escaping rules. As a way to learn about WTP (with the ultimate goal of replacing the piece-of-shit publishing framework in WTP) I set out to fix this. These documents serve as a set of reminders through the process, and may perhaps help other people that want to hack the source. I found some helpful documents on the internals of the WTP SSE editors here and here.

Eclipse Bookmarks plugin

I just created my second Eclipse plugin which adds several bookmark methods to the editor. The "default" bookmark methods of Eclipse ask for a name and this is often not very useful. The code here adds bookmarks a la "Borland" and bookmarks a la "JCreator". The code has the following options which can all be bound/rebound with the keys dialog under the "Edit" category:

  • Add a numbered bookmark at the cursor: Alt+[digit]. This creates a quick bookmark with the specified number using a "single" keypress. Only one bookmark of the given number can be present in the workspace. Setting the same number bookmark again will clear the earlier instance.
  • Goto a numbered bookmark: Alt+Shift+[digit]. Moves to the bookmark as it was set using Alt+[digit].
  • Toggle Bookmark: Ctrl+B. This drops an unnamed bookmark at the current location. Pressing Ctrl+B again releases the bookmark at that location again. This is often used with "Goto next bookmark" and "Goto previous bookmark".
  • Goto next bookmark in file: Ctrl+N. This locates the next bookmark in the current file and moves there.
  • Goto previous bookmark in file: Ctrl+P. This locates the previous bookmark in the current file and moves there. warning: the Ctrl+P binding is a suggestion only; since Ctrl+P is currently assigned you must add your own key binding using Window -> Preferences -> General -> Keys.

I'll be posting the source of the plugin later on; the plugin can be installed using the update site http://eclipse.etc.to/updates/

Eclipse plugin programming quick tips

Getting the IWorkbench

To get the IWorkbench from a plugin use IWorkbench wb = PlatformUI.getWorkbench();

Getting the IWorkspace

The workspace can be gotten using ResourcesPlugin.getWorkspace();

Getting the "root" IResource of the workspace

This can be gotten from IWorkspace.getRoot()

Getting the "active" editor from an Action/command

public ITextEditor getTextEditor()
{
IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
IWorkbenchPage page = win.getActivePage();
IEditorPart editor = page.getActiveEditor();
return (ITextEditor) editor;
}

Java Advanced Imaging: resizing tiffs

The Java Advanced Imaging toolkit contains lots of stuff to work with images. The documentation leaves a lot to be desired though: it is often factually incorrect due to version differences, and examples for common operations are hard to come by.

I needed a way to "resize" monochrome tiffs. The default "scale" operation leaves the result as a black-and-white image, and this results in a reduced image with a lousy quality. To get a better quality the image must be converted to grayscale and then rescaled using a resampler filter.

Most examples tell you to use either the "ColorConvert" or the "BandCombine" JAI operations. But sadly all of the examples I tried threw exceptions at one part or another.

The Java cookbook

This part of the site contains short pieces on doing stuff with Java, JSP and other Java-related stuff..

Common misconceptions about JSP tag librari

There are some common misconceptions on how tag handlers work, and what methods get called at what time and when. This document contains a collection of pitfalls you can encounter when writing tag libraries.

release()

Misconception: release() gets called at the end of a page. This is not true! Some idiot writing JSP 1.2 decided that release should only be called just before the tag handler is released to the garbage collector! This means that when a tag handler gets cached by a container (like Tomcat's Jasper engine does by default) the release() method gets called at most once(!) even if the tag gets reused many times on several pages! There is currently NO failsafe way to clean up your tag handler between invocations. The best you can do is to cleanup at your own known exit points. This clearly sucks, but what can you do..

Syndicate content