View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  
20  package org.xnap.i18n;
21  
22  import java.io.*;
23  import java.util.*;
24  
25  public class SyncKeys {
26  
27      /***
28       * 
29       */
30      public static void main(String[] argv)
31      {
32  		if (argv.length < 2) {
33  			System.err.println("usage: SyncKeys syncfile file [file...]");
34  			System.exit(1);
35  		}
36  
37  		Hashtable table = null;
38  		try {
39  			System.out.println("Using Sync table: " + argv[0]);
40  			table = I18nHelper.readI18nFile(argv[0], true);
41  		}
42  		catch (IOException e) {
43  			System.err.println("Error: " + e.getMessage());
44  			System.exit(1);
45  		}
46  
47  		for (int i = 1; i < argv.length; i++) {
48  			try {
49  				System.out.println("Syncing keys in file: " + argv[i]);
50  				sync(argv[i], table);
51  			}
52  			catch (IOException e) {
53  				System.err.println("Error: " + e.getMessage());
54  			}
55  		}
56      }
57  
58      public static void sync(String filename, Hashtable table)
59  		throws IOException
60      {
61  		Hashtable fileTable = I18nHelper.readI18nFile(filename, false);
62  
63  		for (Iterator i = table.keySet().iterator(); i.hasNext();) {
64  			String oldKey = (String)i.next();
65  			String newKey = (String)table.get(oldKey);
66  	   
67  			if (!oldKey.equals(newKey)) {
68  				String value = (String)fileTable.get(oldKey);
69  				if (value != null) {
70  					System.out.println(oldKey + " -> " + newKey + " = " 
71  									   + value);
72  					fileTable.remove(oldKey);
73  					fileTable.put(newKey, value);
74  				}
75  			}
76  		}
77  
78  		I18nHelper.writeI18nFile(filename, fileTable);
79      }
80  		
81  }
82  
83