}
public WGLanguage webtmlSelectDatabaseLanguage(WGDatabase db, TMLContext context) throws WGAPIException {
WGLanguage lang = null;
// First try: Current context language
String currentLangName = null;
if (LanguageBehaviourTools.isMultiLanguageContext(context)) {
currentLangName = context.content().getLanguage().getName();
if (LanguageBehaviourTools.isMultiLanguageContext(context)) {
lang = db.getLanguage(currentLangName);
if (lang != null && !lang.isDummy()) {
return lang;
}
}
}
// Second try: Main context language
if (LanguageBehaviourTools.isMultiLanguageContext(context.getmaincontext())) {
String mainLangName = context.getmaincontext().content().getLanguage().getName();
if (!mainLangName.equals(currentLangName)) {
lang = db.getLanguage(mainLangName);
if (lang != null && !lang.isDummy()) {
return lang;
}
}
}
// Third try: Request locales
if (context.iswebenvironment()) {
lang = LanguageBehaviourTools.chooseLanguageByRequestLocales(db, context.getrequest());
if (lang != null && !lang.isDummy()) {
return lang;
}
}
// Fourth try: Database default language
String defaultLangName = db.getDefaultLanguage();
lang = db.getLanguage(defaultLangName);
if (lang != null && !lang.isDummy()) {
return lang;
}
return null;
}