Previous | Next | Trail Map | Getting Started


The "text/plain" Content Handler

Note: This page reflects the 1.0 Alpha 3 release of HotJava and Java. It will be updated for the Beta release of HotJava.

By following the steps on this page, you can create and use a content handler. Content handlers are Java programs that HotJava loads when it needs to interpret a particular MIME type/subtype combination. Some examples of MIME type/subtype combinations are text/plain, text/richtext, image/gif, and so on. (You can download the official list of MIME types.) When you've followed all the steps, your directory (folder) structure should look something like this:

Create directories

Create the directory structure shown in the figure above: classes/net/www/content/text.

By convention, the directory structure starts with a directory named classes. The next three directories must be named as shown (net/www/content). The final directory must have the same name as the MIME type of the data. In this case, this is "text". In the next step, you'll create a Java source file named after the MIME subtype of the data ("plain").

Create a Java source file for the content type

In the text directory, create a file named plain.java with these contents. This file defines a class named plain that's a subclass of ContentHandler (a class in the net.www.html package). The name of each ContentHandler subclass must match the name of the MIME subtype it handles [or Generic if it handles all subtypes of the type? (not implemented yet)].

Compile the Java source file

Compile the content handler using the Java compiler.

If compilation succeeds, the compiler creates a file named plain.class. If compilation fails, make sure you typed in and named the program exactly as shown above.

Set the CLASSPATH environment variable

Set the CLASSPATH environment variable to include the classes directory, so that HotJava can find the content handler.

Turn off any special mailcap handling of text/plain

If you've used a mailcap file to specify special handling of the text/plain MIME type/subtype, you need to turn off that special handling, so that HotJava will use your content handler instead.

Start HotJava

Even if HotJava is already running, you need to quit and restart it so that it can read the new value of the CLASSPATH environment variable and (if appropriate) reread the mailcap file.

Load the content handler

The content handler is automatically loaded the first time you visit a plain/text document.

Load the content handler by viewing a plain text document, such as this one. You should see the contents of the file in the browser, followed by this text:

-- This closing message brought to you by your plain/text
content handler. To remove this content handler, delete the
net.www.content.text.plain class from your class path.

Now what?

Now you can either:


Previous | Next | Trail Map | Getting Started