mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-23 09:31:32 +01:00
reduced code duplication
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.owasp.dependencycheck.xml.hints;
|
package org.owasp.dependencycheck.xml.hints;
|
||||||
|
|
||||||
|
import org.owasp.dependencycheck.utils.XmlUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.xml.sax.ErrorHandler;
|
import org.xml.sax.ErrorHandler;
|
||||||
@@ -35,33 +36,6 @@ public class HintErrorHandler implements ErrorHandler {
|
|||||||
*/
|
*/
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(HintErrorHandler.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(HintErrorHandler.class);
|
||||||
|
|
||||||
/**
|
|
||||||
* Builds a prettier exception message.
|
|
||||||
*
|
|
||||||
* @param ex the SAXParseException
|
|
||||||
* @return an easier to read exception message
|
|
||||||
*/
|
|
||||||
private String getPrettyParseExceptionInfo(SAXParseException ex) {
|
|
||||||
|
|
||||||
final StringBuilder sb = new StringBuilder();
|
|
||||||
|
|
||||||
if (ex.getSystemId() != null) {
|
|
||||||
sb.append("systemId=").append(ex.getSystemId()).append(", ");
|
|
||||||
}
|
|
||||||
if (ex.getPublicId() != null) {
|
|
||||||
sb.append("publicId=").append(ex.getPublicId()).append(", ");
|
|
||||||
}
|
|
||||||
if (ex.getLineNumber() > 0) {
|
|
||||||
sb.append("Line=").append(ex.getLineNumber());
|
|
||||||
}
|
|
||||||
if (ex.getColumnNumber() > 0) {
|
|
||||||
sb.append(", Column=").append(ex.getColumnNumber());
|
|
||||||
}
|
|
||||||
sb.append(": ").append(ex.getMessage());
|
|
||||||
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs warnings.
|
* Logs warnings.
|
||||||
*
|
*
|
||||||
@@ -81,7 +55,7 @@ public class HintErrorHandler implements ErrorHandler {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void error(SAXParseException ex) throws SAXException {
|
public void error(SAXParseException ex) throws SAXException {
|
||||||
throw new SAXException(getPrettyParseExceptionInfo(ex));
|
throw new SAXException(XmlUtils.getPrettyParseExceptionInfo(ex));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -92,6 +66,6 @@ public class HintErrorHandler implements ErrorHandler {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void fatalError(SAXParseException ex) throws SAXException {
|
public void fatalError(SAXParseException ex) throws SAXException {
|
||||||
throw new SAXException(getPrettyParseExceptionInfo(ex));
|
throw new SAXException(XmlUtils.getPrettyParseExceptionInfo(ex));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.owasp.dependencycheck.xml.suppression;
|
package org.owasp.dependencycheck.xml.suppression;
|
||||||
|
|
||||||
|
import org.owasp.dependencycheck.utils.XmlUtils;
|
||||||
import org.xml.sax.ErrorHandler;
|
import org.xml.sax.ErrorHandler;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
import org.xml.sax.SAXParseException;
|
import org.xml.sax.SAXParseException;
|
||||||
@@ -33,33 +34,6 @@ public class SuppressionErrorHandler implements ErrorHandler {
|
|||||||
*/
|
*/
|
||||||
//private static final Logger LOGGER = LoggerFactory.getLogger(SuppressionErrorHandler.class);
|
//private static final Logger LOGGER = LoggerFactory.getLogger(SuppressionErrorHandler.class);
|
||||||
|
|
||||||
/**
|
|
||||||
* Builds a prettier exception message.
|
|
||||||
*
|
|
||||||
* @param ex the SAXParseException
|
|
||||||
* @return an easier to read exception message
|
|
||||||
*/
|
|
||||||
private String getPrettyParseExceptionInfo(SAXParseException ex) {
|
|
||||||
|
|
||||||
final StringBuilder sb = new StringBuilder();
|
|
||||||
|
|
||||||
if (ex.getSystemId() != null) {
|
|
||||||
sb.append("systemId=").append(ex.getSystemId()).append(", ");
|
|
||||||
}
|
|
||||||
if (ex.getPublicId() != null) {
|
|
||||||
sb.append("publicId=").append(ex.getPublicId()).append(", ");
|
|
||||||
}
|
|
||||||
if (ex.getLineNumber() > 0) {
|
|
||||||
sb.append("Line=").append(ex.getLineNumber());
|
|
||||||
}
|
|
||||||
if (ex.getColumnNumber() > 0) {
|
|
||||||
sb.append(", Column=").append(ex.getColumnNumber());
|
|
||||||
}
|
|
||||||
sb.append(": ").append(ex.getMessage());
|
|
||||||
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs warnings.
|
* Logs warnings.
|
||||||
*
|
*
|
||||||
@@ -79,7 +53,7 @@ public class SuppressionErrorHandler implements ErrorHandler {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void error(SAXParseException ex) throws SAXException {
|
public void error(SAXParseException ex) throws SAXException {
|
||||||
throw new SAXException(getPrettyParseExceptionInfo(ex));
|
throw new SAXException(XmlUtils.getPrettyParseExceptionInfo(ex));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -90,6 +64,6 @@ public class SuppressionErrorHandler implements ErrorHandler {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void fatalError(SAXParseException ex) throws SAXException {
|
public void fatalError(SAXParseException ex) throws SAXException {
|
||||||
throw new SAXException(getPrettyParseExceptionInfo(ex));
|
throw new SAXException(XmlUtils.getPrettyParseExceptionInfo(ex));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import javax.xml.parsers.SAXParserFactory;
|
|||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
import org.xml.sax.SAXNotRecognizedException;
|
import org.xml.sax.SAXNotRecognizedException;
|
||||||
import org.xml.sax.SAXNotSupportedException;
|
import org.xml.sax.SAXNotSupportedException;
|
||||||
|
import org.xml.sax.SAXParseException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collection of XML related code.
|
* Collection of XML related code.
|
||||||
@@ -122,4 +123,31 @@ public final class XmlUtils {
|
|||||||
final DocumentBuilder db = factory.newDocumentBuilder();
|
final DocumentBuilder db = factory.newDocumentBuilder();
|
||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds a prettier exception message.
|
||||||
|
*
|
||||||
|
* @param ex the SAXParseException
|
||||||
|
* @return an easier to read exception message
|
||||||
|
*/
|
||||||
|
public static String getPrettyParseExceptionInfo(SAXParseException ex) {
|
||||||
|
|
||||||
|
final StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
if (ex.getSystemId() != null) {
|
||||||
|
sb.append("systemId=").append(ex.getSystemId()).append(", ");
|
||||||
|
}
|
||||||
|
if (ex.getPublicId() != null) {
|
||||||
|
sb.append("publicId=").append(ex.getPublicId()).append(", ");
|
||||||
|
}
|
||||||
|
if (ex.getLineNumber() > 0) {
|
||||||
|
sb.append("Line=").append(ex.getLineNumber());
|
||||||
|
}
|
||||||
|
if (ex.getColumnNumber() > 0) {
|
||||||
|
sb.append(", Column=").append(ex.getColumnNumber());
|
||||||
|
}
|
||||||
|
sb.append(": ").append(ex.getMessage());
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user