use of org.w3c.tidy.Tidy in project jmeter by apache.
the class RenderAsXML method showRenderXMLResponse.
private void showRenderXMLResponse(SampleResult res) {
// $NON-NLS-1$
results.setContentType("text/xml");
results.setCaretPosition(0);
byte[] source = res.getResponseData();
final ByteArrayInputStream baIS = new ByteArrayInputStream(source);
for (int i = 0; i < source.length - XML_PFX.length; i++) {
if (JOrphanUtils.startsWith(source, XML_PFX, i)) {
// NOSONAR Skip the leading bytes (if any)
baIS.skip(i);
break;
}
}
StringWriter sw = new StringWriter();
Tidy tidy = XPathUtil.makeTidyParser(true, true, true, sw);
org.w3c.dom.Document document = tidy.parseDOM(baIS, null);
document.normalize();
if (tidy.getParseErrors() > 0) {
showErrorMessageDialog(sw.toString(), "Tidy: " + tidy.getParseErrors() + " errors, " + tidy.getParseWarnings() + " warnings", JOptionPane.WARNING_MESSAGE);
}
JPanel domTreePanel = new DOMTreePanel(document);
resultsScrollPane.setViewportView(domTreePanel);
}
use of org.w3c.tidy.Tidy in project jmeter by apache.
the class XPathUtil method tidyDoc.
/**
* 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;
}
Aggregations