if (languageCodes == null) return null;
int index = Integer.MAX_VALUE;
int currentIndex = 0;
logger.info("Coming in with languageCodes:" + languageCodes);
Language language = null;
SiteNode siteNode = (SiteNode)getObjectWithId(SiteNodeImpl.class, siteNodeId, db);
Repository repository = siteNode.getRepository();
if(repository != null)
{
Collection languages = repository.getRepositoryLanguages();
Iterator languageIterator = languages.iterator();
while(languageIterator.hasNext())
{
RepositoryLanguage repositoryLanguage = (RepositoryLanguage)languageIterator.next();
Language currentLanguage = repositoryLanguage.getLanguage();
logger.info("CurrentLanguageCode:" + currentLanguage.getLanguageCode());
currentIndex = languageCodes.toLowerCase().indexOf(currentLanguage.getLanguageCode().toLowerCase());
if( currentIndex > -1 && currentIndex < index)
{
index = currentIndex;
logger.info("Found the language in the list of supported languages for this site: " + currentLanguage.getName() + " - priority:" + index);
language = currentLanguage;
if (index==0) break; // Continue and try to find a better candidate unless index is 0 (first prio)
}
}
}