//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 */
|
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.
//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 */
|
For a detailed description of the available options have a look at {@link de.java2html.converter.Java2HtmlConversionOptions}.
For a detailed description have a look at {@link de.java2html.Java2Html}.