private static XMLStreamException wrapMissingRequiredAttribute(final XMLStreamException ex, final XMLStreamReader reader, final Set<String> required) { return new XMLStreamValidationException(ex.getMessage(), ValidationError.from(ex, ErrorType.REQUIRED_ATTRIBUTE_MISSING) .element(reader.getName()) .alternatives(required), ex); }
private static XMLStreamException wrapMissingRequiredAttribute(final XMLStreamException ex, final XMLStreamReader reader, final Set<String> required) { return new XMLStreamValidationException(ex.getMessage(), ValidationError.from(ex, ErrorType.REQUIRED_ATTRIBUTE_MISSING) .element(reader.getName()) .alternatives(required), ex); }
@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; } }
/** * Get an exception reporting a missing, required XML child element. * @param reader the stream reader * @param required a set of enums whose toString method returns the * attribute name * @return the exception */ public static XMLStreamException missingRequiredElement(final XMLExtendedStreamReader reader, final Set<?> required) { final StringBuilder b = new StringBuilder(); Iterator<?> iterator = required.iterator(); while (iterator.hasNext()) { final Object o = iterator.next(); b.append(o.toString()); if (iterator.hasNext()) { b.append(", "); } } final XMLStreamException ex = ControllerLogger.ROOT_LOGGER.missingRequiredElements(b, reader.getLocation()); Set<String> set = new HashSet<>(); for (Object o : required) { String toString = o.toString(); set.add(toString); } return new XMLStreamValidationException(ex.getMessage(), ValidationError.from(ex, ErrorType.REQUIRED_ELEMENTS_MISSING) .element(reader.getName()) .alternatives(set), ex); }
/** * Get an exception reporting a missing, required XML child element. * @param reader the stream reader * @param required a set of enums whose toString method returns the * attribute name * @return the exception */ public static XMLStreamException missingOneOf(final XMLExtendedStreamReader reader, final Set<?> required) { final StringBuilder b = new StringBuilder(); Iterator<?> iterator = required.iterator(); while (iterator.hasNext()) { final Object o = iterator.next(); b.append(o.toString()); if (iterator.hasNext()) { b.append(", "); } } final XMLStreamException ex = ControllerLogger.ROOT_LOGGER.missingOneOf(b, reader.getLocation()); Set<String> set = new HashSet<>(); for (Object o : required) { String toString = o.toString(); set.add(toString); } return new XMLStreamValidationException(ex.getMessage(), ValidationError.from(ex, ErrorType.REQUIRED_ELEMENT_MISSING) .element(reader.getName()) .alternatives(set), ex); }
/** * Get an exception reporting a missing, required XML child element. * @param reader the stream reader * @param required a set of enums whose toString method returns the * attribute name * @return the exception */ public static XMLStreamException missingRequiredElement(final XMLExtendedStreamReader reader, final Set<?> required) { final StringBuilder b = new StringBuilder(); Iterator<?> iterator = required.iterator(); while (iterator.hasNext()) { final Object o = iterator.next(); b.append(o.toString()); if (iterator.hasNext()) { b.append(", "); } } final XMLStreamException ex = ControllerLogger.ROOT_LOGGER.missingRequiredElements(b, reader.getLocation()); Set<String> set = new HashSet<>(); for (Object o : required) { String toString = o.toString(); set.add(toString); } return new XMLStreamValidationException(ex.getMessage(), ValidationError.from(ex, ErrorType.REQUIRED_ELEMENTS_MISSING) .element(reader.getName()) .alternatives(set), ex); }
/** * Get an exception reporting a missing, required XML child element. * @param reader the stream reader * @param required a set of enums whose toString method returns the * attribute name * @return the exception */ public static XMLStreamException missingOneOf(final XMLExtendedStreamReader reader, final Set<?> required) { final StringBuilder b = new StringBuilder(); Iterator<?> iterator = required.iterator(); while (iterator.hasNext()) { final Object o = iterator.next(); b.append(o.toString()); if (iterator.hasNext()) { b.append(", "); } } final XMLStreamException ex = ControllerLogger.ROOT_LOGGER.missingOneOf(b, reader.getLocation()); Set<String> set = new HashSet<>(); for (Object o : required) { String toString = o.toString(); set.add(toString); } return new XMLStreamValidationException(ex.getMessage(), ValidationError.from(ex, ErrorType.REQUIRED_ELEMENT_MISSING) .element(reader.getName()) .alternatives(set), ex); }
@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; }
/** * Get an exception reporting an unexpected XML element. * @param reader the stream reader * @return the exception */ public static XMLStreamException unexpectedElement(final XMLExtendedStreamReader reader, Set<String> possible) { final XMLStreamException ex = ControllerLogger.ROOT_LOGGER.unexpectedElement(reader.getName(), asStringList(possible), reader.getLocation()); return new XMLStreamValidationException(ex.getMessage(), ValidationError.from(ex, ErrorType.UNEXPECTED_ELEMENT) .element(reader.getName()) .alternatives(possible), ex); }
/** * Get an exception reporting an unexpected XML element. * @param reader the stream reader * @return the exception */ public static XMLStreamException unexpectedElement(final XMLExtendedStreamReader reader, Set<String> possible) { final XMLStreamException ex = ControllerLogger.ROOT_LOGGER.unexpectedElement(reader.getName(), asStringList(possible), reader.getLocation()); return new XMLStreamValidationException(ex.getMessage(), ValidationError.from(ex, ErrorType.UNEXPECTED_ELEMENT) .element(reader.getName()) .alternatives(possible), ex); }
if (error.alternatives().isEmpty()) { List<DocElement> pathToDocElement = ctx.pathToDocElement(el, error.position()); otherElements = Util.asSortedList(error.alternatives());
/** * Get an exception reporting a missing, required XML attribute. * @param reader the stream reader * @param supportedElement the element that is to be used in place of the unsupported one. * @return the exception */ public static XMLStreamException unsupportedElement(final XMLExtendedStreamReader reader, String supportedElement) { XMLStreamException ex = ControllerLogger.ROOT_LOGGER.unsupportedElement( new QName(reader.getNamespaceURI(), reader.getLocalName(),reader.getPrefix()), reader.getLocation(), supportedElement); return new XMLStreamValidationException(ex.getMessage(), ValidationError.from(ex, ErrorType.UNSUPPORTED_ELEMENT) .element(reader.getName()) .alternatives(new HashSet<String>() {{add(supportedElement);}}), ex); } }
/** * Get an exception reporting a missing, required XML attribute. * @param reader the stream reader * @param supportedElement the element that is to be used in place of the unsupported one. * @return the exception */ public static XMLStreamException unsupportedElement(final XMLExtendedStreamReader reader, String supportedElement) { XMLStreamException ex = ControllerLogger.ROOT_LOGGER.unsupportedElement( new QName(reader.getNamespaceURI(), reader.getLocalName(),reader.getPrefix()), reader.getLocation(), supportedElement); return new XMLStreamValidationException(ex.getMessage(), ValidationError.from(ex, ErrorType.UNSUPPORTED_ELEMENT) .element(reader.getName()) .alternatives(new HashSet<String>() {{add(supportedElement);}}), ex); } }
if (error.alternatives().isEmpty()) { final List<SchemaElement> schemaPath = ctx.mapDocLocationToSchemaPath(error.element(), error.position()); if (schemaPath.isEmpty()) { otherAttributes = Util.asSortedList(error.alternatives());
/** * Get an exception reporting an unexpected XML attribute. * @param reader the stream reader * @param index the attribute index * @param possibleAttributes attributes that are expected on this element * @return the exception */ public static XMLStreamException unexpectedAttribute(final XMLExtendedStreamReader reader, final int index, Set<String> possibleAttributes) { final XMLStreamException ex = ControllerLogger.ROOT_LOGGER.unexpectedAttribute(reader.getAttributeName(index), asStringList(possibleAttributes), reader.getLocation()); return new XMLStreamValidationException(ex.getMessage(), ValidationError.from(ex, ErrorType.UNEXPECTED_ATTRIBUTE) .element(reader.getName()) .attribute(reader.getAttributeName(index)) .alternatives(possibleAttributes), ex); }
/** * Get an exception reporting an unexpected XML attribute. * @param reader the stream reader * @param index the attribute index * @param possibleAttributes attributes that are expected on this element * @return the exception */ public static XMLStreamException unexpectedAttribute(final XMLExtendedStreamReader reader, final int index, Set<String> possibleAttributes) { final XMLStreamException ex = ControllerLogger.ROOT_LOGGER.unexpectedAttribute(reader.getAttributeName(index), asStringList(possibleAttributes), reader.getLocation()); return new XMLStreamValidationException(ex.getMessage(), ValidationError.from(ex, ErrorType.UNEXPECTED_ATTRIBUTE) .element(reader.getName()) .attribute(reader.getAttributeName(index)) .alternatives(possibleAttributes), ex); }