Lines 27-32
Link Here
|
27 |
|
27 |
|
28 |
import org.apache.jorphan.logging.LoggingManager; |
28 |
import org.apache.jorphan.logging.LoggingManager; |
29 |
import org.apache.log.Logger; |
29 |
import org.apache.log.Logger; |
|
|
30 |
import org.apache.jmeter.util.TidyException; |
31 |
|
30 |
import org.w3c.dom.Document; |
32 |
import org.w3c.dom.Document; |
31 |
import org.w3c.tidy.Tidy; |
33 |
import org.w3c.tidy.Tidy; |
32 |
import org.xml.sax.ErrorHandler; |
34 |
import org.xml.sax.ErrorHandler; |
Lines 104-110
Link Here
|
104 |
* @throws SAXException |
106 |
* @throws SAXException |
105 |
*/ |
107 |
*/ |
106 |
public static Document makeDocument(InputStream stream, boolean validate, boolean whitespace, boolean namespace, |
108 |
public static Document makeDocument(InputStream stream, boolean validate, boolean whitespace, boolean namespace, |
107 |
boolean tolerant) throws ParserConfigurationException, SAXException, IOException { |
109 |
boolean tolerant) throws ParserConfigurationException, SAXException, IOException, TidyException { |
108 |
Document doc; |
110 |
Document doc; |
109 |
if (tolerant) { |
111 |
if (tolerant) { |
110 |
doc = tidyDoc(stream); |
112 |
doc = tidyDoc(stream); |
Lines 124-132
Link Here
|
124 |
// return builder; |
126 |
// return builder; |
125 |
// } |
127 |
// } |
126 |
|
128 |
|
127 |
private static Document tidyDoc(InputStream stream) { |
129 |
private static Document tidyDoc(InputStream stream) throws TidyException { |
128 |
Document doc = null; |
130 |
Document doc = null; |
129 |
doc = makeTidyParser().parseDOM(stream, null); |
131 |
Tidy tidy = makeTidyParser(); |
|
|
132 |
java.io.StringWriter sw = new java.io.StringWriter(); |
133 |
tidy.setErrout(new java.io.PrintWriter(sw)); |
134 |
doc = tidy.parseDOM(stream, null); |
130 |
doc.normalize(); |
135 |
doc.normalize(); |
131 |
// remove the document declaration cause I think it causes |
136 |
// remove the document declaration cause I think it causes |
132 |
// issues this is only needed for JDOM, since I am not |
137 |
// issues this is only needed for JDOM, since I am not |
Lines 134-147
Link Here
|
134 |
// Node name = doc.getDoctype(); |
139 |
// Node name = doc.getDoctype(); |
135 |
// doc.removeChild(name); |
140 |
// doc.removeChild(name); |
136 |
|
141 |
|
|
|
142 |
boolean tolerate_errors = JMeterUtils.getPropDefault("tidy.tolerate_errors", true); |
143 |
if (!tolerate_errors && tidy.getParseErrors() > 0) { |
144 |
log.error("Caught TidyException: " + sw.toString()); |
145 |
throw new TidyException("tidy: " + tidy.getParseErrors() + " errors, " + tidy.getParseWarnings() + " warnings\n"); |
146 |
} |
137 |
return doc; |
147 |
return doc; |
138 |
} |
148 |
} |
139 |
|
149 |
|
140 |
private static Tidy makeTidyParser() { |
150 |
private static Tidy makeTidyParser() { |
141 |
Tidy tidy = new Tidy(); |
151 |
Tidy tidy = new Tidy(); |
142 |
tidy.setCharEncoding(org.w3c.tidy.Configuration.UTF8); |
152 |
tidy.setCharEncoding(org.w3c.tidy.Configuration.UTF8); |
143 |
tidy.setQuiet(true); |
153 |
tidy.setQuiet(JMeterUtils.getPropDefault("tidy.quiet", true)); |
144 |
tidy.setShowWarnings(false); |
154 |
tidy.setShowWarnings(JMeterUtils.getPropDefault("tidy.showwarnings", false)); |
145 |
tidy.setMakeClean(true); |
155 |
tidy.setMakeClean(true); |
146 |
tidy.setXmlTags(false); // Input is not valid XML |
156 |
tidy.setXmlTags(false); // Input is not valid XML |
147 |
// tidy.setShowErrors(1); |
157 |
// tidy.setShowErrors(1); |