01: /**
02: *******************************************************************************
03: * Copyright (C) 2005-2006, International Business Machines Corporation and *
04: * others. All Rights Reserved. *
05: *******************************************************************************
06: */package com.ibm.icu.dev.tool.index;
07:
08: import java.io.*;
09: import java.text.*;
10: import java.util.*;
11:
12: public class IndexGenerator {
13:
14: private final static String stoplist = ",char.res,CurrencyData.res,invuca.res,line.res,line_th.res,pnames.res,res_index.res,sent.res,title.res,ucadata.res,ucase.res,uidna.res,unames.res,unorm.res,uprops.res,word.res,word_ja.res,word_POSIX.res,word_th.res";
15:
16: public static void main(String[] args) {
17: if (args.length < 1) {
18: usage("too few arguments");
19: }
20:
21: File inDir = new File(args[0]);
22: if (!inDir.isDirectory() || !inDir.exists()) {
23: usage("first argument '" + inDir
24: + "' must be existing directory");
25: }
26:
27: File outDir = inDir;
28: if (args.length > 1) {
29: outDir = new File(args[1]);
30: if (!outDir.isDirectory() || !outDir.exists()) {
31: usage("second argument must be existing directory");
32: }
33: }
34:
35: DateFormat fmt = DateFormat.getDateTimeInstance(
36: DateFormat.LONG, DateFormat.LONG, Locale.US);
37: DateFormat copyfmt = new SimpleDateFormat(
38: "'# Copyright (C) 'yyyy' IBM Inc. All Rights Reserved.'");
39:
40: try {
41: File outFile = new File(outDir, "res_index.txt");
42: PrintWriter pw = new PrintWriter(new BufferedWriter(
43: new FileWriter(outFile)));
44: Date now = new Date();
45: pw.println("# Generated by "
46: + IndexGenerator.class.getName() + " on "
47: + fmt.format(now));
48: pw
49: .println("# from contents of "
50: + inDir.getCanonicalPath());
51: pw.println(copyfmt.format(now));
52: File[] files = inDir.listFiles();
53: int count = 0;
54: if (files != null) {
55: for (int i = 0; i < files.length; i++) {
56: if (!files[i].isDirectory()) {
57: String name = "," + files[i].getName(); // add ',' to get exact match
58: if (name.endsWith(".res")
59: && stoplist.indexOf(name) == -1) {
60: pw.println(name.substring(1, name
61: .lastIndexOf('.'))); // 1 to trim off ','
62: ++count;
63: }
64: }
65: }
66: }
67: pw.println("# Found " + count + " files");
68: pw.println("# End of file");
69: if (count == 0) {
70: System.err.println("Warning: matched no files");
71: }
72: pw.close();
73: } catch (IOException e) {
74: usage(e.getMessage());
75: }
76: }
77:
78: private static void usage(String msg) {
79: if (msg != null) {
80: System.err.println("Error: " + msg);
81: }
82: System.out.println("Usage: IndexGenerator inDir outDir");
83: System.out
84: .println(" inDir is an existing directory whose locale-based resources are to be enumerated");
85: System.out
86: .println(" outDir is an existing directory in which the res_index.txt file will be placed");
87: throw new IllegalStateException("Usage");
88: }
89: }
|