/** * Copy constructor. * @param src The original XmlError to copy. */ public XmlError(XmlError src) { _message = src.getMessage(); _code = src.getErrorCode(); _severity = src.getSeverity(); _source = src.getSourceName(); _line = src.getLine(); _column = src.getColumn(); _offset = src.getOffset(); _cursor = src.getCursorLocation(); }
/** * Validates a specified XmlObject along with logging errors if any. * * @param xmlObject */ public static void validate(XmlObject xmlObject) throws UtilsException { XmlOptions validateOptions = new XmlOptions(); ArrayList errorList = new ArrayList(); validateOptions.setErrorListener(errorList); boolean isValid = xmlObject.validate(validateOptions); if (isValid) { // Valid return; } // Error StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < errorList.size(); i++) { XmlError error = (XmlError) errorList.get(i); logger.warn("Message: " + error.getMessage()); logger.warn("Location of invalid XML: " + error.getCursorLocation().xmlText()); stringBuilder.append("Message:" + error.getMessage()); stringBuilder.append("Location of invalid XML: " + error.getCursorLocation().xmlText()); } throw new UtilsException(stringBuilder.toString()); }
/** * Validates a specified XmlObject along with logging errors if any. * * @param xmlObject */ public static void validate(XmlObject xmlObject) throws UtilsException { XmlOptions validateOptions = new XmlOptions(); ArrayList errorList = new ArrayList(); validateOptions.setErrorListener(errorList); boolean isValid = xmlObject.validate(validateOptions); if (isValid) { // Valid return; } // Error StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < errorList.size(); i++) { XmlError error = (XmlError) errorList.get(i); logger.warn("Message: " + error.getMessage()); logger.warn("Location of invalid XML: " + error.getCursorLocation().xmlText()); stringBuilder.append("Message:" + error.getMessage()); stringBuilder.append("Location of invalid XML: " + error.getCursorLocation().xmlText()); } throw new UtilsException(stringBuilder.toString()); }
/** * Validates the xml after creation * * @param defdoc * @return boolean valid? */ private boolean validate(DefinitionsDocument defdoc) { List<XmlError> errorList = new ArrayList<>(); XmlOptions options = new XmlOptions().setSavePrettyPrint().setSavePrettyPrintIndent(2) .setSaveAggressiveNamespaces(); options.setErrorListener(errorList); System.out.println("!--toString---"); System.out.println(defdoc.toString()); boolean valid = defdoc.validate(options); System.out.println("Document is " + (valid ? "valid" : "invalid")); if (!valid) { for (int i = 0; i < errorList.size(); i++) { XmlError error = errorList.get(i); System.out.println("\n"); System.out.println("Message: " + error.getMessage() + "\n"); System.out.println( "Location of invalid XML: " + error.getCursorLocation().xmlText() + "\n"); } } return valid; }
sb.append( "\n" ); sb.append( "Location of invalid XML: " ); sb.append(error.getCursorLocation().xmlText()); sb.append( "\n\n" );
if (error.getCursorLocation() != null) { LOGGER.error(" " + error.getCursorLocation().xmlText());
/** * Copy constructor. * @param src The original XmlError to copy. */ public XmlError(XmlError src) { _message = src.getMessage(); _code = src.getErrorCode(); _severity = src.getSeverity(); _source = src.getSourceName(); _line = src.getLine(); _column = src.getColumn(); _offset = src.getOffset(); _cursor = src.getCursorLocation(); }
/** * Copy constructor. * @param src The original XmlError to copy. */ public XmlError(XmlError src) { _message = src.getMessage(); _code = src.getErrorCode(); _severity = src.getSeverity(); _source = src.getSourceName(); _line = src.getLine(); _column = src.getColumn(); _offset = src.getOffset(); _cursor = src.getCursorLocation(); }