@Test public void shouldGenerateIcon() { for (int letter = 'A'; letter <= 'Z'; letter++) { final String letterString = String.valueOf((char) letter); final String icon = IconGenerator.generate("swagger-connector-template", letterString); assertThat(icon).startsWith(PREFIX); assertThat(icon).matches(".*circle.*%20style%3D%22fill%3A%23fff.*"); assertThat(icon).matches(".*path.*%20style%3D%22fill%3A%23fff.*"); } }
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); } }
IconGenerator { 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); } } }
IconGenerator { 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); } } private  IconGenerator(); }
IconGenerator { 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); } } private  IconGenerator(); static String generate(final String template, final String name); }
IconGenerator { 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); } } private  IconGenerator(); static String generate(final String template, final String name);  }