@Test public void transformation() { assertEquals("test", slugNameValidator.transform("test")); assertEquals("test", slugNameValidator.transform("tést")); assertEquals("test-with-accents-and-special-characters", slugNameValidator.transform("test with âccents/and.special%characters")); assertEquals("test-many-forbidden", slugNameValidator.transform("+test | many forbidden:.?")); assertEquals("test-many-forbidden", slugNameValidator.transform("-test---many-forbidden---")); assertEquals("1-test-many-forbidden", slugNameValidator.transform("1-test---many-forbidden---")); }
@Override public String transform(String name) { String strippedAccents = StringUtils.stripAccents(name); String result = RegExUtils.replaceAll(strippedAccents, "[\\W]", REPLACEMENT_CHARACTER); result = RegExUtils.replaceAll(result, "[-]+", REPLACEMENT_CHARACTER); if (result.endsWith(REPLACEMENT_CHARACTER)) { result = result.substring(0, result.length() - 1); } if (result.startsWith(REPLACEMENT_CHARACTER)) { result = result.substring(1); } return result; }
SlugEntityNameValidation extends AbstractEntityNameValidation { @Override public String transform(String name) { String strippedAccents = StringUtils.stripAccents(name); String result = RegExUtils.replaceAll(strippedAccents, "[\\W]", REPLACEMENT_CHARACTER); result = RegExUtils.replaceAll(result, "[-]+", REPLACEMENT_CHARACTER); if (result.endsWith(REPLACEMENT_CHARACTER)) { result = result.substring(0, result.length() - 1); } if (result.startsWith(REPLACEMENT_CHARACTER)) { result = result.substring(1); } return result; } }
SlugEntityNameValidation extends AbstractEntityNameValidation { @Override public String transform(String name) { String strippedAccents = StringUtils.stripAccents(name); String result = RegExUtils.replaceAll(strippedAccents, "[\\W]", REPLACEMENT_CHARACTER); result = RegExUtils.replaceAll(result, "[-]+", REPLACEMENT_CHARACTER); if (result.endsWith(REPLACEMENT_CHARACTER)) { result = result.substring(0, result.length() - 1); } if (result.startsWith(REPLACEMENT_CHARACTER)) { result = result.substring(1); } return result; }  }
SlugEntityNameValidation extends AbstractEntityNameValidation { @Override public String transform(String name) { String strippedAccents = StringUtils.stripAccents(name); String result = RegExUtils.replaceAll(strippedAccents, "[\\W]", REPLACEMENT_CHARACTER); result = RegExUtils.replaceAll(result, "[-]+", REPLACEMENT_CHARACTER); if (result.endsWith(REPLACEMENT_CHARACTER)) { result = result.substring(0, result.length() - 1); } if (result.startsWith(REPLACEMENT_CHARACTER)) { result = result.substring(1); } return result; }  @Override String transform(String name); @Override boolean isValid(String name); }
SlugEntityNameValidation extends AbstractEntityNameValidation { @Override public String transform(String name) { String strippedAccents = StringUtils.stripAccents(name); String result = RegExUtils.replaceAll(strippedAccents, "[\\W]", REPLACEMENT_CHARACTER); result = RegExUtils.replaceAll(result, "[-]+", REPLACEMENT_CHARACTER); if (result.endsWith(REPLACEMENT_CHARACTER)) { result = result.substring(0, result.length() - 1); } if (result.startsWith(REPLACEMENT_CHARACTER)) { result = result.substring(1); } return result; }  @Override String transform(String name); @Override boolean isValid(String name);  }