@Override public HandledResult handle(ValidationContext ctx, ValidationError error) { final Location loc = error.location(); final String attr = error.attribute().getLocalPart(); final Position pos = ctx.searchForward(loc.getLineNumber() - 1, loc.getColumnNumber(), Pattern.compile(attr + "\\s*=")); final HandledResult result = HandledResult.from(error) .addPrimaryMessage(I18N.Key.ATTRIBUTE_INVALID_VALUE, error.attributeValue(), attr); if (pos != null) { result.line(pos.line).column(pos.col); } return result; } }
/** * Get an exception reporting that an element of a given type and name has * already been declared in this scope. * @param reader the stream reader * @param name the name that was redeclared * @return the exception */ public static XMLStreamException duplicateNamedElement(final XMLExtendedStreamReader reader, final String name) { final XMLStreamException ex = ControllerLogger.ROOT_LOGGER.duplicateNamedElement(name, reader.getLocation()); return new XMLStreamValidationException(ex.getMessage(), ValidationError.from(ex, ErrorType.DUPLICATE_ELEMENT) .element(reader.getName()) .attribute(QName.valueOf("name")) .attributeValue(name), ex); }
/** * Get an exception reporting that an element of a given type and name has * already been declared in this scope. * @param reader the stream reader * @param name the name that was redeclared * @return the exception */ public static XMLStreamException duplicateNamedElement(final XMLExtendedStreamReader reader, final String name) { final XMLStreamException ex = ControllerLogger.ROOT_LOGGER.duplicateNamedElement(name, reader.getLocation()); return new XMLStreamValidationException(ex.getMessage(), ValidationError.from(ex, ErrorType.DUPLICATE_ELEMENT) .element(reader.getName()) .attribute(QName.valueOf("name")) .attributeValue(name), ex); }
final String el = error.element().getLocalPart(); final String attr = error.attribute() != null ? error.attribute().getLocalPart() : null; final String attrValue = error.attributeValue();
/** * Get an exception reporting an invalid XML attribute value. * @param reader the stream reader * @param index the attribute index * @return the exception */ public static XMLStreamException invalidAttributeValue(final XMLExtendedStreamReader reader, final int index) { final XMLStreamException ex = ControllerLogger.ROOT_LOGGER.invalidAttributeValue(reader.getAttributeValue(index), reader.getAttributeName(index), reader.getLocation()); return new XMLStreamValidationException(ex.getMessage(), ValidationError.from(ex, ErrorType.INVALID_ATTRIBUTE_VALUE) .element(reader.getName()) .attribute(reader.getAttributeName(index)) .attributeValue(reader.getAttributeValue(index)), ex); }
/** * Get an exception reporting an invalid XML attribute value. * @param reader the stream reader * @param index the attribute index * @return the exception */ public static XMLStreamException invalidAttributeValue(final XMLExtendedStreamReader reader, final int index) { final XMLStreamException ex = ControllerLogger.ROOT_LOGGER.invalidAttributeValue(reader.getAttributeValue(index), reader.getAttributeName(index), reader.getLocation()); return new XMLStreamValidationException(ex.getMessage(), ValidationError.from(ex, ErrorType.INVALID_ATTRIBUTE_VALUE) .element(reader.getName()) .attribute(reader.getAttributeName(index)) .attributeValue(reader.getAttributeValue(index)), ex); }