final List exceptions = new ArrayList(); db.setErrorHandler(new ErrorHandler() { public void error(SAXParseException exception) { addMessage(exception); }  public void fatalError(SAXParseException exception) { addMessage(exception); }  public void warning(SAXParseException exception) { }  private void addMessage(SAXParseException exception) { exceptions.add(exception.getMessage() + " (line:" + exception.getLineNumber() + ((exception.getColumnNumber() > -1) ? (" col:" + exception.getColumnNumber()) : "") + ")"); } });
WorkflowLoader.AllExceptionsErrorHandler errorHandler = new WorkflowLoader.AllExceptionsErrorHandler(); db.setErrorHandler(errorHandler);
    private void validateDTD() throws InvalidWorkflowDescriptorException {        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();        dbf.setNamespaceAware(true);        dbf.setValidating(true);        StringWriter sw = new StringWriter();        PrintWriter writer = new PrintWriter(sw);        writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");        writer.println("<!DOCTYPE workflow PUBLIC \"-//OpenSymphony Group//DTD OSWorkflow 2.7//EN\" \"http://www.opensymphony.com/osworkflow/workflow_2_7.dtd\">");        writeXML(writer, 0);        try {            DocumentBuilder db = dbf.newDocumentBuilder();            db.setEntityResolver(new DTDEntityResolver());            final List exceptions = new ArrayList();            db.setErrorHandler(new ErrorHandler() {                    public void error(SAXParseException exception) {                        addMessage(exception);                    }                    public void fatalError(SAXParseException exception) {                        addMessage(exception);                    }                    public void warning(SAXParseException exception) {                    }                    private void addMessage(SAXParseException exception) {                        exceptions.add(exception.getMessage() + " (line:" + exception.getLineNumber() + ((exception.getColumnNumber() > -1) ? (" col:" + exception.getColumnNumber()) : "") + ")");                    }                });            db.parse(new InputSource(new StringReader(sw.toString())));            if (exceptions.size() > 0) {                throw new InvalidWorkflowDescriptorException(exceptions.toString());            }        } catch (InvalidWorkflowDescriptorException e) {            throw e;        } catch (Exception e) {            throw new InvalidWorkflowDescriptorException(e.toString());        }    }