01: package org.netbeans.jellytools;
02:
03: import java.io.File;
04: import java.io.FileInputStream;
05: import java.io.FileOutputStream;
06: import java.io.PrintStream;
07: import java.util.ArrayList;
08: import java.util.Iterator;
09: import java.util.TreeMap;
10: import java.util.TreeSet;
11: import java.util.regex.*;
12:
13: /*
14: * CollectBundleKeys.java
15: *
16: * Created on August 1, 2002, 9:36 AM
17: */
18:
19: /**
20: *
21: * @author <a href="mailto:adam.sotona@sun.com">Adam Sotona</a>
22: */
23: public class CollectBundleKeys {
24:
25: static final Pattern pat = Pattern
26: .compile(
27: "Bundle.getString(Trimmed)?\\s*\\(\\s*\"([^\"]*)\"\\s*,\\s*\"([^\"]*)\"",
28: Pattern.MULTILINE);
29:
30: /**
31: * @param args the command line arguments
32: */
33: public static void main(String[] args) throws Exception {
34: if (args.length < 2) {
35: System.out
36: .println("Missing command-line arguments: <source directory> <output property file> !");
37: System.exit(1);
38: }
39: StringBuffer sb = new StringBuffer();
40: byte b[] = new byte[1000];
41: int i;
42: ArrayList dirs = new ArrayList();
43: File sub[];
44: dirs.add(new File(args[0]));
45: TreeMap bundles = new TreeMap();
46: String bundle, key;
47: TreeSet keys;
48: while (dirs.size() > 0) {
49: sub = ((File) dirs.remove(0)).listFiles();
50: for (int j = 0; sub != null && j < sub.length; j++) {
51: if (sub[j].isDirectory()) {
52: dirs.add(sub[j]);
53: } else if (sub[j].getName().toLowerCase().endsWith(
54: ".java")) {
55: FileInputStream in = new FileInputStream(sub[j]);
56: while ((i = in.read(b)) >= 0)
57: sb.append(new String(b, 0, i));
58: in.close();
59: Matcher m = pat.matcher(sb);
60: while (m.find()) {
61: bundle = m.group(2);
62: key = m.group(3);
63: if (bundles.containsKey(bundle)) {
64: ((TreeSet) bundles.get(bundle)).add(key);
65: } else {
66: keys = new TreeSet();
67: keys.add(key);
68: bundles.put(bundle, keys);
69: }
70: }
71: }
72: }
73: }
74: Iterator bi = bundles.keySet().iterator();
75: Iterator ki;
76: int bs = 0, ks = 0;
77: PrintStream out = new PrintStream(new FileOutputStream(args[1]));
78: while (bi.hasNext()) {
79: bs++;
80: bundle = (String) bi.next();
81: ki = ((TreeSet) bundles.get(bundle)).iterator();
82: out.print(bundle + "=");
83: out.print((String) ki.next());
84: ks++;
85: while (ki.hasNext()) {
86: out.print("," + (String) ki.next());
87: ks++;
88: }
89: out.println();
90: }
91: out.close();
92: System.out.println("Finished " + String.valueOf(ks)
93: + " keys from " + String.valueOf(bs) + " bundles.");
94: }
95:
96: }
|