W3C home > Mailing lists > Public > www-validator-cvs@w3.org > October 2009

2006/unicorn/src/org/w3c/unicorn/action LanguageAction.java,1.6,1.7

From: Thomas Gambet via cvs-syncmail <cvsmail@w3.org>
Date: Fri, 09 Oct 2009 06:48:08 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1Mw9Gq-0007E8-He@lionel-hutz.w3.org>
Update of /sources/public/2006/unicorn/src/org/w3c/unicorn/action
In directory hutz:/tmp/cvs-serv27757/src/org/w3c/unicorn/action

Modified Files:
	LanguageAction.java 
Log Message:
up

Index: LanguageAction.java
===================================================================
RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/action/LanguageAction.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- LanguageAction.java	7 Oct 2009 15:55:55 -0000	1.6
+++ LanguageAction.java	9 Oct 2009 06:48:06 -0000	1.7
@@ -1,9 +1,25 @@
 package org.w3c.unicorn.action;
 
+import java.io.CharArrayWriter;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
 import java.io.IOException;
+import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
+import java.io.Writer;
+import java.net.URLDecoder;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CharsetEncoder;
+import java.util.ArrayList;
 import java.util.Hashtable;
+import java.util.List;
 import java.util.Locale;
+import java.util.Map;
 import java.util.Properties;
 import java.util.TreeMap;
 
@@ -11,9 +27,12 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.commons.io.output.ByteArrayOutputStream;
 import org.apache.velocity.VelocityContext;
 import org.w3c.unicorn.Framework;
 import org.w3c.unicorn.exceptions.UnicornException;
+import org.w3c.unicorn.output.AttachmentOutputFormater;
+import org.w3c.unicorn.output.OutputFormater;
 import org.w3c.unicorn.output.SimpleOutputFormater;
 import org.w3c.unicorn.util.Language;
 import org.w3c.unicorn.util.Message;
