- From: Thomas Gambet via cvs-syncmail <cvsmail@w3.org>
- Date: Tue, 06 Oct 2009 08:16:04 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2006/unicorn/src/org/w3c/unicorn/action In directory hutz:/tmp/cvs-serv21432/src/org/w3c/unicorn/action Modified Files: LanguageAction.java IndexAction.java Action.java ObserveAction.java Log Message: working on language strings Index: IndexAction.java =================================================================== RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/action/IndexAction.java,v retrieving revision 1.24 retrieving revision 1.25 diff -u -d -r1.24 -r1.25 --- IndexAction.java 2 Oct 2009 16:49:52 -0000 1.24 +++ IndexAction.java 6 Oct 2009 08:16:02 -0000 1.25 @@ -18,7 +18,7 @@ import org.apache.velocity.VelocityContext; import org.w3c.unicorn.Framework; 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; @@ -43,32 +43,20 @@ resp.setContentType("text/html; charset=UTF-8"); - ArrayList<Message> messages = new ArrayList<Message>(); + //ArrayList<Message> messages = new ArrayList<Message>(); + MessageList messages = new MessageList(Property.get("DEFAULT_LANGUAGE")); String paramPrefix = Property.get("UNICORN_PARAMETER_PREFIX"); - String lang; - String task; String queryString = "./" + getQueryStringWithout(paramPrefix + "lang", req); - /*if (req.getAttribute("unicorn_parameters") instanceof Map<?, ?>) { - Map<?, ?> reqParams = (Map<?, ?>) req.getAttribute("unicorn_parameters"); - lang = getLanguage((String) reqParams.get(paramPrefix + "lang"), req, messages); - task = getTask((String) reqParams.get(paramPrefix + "task"), null); - } else {*/ - lang = getLanguage((String) req.getParameter(paramPrefix + "lang"), req, messages); - task = getTask((String) req.getParameter(paramPrefix + "task"), null); - //} - - /*if (req.getAttribute("unicorn_messages") != null) { - ArrayList<?> ucnMessages = (ArrayList<?>) req.getAttribute("unicorn_messages"); - for (Object mess : ucnMessages) - messages.add((Message) mess); - }*/ + String lang = getLanguage((String) req.getParameter(paramPrefix + "lang"), req, messages); + messages.setLang(lang); + String task = getTask((String) req.getParameter(paramPrefix + "task"), null); VelocityContext velocityContext = new VelocityContext(Language.getContext(lang)); velocityContext.put("queryString", queryString); velocityContext.put("messages", messages); velocityContext.put("current_task", Framework.mapOfTask.get(task)); - velocityContext.put("default_task", Framework.mapOfTask.get(Framework.mapOfTask.getDefaultTaskId())); + velocityContext.put("default_task", Framework.mapOfTask.getDefaultTask()); velocityContext.put("baseUri", "./"); Enumeration<?> paramEnum = req.getParameterNames(); @@ -93,31 +81,6 @@ } } - /*if (req.getAttribute("unicorn_parameters") instanceof Map<?, ?>) { - Map<?, ?> reqParams = (Map<?, ?>) req.getAttribute("unicorn_parameters"); - - for (Object objKey : reqParams.keySet()) { - String key = (String) objKey; - String ref; - if (key.startsWith(Property.get("UNICORN_PARAMETER_OUTPUT_PREFIX"))) - continue; - if (key.startsWith(paramPrefix)) - ref = "param_" + key.substring(paramPrefix.length()); - else - ref = "param_" + key; - if (reqParams.get(key) instanceof String[]) { - String[] s = (String[]) reqParams.get(key); - ArrayList<String> array = new ArrayList<String>(); - for (int i = 0; i < s.length; i++) - array.add(s[i]); - velocityContext.put(ref, array); - } - else { - velocityContext.put(ref, reqParams.get(key)); - } - } - }*/ - PrintWriter writer = resp.getWriter(); if (req.getHeader("X-Requested-With") != null && req.getHeader("X-Requested-With").equals("XMLHttpRequest")) { velocityContext.put("ajaxCall", "true"); Index: ObserveAction.java =================================================================== RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/action/ObserveAction.java,v retrieving revision 1.48 retrieving revision 1.49 diff -u -d -r1.48 -r1.49 --- ObserveAction.java 5 Oct 2009 14:25:42 -0000 1.48 +++ ObserveAction.java 6 Oct 2009 08:16:02 -0000 1.49 @@ -33,6 +33,7 @@ import org.w3c.unicorn.output.OutputFactory; import org.w3c.unicorn.output.OutputModule; import org.w3c.unicorn.util.Message; +import org.w3c.unicorn.util.MessageList; import org.w3c.unicorn.util.Property; import org.w3c.unicorn.Framework; @@ -87,7 +88,7 @@ Map<String, Object> mapOfStringObject = new LinkedHashMap<String, Object>(); Map<String, String> mapOfSpecificParameter = new Hashtable<String, String>(); Map<String, String> mapOfOutputParameter = new Hashtable<String, String>(); - ArrayList<Message> messages = new ArrayList<Message>(); + MessageList messages = new MessageList(); UnicornCall aUnicornCall = new UnicornCall(); // Default output parameters @@ -139,6 +140,7 @@ if (paramName.equals("lang")) { logger.trace("Lang parameter: " + key + " - " + (String) reqParams.get(key)); String lang = getLanguage((String) reqParams.get(key), req, null); + messages.setLang(lang); mapOfOutputParameter.put(paramName, lang); String aLocale = convertEnumerationToString(req.getLocales()); if (null == aLocale) @@ -154,7 +156,7 @@ String task = getTask((String) reqParams.get(key), messages); mapOfStringObject.put("current_task", Framework.mapOfTask.get(task)); if (!task.equals(reqParams.get(key))) { - mapOfStringObject.put("default_task", Framework.mapOfTask.get(Framework.mapOfTask.getDefaultTaskId())); + mapOfStringObject.put("default_task", Framework.mapOfTask.getDefaultTask()); logger.trace("Task parameter unsupported. Resolved to: " + task); reqParams.put(key, task); } @@ -190,6 +192,7 @@ // Check that all mandatory parameters are set if (!reqParams.containsKey(paramPrefix + "lang")) { String lang = getLanguage(null, req, null); + messages.setLang(lang); reqParams.put(paramPrefix + "lang", getLanguage(null, req, null)); logger.debug("No language parameter found. Language negociation resolved language to: " + lang); mapOfOutputParameter.put("lang", lang); @@ -211,7 +214,7 @@ String task = getTask(null, messages); reqParams.put(paramPrefix + "task", task); logger.debug("No task parameter found. Task parameter is set to task id: " + task); - mapOfStringObject.put("default_task", Framework.mapOfTask.get(Framework.mapOfTask.getDefaultTaskId())); + mapOfStringObject.put("default_task", Framework.mapOfTask.getDefaultTask()); mapOfStringObject.put("current_task", Framework.mapOfTask.get(task)); aUnicornCall.setTask(task); } Index: LanguageAction.java =================================================================== RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/action/LanguageAction.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- LanguageAction.java 5 Oct 2009 12:13:16 -0000 1.3 +++ LanguageAction.java 6 Oct 2009 08:16:02 -0000 1.4 @@ -2,7 +2,6 @@ import java.io.IOException; import java.io.PrintWriter; -import java.util.ArrayList; import java.util.Hashtable; import java.util.Properties; import java.util.TreeMap; @@ -14,7 +13,7 @@ import org.apache.velocity.VelocityContext; import org.w3c.unicorn.Framework; 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; @@ -44,7 +43,7 @@ String defaultLang = Property.get("DEFAULT_LANGUAGE"); - ArrayList<Message> messages = new ArrayList<Message>(); + MessageList messages = new MessageList(defaultLang); resp.setContentType("text/html; charset=UTF-8"); @@ -52,20 +51,17 @@ velocityContext.put("queryString", "./"); velocityContext.put("messages", messages); velocityContext.put("baseUri", "./"); - Hashtable<String, String> languages = new Hashtable<String, String>(); - - + Hashtable<String, String> languages = new Hashtable<String, String>(); languages.put(defaultLang, defaultProperties.get("language")); velocityContext.put("languages", languages); + languageProperties.remove(defaultLang); velocityContext.put("languageProps", languageProperties); velocityContext.put("defaultProps", defaultProperties); PrintWriter writer = resp.getWriter(); Templates.write("language.vm", velocityContext, writer); - //writer.println(languageProperties); - //writer.println(languages); writer.close(); } Index: Action.java =================================================================== RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/action/Action.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- Action.java 5 Oct 2009 14:25:42 -0000 1.15 +++ Action.java 6 Oct 2009 08:16:02 -0000 1.16 @@ -19,6 +19,7 @@ import org.w3c.unicorn.Framework; import org.w3c.unicorn.util.Language; import org.w3c.unicorn.util.Message; +import org.w3c.unicorn.util.MessageList; import org.w3c.unicorn.util.Property; public abstract class Action extends HttpServlet { @@ -71,25 +72,27 @@ if (messages == null) return lang; - if (!Language.isComplete(lang)) - messages.add(new Message(Message.INFO, "$message_incomplete_language. $message_translation", null)); - else if (!Framework.getLanguageProperties().containsKey(req.getLocale().getLanguage()) && Property.get("SHOW_LANGUAGE_UNAVAILABLE_MESSAGE").equals("true")) - messages.add(new Message(Message.INFO, "$message_unavailable_language (" + req.getLocale().getDisplayLanguage(req.getLocale()) + "). $message_translation", null)); - else if (langParameter != null && !Framework.getLanguageProperties().containsKey(langParameter)) { + if (langParameter != null && !Framework.getLanguageProperties().containsKey(langParameter)) { if (Language.isISOLanguageCode(langParameter)) { Locale locale = Language.getLocale(langParameter); if (locale == null) logger.warn("Missing locale: " + langParameter + ". This locale should be installed on the system in order to translate Unicorn in this language."); - messages.add(new Message(Message.INFO, "$message_unavailable_requested_language (" + locale.getDisplayLanguage(locale) + "). $message_translation", null)); + messages.add(new Message(Message.INFO, + Language.evaluate(lang, "$message_unavailable_requested_language", locale.getDisplayLanguage(locale)))); } else { - messages.add(new Message(Message.INFO, "$message_invalid_requested_language (" + langParameter + ")", null)); + messages.add(new Message(Message.INFO, + Language.evaluate(lang, "$message_invalid_requested_language", langParameter))); } - } + } else if (!Framework.getLanguageProperties().containsKey(req.getLocale().getLanguage()) && Property.get("SHOW_LANGUAGE_UNAVAILABLE_MESSAGE").equals("true")) + messages.add(new Message(Message.INFO, + Language.evaluate(lang, "$message_unavailable_language", req.getLocale().getDisplayLanguage(req.getLocale())))); + else if (!Language.isComplete(lang)) + messages.add(new Message(Message.INFO, "$message_incomplete_language")); return lang; } - public static String getTask(String taskParameter, ArrayList<Message> messages) { + public static String getTask(String taskParameter, MessageList messages) { String task; if (taskParameter == null || !Framework.mapOfTask.containsKey(taskParameter)) @@ -101,10 +104,12 @@ return task; if (taskParameter == null) { - Message mess = new Message(Message.WARNING, "$message_no_task " + "$default_task.getLongName($lang) ", null); + Message mess = new Message(Message.WARNING, + Language.evaluate(messages.getLang(), "$message_no_task", Framework.getDefaultTask().getLongName(messages.getLang()))); messages.add(mess); } else if (!Framework.mapOfTask.containsKey(taskParameter)) { - Message mess = new Message(Message.WARNING, "$message_unknown_task " + "$default_task.getLongName($lang) ", null); + Message mess = new Message(Message.WARNING, + Language.evaluate(messages.getLang(), "$message_unknown_task", taskParameter, Framework.getDefaultTask().getLongName(messages.getLang()))); messages.add(mess); }
Received on Tuesday, 6 October 2009 08:16:08 UTC