26 package propertiesparser; |
26 package propertiesparser; |
27 |
27 |
28 import propertiesparser.parser.MessageFile; |
28 import propertiesparser.parser.MessageFile; |
29 import propertiesparser.gen.ClassGenerator; |
29 import propertiesparser.gen.ClassGenerator; |
30 |
30 |
31 import java.io.BufferedWriter; |
|
32 import java.io.File; |
31 import java.io.File; |
33 import java.io.FileInputStream; |
32 import java.io.PrintStream; |
34 import java.io.FileNotFoundException; |
|
35 import java.io.FileOutputStream; |
|
36 import java.io.IOException; |
|
37 import java.io.OutputStreamWriter; |
|
38 import java.io.Writer; |
|
39 import java.lang.RuntimeException; |
|
40 import java.lang.Throwable; |
|
41 import java.text.MessageFormat; |
|
42 import java.util.ArrayList; |
|
43 import java.util.Collections; |
|
44 import java.util.HashMap; |
33 import java.util.HashMap; |
45 import java.util.Iterator; |
|
46 import java.util.List; |
|
47 import java.util.Map; |
34 import java.util.Map; |
48 import java.util.Properties; |
|
49 |
35 |
50 /** Translates a .properties file into a .java file containing an enum-like Java class |
36 /** Translates a .properties file into a .java file containing an enum-like Java class |
51 * which defines static factory methods for all resource keys in a given resource file. <P> |
37 * which defines static factory methods for all resource keys in a given resource file. <P> |
52 * |
38 * |
53 * Usage: java PropertiesParser -compile [path to .properties file] [output folder where .java file will be written] |
39 * Usage: java PropertiesParser -compile [path to .properties file] [output folder where .java file will be written] |
62 public PropertiesParser(Logger logger) { |
48 public PropertiesParser(Logger logger) { |
63 this.logger = logger; |
49 this.logger = logger; |
64 } |
50 } |
65 |
51 |
66 public static void main(String[] args) { |
52 public static void main(String[] args) { |
67 PropertiesParser pp = new PropertiesParser(msg -> System.out.println(msg)); |
53 boolean ok = run(args, System.out); |
68 boolean ok = pp.run(args); |
|
69 if ( !ok ) { |
54 if ( !ok ) { |
70 System.exit(1); |
55 System.exit(1); |
71 } |
56 } |
|
57 } |
|
58 |
|
59 public static boolean run(String[] args, PrintStream out) { |
|
60 PropertiesParser pp = new PropertiesParser(msg -> out.println(msg)); |
|
61 return pp.run(args); |
72 } |
62 } |
73 |
63 |
74 public static interface Logger { |
64 public static interface Logger { |
75 void info(String msg); |
65 void info(String msg); |
76 } |
66 } |