5 import org.apache.commons.collections.*;
\r
9 public class BundleTool {
\r
10 public static void main(String[] anArguments) {
\r
12 if (anArguments.length!=3) {
\r
13 System.out.println("Usage:");
\r
15 System.out.println(" BundleTool <bundle base> <master locale> <slave locale>");
\r
16 System.out.println("");
\r
17 System.out.println("Description:");
\r
18 System.out.println(" Reorders keys/values from a slave bundle according to a master bundle.");
\r
23 PropertiesManipulator master;
\r
24 PropertiesManipulator slave;
\r
25 PropertiesManipulator result;
\r
28 master = PropertiesManipulator.readProperties(new FileInputStream(new File(anArguments[0] + "_" + anArguments[1] + ".properties")));
\r
30 catch (Throwable t) {
\r
31 System.out.println("Unable to read master properties: " + t.getMessage());
\r
36 slave = PropertiesManipulator.readProperties(new FileInputStream(new File(anArguments[0] + "_" + anArguments[2] + ".properties")));
\r
38 catch (FileNotFoundException t) {
\r
39 slave = new PropertiesManipulator();
\r
41 catch (Throwable t) {
\r
42 System.out.println("Unable to read slave properties: " + t.getMessage());
\r
45 result = new PropertiesManipulator();
\r
47 Iterator i = slave.getEntries();
\r
48 while (i.hasNext()) {
\r
49 Object e = i.next();
\r
51 if (e instanceof PropertiesManipulator.EmptyLine) {
\r
52 result.addEmptyLine();
\r
54 else if (e instanceof PropertiesManipulator.Comment) {
\r
55 result.addComment(((PropertiesManipulator.Comment) e).getComment());
\r
58 if (!(e instanceof PropertiesManipulator.Comment))
\r
62 boolean insideHeader=true;
\r
63 i = master.getEntries();
\r
64 while (i.hasNext()) {
\r
65 Object e = i.next();
\r
67 if (!insideHeader && (e instanceof PropertiesManipulator.EmptyLine)) {
\r
68 result.addEmptyLine();
\r
70 else if (!insideHeader && e instanceof PropertiesManipulator.Comment) {
\r
71 result.addComment(((PropertiesManipulator.Comment) e).getComment());
\r
73 else if (e instanceof PropertiesManipulator.Entry) {
\r
74 String key = ((PropertiesManipulator.Entry) e).getKey();
\r
75 String value = slave.get(key);
\r
76 result.addEntry(key,value);
\r
79 insideHeader = insideHeader && (e instanceof PropertiesManipulator.Comment);
\r
82 PropertiesManipulator.writeProperties(result, new FileOutputStream(new File(anArguments[0] + "_" + anArguments[2] + ".properties")));
\r
84 catch (Throwable t) {
\r
85 System.out.println("Unable to write slave properties: " + t.getMessage());
\r