@Override public HandledResult handle(ValidationContext ctx, ValidationError error) { final String el = error.element().getLocalPart(); final Set<String> alts = error.alternatives(); final HandledResult result = HandledResult.from(error) .addPrimaryMessage(I18N.Key.ATTRIBUTE_REQUIRED_MISSING, el); if (!alts.isEmpty()) { final List<SchemaElement> path = ctx.mapDocLocationToSchemaPath(error.element(), error.position()); if (path.isEmpty()) { result.possiblyMalformed(true); } final Set<String> attributesForElement = ctx.attributesForElement(path); result.addPrimaryMessage(I18N.Key.ATTRIBUTE_REQUIRED_MISSING_LIST, Util.asSortedList(alts).stream() .map(String::toLowerCase) .map(Util.possiblyUnderscoredName(attributesForElement)) .collect(Collectors.toList())); } return result; } }
@Override public HandledResult handle(ValidationContext ctx, ValidationError error) { final String el = error.element().getLocalPart(); final Set<String> alts = error.alternatives(); final Location loc = error.location(); final Position pos = ctx.searchBackward(loc.getLineNumber() - 1, loc.getColumnNumber(), Pattern.compile(String.format("<%s[ >/]", el))); final HandledResult result = HandledResult.from(error) .addPrimaryMessage(this.primaryMessageKey, el); if (pos != null) { result.line(pos.line).column(pos.col); } if (!alts.isEmpty()) { final List<SchemaElement> path = ctx.mapDocLocationToSchemaPath(error.element(), error.position()); if (path.isEmpty()) { result.possiblyMalformed(true); } Set<String> otherElements = ctx.elementsForElement(path).stream() .map(SchemaElement::name) .collect(Collectors.toSet()); result.addPrimaryMessage(this.optionsMessageKey, Util.asSortedList(alts).stream() .map(String::toLowerCase) .map(Util.possiblyUnderscoredName(otherElements)) .collect(Collectors.toList())); } return result; }
final List<DocElement> docPath = ctx.pathToDocElement(error.element(), error.position()); if (attr != null) { result.addPrimaryMessage(I18N.Key.ELEMENT_WITH_ATTRIBUTE_DUPLICATED, el, attr, attrValue);
final List<SchemaElement> schemaPath = ctx.mapDocLocationToSchemaPath(error.element(), error.position()); if (schemaPath.isEmpty()) { result.possiblyMalformed(true);