HTML Validator for Java
The HTML Validator for Java is a Java class/Servlet filter designed to submit a HTML interfaces of dynamic web applications to the W3C HTML Markup Validation Service and display the results in an HTML table. It is designed to be super easy to use.
Usage
To use this class, you will need a Java Servlet container that supports the Servlet API version 2.3 or greater.
- drop validator.jar in your web apps lib directory
- add the following code to your web app's WEB-INF/web.xml file
<filter-name>HTMLValidatorFilter</filter-name>
<filter-class>org.twine.filter.HTMLValidatorFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HTMLValidatorFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
...and you are ready to go. This will result in the current JSP page being submitted to the W3C validation service and the results displayed in an inline table. Note that by default, the above <filter-mapping> element in web.xml sets the validator to work only with files with a .jsp extension. To change this, see below.
Configuration options
config option | default value | description |
---|---|---|
fileExtension | .validate.html | the file extension given to the temporary file written to disk |
workDir | [directory where JSP script was run] | the directory where static files should be written to disk |
workDirUrl | [web path to directory where JSP script was run] | the web server URL for the workDir; used to show the validation service where to access the static HTML files |
In your web.xml file, configuration would look like this:
<filter-name>HTMLValidatorFilter</filter-name>
<filter-class>org.twine.filter.HTMLValidatorFilter</filter-class>
<init-param>
<param-name>fileExtension</param-name>
<param-value>.temp.html</param-value>
</init-param>
<init-param>
<param-name>workDir</param-name>
<param-value>/path/to/some/dir</param-value>
</init-param>
<init-param>
<param-name>workDirUrl</param-name>
<param-value>http://host.server/dir/</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>ValidatorFilter</filter-name>
<url-pattern>/*.jsp</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>ValidatorFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
To configure the display of the output, you can use CSS. The results are displayed in a div with an 'id' of 'htmlvalidator', and you can use CSS selectors to modify the display. For example, to set a 1 pixel border on the table and its cells, you could do this:
border:1px solid #ccc;
border-collapse:collapse;
}
#htmlvalidator td {
border:1px solid #ccc;
border-collapse:collapse;
}