Search in sources :

Example 6 with Tidy

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);
}
Also used : JPanel(javax.swing.JPanel) StringWriter(java.io.StringWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) Tidy(org.w3c.tidy.Tidy)

Example 7 with Tidy

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;
}
Also used : StringWriter(java.io.StringWriter) Document(org.w3c.dom.Document) Tidy(org.w3c.tidy.Tidy)

Aggregations

Tidy (org.w3c.tidy.Tidy)7 PrintWriter (java.io.PrintWriter)3 StringWriter (java.io.StringWriter)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 AbortException (hudson.AbortException)1 IOException2 (hudson.util.IOException2)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 JPanel (javax.swing.JPanel)1 NullWriter (org.apache.commons.io.output.NullWriter)1 Document (org.dom4j.Document)1 Element (org.dom4j.Element)1 DOMReader (org.dom4j.io.DOMReader)1 Document (org.w3c.dom.Document)1 Node (org.w3c.tidy.Node)1