Over a million developers have joined DZone.
Platinum Partner

How to Add Syntax Coloring for XML in the Lobo Java Web Browser

· Java Zone

The Java Zone is brought to you in partnership with ZeroTurnaround. Discover how you can skip the build and redeploy process by using JRebel by ZeroTurnaround.

Yesterday we explored the general approach by which plugins can be created for the rendering of new content types in Lobo's Java Web Browser. Today, let's take those general principles a step further and... color the syntax of XML shown in the Lobo browser. We will start by identifying the application/xml and text/xml MIME types and then integrate Batik's XML Editor, created by Tonny Kohar, into the browser. So, when you finish this article, you will have first class XML support for the Lobo browser.

Normally, when you open an XML file in the Lobo browser, you find that the XML is handled as plain text. However, the fact that you are able to open an XML file at all indicates that there must be a clientlet that handles XML (otherwise you'd get an error message as shown yesterday in the first illustration of the Manifest article). Nevertheless, I found that the plugin I created overwrites, somehow, the clientlet that already handles XML files. And the priority in the properties file has nothing to do with it, because I tried all different levels with the same outcome. So, I don't exactly understand how come mine overwrites the existing clientlet, but the fact that it does so is enough for me.

Hence, this is how an XML file is normally rendered:

So, the first step, as yesterday, is to create a new clientlet when NavigatorExtension.init identifies the XML MIME types:

private ClientletSelector selector;
private XmlClientlet xmlClient;

public void init(final NavigatorExtensionContext ctx) {
selector = new ClientletSelector() {

public Clientlet select(ClientletRequest request, ClientletResponse response) {
if (response.matches("text/xml", new String[]{""}) ||
response.matches("application/xml", new String[]{""})) {
xmlClient = new XmlClientlet();
return xmlClient;
return null;

public Clientlet lastResortSelect(ClientletRequest arg0, ClientletResponse arg1) {
return null;

Above, lines 9 and 10 identify our XML MIME types. Then I copied the whole content of the XML Editor from Batik's org.apache.batik.util.gui.xmleditor package. Now that I had the XML Editor in my sources, I was able to define the rendering, in my Clientlet definition, which is instantiated when the XML MIME type is identified:

public class XmlClientlet implements Clientlet {

public void process(ClientletContext context) throws ClientletException {
try {
InputStream in = context.getResponse().getInputStream();
try {
String text = IORoutines.loadAsText(in, "ISO-8859-1");
JEditorPane xmlEditorPane = new JEditorPane();
XMLEditorKit editorKit = new XMLEditorKit();
xmlEditorPane.setEditorKitForContentType(XMLEditorKit.XML_MIME_TYPE, editorKit);
Font defaultFont = new Font("Monospaced", Font.PLAIN, 12);
JScrollPane pane = new JScrollPane(xmlEditorPane);
} finally {
} catch (IOException ioe) {
throw new ClientletException(ioe);

At this stage, my plugin's sources are as follows:

I then ran the browser, with my newly created JAR in the distro's ext folder, and now XML files look as follows:

If you want to take the plugin for a spin, here it is: LoboXMLClientletPlugin.jar . Put it in the Lobo distro's ext folder and then start the Lobo browser. Then open an XML file (either online or locally on disk)... and let me know if it works for you!


The Java Zone is brought to you in partnership with ZeroTurnaround. Discover how you can skip the build and redeploy process by using JRebel by ZeroTurnaround.


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

{{ parent.tldr }}

{{ parent.urlSource.name }}