Java library for cleaning up user-entered title to make it show up in a URL? -


i doing web application. have seo-friendly link such following:

http://somesite.org/user-entered-title 

the above user-entered-title extracted user-created records have field called title.

i wondering whether there java library cleaning such user-entered text (remove spaces, example) before displaying in url.

my target text such "stackoverflow-is-great" after cleanup user-entered "stackoverflow great".

i able write code replace spaces in string dashes, not sure other rules/ideas/best practices out there making text part of url.

please note user-entered-title may in different languages, not english.

thanks input , pointers!

regards.

what want kind of "slugifying" prhase url, seo-friendly.

once had problem, came use solution provided in maddemcode.com. below you'll find adapted code.

the trick use normalize jdk class little additional cleanup. usage simple:

// casingchange-aeiouaeiou-takesexcess-spaces system.out.println(slugify("casingchange áéíóúâêîôû   takesexcess    spaces  ")); // these-are-good-special-characters-sic system.out.println(slugify("these special characters šíč")); // some-exceptions-123-aeiou system.out.println(slugify(" exceptions ¥123  ã~e~iõ~u!@#$%¨&*() ")); // gonna-accomplish-yadda system.out.println(slugify("gonna accomplish, yadda, 완수하다, 소양양)이 있는 ")); 

function code:

public static string slugify(string input) {     return normalizer.normalize(input, normalizer.form.nfd)             .replaceall("[^\\p{ascii}]", "")             .replaceall("[^ \\w]", "").trim()             .replaceall("\\s+", "-").tolowercase(locale.english); } 

in source page (http://maddemcode.com/java/seo-friendly-urls-using-slugify-in-java/) can take @ comes from. small snippet above, though, works same.

as can see, there exceptional chars aren't converted. knowledge, translates them, uses kind of map, djago's urlify (see example map here). need them, believe best bet making one.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -