Re: Complex URL schema with i18n and l10n

Splash Forums Rewrite Users Complex URL schema with i18n and l10n Re: Complex URL schema with i18n and l10n

#22544

detestable
Participant

Hmmm, may be my case is quite specific, but it would be possible to handle it with regexes.

What do you think about a full regex rule like this :

private static final String pathExpr = "(?<lang>de|fr|it|rm)";
private static final String rootLangPath = "^(/" + pathExpr + ")?";

@Override
public Configuration getConfiguration(ServletContext t) {
return ConfigurationBuilder.begin()
// Binds lang once for all
.addRule(Regex.path(rootLangPath + ".*") // permissive regex
.where("lang")
.bindsTo(El.property("#{langBean.lang}")))

// Index rule
.addRule(Regex.path("^/" + pathExpr + "?$")
.to("/WEB-INF/jsf/index.xhtml"))

// Login rule
.addRule(Regex.path(rootLangPath + "/login$")
.to("/WEB-INF/jsf/login.xhtml"))

// Logout rule
.addRule(Regex.path(rootLangPath + "/logout$")
.to("/WEB-INF/jsf/logout.xhtml"))
/* And so on ... */;
}

I have to admit that it looks like patchwork but it allows us to handle one rule per path, with our optional lang.