use of com.github.mustachejava.MustacheNotFoundException in project syndesis by syndesisio.
the class IconGenerator method generate.
public static String generate(final String template, final String name) {
Mustache mustache;
try {
mustache = MUSTACHE_FACTORY.compile("/icon-generator/" + template + ".svg.mustache");
} catch (final MustacheNotFoundException e) {
LOG.warn("Unable to load icon template for: `{}`, will use default template", template);
LOG.debug("Unable to load icon template for: {}", template, e);
mustache = MUSTACHE_FACTORY.compile("/icon-generator/default.svg.mustache");
}
final Map<String, String> data = new HashMap<>();
final String color = COLORS[(int) (Math.random() * COLORS.length)];
data.put("color", color);
data.put("letter", LETTERS.get(Character.toUpperCase(name.charAt(0))));
try (StringWriter icon = new StringWriter()) {
mustache.execute(icon, data).flush();
final String trimmed = trimXml(icon.toString());
return "data:image/svg+xml," + ESCAPER.escape(trimmed);
} catch (final IOException e) {
throw new SyndesisServerException("Unable to generate icon from template `" + template + "`, for name: " + name, e);
}
}
Aggregations