Over a million developers have joined DZone.

Rendering New Content Types in the Lobo Java Web Browser

DZone's Guide to

Rendering New Content Types in the Lobo Java Web Browser

· Java Zone ·
Free Resource

Download Microservices for Java Developers: A hands-on introduction to frameworks and containers. Brought to you in partnership with Red Hat.

Yesterday we saw how easy it is to get started extending Lobo's Java Web Browser. However, now that we've got the "hello world" scenario under our belt... let's get serious. Let's create a plugin that provides a new Lobo clientlet. A clientlet renders content in the Lobo browser. For example, HTML and Java are already rendered, to varying degrees of sophistication. How would one add a renderer for a new file type? Read on for a full explanation.

Start off by reading the Clientlets in Lobo page and you will have a lot of information, with some significant gaps. First of all, exactly as described in that document, I created a Clientlet for rendering my content:

public class TextClientlet implements Clientlet {

public void process(ClientletContext context) throws ClientletException {
try {
InputStream in = context.getResponse().getInputStream();
try {
String text = IORoutines.loadAsText(in, "ISO-8859-1");
JTextArea textArea = new JTextArea(text);
JScrollPane pane = new JScrollPane(textArea);
} finally {
} catch (IOException ioe) {
throw new ClientletException(ioe);

So, based on a context received from somewhere, a Swing component is created for rendering our content. Here it is very rudimentary, since it is just an example. But we would typically use the class above for parsing the received content and then deciding how to color it, for example. Here, no styling is done at all. The received content is simply put into a text area, which is put into a scrollpane, which in turn is passed to ClientletContext.setResultingContext , for display in the browser. Also note the org.lobobrowser.util.io.IORoutines class, which provides convenience methods for loading our content. If you want to use this class, you will need the lobo.jar on your classpath, in addition to the lobo-pub.jar, which was mentioned yesterday.

That's all well and good. But, how to pass content to the Clientlet? And how to determine which content to pass? Let's say, for the sake of argument, that we want to render Manifest files in the Lobo browser. By default, when you try to open a Manifest file, you will get this message:

So, we need to have Manifest files recognized and, when they are recognized, we want to have the Clientlet above render the Manifest file's content. Yesterday we looked at the NavigatorExtension class, which is the "main class" for a Lobo plugin, that is, its entry point. At that point, we only looked at the NavigatorExtension.windowOpening method. This time, we need to work with the NavigatorExtension.init method. This is where the Clientlet page is pretty scanty in details: "Currently only extensions (plugins) can set up clientlets in Lobo, by calling addClientletSelector when the extension is initiliazed."

So, after studying the related Javadoc (which is all pretty good, if you piece the bits together), I came up with this in my NavigatorExtension.init method:

private ClientletSelector selector;
private TextClientlet textClient;

public void init(final NavigatorExtensionContext ctx) {
selector = new ClientletSelector() {
public Clientlet select(ClientletRequest request, ClientletResponse response) {
if (response.matches("", new String[]{".mf"})){
textClient = new TextClientlet();
return textClient;
return null;
public Clientlet lastResortSelect(ClientletRequest arg0, ClientletResponse arg1) {
return null;

The most interesting line is line 8. Here we can EITHER specify a MIME type OR a (list of) file extension(s). So, in this case, I put a file extension there, that is, the file extension of Manifest files. By the way, I challenge you to find the above snippet anywhere online (or, anywhere else). It's the bit of magic that connects the Lobo plugin's main class to the clientlet that will render the Manifest file.

And that's all you need. Now you're good to go. Remembering the properties file discussed previously, compile the plugin, put the JAR in the distro's ext folder, and when you restart the browser, you will be able to open Manifest files in the browser:

Of course, instead of a Manifest file, you could have anything else. Maybe JavaFX, for example.


Download Building Reactive Microservices in Java: Asynchronous and Event-Based Application Design. Brought to you in partnership with Red Hat


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}