HTMLConverter is the main class of the code2web package. It is the one that gets invoked when code2web is used from the command line, or when the code2web taglib is used.
HTMLConverter uses Javacc-generated parsers for the different languages. The grammars usually have to be modified a bit so that it they don't ignore neither comments nor whitespaces (as both of them have to be present in the final output).Basically, this class invokes the parser for reading tokens from the specified input stream, analyzes them and produces the output on the fly. This means that HTMLConverter does not build an abstract syntax tree in memory, and performs all operations using a single pass on the source code.
The reason for this is that one of the main design decisions for HTMLConverter was to use as little memory as possible, because the main purpose of this library was to publish java code on the web. However, a web page that has a code2web tag may be visited at a point of time by hundreds if not thousands of users. It would be suicidal to have each of these code2web tag instances generate an in-memory syntax tree.
Basic operation with HTMLConverter is easy : you construct an instance using the default constructor, set at least one css using the addSkin() method and call one of the convert() methods, which take either streams or file names as input arguments. This will produce a reasonable output, however you can configure it as much as you like using the many published properties of HTMLConverter.
Using HTMLConverter from code is extremely easy: The basic use is just:
HTMLConverter conv = new HTMLConverter();
// Set various options - many others are available, and almost all
// options have reasonable defaults.
conv.setTitle("ClassResolver.java");
conv.setLocation("http://www.planetalia.com");
conv.setAuthor("Planetalia S.L.");
conv.setGenerateOutline(true);
conv.setGenerateJavadocLinks(true);
// Tell the converter the source code is a Java source code
conv.setLanguage( new JavaDefinition() );
conv.setShowLineNumbers(true);
conv.setGenerateNavigationBox(true);
conv.setGenerateSkinBox(true);
conv.addSkin("Eclipse","styles/eclipse.css");
conv.addSkin("Netbeans","styles/netbeans.css");
conv.addSkin("Citylights","styles/citylights.css");
conv.addSkin("Monochrome","styles/monochrome.css");
// Do the conversion
conv.convert( "f:/dev/code2web/src/org/code2web/html/ClasResolver.java",
"f:/dev/code2web/src/result.html" );
(Press here to see the actual, full-size html output)