@@ -75,13 +94,21 @@
 		if (langParameter == null)
 			Templates.write("language.vm", velocityContext, writer);
 		else {
-			if (Framework.getLanguageProperties().containsKey(langParameter))
+			if (Framework.getLanguageProperties().containsKey(langParameter)) {
+				messages.add(new Message(Message.INFO, "This translation lacks " + (defaultProperties.size() - languageProperties.get(langParameter).size()) + " properties. Help us to improve it."));
 				velocityContext.put("prop", languageProperties.get(langParameter));
-			else if (Language.isISOLanguageCode(langParameter)) {
-				messages.add(new Message(Message.INFO, "Thank you for translating Unicorn in " 
-						+ Language.getLocale(langParameter).getDisplayLanguage(Locale.ENGLISH) 
-						+ ". You can submit a full or a partial translation."));
-				velocityContext.put("prop", createProperties(langParameter));
+			} else if (Language.isISOLanguageCode(langParameter)) {
+				Locale locale = Language.getLocale(langParameter);
+				if (locale == null) {
+					messages.add(new Message(Message.WARNING, "The language code you requested is valid but the coresponding locale seems not to be installed on our system. Please make a request on public-qa-dev@w3.org."));
+					Templates.write("language.vm", velocityContext, writer);
+					writer.close(); return;
+				} else {
+					messages.add(new Message(Message.INFO, "Thank you for translating Unicorn in " 
+							+ Language.getLocale(langParameter).getDisplayLanguage(Locale.ENGLISH) 
+							+ ". You can submit a full or a partial translation."));
+					velocityContext.put("prop", createProperties(langParameter));
+				}
 			} else {
 				messages.add(new Message(Message.ERROR, "$message_invalid_requested_language", null, langParameter));
 				Templates.write("language.vm", velocityContext, writer);
@@ -107,22 +134,85 @@
 		
 		req.setCharacterEncoding("UTF-8");
 		resp.setContentType("text/html; charset=UTF-8");
+	    
+	    //resp.getWriter().println(new String(req.getParameter("ja_universal_checker").getBytes("UTF-8"), "UTF-8"));
+	    
+	    /*File file = new File(Property.get("UPLOADED_FILES_REPOSITORY") + "/test.txt");
+	    file.createNewFile();
+	    FileOutputStream fileStream = new FileOutputStream(file);
+	    OutputStreamWriter os = new OutputStreamWriter(fileStream, "UTF-8");
+	    os.write(req.getParameter("ja_universal_checker"));
+	    os.close();*/
 		
-		if (req.getParameter("translation_language") == null) {
+		String languageParameter = req.getParameter("translation_language");
+		Map<String, Object> contextObjects = new Hashtable<String, Object>();
+
+		if (languageParameter == null) {
 			doGet(req, resp);
 			return;
 		} else {
+			Properties langProps = languageProperties.get(languageParameter);
+			if (langProps == null) {
+				langProps = createProperties(languageParameter);
+				if (langProps == null) {
+					doGet(req, resp);
+					return;
+				}
+			}
+			
+			StringBuilder changeLog = new StringBuilder();
+			
+			for (Object obj : req.getParameterMap().keySet()) {
+				String paramKey = (String) obj;
+				String key;
+				if (!paramKey.startsWith(languageParameter + "_"))
+					continue;
+				else
+					key = paramKey.replace(languageParameter + "_", "");
+				
+				if (!req.getParameter(paramKey).equals("") && !req.getParameter(paramKey).equals(langProps.getProperty(key))) {
+					changeLog.append(key + ":\n");
+					changeLog.append("\t + " + req.getParameter(paramKey) + "\n");
+					if (langProps.getProperty(key) != null)
+						changeLog.append("\t - " + langProps.getProperty(key) + "\n");
+					
+					langProps.put(key, req.getParameter(paramKey));
+				}
+				
+				
+			}
+			
+			
+			
+			//contextObjects.put("changeLog", changeLog);
+			
+			//Writer os = new CharArrayWriter();
+		
+			
+			//langProps.store(new OutputStreamWriter(new ByteArrayOutputStream(), "UTF-8"), "");
+			
+			//contextObjects.put("properties", os.toString());
+			
 			MessageList messages = new MessageList();
-			messages.add(new Message(Message.INFO, "Thank you for your submition."));
+			messages.add(new Message(Message.INFO, "Thank you for your submission."));
 			req.setAttribute("messages", messages);
+			if (req.getParameterMap().containsKey("ucn_lang"))
+				req.getParameterMap().remove("ucn_lang");
 			doGet(req, resp);
 			// From now on the response is committed, careful 
 			
-			String[] recipients = {"thomas.gambet@gmail.com"};
+			String[] recipients = {"thomas.gambet@orange.fr"};
+			
+			OutputFormater mainOutputFormater = new SimpleOutputFormater("language.mail", Property.get("DEFAULT_LANGUAGE"), "text/plain");
+			OutputFormater attachmentOutputFormater = new AttachmentOutputFormater("language.properties", Property.get("DEFAULT_LANGUAGE"), "text/plain", "test.txt");
+			
+			List<OutputFormater> outputFormaters = new ArrayList<OutputFormater>();
+			outputFormaters.add(mainOutputFormater);
+			//outputFormaters.add(attachmentOutputFormater);
 			
 			Mail mailer = new Mail();
 			try {
-				mailer.sendMail(recipients, "test subject", new SimpleOutputFormater("text", Property.get("DEFAULT_LANGUAGE")), null);
+				mailer.sendMail(recipients, "test subject", outputFormaters, contextObjects);
 			} catch (UnicornException e) {
 				// TODO Auto-generated catch block
 				e.printStackTrace();
@@ -136,34 +226,12 @@
 	private Properties createProperties(String langParameter) {
 		Properties props = new Properties();
 		Locale locale = Language.getLocale(langParameter);
+		if (locale == null)
+			return null;
 		props.put("lang", locale.getLanguage());
-		props.put("language", locale.getDisplayLanguage(Locale.ENGLISH));
+		props.put("language", locale.getDisplayLanguage(locale));
 		return props;
 	}
-	
-	private void checkParameters(HttpServletRequest req) {
-		
-		/*String languageParameter = req.getParameter("translation_language");
-		
-		for (Object obj : req.getParameterMap().keySet()) {
-			
-			String paramKey = (String) obj;
-			String key;
-			
-			if (!paramKey.startsWith(languageParameter + "_"))
-				continue;
-			else
-				key = paramKey.replace(languageParameter + "_", "");
-			
-			Properties langProps = languageProperties.get(languageParameter);
-			
-			if (langProps.getProperty(key) == null || !req.getParameter(paramKey).equals(langProps.getProperty(key))) {
-				
-			}
-			
-		}*/
-		
-	}
 
 	public static void addLanguageProperties(Properties props) {
 		languageProperties.put(props.getProperty("lang"), (Properties) props.clone());
Received on Friday, 9 October 2009 06:48:13 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 15:17:39 UTC