in log4j-changelog/src/main/java/org/apache/logging/log4j/changelog/ChangelogEntry.java [149:203]
public static ChangelogEntry readFromXmlFile(final Path path) {
// Read the `entry` root element
final Element entryElement = XmlReader.readXmlFileRootElement(path, "entry");
final String typeAttribute = XmlReader.requireAttribute(entryElement, "type");
final Type type;
try {
type = Type.fromXmlAttribute(typeAttribute);
} catch (final Exception error) {
throw XmlReader.failureAtXmlNode(error, entryElement, "`type` attribute read failure");
}
// Read the `issue` elements
final List<Issue> issues = XmlReader
.findChildElementsMatchingName(entryElement, "issue")
.map(issueElement -> {
final String issueId = XmlReader.requireAttribute(issueElement, "id");
final String issueLink = XmlReader.requireAttribute(issueElement, "link");
return new Issue(issueId, issueLink);
})
.collect(Collectors.toList());
// Read the `author` elements
final List<Author> authors = XmlReader
.findChildElementsMatchingName(entryElement, "author")
.map(authorElement -> {
@Nullable
final String authorId = authorElement.hasAttribute("id")
? authorElement.getAttribute("id")
: null;
@Nullable
final String authorName = authorElement.hasAttribute("name")
? authorElement.getAttribute("name")
: null;
if (authorId == null && authorName == null) {
throw XmlReader.failureAtXmlNode(
authorElement, "`author` must have at least one of `id` or `name` attributes");
}
return new Author(authorId, authorName);
})
.collect(Collectors.toList());
if (authors.isEmpty()) {
throw XmlReader.failureAtXmlNode(entryElement, "no `author` elements found");
}
// Read the `description` element
final Element descriptionElement = XmlReader.requireChildElementMatchingName(entryElement, "description");
final String descriptionFormat = XmlReader.requireAttribute(descriptionElement, "format");
final String descriptionText = StringUtils.trimNullable(descriptionElement.getTextContent());
final Description description = new Description(descriptionFormat, descriptionText);
// Create the instance
return new ChangelogEntry(type, issues, authors, description);
}