1 |
package gnu.localegen; |
package gnu.localegen; |
2 |
|
|
3 |
import gnu.ldml.Analyzer; |
import gnu.ldml.Analyzer; |
4 |
|
import java.net.MalformedURLException; |
5 |
import java.net.URL; |
import java.net.URL; |
6 |
import java.util.Hashtable; |
import java.util.Arrays; |
7 |
import java.util.Enumeration; |
import java.util.Collection; |
8 |
|
import java.util.Collections; |
9 |
|
import java.util.HashMap; |
10 |
|
import java.util.Iterator; |
11 |
|
import java.util.List; |
12 |
|
import java.util.Map; |
13 |
import gnu.ldml.Element; |
import gnu.ldml.Element; |
14 |
import java.io.IOException; |
import java.io.IOException; |
15 |
|
|
42 |
{ |
{ |
43 |
System.out.println("Invalid number of arguments."); |
System.out.println("Invalid number of arguments."); |
44 |
printUsage(); |
printUsage(); |
45 |
|
return; |
46 |
} |
} |
47 |
|
|
48 |
|
Map localeAnalyzers = new HashMap(); |
49 |
|
Map collationAnalyzers = new HashMap(); |
50 |
|
|
51 |
for (int i = 0; i < args.length; i++) |
for (int i = 0; i < args.length; i++) |
52 |
{ |
{ |
53 |
URL u; |
URL u; |
55 |
|
|
56 |
try |
try |
57 |
{ |
{ |
58 |
u = new URL(args[i]); |
try |
59 |
|
{ |
60 |
System.out.println("Parsing/Analyzing initial URL " + u); |
u = new URL(args[i]); |
61 |
a = new Analyzer(u); |
} |
62 |
} |
catch (MalformedURLException e) |
63 |
|
{ |
64 |
|
u = new URL("file:" + args[i]); |
65 |
|
} |
66 |
|
System.out.println("Parsing/Analyzing initial URL " + u); |
67 |
|
a = new Analyzer(u); |
68 |
|
} |
69 |
catch (IOException e) |
catch (IOException e) |
70 |
{ |
{ |
71 |
System.out.println("It is impossible to grab the requested file (reason="+ e.getMessage() + ")"); |
System.out.println("It is impossible to grab the requested file (reason="+ e.getMessage() + ")"); |
74 |
return; |
return; |
75 |
} |
} |
76 |
|
|
|
System.out.println("Parsed. Generating Java source code for " + a.getParser().getName() + " in gnu.java.locale"); |
|
77 |
|
|
78 |
Hashtable flattree = a.flattenTree(); |
a.flattenTree(); |
79 |
Enumeration keys = flattree.keys(); |
Collection locales = a.getLocales(); |
80 |
JavaGenerator generator; |
for (Iterator j = locales.iterator(); j.hasNext(); ) |
81 |
|
{ |
82 |
|
String locale = (String) j.next(); |
83 |
|
if (a.isCollation()) |
84 |
|
{ |
85 |
|
collationAnalyzers.put(locale, a); |
86 |
|
} |
87 |
|
else |
88 |
|
{ |
89 |
|
localeAnalyzers.put(locale, a); |
90 |
|
} |
91 |
|
} |
92 |
|
} |
93 |
|
|
94 |
|
for (Iterator i = localeAnalyzers.keySet().iterator(); i.hasNext(); ) |
95 |
|
{ |
96 |
|
String locale = (String) i.next(); |
97 |
|
Analyzer a = (Analyzer) localeAnalyzers.get(locale); |
98 |
|
Analyzer ca = (Analyzer) collationAnalyzers.get(locale); |
99 |
|
|
100 |
generator = new JavaGenerator("gnu.java.locale", a); |
List analyzers = (ca == null) ? Collections.singletonList(a) : |
101 |
|
Arrays.asList(new Analyzer[] {a, ca}); |
102 |
|
|
103 |
|
System.out.println("Generating Java source code for " + locale + |
104 |
|
" in gnu.java.locale"); |
105 |
|
JavaGenerator generator = new JavaGenerator("gnu.java.locale", |
106 |
|
analyzers, locale); |
107 |
generator.generate(null); |
generator.generate(null); |
108 |
} |
} |
109 |
} |
} |