<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
<article id="JavaHelp">
  <articleinfo>
    <title>JavaHelp</title>
    <author>
      <firstname>Ashley</firstname>
      <othername>J.S</othername>
      <surname>Mills</surname>
      <affiliation>
        <address><email>ashley@ashleymills.com</email></address>
      </affiliation>
    </author>

    <copyright>
      <year>2005</year>
      <holder role="mailto:ashley@ashleymills.com">The University Of Birmingham</holder>
    </copyright>
  </articleinfo>

  <sect1 id="JavaHelp-Introduction"><title>Introduction</title>
    <para>
      JavaHelp is a standard extension to the J2SE programming environment available from Sun. It provides the developer with a help interface written entirely in Java. The help interface looks like this:
    </para>

    <mediaobject>
      <imageobject>
        <imagedata fileref="files/images/javahelpinterface.png" format="PNG" align="center"/>
      </imageobject>
      <textobject><phrase>The JavaHelp interface showing table of contents</phrase></textobject>
    </mediaobject>

    <para>
      The left pane contains three tabs, the first, as shown above, contains the table of contents, the second contains the index and is shown below: 
    </para>

    <mediaobject>
      <imageobject>
        <imagedata fileref="files/images/javahelpindex.png" format="PNG" align="center"/>
      </imageobject>
      <textobject><phrase>The JavaHelp interface showing index</phrase></textobject>
    </mediaobject>

    <para>
      The third tab contains an interface to a search engine that allows one to search the help documentation:
    </para>

    <mediaobject>
      <imageobject>
        <imagedata fileref="files/images/javahelpsearch.png" format="PNG" align="center"/>
      </imageobject>
      <textobject><phrase>The JavaHelp interface showing search capability</phrase></textobject>
    </mediaobject>
  </sect1>

  <sect1 id="JavaHelp-Conceptual-Overview"><title>Conceptual Overview</title>
    <sect2 id="JavaHelpConceptual-Overview-Components"><title>Components</title>
      <para>
        In order to illustrate an overview of the system, a real, but very simple example will be used. There are six core components to the JavaHelp system:
      </para>

      <sect3 id="JavaHelp-Conceptual-Overview-Components-Docs"><title>The documentation</title>
        <para>
          The first is the documentation itself which is written in HTML 3.2, this usually spans over many different files and contains certain special elements that are used by the JavaHelp system, checkout the files <ulink url="files/index.html">index.html</ulink> and <ulink url="files/ar01s02.html">ar01s02.html</ulink>, these were automatically generated using an XSLT tool from an <acronym>XML</acronym> DocBook document.
        </para>
      </sect3>
  
      <sect3 id="JavaHelp-Conceptual-Overview-Components-Helpset"><title>The HelpSet file (jhelpset.hs)</title>
        <para>
          The second component is the HelpSet file, this contains information about the whole help system and is the file read by the HelpViewer when the help system is loaded by an application. The HelpSet file that corresponds to the <acronym>HTML</acronym> pages linked to above is shown below:
        </para>
  
        <programlisting>
  &lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot; standalone=&quot;no&quot;?&gt;
  &lt;!DOCTYPE helpset PUBLIC &quot;-//Sun Microsystems Inc.//DTD JavaHelp HelpSet Version 1.0//EN&quot; &quot;http://java.sun.com/products/javahelp/helpset_1_0.dtd&quot;&gt;
  &lt;helpset version=&quot;1.0&quot;&gt;
    &lt;title&gt;Title&lt;/title&gt;
    &lt;maps&gt;
      &lt;homeID&gt;top&lt;/homeID&gt;
      &lt;mapref location=&quot;jhelpmap.jhm&quot;/&gt;
    &lt;/maps&gt;
    &lt;view&gt;
      &lt;name&gt;TOC&lt;/name&gt;
      &lt;label&gt;Table Of Contents&lt;/label&gt;
      &lt;type&gt;javax.help.TOCView&lt;/type&gt;
      &lt;data&gt;jhelptoc.xml&lt;/data&gt;
    &lt;/view&gt;
    &lt;view&gt;
      &lt;name&gt;Index&lt;/name&gt;
      &lt;label&gt;Index&lt;/label&gt;
      &lt;type&gt;javax.help.IndexView&lt;/type&gt;
      &lt;data&gt;jhelpidx.xml&lt;/data&gt;
    &lt;/view&gt;
    &lt;view&gt;
      &lt;name&gt;Search&lt;/name&gt;
      &lt;label&gt;Search&lt;/label&gt;
      &lt;type&gt;javax.help.SearchView&lt;/type&gt;
      &lt;data engine=&quot;com.sun.java.help.search.DefaultSearchEngine&quot;&gt;JavaHelpSearch&lt;/data&gt;
    &lt;/view&gt;
  &lt;/helpset&gt;</programlisting>
  
        <para>
          It contains information like the location of the map file, explained next, and view information which specifies information about the types of view that the Help viewer should display and how it should display them.
        </para>
      </sect3>
  
      <sect3 id="JavaHelp-Conceptual-Overview-Components-MapFile"><title>The JavaHelp map file (jhelpmap.jhm)</title>
        <para>
          The third component of the JavaHelp system is the JavaHelp map file. The map file for the project under discussion is shown below:
        </para>
  
        <programlisting>
  &lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot; standalone=&quot;no&quot;?&gt;
  &lt;!DOCTYPE map PUBLIC &quot;-//Sun Microsystems Inc.//DTD JavaHelp Map Version 1.0//EN&quot; &quot;http://java.sun.com/products/javahelp/map_1_0.dtd&quot;&gt;
  &lt;map version=&quot;1.0&quot;&gt;
    &lt;mapID target=&quot;Simple&quot; url=&quot;index.html&quot;/&gt;
    &lt;mapID target=&quot;Simple.Introduction&quot; url=&quot;index.html&quot;/&gt;
    &lt;mapID target=&quot;Simple.Explanation&quot; url=&quot;ar01s02.html&quot;/&gt;
    &lt;mapID target=&quot;Simple.Explanation.Files&quot; url=&quot;ar01s02.html&quot;/&gt;
    &lt;mapID target=&quot;Simple.Explanation.Cheater&quot; url=&quot;ar01s02.html&quot;/&gt;
    &lt;mapID target=&quot;id328078&quot; url=&quot;ar01s02.html#cheating&quot;/&gt;
  &lt;/map&gt;</programlisting>
  
        <para>
          The map file &quot;map&quot;s the id's used in the documentation to the HTML page or position in a HTML page they correspond to.
        </para>
      </sect3>
  
      <sect3 id="JavaHelp-Conceptual-Overview-Components-TocFile"><title>The JavaHelp table of contents file (jhelptoc.xml)</title>
        <para>
          The fourth component of the JavaHelp system is the JavaHelp table of contents file, the TOC file for the project under discussion is shown below:
        </para>
  
        <programlisting>
  &lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot; standalone=&quot;no&quot;?&gt;
  &lt;!DOCTYPE toc PUBLIC &quot;-//Sun Microsystems Inc.//DTD JavaHelp TOC Version 1.0//EN&quot; &quot;http://java.sun.com/products/javahelp/toc_1_0.dtd&quot;&gt;
  &lt;toc version=&quot;1.0&quot;&gt;
    &lt;tocitem target=&quot;Simple&quot; text=&quot;Title&quot;&gt;
      &lt;tocitem target=&quot;Simple.Introduction&quot; text=&quot;Introduction&quot;/&gt;
      &lt;tocitem target=&quot;Simple.Explanation&quot; text=&quot;Explanation&quot;&gt;
        &lt;tocitem target=&quot;Simple.Explanation.Files&quot; text=&quot;Lots of files&quot;/&gt;
        &lt;tocitem target=&quot;Simple.Explanation.Cheater&quot; text=&quot;Cheating&quot;/&gt;
      &lt;/tocitem&gt;
    &lt;/tocitem&gt;
  &lt;/toc&gt;</programlisting>
  
        <para>
          The toc element specifies the titles that should be used for each of the sections in the documentation as indicated by the id's which were mapped to the HTML files by the map file.
        </para>
      </sect3>
  
      <sect3 id="JavaHelp-Conceptual-Overview-Components-IndexFile"><title>The index file (jhelpidx.xml)</title>
        <para>
          The fifth component of the JavaHelp system is the index file. The index file for the project under discussion is shown below:
        </para>
  
        <programlisting>
  &lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot; standalone=&quot;no&quot;?&gt;
  &lt;!DOCTYPE index PUBLIC &quot;-//Sun Microsystems Inc.//DTD JavaHelp Index Version 1.0//EN&quot; &quot;http://java.sun.com/products/javahelp/index_1_0.dtd&quot;&gt;
  &lt;index version=&quot;1.0&quot;&gt;
    &lt;indexitem text=&quot;cheater&quot; target=&quot;id328078&quot;/&gt;
  &lt;/index&gt;</programlisting>
  
        <para>
          This maps any index terms to particular IDs which are in turn mapped to HTML pages via the map file.
        </para>
      </sect3>

      <sect3 id="JavaHelp-Conceptual-Overview-Components-SearchData"><title>The search data</title>
        <para>
          The sixth component of the JavaHelp system is the search data, generated like this:
        </para>

        <screen><command>jhindexer</command> *.html</screen>

        <para>
          Which generates the directory <filename>JavaHelpSearch</filename> which is referenced in <link linkend="JavaHelp-Conceptual-Overview-Components-Helpset">jhelpset.hs</link>. Note that the reference in <filename>jhelpset.hs</filename> refers to the <filename>JavaHelpSearch</filename> directory directly because it is in the same directory but that this could theoretically be placed anywhere on the local system as long as the reference reflected the location. The example below uses the search data to create its search engine.
        </para>
      </sect3>
    </sect2>

    <sect2 id="JavaHelpConceptual-Overview-Example"><title>Example</title>
      <para>
        The various components of the JavaHelp system have been shown, not all of them are compulsory, one may choose whether or not to include index information for example. The JavaHelp documentation illustrated in the past few paragraphs is shown in the JavaHelp viewer below:
      </para>

      <mediaobject>
        <imageobject>
          <imagedata fileref="files/images/javahelpforexample.png" format="PNG" align="center"/>
        </imageobject>
        <textobject><phrase>JavaHelp system discussed showing initial state.</phrase></textobject>
      </mediaobject>
  
      <mediaobject>
        <imageobject>
          <imagedata fileref="files/images/javahelpforexampleindex.png" format="PNG" align="center"/>
        </imageobject>
        <textobject><phrase>JavaHelp system discussed showing index term.</phrase></textobject>
      </mediaobject>
  
      <para>
        This can be instantiated very easily from within Java, the program used to instantiate the JavaHelp viewer shown above is shown below:
      </para>
  
      <programlisting>
