2 *******************************************************************************
3 * Copyright (C) 2005-2010, International Business Machines Corporation and *
4 * others. All Rights Reserved. *
5 *******************************************************************************
7 package com.ibm.icu.dev.tool.index;
9 import java.io.BufferedWriter;
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;
20 import java.util.TreeSet;
22 public class IndexGenerator {
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";
26 public static void main(String[] args) {
27 if (args.length < 1) {
28 usage("too few arguments");
31 File inDir = new File(args[0]);
32 if (!inDir.exists()) {
33 System.out.println("skipping nonexistent directory " + inDir);
37 if (!inDir.isDirectory()) {
38 usage("first argument '" + inDir + "' must be a directory");
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");
49 Set names = new TreeSet();
50 File[] files = inDir.listFiles();
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 ','
62 DateFormat fmt = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, Locale.US);
63 DateFormat copyfmt = new SimpleDateFormat("'# Copyright (C) 'yyyy' IBM Inc. All Rights Reserved.'");
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();
76 int count = names.size();
77 pw.println("# Found " + count + " files");
78 pw.println("# End of file");
80 System.err.println("Warning: matched no files");
84 catch (IOException e) {
85 usage(e.getMessage());
89 private static void usage(String msg) {
91 System.err.println("Error: " + msg);
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");