- From: Denis Tea via cvs-syncmail <cvsmail@w3.org>
- Date: Tue, 12 Feb 2008 09:20:54 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2006/unicorn/org/w3c/unicorn/tests In directory hutz:/tmp/cvs-serv24308/org/w3c/unicorn/tests Modified Files: FirstServlet.java Log Message: if ucn_lang is null, the language for the template is choosen in the Accept-Language List. Index: FirstServlet.java =================================================================== RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/tests/FirstServlet.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- FirstServlet.java 11 Feb 2008 14:17:56 -0000 1.5 +++ FirstServlet.java 12 Feb 2008 09:20:52 -0000 1.6 @@ -13,6 +13,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Set; import javax.servlet.ServletConfig; import javax.servlet.ServletException; @@ -138,8 +139,9 @@ if (aHttpServletRequest.getParameterValues("ucn_lang") != null){ templateLang = aHttpServletRequest.getParameterValues("ucn_lang")[0]; } - else - templateLang = LocalizedString.DEFAULT_LANGUAGE; + else { + templateLang = chooseTemplateLang(aLocale); + } mapOfOutputParameter.put("lang", templateLang); @@ -233,7 +235,7 @@ // Language of the template // ucn_lang is a parameter which is define in xx_index.html.vm. // It is an hidden parameter of a form. - String templateLang = LocalizedString.DEFAULT_LANGUAGE; + String templateLang = null; FirstServlet.logger.trace("doPost"); @@ -270,6 +272,9 @@ } } + if (templateLang == null) + templateLang = chooseTemplateLang(aLocale); + if (null == aLocale) { aUnicornCall.setLang(LocalizedString.DEFAULT_LANGUAGE); } else { @@ -467,5 +472,23 @@ aHttpServletResponse.getWriter().println("</pre>"); } } + + + /* + * This method returns the first language of the accept language list + * which is equal to one of available index template language + */ + private String chooseTemplateLang(String aLocale){ + String[] tabLang = aLocale.split(";|,"); + + for (int i=0; i<tabLang.length; i++){ + if (Framework.outputLang.contains(tabLang[i])) + return tabLang[i]; + else if (Framework.outputLang.contains(tabLang[i].split("-")[0])) + return tabLang[i].split("-")[0]; + } + + return LocalizedString.DEFAULT_LANGUAGE; + } }
Received on Tuesday, 12 February 2008 09:21:05 UTC