W3C home > Mailing lists > Public > www-validator-cvs@w3.org > January 2008

2006/unicorn/org/w3c/unicorn/tests FirstServlet.java,1.3,1.4

From: Denis Tea via cvs-syncmail <cvsmail@w3.org>
Date: Tue, 22 Jan 2008 13:55:11 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1JHJap-0004QD-Ut@lionel-hutz.w3.org>

Update of /sources/public/2006/unicorn/org/w3c/unicorn/tests
In directory hutz:/tmp/cvs-serv16946/org/w3c/unicorn/tests

Modified Files:
	FirstServlet.java 
Log Message:
Internationalization : Addition of template language in accept language list.

Index: FirstServlet.java
===================================================================
RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/tests/FirstServlet.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- FirstServlet.java	21 Sep 2006 16:01:25 -0000	1.3
+++ FirstServlet.java	22 Jan 2008 13:55:09 -0000	1.4
@@ -29,6 +29,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.velocity.exception.ParseErrorException;
 import org.apache.velocity.exception.ResourceNotFoundException;
+import org.w3c.unicorn.Framework;
 import org.w3c.unicorn.UnicornCall;
 import org.w3c.unicorn.contract.EnumInputMethod;
 import org.w3c.unicorn.exceptions.NoTaskException;
@@ -116,7 +117,6 @@
 	throws ServletException, IOException {
 		FirstServlet.logger.trace("doGet");
 
-
 		// Variables related to the output
 		final Map<String, String[]> mapOfSpecificParameter = new Hashtable<String, String[]>();
 		final Map<String, String> mapOfOutputParameter = new Hashtable<String, String>();
@@ -124,17 +124,31 @@
 		mapOfOutputParameter.put("format", "xhtml10");
 		mapOfOutputParameter.put("charset", "UTF-8");
 		mapOfOutputParameter.put("mimetype", "text/html");
-		final Locale aLocale = aHttpServletRequest.getLocale();
-		final UnicornCall aUnicornCall = new UnicornCall();
+		
+		// Returns the preferred Locale that the client will accept content in, 
+		// based on the Accept-Language header
+		final String aLocale = aHttpServletRequest.getHeader("Accept-Language");
+		
+		final UnicornCall aUnicornCall = new UnicornCall();	
+		
+		// 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 = null;
+		if (aHttpServletRequest.getParameterValues("ucn_lang") != null){
+			templateLang = aHttpServletRequest.getParameterValues("ucn_lang")[0];
+		}
+		else
+			templateLang = aLocale.toString();
+		
+		mapOfOutputParameter.put("lang", templateLang);
+		
 		if (null == aLocale) {
-			mapOfOutputParameter.put("lang", LocalizedString.DEFAULT_LANGUAGE);
 			aUnicornCall.setLang(LocalizedString.DEFAULT_LANGUAGE);
 		} else {
-			mapOfOutputParameter.put("lang", aLocale.toString());
-			aUnicornCall.setLang(aLocale.toString());
+			aUnicornCall.setLang(templateLang + "," + aLocale);		
 		}
-
-		
+	
 		for (
 				final Enumeration aEnumParamName = aHttpServletRequest.getParameterNames();
 				aEnumParamName.hasMoreElements();) {
@@ -182,6 +196,8 @@
 	 * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 	 */
 	@Override
+	
+	
 	protected void doPost (
 			final HttpServletRequest aHttpServletRequest,
 			final HttpServletResponse aHttpServletResponse)
@@ -209,13 +225,18 @@
 		mapOfOutputParameter.put("charset", "UTF-8");
 		mapOfOutputParameter.put("mimetype", "text/html");
 		final Locale aLocale = aHttpServletRequest.getLocale();
-		if (null == aLocale) {
+		
+		if (null == aLocale) {		
 			mapOfOutputParameter.put("lang", LocalizedString.DEFAULT_LANGUAGE);
 			aUnicornCall.setLang(LocalizedString.DEFAULT_LANGUAGE);
+			
 		} else {
 			mapOfOutputParameter.put("lang", aLocale.toString());
-			aUnicornCall.setLang(aLocale.toString());
+			
+			//aUnicornCall.setLang(aLocale.toString());
+			aUnicornCall.setLang("fr");
 		}
+	
 		final Map<String, String[]> mapOfSpecificParameter = new Hashtable<String, String[]>();
 		
 		FileItem aFileItemUploaded = null;
@@ -304,13 +325,19 @@
 		
 		// Unicorn parameter
 		sParamName = sParamName.substring(4);
-
+		
+		
 		// Output specific parameter
 		if (sParamName.startsWith(Property.get("UNICORN_PARAMETER_OUTPUT_PREFIX"))) {
 			sParamName = sParamName.substring(4);
 			mapOfSpecificParameter.put(sParamName, tStringParamValue);
 			return;
 		}
+		
+		if (sParamName.equals("lang")) {
+			aUnicornCall.addParameter("ucn_lang", tStringParamValue);
+		}
+		
 		// Global Unicorn parameter
 		if (sParamName.equals("task")) {
 			//FirstServlet.logger.debug("");
Received on Tuesday, 22 January 2008 13:55:22 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Thursday, 26 April 2012 12:55:00 GMT