## Java2Html converter.

- Author: Markus Gebhard
- Homepage: http://www.java2html.de

## Features

- Open Source
- Parses source files even if grammatically incorrect (e.g. code snippets)
- Conversion output can be configured (Color, style,...)
- Available as Application, Applet, Eclipse plugin and library.
- Can easily be integrated into other projects (e.g. Wikis)

## Example usage

Here is an example of the typical usage of this library:

    //Create a reader of the raw input text
    StringReader stringReader = new StringReader(
      "/** Simple Java2Html Demo */\r\n"+
      "public static int doThis(String text){ return text.length() + 2; }");

    //Parse the raw text to a JavaSource object
    JavaSource source = null;
    try {
      source = new JavaSourceParser().parse(stringReader);
    } catch (IOException e) {
      e.printStackTrace();
      System.exit(1);
    }

    //Create a converter and write the JavaSource object as Html
    JavaSource2HTMLConverter converter = new JavaSource2HTMLConverter(source);
    StringWriter writer = new StringWriter();
    try {
      converter.convert(writer);
    } catch (IOException e) {
    }
    System.out.println(writer.toString());

The output of this program will look like this:

`1 /** Simple Java2Html Demo */ 2 public static int doThis(String text){ return text.length() + 2; }`

The above example uses a `java.io.StringReader` to read the raw text from and a `java.io.StringWriter` to write the output to. You may want to use a `java.io.FileReader` and/or a `java.io.FileWriter` or others instead.

## Conversion options

If you don't like the default options of the converter you can also change the colors and style of the output. Just add a few lines before the conversion:

    //Get the default options and adjust it to your needs
    Java2HtmlConversionOptions options =
      Java2HtmlConversionOptions.getDefault();
    options.setShowLineNumbers(false);
    options.getStyleTable().put(
      JavaSourceType.KEYWORD,
      new JavaSourceStyleEntry(Color.orange, true, false));
    converter.setConversionOptions(options);

Conversion output:

`/** Simple Java2Html Demo */ public static int doThis(String text){ return text.length() + 2; }`

For a detailed description of the available options have a look at {@link de.java2html.converter.Java2HtmlConversionOptions}.

## Convenience class

If you don't want to care about the handling Writers and Readers there is also a convenience class for converting directly from a String to a String using the default converter options.

For a detailed description have a look at {@link de.java2html.Java2Html}.

## Further development:

- Additional output styles
- Improved API
- Additional conversion targets
  Take JavaSource2HtmlConverter and change it to produce other output formats.
- Speedup
  As far as I remember in the parser there are a lot of O(n) lookups that could be replaced by much faster hashtable lookups. Also at some situations StringTokenizers are used for splitting the code. This is time-consuming and should be done by state machines.

## Not included in further development:

- Links
  Links to superclass, interfaces, used classes, etc. is a feature that can not easily be done with the type of parser in this project. The parser is intended to even parse syntactically wrong code and does not build a syntax tree or whatever. If you need this feature you should look for a different project.