@Test public void testUrlFriendly() throws Exception { String sentence = "Männer fahren gerne mit dem Floß und springen über Möhren, daß ist schön. [ ] 12.01.2012 ?*#."; String urlfriendly = SeoUtils.urlFriendly(sentence); assertEquals("maenner-fahren-gerne-mit-dem-floss-und-springen-ueber-moehren-dass-ist-schoen-12-01-2012", urlfriendly); }
public static String urlFriendly(String urlUnfriendly) { String urlFriendly = urlUnfriendly.toLowerCase(); urlFriendly = urlFriendly.replaceAll("ä", "ae"); urlFriendly = urlFriendly.replaceAll("ö", "oe"); urlFriendly = urlFriendly.replaceAll("ü", "ue"); urlFriendly = urlFriendly.replaceAll("ß", "ss"); urlFriendly = urlFriendly.replaceAll("ß", "ss"); urlFriendly = urlFriendly.replaceAll("\\.", "-"); urlFriendly = urlFriendly.replaceAll(",", "-"); urlFriendly = urlFriendly.replaceAll("\\s", "-"); urlFriendly = urlFriendly.replaceAll("[^a-z0-9\\-]+", ""); urlFriendly = urlFriendly.replaceAll("\\-+", "-"); if (urlFriendly.endsWith("-")) { return urlFriendly.substring(0, urlFriendly.length() - 1); } return urlFriendly; }
SeoUtils { public static String urlFriendly(String urlUnfriendly) { String urlFriendly = urlUnfriendly.toLowerCase(); urlFriendly = urlFriendly.replaceAll("ä", "ae"); urlFriendly = urlFriendly.replaceAll("ö", "oe"); urlFriendly = urlFriendly.replaceAll("ü", "ue"); urlFriendly = urlFriendly.replaceAll("ß", "ss"); urlFriendly = urlFriendly.replaceAll("ß", "ss"); urlFriendly = urlFriendly.replaceAll("\\.", "-"); urlFriendly = urlFriendly.replaceAll(",", "-"); urlFriendly = urlFriendly.replaceAll("\\s", "-"); urlFriendly = urlFriendly.replaceAll("[^a-z0-9\\-]+", ""); urlFriendly = urlFriendly.replaceAll("\\-+", "-"); if (urlFriendly.endsWith("-")) { return urlFriendly.substring(0, urlFriendly.length() - 1); } return urlFriendly; } }
SeoUtils { public static String urlFriendly(String urlUnfriendly) { String urlFriendly = urlUnfriendly.toLowerCase(); urlFriendly = urlFriendly.replaceAll("ä", "ae"); urlFriendly = urlFriendly.replaceAll("ö", "oe"); urlFriendly = urlFriendly.replaceAll("ü", "ue"); urlFriendly = urlFriendly.replaceAll("ß", "ss"); urlFriendly = urlFriendly.replaceAll("ß", "ss"); urlFriendly = urlFriendly.replaceAll("\\.", "-"); urlFriendly = urlFriendly.replaceAll(",", "-"); urlFriendly = urlFriendly.replaceAll("\\s", "-"); urlFriendly = urlFriendly.replaceAll("[^a-z0-9\\-]+", ""); urlFriendly = urlFriendly.replaceAll("\\-+", "-"); if (urlFriendly.endsWith("-")) { return urlFriendly.substring(0, urlFriendly.length() - 1); } return urlFriendly; } private  SeoUtils(); }
SeoUtils { public static String urlFriendly(String urlUnfriendly) { String urlFriendly = urlUnfriendly.toLowerCase(); urlFriendly = urlFriendly.replaceAll("ä", "ae"); urlFriendly = urlFriendly.replaceAll("ö", "oe"); urlFriendly = urlFriendly.replaceAll("ü", "ue"); urlFriendly = urlFriendly.replaceAll("ß", "ss"); urlFriendly = urlFriendly.replaceAll("ß", "ss"); urlFriendly = urlFriendly.replaceAll("\\.", "-"); urlFriendly = urlFriendly.replaceAll(",", "-"); urlFriendly = urlFriendly.replaceAll("\\s", "-"); urlFriendly = urlFriendly.replaceAll("[^a-z0-9\\-]+", ""); urlFriendly = urlFriendly.replaceAll("\\-+", "-"); if (urlFriendly.endsWith("-")) { return urlFriendly.substring(0, urlFriendly.length() - 1); } return urlFriendly; } private  SeoUtils(); static String urlFriendly(String urlUnfriendly); }
SeoUtils { public static String urlFriendly(String urlUnfriendly) { String urlFriendly = urlUnfriendly.toLowerCase(); urlFriendly = urlFriendly.replaceAll("ä", "ae"); urlFriendly = urlFriendly.replaceAll("ö", "oe"); urlFriendly = urlFriendly.replaceAll("ü", "ue"); urlFriendly = urlFriendly.replaceAll("ß", "ss"); urlFriendly = urlFriendly.replaceAll("ß", "ss"); urlFriendly = urlFriendly.replaceAll("\\.", "-"); urlFriendly = urlFriendly.replaceAll(",", "-"); urlFriendly = urlFriendly.replaceAll("\\s", "-"); urlFriendly = urlFriendly.replaceAll("[^a-z0-9\\-]+", ""); urlFriendly = urlFriendly.replaceAll("\\-+", "-"); if (urlFriendly.endsWith("-")) { return urlFriendly.substring(0, urlFriendly.length() - 1); } return urlFriendly; } private  SeoUtils(); static String urlFriendly(String urlUnfriendly);  }