public void validate(Source source, Result result)
throws SAXException, IOException {
if (result instanceof SAXResult || result == null) {
final SAXSource saxSource = (SAXSource) source;
final SAXResult saxResult = (SAXResult) result;
LexicalHandler lh = null;
if (result != null) {
ContentHandler ch = saxResult.getHandler();
lh = saxResult.getLexicalHandler();
/** If the lexical handler is not set try casting the ContentHandler. **/
if (lh == null && ch instanceof LexicalHandler) {
lh = (LexicalHandler) ch;
}
setContentHandler(ch);