- From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
- Date: Wed, 10 Dec 2008 15:25:54 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2002/css-validator/org/w3c/css/index In directory hutz:/tmp/cvs-serv3613/index Modified Files: IndexGenerator.java TranslationTableGenerator.java Log Message: various cleanup + templating Index: TranslationTableGenerator.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/index/TranslationTableGenerator.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- TranslationTableGenerator.java 6 Mar 2008 23:04:59 -0000 1.7 +++ TranslationTableGenerator.java 10 Dec 2008 15:25:52 -0000 1.8 @@ -36,142 +36,146 @@ * */ class AlphaComparator implements Comparator { - public int compare(Object o1, Object o2) { - String s1 = (String) o1; - String s2 = (String) o2; - return s1.toLowerCase().compareTo(s2.toLowerCase()); - } + public int compare(Object o1, Object o2) { + String s1 = (String) o1; + String s2 = (String) o2; + // return s1.toLowerCase().compareTo(s2.toLowerCase()); + return s1.compareToIgnoreCase(s2); + } } public class TranslationTableGenerator { - // the velocity context used to generate the index - // (NB: the same context is used for each index page, changing every thing - // inside) - private static String html_files_path = "../../../../"; - private static boolean done = false; - public static VelocityContext vc = new VelocityContext(); - private static String template_name = "translations.vm"; + // the velocity context used to generate the index + // (NB: the same context is used for each index page, changing every thing + // inside) + private static String html_files_path = "../../../../"; + private static boolean done = false; + public static VelocityContext vc; + private static String template_name = "translations.vm"; + + static { + vc = new VelocityContext(); + } - /** - * @param args - */ - public static void main(String[] args) { - TranslationTableGenerator.generateTable(); - } + /** + * @param args + */ + public static void main(String[] args) { + TranslationTableGenerator.generateTable(); + } - /** - * This method generates the index in every possible language we have the translation - * @see org.w3c.css.util.Messages - */ - public static synchronized void generateTable() { + /** + * This method generates the index in every possible language we have the translation + * @see org.w3c.css.util.Messages + */ + public static synchronized void generateTable() { - String default_lang = "en", name, path, translations_table, table_head; - File out_file; - path = TranslationTableGenerator.class.getResource("").getPath(); + String default_lang = "en"; + String name, path; + StringBuilder table_head = new StringBuilder(); + StringBuilder translations_table = new StringBuilder(); + File out_file; + path = TranslationTableGenerator.class.getResource("").getPath(); + try { - path = new URI(path).getPath(); - Velocity.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, path); - Velocity.addProperty(Velocity.FILE_RESOURCE_LOADER_PATH, path + "../css/"); - Velocity.init(); - - Template tpl = Velocity.getTemplate(template_name, "UTF-8"); - out_file = new File(path + html_files_path + "translations.html"); - + path = new URI(path).getPath(); + Velocity.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, path); + Velocity.addProperty(Velocity.FILE_RESOURCE_LOADER_PATH, path + "../css/"); + Velocity.init(); + Template tpl = Velocity.getTemplate(template_name, "UTF-8"); + out_file = new File(path + html_files_path + "translations.html"); ApplContext ac_default= new ApplContext(default_lang); - // Getting the differents languages informations (for the lang choice) - HashMap[] languages = new HashMap[Messages.languages_name.size()]; - HashMap translations = new HashMap(); - HashMap translation_completeness = new HashMap(); - table_head ="<tr><th scope='col'>Property</th>"; - for (int i = 0; i < Messages.languages_name.size(); ++i) { - name = String.valueOf(Messages.languages_name.get(i)); - HashMap l = new HashMap(); - l.put("name", name); - l.put("real", ((Utf8Properties) Messages.languages.get(name)).getProperty("language_name")); - languages[i] = l; - ApplContext ac_translated = new ApplContext(name); - if (!name.equals(default_lang)){ - table_head=table_head+"<th>"+l.get("real")+"</th>"; + // Getting the differents languages informations (for the lang choice) + HashMap[] languages = new HashMap[Messages.languages_name.size()]; + HashMap translations = new HashMap(); + HashMap translation_completeness = new HashMap(); + table_head.append("<tr><th scope='col'>Property</th>"); + for (int i = 0; i < Messages.languages_name.size(); ++i) { + name = String.valueOf(Messages.languages_name.get(i)); + HashMap l = new HashMap(); + l.put("name", name); + l.put("real", ((Utf8Properties) Messages.languages.get(name)).getProperty("language_name")); + languages[i] = l; + ApplContext ac_translated = new ApplContext(name); + if (!name.equals(default_lang)) { + table_head.append("<th>").append(l.get("real")).append("</th>"); } - translations.put(name,ac_translated); - translation_completeness.put(name, 0); + translations.put(name,ac_translated); + translation_completeness.put(name, 0); - } - table_head = table_head+"</tr>"; - Vector sorted_properties_keys = new Vector(ac_default.getMsg().properties.keySet()); - Collections.sort(sorted_properties_keys, new AlphaComparator()); + } + table_head.append("</tr>"); + Vector sorted_properties_keys = new Vector(ac_default.getMsg().properties.keySet()); + Collections.sort(sorted_properties_keys, new AlphaComparator()); Iterator properties_iterator = sorted_properties_keys.iterator(); - translations_table = "<tbody>"; - int num_properties = 0; - while (properties_iterator.hasNext()) { - ++num_properties; - String property_name = String.valueOf(properties_iterator.next()); - translations_table = translations_table + "<tr><th scope=\"row\" class=\"property_name\">"+property_name; - translations_table = translations_table+"<p>"+StringEscapeUtils.escapeHtml(ac_default.getMsg().getString(property_name))+"</p></th>"; - for (int i = 0; i < Messages.languages_name.size(); ++i) { - HashMap language = languages[i]; - ApplContext translation = (ApplContext) translations.get(language.get("name")); - String property_translated = translation.getMsg().getString(property_name); - if (language.get("name").equals(default_lang)) { - vc.put(property_name, property_translated); - } - else { - URI mail_translation = new URI("mailto", "w3c-translators@w3.org?Subject=["+property_name+"] CSS Validator Translation&body=Property:\n "+property_name+"\n\nText in English:\n "+ac_default.getMsg().getString(property_name)+"\n\nLanguage:\n "+language.get("name")+"\n\nTranslation:\n\n\n-- Help translate the CSS Validator:\nhttp://qa-dev.w3.org:8001/css-validator/translations.html", ""); - if (property_translated == null) { - translations_table = translations_table + "<td class=\"table_translation_missing\"><a title=\"submit a missing translation\" href=\""+StringEscapeUtils.escapeHtml(mail_translation.toASCIIString())+"\">✘</a></td>\n"; - } - else if ( property_translated.matches(".*translation unavailable.*")){ - translations_table = translations_table + "<td class=\"table_translation_missing\"><a title=\"submit a missing translation\" href=\""+StringEscapeUtils.escapeHtml(mail_translation.toASCIIString())+"\">✘</a></td>\n"; - } - else { - translations_table = translations_table + "<td class=\"table_translation_ok\"><span title=\""+StringEscapeUtils.escapeHtml(property_translated)+"\">✔</span></td>\n"; - int completed = Integer.parseInt(translation_completeness.get(language.get("name")).toString()); - ++completed; - translation_completeness.put(language.get("name"), completed); - //System.out.println(language.get("name")+": "+completed); - } - } + translations_table.append("<tbody>"); + int num_properties = 0; + while (properties_iterator.hasNext()) { + ++num_properties; + String property_name = String.valueOf(properties_iterator.next()); + translations_table.append("<tr><th scope=\"row\" class=\"property_name\">").append(property_name); + translations_table.append("<p>").append(StringEscapeUtils.escapeHtml(ac_default.getMsg().getString(property_name))); + translations_table.append("</p></th>"); + for (int i = 0; i < Messages.languages_name.size(); ++i) { + HashMap language = languages[i]; + ApplContext translation = (ApplContext) translations.get(language.get("name")); + String property_translated = translation.getMsg().getString(property_name); + if (language.get("name").equals(default_lang)) { + vc.put(property_name, property_translated); + } else { + URI mail_translation = new URI("mailto", "w3c-translators@w3.org?Subject=["+property_name+"] CSS Validator Translation&body=Property:\n "+property_name+"\n\nText in English:\n "+ac_default.getMsg().getString(property_name)+"\n\nLanguage:\n "+language.get("name")+"\n\nTranslation:\n\n\n-- Help translate the CSS Validator:\nhttp://qa-dev.w3.org:8001/css-validator/translations.html", ""); + if (property_translated == null) { + translations_table.append("<td class=\"table_translation_missing\"><a title=\"submit a missing translation\" href=\"").append(StringEscapeUtils.escapeHtml(mail_translation.toASCIIString())).append("\">✘</a></td>\n"); + } else if ( property_translated.matches(".*translation unavailable.*")) { + translations_table.append("<td class=\"table_translation_missing\"><a title=\"submit a missing translation\" href=\"").append(StringEscapeUtils.escapeHtml(mail_translation.toASCIIString())).append("\">✘</a></td>\n"); + } else { + translations_table.append("<td class=\"table_translation_ok\"><span title=\"").append(StringEscapeUtils.escapeHtml(property_translated)).append("\">✔</span></td>\n"); + int completed = Integer.parseInt(translation_completeness.get(language.get("name")).toString()); + completed++; + translation_completeness.put(language.get("name"), completed); + //System.out.println(language.get("name")+": "+completed); + } + } } - translations_table = translations_table + "</tr>"; - if(num_properties%12 == 0) { - translations_table = translations_table+"</tbody><tbody>"+table_head; + translations_table.append("</tr>"); + if ( num_properties % 12 == 0) { + translations_table.append("</tbody><tbody>").append(table_head); } } - translations_table = translations_table + "</tbody></table>"; - for (int i = 0; i < Messages.languages_name.size(); ++i) { - name = String.valueOf(Messages.languages_name.get(i)); - HashMap l = (HashMap) languages[i]; - int completeness_percent = 100*Integer.parseInt(translation_completeness.get(l.get("name")).toString()); - completeness_percent = completeness_percent /ac_default.getMsg().properties.size(); - l.put("completeness", completeness_percent); - languages[i] = l; - } - vc.put("languages", languages); - vc.put("num_languages", Messages.languages_name.size()); - vc.put("total_properties", ac_default.getMsg().properties.size()); - vc.put("translations_table", translations_table); + translations_table.append("</tbody></table>"); + for (int i = 0; i < Messages.languages_name.size(); i++) { + name = String.valueOf(Messages.languages_name.get(i)); + HashMap l = (HashMap) languages[i]; + int completeness_percent = 100*Integer.parseInt(translation_completeness.get(l.get("name")).toString()); + completeness_percent = completeness_percent /ac_default.getMsg().properties.size(); + l.put("completeness", completeness_percent); + languages[i] = l; + } + vc.put("languages", languages); + vc.put("num_languages", Messages.languages_name.size()); + vc.put("total_properties", ac_default.getMsg().properties.size()); + vc.put("translations_table", translations_table.toString()); vc.put("lang", "en"); - OutputStreamWriter aFileWriter = new OutputStreamWriter(new FileOutputStream(out_file), "UTF-8"); - tpl.merge(vc, aFileWriter); - aFileWriter.close(); + OutputStreamWriter aFileWriter = new OutputStreamWriter(new FileOutputStream(out_file), "UTF-8"); + tpl.merge(vc, aFileWriter); + aFileWriter.close(); } catch (URISyntaxException e) { - e.printStackTrace(); + e.printStackTrace(); } catch (ResourceNotFoundException e) { - e.printStackTrace(); - } catch (ParseErrorException e) { - e.printStackTrace(); - } catch (MethodInvocationException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (Exception e) { - e.printStackTrace(); - } finally { - done = true; - } + e.printStackTrace(); + } catch (ParseErrorException e) { + e.printStackTrace(); + } catch (MethodInvocationException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + done = true; + } } - } Index: IndexGenerator.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/index/IndexGenerator.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- IndexGenerator.java 27 Sep 2007 08:46:45 -0000 1.6 +++ IndexGenerator.java 10 Dec 2008 15:25:52 -0000 1.7 @@ -33,124 +33,125 @@ */ public class IndexGenerator { - // the velocity context used to generate the index - // (NB: the same context is used for each index page, changing every thing - // inside) - public static VelocityContext vc = new VelocityContext(); - private static String template_name = "validator.vm"; - private static String html_files_path = "../../../../"; - private static boolean done = false; + // the velocity context used to generate the index + // (NB: the same context is used for each index page, changing every thing + // inside) + public static VelocityContext vc = new VelocityContext(); + private static String template_name = "validator.vm"; + private static String html_files_path = "../../../../"; + private static boolean done = false; - /** - * @param args - */ - public static void main(String[] args) { - IndexGenerator.generatesIndex(false); - } + /** + * @param args + */ + public static void main(String[] args) { + IndexGenerator.generatesIndex(false); + } - /** - * This method generates the index in every possible language we have the translation - * @see org.w3c.css.util.Messages - * @param servlet, if this method is called from the servlet, - * the path is a bit different and need to be changed. - */ - public static synchronized void generatesIndex(boolean servlet) { - if (done) - return; + /** + * This method generates the index in every possible language we have the translation + * @see org.w3c.css.util.Messages + * @param servlet, if this method is called from the servlet, + * the path is a bit different and need to be changed. + */ + public static synchronized void generatesIndex(boolean servlet) { + if (done) + return; - String default_lang = "en", k, name, path; - ApplContext ac_default = new ApplContext(default_lang); - File tmpFile; - Iterator it; + String default_lang = "en"; + String k, name, path; + ApplContext ac_default = new ApplContext(default_lang); + File tmpFile; + Iterator it; - // Getting the differents languages informations (for the lang choice) - HashMap[] languages = new HashMap[Messages.languages_name.size()]; - for (int i = 0; i < Messages.languages_name.size(); ++i) { - name = String.valueOf(Messages.languages_name.get(i)); - HashMap l = new HashMap(); - l.put("name", name); - l.put("real", ((Utf8Properties) Messages.languages.get(name)).getProperty("language_name")); - languages[i] = l; - } - // Adding the result to the context - vc.put("languages", languages); + // Getting the differents languages informations (for the lang choice) + HashMap[] languages = new HashMap[Messages.languages_name.size()]; + for (int i = 0; i < Messages.languages_name.size(); ++i) { + name = String.valueOf(Messages.languages_name.get(i)); + HashMap<String,String> l = new HashMap<String,String>(); + l.put("name", name); + l.put("real", ((Utf8Properties) Messages.languages.get(name)).getProperty("language_name")); + languages[i] = l; + } + // Adding the result to the context + vc.put("languages", languages); - try { - //setting the path were to find the template - path = IndexGenerator.class.getResource("").getPath(); - if (servlet) - path = path.replace("file://localhost", ""); - else - path = new URI(path).getPath(); + try { + //setting the path were to find the template + path = IndexGenerator.class.getResource("").getPath(); + if (servlet) + path = path.replace("file://localhost", ""); + else + path = new URI(path).getPath(); - /* - * This code set the velocity properties to be used - * A new jar is needed to use file logging (avalon-logkit.jar) - */ - Velocity.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, path); - Velocity.addProperty(Velocity.FILE_RESOURCE_LOADER_PATH, path + "../css/"); - Velocity.setProperty(Velocity.RUNTIME_LOG, - "velocity-" + new SimpleDateFormat("yyyy-MM-dd_HHmm").format(new Date()) + ".log"); + /* + * This code set the velocity properties to be used + * A new jar is needed to use file logging (avalon-logkit.jar) + */ + Velocity.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, path); + Velocity.addProperty(Velocity.FILE_RESOURCE_LOADER_PATH, path + "../css/"); + Velocity.setProperty(Velocity.RUNTIME_LOG, + "velocity-" + new SimpleDateFormat("yyyy-MM-dd_HHmm").format(new Date()) + ".log"); - Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.runtime.log.AvalonLogChute"); - Velocity.init(); - if (!new File(path + template_name).exists()) { - template_name = "org/w3c/css/css/" + template_name; - html_files_path = ""; - } - Template tpl = Velocity.getTemplate(template_name, "UTF-8"); - int count = 0; + Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.runtime.log.AvalonLogChute"); + Velocity.init(); + if (!new File(path + template_name).exists()) { + template_name = "org/w3c/css/css/" + template_name; + html_files_path = ""; + } + Template tpl = Velocity.getTemplate(template_name, "UTF-8"); + int count = 0; - // For each language, we set the context are create the template - for (int i = 0; i < Messages.languages_name.size(); ++i) { - name = String.valueOf(Messages.languages_name.get(i)); - tmpFile = new File(path + html_files_path + "validator.html." + name); + // For each language, we set the context are create the template + for (int i = 0; i < Messages.languages_name.size(); ++i) { + name = String.valueOf(Messages.languages_name.get(i)); + tmpFile = new File(path + html_files_path + "validator.html." + name); - // Checking if the index files exists - // and if they have been created after the last template modification - if ((tmpFile.lastModified() < tpl.getLastModified()) || !tmpFile.exists()) { - ApplContext ac = new ApplContext(name); - vc.put("lang", name); + // Checking if the index files exists + // and if they have been created after the last template modification + if ((tmpFile.lastModified() < tpl.getLastModified()) || !tmpFile.exists()) { + ApplContext ac = new ApplContext(name); + vc.put("lang", name); - if (ac.getLang().equals(default_lang)) { - it = ac_default.getMsg().properties.keySet().iterator(); - while (it.hasNext()) { - k = String.valueOf(it.next()); - vc.put(k, ac.getMsg().getString(k)); - } - } else { - it = ac_default.getMsg().properties.keySet().iterator(); - while (it.hasNext()) { - k = String.valueOf(it.next()); - if (ac.getMsg().getString(k) == null) - vc.put(k, ac_default.getMsg().getString(k)); - else - vc.put(k, ac.getMsg().getString(k)); - } - } - OutputStreamWriter aFileWriter = new OutputStreamWriter(new FileOutputStream(tmpFile), "UTF-8"); - tpl.merge(vc, aFileWriter); - aFileWriter.close(); - ++count; - } + if (ac.getLang().equals(default_lang)) { + it = ac_default.getMsg().properties.keySet().iterator(); + while (it.hasNext()) { + k = String.valueOf(it.next()); + vc.put(k, ac.getMsg().getString(k)); } - Velocity.getLog().info("IndexGenerator : " + count + " index file(s) created or modified"); - done = true; - } catch (ResourceNotFoundException e) { - e.printStackTrace(); - } catch (ParseErrorException e) { - e.printStackTrace(); - } catch (MethodInvocationException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (URISyntaxException e1) { - e1.printStackTrace(); - } catch (Exception e) { - e.printStackTrace(); - } finally { - done = true; + } else { + it = ac_default.getMsg().properties.keySet().iterator(); + while (it.hasNext()) { + k = String.valueOf(it.next()); + if (ac.getMsg().getString(k) == null) + vc.put(k, ac_default.getMsg().getString(k)); + else + vc.put(k, ac.getMsg().getString(k)); + } + } + OutputStreamWriter aFileWriter = new OutputStreamWriter(new FileOutputStream(tmpFile), "UTF-8"); + tpl.merge(vc, aFileWriter); + aFileWriter.close(); + ++count; } + } + Velocity.getLog().info("IndexGenerator : " + count + " index file(s) created or modified"); + done = true; + } catch (ResourceNotFoundException e) { + e.printStackTrace(); + } catch (ParseErrorException e) { + e.printStackTrace(); + } catch (MethodInvocationException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (URISyntaxException e1) { + e1.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + done = true; } + } }
Received on Wednesday, 10 December 2008 15:26:05 UTC