// Import the javahelp files.
import javax.help.*;
import java.net.URL;
import javax.swing.*;
public class JavaHelpTest {
   public static void main(String args[]) {
      JHelp helpViewer = null;
      try {
         // Get the classloader of this class.
	      ClassLoader cl = JavaHelpTest.class.getClassLoader();
         // Use the findHelpSet method of HelpSet to create a URL referencing the helpset file.
         // Note that in this example the location of the helpset is implied as being in the same
         // directory as the program by specifying &quot;jhelpset.hs&quot; without any directory prefix,
         // this should be adjusted to suit the implementation.
	      URL url = HelpSet.findHelpSet(cl, &quot;jhelpset.hs&quot;);
         // Create a new JHelp object with a new HelpSet.
         helpViewer = new JHelp(new HelpSet(cl, url));
         // Set the initial entry point in the table of contents.
         helpViewer.setCurrentID(&quot;Simple.Introduction&quot;);
	   } catch (Exception e) {
	      System.err.println(&quot;API Help Set not found&quot;);
     	}

      // Create a new frame.
      JFrame frame = new JFrame();
      // Set it's size.
      frame.setSize(500,500);
      // Add the created helpViewer to it.
      frame.getContentPane().add(helpViewer);
      // Set a default close operation.
      frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
      // Make the frame visible.
      frame.setVisible(true);
   }
}</programlisting>

      <para>
        The <emphasis>JHelp</emphasis> object extends <emphasis>javax.swing.JComponent</emphasis>, this is why it can be added directly to a frame. The JavaHelp API comes with JavaHelp and can be viewed online at:
      </para>

      <para>
        This is as far as this tutorial is going to go, I have provided enough information for a normal person to be able to get going with JavaHelp and links to find out more information.
      </para>
    </sect2>
  </sect1>

  <sect1 id="JavaHelp-Installation"><title>Installation</title>
    <para>
    </para>
    <orderedlist>
      <listitem>
        <para>
          Download the zipped archive of the JavaHelp software from <ulink url="http://java.sun.com/products/javahelp/download_binary.html#download">http://java.sun.com/products/javahelp/download_binary.html#download</ulink>.
        </para>
      </listitem>
      <listitem>
        <para>
          Extract the zipped archive to some suitable location. 
        </para>
      </listitem>

      <listitem>
        <para>
          Set the <envar>JAVAHELP_HOME</envar> environment variable to point to the directory the archive was extracted to.
        </para>
      </listitem>

      <listitem>
        <para>
          Append <filename>(where you extracted the javahelp archive)/javahelp/lib/jh.jar</filename> to the <envar>CLASSPATH</envar> environment variable.
        </para>
      </listitem>

      <listitem>
        <para>
          Append <filename>(where you extracted the javahelp archive)/javahelp/bin</filename> to the <envar>PATH</envar> environment variable. 
        </para>
      </listitem>
    </orderedlist>

    <para>
      JavaHelp is now installed, the classes may be imported into Java programs and the tools that came with the distribution may be used. The API is in the <filename>doc</filename> sub directory.
    </para>
  </sect1>

  <sect1 id="JavaHelp-References"><title>References (and links you may find useful)</title>
    <itemizedlist>
      <listitem>
        <para><ulink url="http://java.sun.com/products/javahelp/">http://java.sun.com/products/javahelp/</ulink></para>
        <para>The JavaHelp homepage</para>
      </listitem>

      <listitem>
        <para><ulink url="http://java.sun.com/products/javahelp/">http://java.sun.com/products/javahelp/</ulink></para>
        <para>The JavaHelp FAQ</para>
      </listitem>

      <listitem>
        <para><ulink url="http://www.javaworld.com/javaworld/javaone98/j1-98-help.html">http://www.javaworld.com/javaworld/javaone98/j1-98-help.html</ulink></para>
        <para>A short article called <citetitle>Java Apps Get Help!</citetitle> about JavaHelp from javaworld.</para>
      </listitem>
    </itemizedlist>
  </sect1>
</article>

