/** * Create a document using Tidy * * @param stream - input * @param quiet - set Tidy quiet? * @param showWarnings - show Tidy warnings? * @param report_errors - log errors and throw TidyException? * @param isXML - treat document as XML? * @param out OutputStream, null if no output required * @return the document * * @throws TidyException if a ParseError is detected and report_errors is true */ private static Document tidyDoc(InputStream stream, boolean quiet, boolean showWarnings, boolean report_errors, boolean isXML, OutputStream out) throws TidyException { StringWriter sw = new StringWriter(); Tidy tidy = makeTidyParser(quiet, showWarnings, isXML, sw); Document doc = tidy.parseDOM(stream, out); doc.normalize(); if (tidy.getParseErrors() > 0) { if (report_errors) { log.error("TidyException: {}", sw); throw new TidyException(tidy.getParseErrors(),tidy.getParseWarnings()); } log.warn("Tidy errors: {}", sw); } return doc; }
} catch (TidyException e) { result.setError(true); result.setFailureMessage(e.getMessage()); return result;