- From: Thomas Gambet via cvs-syncmail <cvsmail@w3.org>
- Date: Wed, 07 Oct 2009 15:55:57 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2006/unicorn/src/org/w3c/unicorn/action In directory hutz:/tmp/cvs-serv9180/src/org/w3c/unicorn/action Modified Files: LanguageAction.java Log Message: added doPost method Index: LanguageAction.java =================================================================== RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/action/LanguageAction.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- LanguageAction.java 6 Oct 2009 16:33:00 -0000 1.5 +++ LanguageAction.java 7 Oct 2009 15:55:55 -0000 1.6 @@ -3,6 +3,7 @@ import java.io.IOException; import java.io.PrintWriter; import java.util.Hashtable; +import java.util.Locale; import java.util.Properties; import java.util.TreeMap; @@ -12,10 +13,14 @@ import org.apache.velocity.VelocityContext; import org.w3c.unicorn.Framework; +import org.w3c.unicorn.exceptions.UnicornException; +import org.w3c.unicorn.output.SimpleOutputFormater; import org.w3c.unicorn.util.Language; +import org.w3c.unicorn.util.Message; import org.w3c.unicorn.util.MessageList; import org.w3c.unicorn.util.Property; import org.w3c.unicorn.util.Templates; +import org.w3c.unicorn.util.Mail; /** * Servlet implementation class LanguageServlet @@ -41,11 +46,16 @@ } } - String defaultLang = Property.get("DEFAULT_LANGUAGE"); + req.setCharacterEncoding("UTF-8"); + resp.setContentType("text/html; charset=UTF-8"); - MessageList messages = new MessageList(defaultLang); + String defaultLang = Property.get("DEFAULT_LANGUAGE"); + MessageList messages; - resp.setContentType("text/html; charset=UTF-8"); + if (req.getAttribute("messages") != null && req.getAttribute("messages") instanceof MessageList) + messages = (MessageList) req.getAttribute("messages"); + else + messages = new MessageList(); VelocityContext velocityContext = new VelocityContext(Language.getContext(defaultLang)); velocityContext.put("queryString", "./"); @@ -65,17 +75,94 @@ if (langParameter == null) Templates.write("language.vm", velocityContext, writer); else { - velocityContext.put("prop", languageProperties.get(langParameter)); + if (Framework.getLanguageProperties().containsKey(langParameter)) + 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 { + messages.add(new Message(Message.ERROR, "$message_invalid_requested_language", null, langParameter)); + Templates.write("language.vm", velocityContext, writer); + writer.close(); return; + } Templates.write("language.form.vm", velocityContext, writer); + writer.close(); } - writer.close(); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ - protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - doGet(request, response); + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + + if (!Framework.isUcnInitialized) { + Framework.init(); + if (!Framework.isUcnInitialized) { + resp.sendError(500, "Unicorn is not initialized properly. Check logs."); + return; + } + } + + req.setCharacterEncoding("UTF-8"); + resp.setContentType("text/html; charset=UTF-8"); + + if (req.getParameter("translation_language") == null) { + doGet(req, resp); + return; + } else { + MessageList messages = new MessageList(); + messages.add(new Message(Message.INFO, "Thank you for your submition.")); + req.setAttribute("messages", messages); + doGet(req, resp); + // From now on the response is committed, careful + + String[] recipients = {"thomas.gambet@gmail.com"}; + + Mail mailer = new Mail(); + try { + mailer.sendMail(recipients, "test subject", new SimpleOutputFormater("text", Property.get("DEFAULT_LANGUAGE")), null); + } catch (UnicornException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + //checkParameters(req); + } + + } + + private Properties createProperties(String langParameter) { + Properties props = new Properties(); + Locale locale = Language.getLocale(langParameter); + props.put("lang", locale.getLanguage()); + props.put("language", locale.getDisplayLanguage(Locale.ENGLISH)); + 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) {
Received on Wednesday, 7 October 2009 15:55:59 UTC