]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-52_1/tools/build/src/com/ibm/icu/dev/tool/index/IndexGenerator.java
Upgrade ICU4J.
[Dictionary.git] / jars / icu4j-52_1 / tools / build / src / com / ibm / icu / dev / tool / index / IndexGenerator.java
1 /**
2 *******************************************************************************
3 * Copyright (C) 2005-2010, International Business Machines Corporation and    *
4 * others. All Rights Reserved.                                                *
5 *******************************************************************************
6 */
7 package com.ibm.icu.dev.tool.index;
8
9 import java.io.BufferedWriter;
10 import java.io.File;
11 import java.io.FileWriter;
12 import java.io.IOException;
13 import java.io.PrintWriter;
14 import java.text.DateFormat;
15 import java.text.SimpleDateFormat;
16 import java.util.Date;
17 import java.util.Iterator;
18 import java.util.Locale;
19 import java.util.Set;
20 import java.util.TreeSet;
21
22 public class IndexGenerator {
23     
24     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";
25
26     public static void main(String[] args) {
27         if (args.length < 1) {
28             usage("too few arguments");
29         }
30
31         File inDir = new File(args[0]);
32         if (!inDir.exists()) {
33             System.out.println("skipping nonexistent directory " + inDir);
34             return;
35         }
36
37         if (!inDir.isDirectory()) {
38             usage("first argument '" + inDir + "' must be a directory");
39         }
40
41         File outDir = inDir;
42         if (args.length > 1) {
43             outDir = new File(args[1]);
44             if (!outDir.isDirectory() || !outDir.exists()) {
45                 usage("second argument must be existing directory");
46             }
47         }
48
49         Set names = new TreeSet();
50         File[] files = inDir.listFiles();
51         if (files != null) {
52             for (int i = 0; i < files.length; i++){
53                 if (!files[i].isDirectory()) {
54                     String name = "," + files[i].getName(); // add ',' to get exact match
55                     if (name.endsWith(".res") && stoplist.indexOf(name) == -1) {
56                         names.add(name.substring(1, name.lastIndexOf('.'))); // 1 to trim off ','
57                     }
58                 }
59             }
60         }
61
62         DateFormat fmt = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, Locale.US);
63         DateFormat copyfmt = new SimpleDateFormat("'# Copyright (C) 'yyyy' IBM Inc.  All Rights Reserved.'");
64
65         try {
66             File outFile = new File(outDir, "res_index.txt");
67             PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(outFile)));
68             Date now = new Date();
69             pw.println("# Generated by " + IndexGenerator.class.getName() + " on " + fmt.format(now));
70             pw.println("# from contents of " + inDir.getCanonicalPath());
71             pw.println(copyfmt.format(now));
72             Iterator i = names.iterator();
73             while (i.hasNext()) {
74                 pw.println(i.next());
75             }
76             int count = names.size();
77             pw.println("# Found " + count + " files");
78             pw.println("# End of file");
79             if (count == 0) {
80                 System.err.println("Warning: matched no files");
81             } 
82             pw.close();
83         }
84         catch (IOException e) {
85             usage(e.getMessage());
86         }
87     }
88
89     private static void usage(String msg) {
90         if (msg != null) {
91             System.err.println("Error: " + msg);
92         }
93         System.out.println("Usage: IndexGenerator inDir outDir");
94         System.out.println("  inDir is an existing directory whose locale-based resources are to be enumerated");
95         System.out.println("  outDir is an existing directory in which the res_index.txt file will be placed");
96         throw new IllegalStateException("Usage");
97     }
98 }
99