Property To List Resource Bundle
/* Java Internationalization By Andy Deitsch, David Czarnecki ISBN: 0-596-00019-7 O'Reilly */ /*import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; import java.io.OutputStreamWriter; import java.util.Enumeration; import java.util.Locale; import java.util.Properties; import java.util.MissingResourceException; public class PropertyToListResourceBundle { public static void main(String [] argv) { if (argv.length < 1) { System.exit(1); } try { String bundleName = argv[0] + "_" + Locale.getDefault().toString(); Properties propertiesFile = new Properties(); propertiesFile.load(new FileInputStream(bundleName + ".properties")); FileWriter fw = new FileWriter(bundleName + ".java"); String key; fw.write("import java.util.ListResourceBundle;\n\n"); fw.write("public class " + bundleName + " extends ListResourceBundle {\n\n"); fw.write(" public Object [][] getContents() {\n"); fw.write(" return contents;\n"); fw.write(" }\n\n"); fw.write(" static final Object [][] contents = {\n"); Enumeration e = propertiesFile.propertyNames(); while (e.hasMoreElements()) { key = (String)e.nextElement(); fw.write(" {\"" + key + "\", " + "\"" + propertiesFile.getProperty(key) + "\"},\n"); } fw.write(" {\"PropertyToListResourceBundleCreator\", " + "\"O'Reilly\"}\n"); fw.write(" };\n"); fw.write("}\n"); fw.close(); } catch (MissingResourceException mre) { mre.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } } } */ import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; import java.io.OutputStreamWriter; import java.util.Enumeration; import java.util.Locale; import java.util.Properties; import java.util.MissingResourceException; public class PropertyToListResourceBundle { public static void main(String [] argv) { if (argv.length < 1) { System.exit(1); } try { String bundleName = argv[0] + "_" + Locale.getDefault().toString(); Properties propertiesFile = new Properties(); propertiesFile.load(new FileInputStream(bundleName + ".properties")); FileWriter fw = new FileWriter(bundleName + ".java"); String key; fw.write("import java.util.ListResourceBundle;\n\n"); fw.write("public class " + bundleName + " extends ListResourceBundle {\n\n"); fw.write(" public Object [][] getContents() {\n"); fw.write(" return contents;\n"); fw.write(" }\n\n"); fw.write(" static final Object [][] contents = {\n"); Enumeration e = propertiesFile.propertyNames(); while (e.hasMoreElements()) { key = (String)e.nextElement(); fw.write(" {\"" + key + "\", " + "\"" + propertiesFile.getProperty(key) + "\"},\n"); } fw.write(" {\"PropertyToListResourceBundleCreator\", " + "\"O'Reilly\"}\n"); fw.write(" };\n"); fw.write("}\n"); fw.close(); } catch (MissingResourceException mre) { mre.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } } }