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; } }
@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; } }
/** * Get an exception reporting that an attribute of a given 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 duplicateAttribute(final XMLExtendedStreamReader reader, final String name) { final XMLStreamException ex = ControllerLogger.ROOT_LOGGER.duplicateAttribute(name, reader.getLocation()); return new XMLStreamValidationException(ex.getMessage(), ValidationError.from(ex, ErrorType.DUPLICATE_ATTRIBUTE) .element(reader.getName()) .attribute(new QName(name)), ex); }
/** * Get an exception reporting that an attribute of a given 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 duplicateAttribute(final XMLExtendedStreamReader reader, final String name) { final XMLStreamException ex = ControllerLogger.ROOT_LOGGER.duplicateAttribute(name, reader.getLocation()); return new XMLStreamValidationException(ex.getMessage(), ValidationError.from(ex, ErrorType.DUPLICATE_ATTRIBUTE) .element(reader.getName()) .attribute(new QName(name)), ex); }
/** * Get an exception reporting an unexpected XML element. * @param reader the stream reader * @return the exception */ public static XMLStreamException unexpectedElement(final XMLExtendedStreamReader reader) { final XMLStreamException ex = ControllerLogger.ROOT_LOGGER.unexpectedElement(reader.getName(), reader.getLocation()); return new XMLStreamValidationException(ex.getMessage(), ValidationError.from(ex, ErrorType.UNEXPECTED_ELEMENT) .element(reader.getName()), ex); }
/** * Get an exception reporting an unexpected XML element. * @param reader the stream reader * @return the exception */ public static XMLStreamException unexpectedElement(final XMLExtendedStreamReader reader) { final XMLStreamException ex = ControllerLogger.ROOT_LOGGER.unexpectedElement(reader.getName(), reader.getLocation()); return new XMLStreamValidationException(ex.getMessage(), ValidationError.from(ex, ErrorType.UNEXPECTED_ELEMENT) .element(reader.getName()), 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); }
/** * 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 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 attribute. * @param reader the stream reader * @param index the attribute index * @return the exception */ public static XMLStreamException unexpectedAttribute(final XMLExtendedStreamReader reader, final int index) { final XMLStreamException ex = ControllerLogger.ROOT_LOGGER.unexpectedAttribute(reader.getAttributeName(index), reader.getLocation()); return new XMLStreamValidationException(ex.getMessage(), ValidationError.from(ex, ErrorType.UNEXPECTED_ATTRIBUTE) .element(reader.getName()) .attribute(reader.getAttributeName(index)), 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); }
/** * 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 an unexpected XML attribute. * @param reader the stream reader * @param index the attribute index * @return the exception */ public static XMLStreamException unexpectedAttribute(final XMLExtendedStreamReader reader, final int index) { final XMLStreamException ex = ControllerLogger.ROOT_LOGGER.unexpectedAttribute(reader.getAttributeName(index), reader.getLocation()); return new XMLStreamValidationException(ex.getMessage(), ValidationError.from(ex, ErrorType.UNEXPECTED_ATTRIBUTE) .element(reader.getName()) .attribute(reader.getAttributeName(index)), 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); } }
/** * 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 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 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 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); }