Custom Validator for Java
The Custom Validator for Java is a Java class/Servlet filter designed to submit a HTML interfaces of dynamic web applications to online validation services.
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
- copy the contents of one of the sample web.xml files into your web app's WEB-INF/web.xml file
...and you are ready to go. This will result in the current page being submitted to the W3C validation service and the results displayed in a new window. To configure the output and other parameters of the validator filter, configure the class by modifying or adding init-param elements to the filer element in the web.xml file (see example below). Configuration options include:
method signature | default value | description |
---|---|---|
validatorUrl | http://validator.w3.org/check? uri=###URL###" |
the URL of the validator to submit this page to; place the string '###URL###' where the URL of the resource to be validated should go (as in the default) |
fileExtension | .validate.html | this is extension added to the script name when the HTTP request is written to disk |
buttonText | validate | this is the text which appears in the validate button |
buttonMarker | [places marker at end of HTML <body> element] | this asks the validator to substitute a string in the target page with the validation link, allowing you to avoid a sure-fire validation error (the validator drops the link at the end of the file by default) as well as customize the display |
targetWindow | newWindow | the name of the window to direct validation results to; you may use the typical constants, '_blank', '_top', etc. |
windowOptions | scrollbars=yes,location=yes, menubar=yes,titlebar=yes, resizable=yes,width=600, height=450 |
these are the options to use IF opening a browser window to display the results |
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 |
A fuller configuration might look like:
<filter>
<filter-name>ValidatorFilter</filter-name>
<filter-class>org.twine.filter.ValidatorFilter</filter-class>
<init-param>
<param-name>validatorUrl</param-name>
<param-value>http://validator.w3.org/check?uri=###URL###</param-value>
</init-param>
<init-param>
<param-name>buttonText</param-name>
<param-value>[validate]</param-value>
</init-param>
<init-param>
<param-name>buttonMarker</param-name>
<param-value>###BUTTON###</param-value>
</init-param>
<init-param>
<param-name>fileExtension</param-name>
<param-value>.validate.html</param-value>
</init-param>
<init-param>
<param-name>targetWindow</param-name>
<param-value>someWindow</param-value>
</init-param>
<init-param>
<param-name>windowOptions</param-name>
<param-value>scrollbars=yes,location=yes,menubar=yes,titlebar=yes,resizable=yes,width=600,height=500</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>
<filter-name>ValidatorFilter</filter-name>
<filter-class>org.twine.filter.ValidatorFilter</filter-class>
<init-param>
<param-name>validatorUrl</param-name>
<param-value>http://validator.w3.org/check?uri=###URL###</param-value>
</init-param>
<init-param>
<param-name>buttonText</param-name>
<param-value>[validate]</param-value>
</init-param>
<init-param>
<param-name>buttonMarker</param-name>
<param-value>###BUTTON###</param-value>
</init-param>
<init-param>
<param-name>fileExtension</param-name>
<param-value>.validate.html</param-value>
</init-param>
<init-param>
<param-name>targetWindow</param-name>
<param-value>someWindow</param-value>
</init-param>
<init-param>
<param-name>windowOptions</param-name>
<param-value>scrollbars=yes,location=yes,menubar=yes,titlebar=yes,resizable=yes,width=600,height=500</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>
This asks the Validator class to...
- set the validation service URL to 'http://validator.w3.org/check?uri=' (an accessibility validator)
- set the button text to '[validate]'
- substitute the text '###BUTTON###' in the source file with the validaton button
- use the file extension '.validate.html' wen writing the request results to disk
- direct the output to the window 'someWindow'
- use the parameters 'scrollbars=yes,location=yes' when opening the window
- finally, a filter-mapping of /* instructs the filter to intercept all web application requests for requests ending in '.jsp' or '.do'