CobrandNameSanitizer implements Sanitizer<String> { @Override public String execute(String content) { if (StringUtils.isBlank(content)) { return content; } Pattern pattern = Pattern.compile("[\\w-]+"); if (!pattern.matcher(content).matches()) { String sanitized = new HtmlSanitizer().execute(content); _logger.warn("Invalid cobrand name (" + sanitized + "). Setting cobrand name to \"default\"."); return "default"; } return content; }  @Override String execute(String content);  }
@Test public void testExecute() throws Exception { CobrandNameSanitizer sanitizer = new CobrandNameSanitizer(); assertEquals("Abc-12_3", sanitizer.execute("Abc-12_3")); assertEquals("", sanitizer.execute("")); assertEquals(" ", sanitizer.execute(" ")); assertEquals(null, sanitizer.execute(null)); assertEquals("default", sanitizer.execute("Abc- 12_3")); assertEquals("default", sanitizer.execute("Abc-12_3!")); assertEquals("default", sanitizer.execute("Abc-12_3'")); assertEquals("default", sanitizer.execute("Abc-12_3\"")); assertEquals("default", sanitizer.execute("<script>")); }