Objective Html - OHtml Compiler
Author Keith Wong, keithwong@optushome.com.au
Last updated: 19th Jan 2002
The OHtml Compiler (ohtmlc) compiles ordinary html files into OHtml-Java code. The compiler provides developers with an easy and clean way to separate presentation design from presentation logic. With this tool your html form designs needn't be corrupted with Java scriplet code or custom tags. They can now remain in ordinary html and hence will always be viewable/modifiable by your favourite WYSIWYG html editor. The tool also provides Java developers with a more efficient way of generating OHtml-Java forms.
Limitations
Before we show you how to use this compiler we will discuss some limitations first. The compiler only accepts well-formed xml documents, this is because the compiler uses a JAXP compatible parser. This means that any html files they do not have closing tags or use compacted boolean attributes will not work. There is a solution however and this is to run the file through HtmlTidy first. HtmlTidy is an excellent tool and will fix up almost any malformed html document you can throw at it. The other limitation is that all tag names and attributes must be in lower-case. HtmlTidy can also fix that problem. For most html documents running the command
htmltidy --output-xml y --uppercase-tags n --uppercase-attributes n htmlfile > outputfile
seems to do the trick most of the time.
Configuration
Two script files are given so that the program can be run on the command line easier. The file ohtmlc.sh is for Unix whilst the file ohtmlc.bat is for Windows. Both script files require some fine tuning before they can be used, simply open the file and edit what is required. Some classpaths need to be set and you need to make sure you have JAXP 1.x compatible XML Parser somewhere in your classpath. If you do not have a JAXP 1.x compatible XML Parser then you will need to download Sun's JAXP Implementation. A JAXP 1.1 compatible XML Parser is provided with Apache Tomcat 4.0.
Usage
ohtmlc [options ]+ htmlfile classname
The default command will parse the file htmlfile and will generate the file classname .java with the source code for the Java class named classname .
Some Things To Know
Options
Option | Description | Values | Default | Example |
-abstract | Specifies whether the generated class should be abstract or not. | none | By default the generated class is not abstract. | ohtmlc -abstract form.html MyForm |
-accesslevel | Specifies the accesslevel for all member variables generated. | protected or public | public | ohtmlc -accesslevel protected form.html MyForm |
-charset | Specifies the charset the file will be written out as. | a valid charset name | ISO-8859-1 | ohtmlc -charset UTF-8 form.html MyForm |
-entities | Specifies the characters that need to entitized. The characters &, <, >, " and the nonbreaking space character ( ) are always entitized. To specify a character or a list of characters you will need to use their unicode values. The unicode values can be specified either as a decimal value or hexidecimal value, for hex values use a x prefix. e.g. xA0. A list of characters can be listed like this 160-255 (xA0-xFF). This will entitize all characters with a unicode value between 160 and 255 (both inclusive). | a set of unicode values | none | ohtmlc -entities 123 124 xA1-xFF form.html MyForm |
-exceptions | Specifies the exceptions that the constructor should throw. Either specify the full name of the exception class or make sure their packages are imported via the -imports option. | a list of exceptions | none | ohtmlc -exceptions InvalidAttributeException InvalidParentWidgetException form.html MyForm |
-extends | Specifies the class to be extended by the generated class. Note that class specified must have the HtmlForm as a parent class. | a class that extends HtmlForm | HtmlForm | ohtmlc -extends BaseForm form.html MyForm |
-form | Indicates the form to compile. This is useful if your html document has multiple forms. Simply name all your forms using the "id" attribute and then specify the name of the form with this option. | the name of a form in the html document | If the option is not then the first form in the document is compiled. | ohtmlc -form customerform manyforms.html Customer |
-imports | Specifies the packages the generated class is to import. The packages objectivehtml.htmlwidget.* and objectivehtml.htmlwidget.exception.* are always imported. | a list of package names | none | ohtmlc -imports java.util.* form.html MyForm |
-nocompress | Specifies that text nodes are not to be compressed. If text nodes are compressed then sequences of whitespace characters will reduced to one whitespace (the space character). The only exception is the text inside a textarea tag. This text is compiled as is from the html file. | none | When not specified the compiler will compress text. | ohtmlc -nocompress form.html MyForm |
-output | Specifies the output file for the generated code. To have the generated code be written to stdout specify this option with no file name. | null or a file name | If the option is not given then the output file will be classname .java. | ohtmlc -output ../javacode/MyClass.java form.html MyClass |
-package | Specifies the package the generated class is to belong to. | the fully qualifed name of a package | none | ohtmlc -package mypackage.form form.html MyForm |
-unicodes | Specifies the characters that need to be escaped in the generated Java code. To specify a character or a list of characters you will need to use their unicode values. See the -entities option for more details. | a set of unicode values | none | ohtmlc -unicodes x4f60 x597d 161-255 form.html MyForm |