@Override public HandledResult handle(ValidationContext ctx, ValidationError error) { final String el = error.element().getLocalPart(); final Set<String> alts = error.alternatives(); final String alt = alts.stream().findFirst().orElse(null); final HandledResult result = HandledResult.from(error); if (alt == null) { result.addPrimaryMessage(I18N.Key.ELEMENT_UNSUPPORTED_NO_ALT, el); } else { result.addPrimaryMessage(I18N.Key.ELEMENT_UNSUPPORTED, el, alt); } 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; }
@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; } }
.addPrimaryMessage(I18N.Key.ELEMENT_NOT_ALLOWED, elName); response.addPrimaryMessage(I18N.Key.DID_YOU_MEAN, altSpelling); response.addPrimaryMessage(I18N.Key.ELEMENTS_ALLOWED_HERE, otherElements);
result.addPrimaryMessage(I18N.Key.ELEMENT_WITH_ATTRIBUTE_DUPLICATED, el, attr, attrValue); } else { String parentName = "parent"; result.addPrimaryMessage(I18N.Key.ELEMENT_DUPLICATED, el, parentName);
final List<List<SchemaElement>> altElements = ctx.alternateElementsForAttribute(attr); final HandledResult result = HandledResult.from(error) .addPrimaryMessage(I18N.Key.ATTRIBUTE_NOT_ALLOWED, attr, el); result.addPrimaryMessage(I18N.Key.ELEMENT_HAS_NO_ATTRIBUTES, el); } else { final String altSpelling = Util.alternateSpelling(attr, otherAttributes); if (altSpelling != null) { result.addPrimaryMessage(I18N.Key.DID_YOU_MEAN, altSpelling); result.addPrimaryMessage(I18N.Key.ATTRIBUTES_ALLOWED_HERE, otherAttributes);
result.addPrimaryMessage(I18N.Key.ATTRIBUTE_DUPLICATED_NO_ELEMENT, attr); } else { result.addPrimaryMessage(I18N.Key.ATTRIBUTE_DUPLICATED, attr, el);
@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; } }
public ErrorHandler.HandledResult handle(ValidationError error) { final ErrorHandler.HandledResult result = error.type().handler().handle(this, error); if (result.isPossiblyMalformed() && !this.docWalker.valid()) { @SuppressWarnings("ThrowableResultOfMethodCallIgnored") final SAXParseException ex = this.docWalker.validationFailure(); final ErrorHandler.HandledResult validationResult = new ErrorHandler.HandledResult(ex.getLineNumber(), ex.getColumnNumber(), null); validationResult.addPrimaryMessage(I18N.Key.PASSTHRU, Util.stripPeriod(ex.getLocalizedMessage())); result.addSecondaryMessage(I18N.Key.MALFORMED_XML, Util.documentName(this.document)); result.addSecondaryResult(validationResult); } return result; }
public HandledResult addPrimaryMessage(final I18N.Key key, Object... args) { return addPrimaryMessage(new Message(key, args)); }
@Override public HandledResult handle(ValidationContext ctx, ValidationError err) { String msg = err.fallbackMessage(); if (msg == null) { msg = err.message(); if (Pattern.matches(".*\\n at.*", msg)) { final String[] parts = msg.split("\\n"); msg = parts[0]; } } return HandledResult.from(err) .addPrimaryMessage(I18N.Key.PASSTHRU, Util.stripPeriod(msg)); } }