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

2006/unicorn/src/org/w3c/unicorn/action LanguageAction.java,1.12,1.13

From: Thomas Gambet via cvs-syncmail <cvsmail@w3.org>
Date: Mon, 12 Oct 2009 16:02:53 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1MxNML-00075S-9h@lionel-hutz.w3.org>
Update of /sources/public/2006/unicorn/src/org/w3c/unicorn/action
In directory hutz:/tmp/cvs-serv27228/src/org/w3c/unicorn/action

Modified Files:
	LanguageAction.java 
Log Message:
do not send a mail if nothing has changed (and display an error message)
+ changed subject in case of an anonymous submission

Index: LanguageAction.java
===================================================================
RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/action/LanguageAction.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- LanguageAction.java	12 Oct 2009 15:26:46 -0000	1.12
+++ LanguageAction.java	12 Oct 2009 16:02:51 -0000	1.13
@@ -92,7 +92,7 @@
 		
 		PrintWriter writer = resp.getWriter();
 		String langParameter = req.getParameter(Property.get("UNICORN_PARAMETER_PREFIX") + "lang");
-		if (langParameter == null)
+		if (langParameter == null || req.getAttribute("submitted") != null)
 			Templates.write("language.vm", velocityContext, writer);
 		else {
 			if (Framework.getLanguageProperties().containsKey(langParameter)) {
@@ -166,6 +166,7 @@
 				langProps = (Properties) languageProperties.get(languageParameter).clone();
 			
 			StringBuilder changeLog = new StringBuilder();
+			boolean changed = false;
 			for (Object obj : req.getParameterMap().keySet()) {
 				String paramKey = (String) obj;
 				String key;
@@ -175,6 +176,8 @@
 					key = paramKey.replace(languageParameter + "_", "");
 				
 				if (!req.getParameter(paramKey).equals("") && !req.getParameter(paramKey).equals(langProps.getProperty(key))) {
+					changed = true;
+					
 					changeLog.append("\n" + key + ":\n");
 					changeLog.append("\t + " + req.getParameter(paramKey) + "\n");
 					if (langProps.getProperty(key) != null)
@@ -184,6 +187,13 @@
 				}
 			}
 			
+			if (!changed) {
+				MessageList messages = new MessageList();
+				messages.add(new Message(Message.ERROR, "You haven't made any changes."));
+				req.setAttribute("messages", messages);
+				doGet(req, resp);
+			}
+			
 			ByteArrayOutputStream baos = new ByteArrayOutputStream();
 			OutputStreamWriter osw = new OutputStreamWriter(baos, "UTF-8");
 			langProps.store(osw, "Submitted by " + req.getParameter("translator_name") + " <" + req.getParameter("translator_mail") + ">");
@@ -206,14 +216,16 @@
 			MessageList messages = new MessageList();
 			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");
+			req.setAttribute("submitted", true);
 			doGet(req, resp);
-			// From now on the response is committed, careful 
 			
 			String[] recipients = {Property.getProps("mail.properties").getProperty("unicorn.mail.language.to"), 
 					req.getParameter("translator_mail")};
-			String subject = "Unicorn - Translation in " + contextObjects.get("language") + " (submitted by " + req.getParameter("translator_name") + ")";
+			String subject;
+			if (!"".equals(req.getParameter("translator_name")))
+				subject = "Unicorn - Translation in " + contextObjects.get("language") + " (submitted by " + req.getParameter("translator_name") + ")";
+			else
+				subject = "Unicorn - Translation in " + contextObjects.get("language") + " (anonymous submission)";
 			
 			OutputFormater mainOutputFormater = new SimpleOutputFormater("language.mail", Property.get("DEFAULT_LANGUAGE"), "text/plain");
 			OutputFormater fileOutputFormater = new FileOutputFormater("language.properties", Property.get("DEFAULT_LANGUAGE"), "text/plain", languageParameter + ".properties");
Received on Monday, 12 October 2009 16:02:57 UTC

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