Github user FSchumacher commented on a diff in the pull request:
https://github.com/apache/jmeter/pull/432#discussion_r235125307
--- Diff:
src/core/org/apache/jmeter/gui/action/template/TemplateManager.java ---
@@ -149,19 +109,107 @@ public TemplateManager reset() {
} else {
if (log.isWarnEnabled()) {
log.warn("Ignoring template file:'{}' as it
does not exist or is not readable",
- f.getAbsolutePath());
+ file.getAbsolutePath());
}
}
} catch(Exception ex) {
if (log.isWarnEnabled()) {
- log.warn("Ignoring template file:'{}', an error
occurred parsing the file", f.getAbsolutePath(),
+ log.warn("Ignoring template file:'{}', an error
occurred parsing the file", file.getAbsolutePath(),
ex);
}
}
}
}
return temps;
}
+
+ public final class LoggingErrorHandler implements ErrorHandler {
+ private Logger logger;
+
+ public LoggingErrorHandler(Logger logger) {
+ this.logger = logger;
+ }
+ @Override
+ public void error(SAXParseException ex) throws SAXException {
+ throw ex;
+ }
+
+ @Override
+ public void fatalError(SAXParseException ex) throws SAXException {
+ throw ex;
+ }
+
+ @Override
+ public void warning(SAXParseException ex) throws SAXException {
+ logger.warn("Warning", ex);
+ }
+ }
+
+ public static class DefaultEntityResolver implements EntityResolver {
+ public DefaultEntityResolver() {
+ super();
+ }
+
+ public InputSource resolveEntity(String publicId, String systemId)
throws SAXException, IOException {
+ if(systemId.endsWith("templates.dtd")) {
+ return new
InputSource(TemplateManager.class.getResourceAsStream("/org/apache/jmeter/gui/action/template/templates.dtd"));
+ } else {
+ return null;
+ }
+ }
+ }
+
+ public Map<String, Template> parseTemplateFile(File file) throws
IOException, SAXException, ParserConfigurationException{
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setValidating(true);
+ dbf.setNamespaceAware(true);
+
dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
+
dbf.setFeature("http://xml.org/sax/features/external-parameter-entities",
false);
+ DocumentBuilder bd = dbf.newDocumentBuilder();
+ bd.setEntityResolver(new DefaultEntityResolver());
+ LoggingErrorHandler errorHandler = new LoggingErrorHandler(log);
--- End diff --
We could hand the filename to the error handler, so that it could be used
in the error messages.
---