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

#22538

detestable
Participant

Wow cool, good news!

If think the most complex part of our needs is the optional part at the beginning of the path.

For the subdomain part, the showcase is quite explicit and a rule like this should do the job :

@Override
public Configuration getConfiguration(final ServletContext context) {
return ConfigurationBuilder
.begin()
.defineRule()
.when(Domain.matches("{subdomain}.domain.com")
.where("subdomain")
.bindsTo(El.property("#{clientStuff.subdomain}"))
.and(DispatchType.isRequest()));
}

With this kind of bean :

// (we are using CDI instead of JSF container)
@Named
@SessionScoped
public class ClientStuff implements Serializable {

private String subdomain;

public String getSubdomain() {
return this.subdomain;
}

public void setSubdomain(String subdomain) {
// BTW, when testing, this setter is called twice (a System.out.println would produce 2 output for a call on en.domain.com for example)
this.subdomain = subdomain;
}
}

When testing I made an other HttpConfigurationProvider for other mappings :

@Override
public Configuration getConfiguration(ServletContext t) {
return ConfigurationBuilder.begin()
.addRule(Join.path("/").to("/WEB-INF/jsf/index.xhtml"))
.addRule(Join.path("/login").to("/WEB-INF/jsf/login.xhtml"))
/* And so on ... */;
}

Which would work flawlessly for :

en.domain.com

en.domain.com/login

uk.domain.com

uk.domain.com/login

(And so on)

Now for the optional part of the path for the language I’m clueless.

Let’s stick with Switzerland example, we know that subdomain “ch” would involve 4 possibilities :

de, it, fr and rm =>

ch.domain.com/de/

ch.domain.com/de/login

ch.domain.com/it/

ch.domain.com/it/login

(And so on)

I need to get the “de” or “it” without confusing with the “login” information.

Shall I add a ConfigurationProvider that would act “between” the domain configuration and the path configuration?

Ooh, while writing an idea comes to me, I could inject my ClientStuff in my configuration provider and rebuild the rules but I’m afraid to loose some flexibility. I’ll give a try and come back with what I did.

Thanks for your answer!