in apache-rat-core/src/main/java/org/apache/rat/configuration/XMLConfigurationWriter.java [198:300]
void writeDescription(final IXmlWriter writer, final Description desc, final IHeaderMatcher comp) throws RatException {
Description description = desc;
IHeaderMatcher component = comp;
try {
switch (description.getType()) {
case MATCHER:
// see if id was registered
Optional<Description> id = description.childrenOfType(ComponentType.PARAMETER).stream()
.filter(i -> XMLConfig.ATT_ID.equals(i.getCommonName())).findFirst();
// id will not be present in matcherRef
if (id.isPresent()) {
String matcherId = id.get().getParamValue(component);
// if we have seen the ID before just put a reference to the other one.
if (matchers.contains(matcherId)) {
component = new MatcherRefBuilder.IHeaderMatcherProxy(matcherId, null);
description = component.getDescription();
} else {
matchers.add(matcherId);
}
// remove the matcher id if it is a UUID
try {
UUID.fromString(matcherId);
description.getChildren().remove(XMLConfig.ATT_ID);
} catch (IllegalArgumentException expected) {
if (description.getCommonName().equals("spdx")) {
description.getChildren().remove(XMLConfig.ATT_ID);
}
}
}
// if resource only list the resource not the contents of the matcher
Optional<Description> resource = description.childrenOfType(ComponentType.PARAMETER).stream()
.filter(i -> XMLConfig.ATT_RESOURCE.equals(i.getCommonName())).findFirst();
if (resource.isPresent()) {
String resourceStr = resource.get().getParamValue(component);
if (StringUtils.isNotBlank(resourceStr)) {
description.getChildren().remove("enclosed");
}
}
writeComment(writer, description);
writer.openElement(description.getCommonName());
writeChildren(writer, description, component);
writer.closeElement();
break;
case LICENSE:
writer.openElement(XMLConfig.LICENSE);
writeChildren(writer, description, component);
writer.closeElement();
break;
case PARAMETER:
if ("id".equals(description.getCommonName())) {
try {
String paramId = description.getParamValue(component);
// if a UUID skip it.
if (paramId != null) {
UUID.fromString(paramId);
return;
}
} catch (IllegalArgumentException expected) {
// do nothing.
}
}
if (description.getChildType() == String.class) {
boolean inline = XMLConfig.isInlineNode(component.getDescription().getCommonName(),
description.getCommonName());
String s = description.getParamValue(component);
if (StringUtils.isNotBlank(s)) {
if (!inline) {
writer.openElement(description.getCommonName());
}
writer.content(description.getParamValue(component));
if (!inline) {
writer.closeElement();
}
}
} else {
try {
if (description.isCollection()) {
for (IHeaderMatcher matcher : (Collection<IHeaderMatcher>) description
.getter(component.getClass()).invoke(component)) {
writeDescription(writer, matcher.getDescription(), matcher);
}
} else {
IHeaderMatcher matcher = (IHeaderMatcher) description.getter(component.getClass())
.invoke(component);
writeDescription(writer, matcher.getDescription(), matcher);
}
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
| NoSuchMethodException | SecurityException | RatException e) {
throw new ImplementationException(e);
}
}
break;
case BUILD_PARAMETER:
// ignore;
break;
}
} catch (IOException e) {
throw new RatException(e);
}
}