in enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/ExternalRules.java [193:214]
InputStream transform(String sourceLocation, InputStream sourceXml, String xsltLocation) {
if (xsltLocation == null || xsltLocation.trim().isEmpty()) {
return sourceXml;
}
try (InputStream in = resolveDescriptor(xsltLocation);
ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
Transformer transformer = TransformerFactory.newInstance().newTransformer(new StreamSource(in));
transformer.transform(new StreamSource(sourceXml), new StreamResult(baos));
final byte[] bytes = baos.toByteArray();
getLog().info(() -> ("Rules transformed by " + xsltLocation + " from " + location + ":\n\n"
+ new String(bytes, StandardCharsets.UTF_8)));
return new ByteArrayInputStream(bytes);
} catch (IOException
| EnforcerRuleException
| TransformerConfigurationException
| TransformerFactoryConfigurationError e) {
throw new RuntimeException("Could not open resource " + xsltLocation);
} catch (TransformerException e) {
throw new RuntimeException("Could not transform " + sourceLocation + " usinng XSLT " + xsltLocation);
}
}