Revision 2500

tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/devtools/ImportFromOneFile.java (revision 2500)
20 20
 *
21 21
 */
22 22
public class ImportFromOneFile {
23

  
23
	
24 24
	public static void main(String[] args) throws UnsupportedEncodingException, FileNotFoundException, IOException {
25

  
25
		
26 26
		WorkspaceMessagesManager wmm = new WorkspaceMessagesManager();
27 27
		LinkedHashMap<File, PluginMessagesManager> h = wmm.getPluginMessages();
28

  
29
		String langs[] = { "", "_fr", "_ru" };
30

  
28
		
29
		String langs[] = { "_ru" }; // "", "_fr",
30
		
31 31
		System.out.println("Importing messages...");
32 32
		int total_update = 0;
33 33
		for (String lang : langs) {
34 34
			System.out.println(" For lang='" + lang + "'...");
35

  
35
			
36 36
			File mergedPropertiesFile = new File(wmm.getWorkspaceLocation(), "org.txm.translate.rcp/messages" + lang + ".properties");
37 37
			Properties mergedProperties = new Properties();
38 38
			mergedProperties.load(IOUtils.getReader(mergedPropertiesFile));
39

  
39
			
40 40
			if (mergedProperties.size() == 0) {
41 41
				System.out.println(" No messages to update");
42 42
				return;
43 43
			}
44

  
44
			
45 45
			int update = 0;
46

  
46
			
47 47
			for (File project : h.keySet()) {
48

  
48
				
49 49
				PluginMessagesManager messages = h.get(project);
50

  
50
				
51 51
				// messages.put(mergedLang, key, value);
52 52
				for (String key : messages.getMessageKeys()) {
53

  
53
					
54 54
					String merged_key = messages.getMessageFullName() + "." + key;
55 55
					// System.out.println(merged_key);
56 56
					if (mergedProperties.containsKey(merged_key)) {
......
59 59
					}
60 60
				}
61 61
			}
62

  
62
			
63 63
			if (update == 0) {
64 64
				System.out.println(" Done, no update done.");
65
			} else {
65
			}
66
			else {
66 67
				System.out.println(" Done, " + update + " update(s) done.");
67 68
			}
68 69
			total_update += update;
69 70
		}
70

  
71
		
71 72
		for (PluginMessagesManager messages : h.values()) {
72 73
			messages.saveChanges(true);
73 74
		}
74

  
75
		
75 76
		if (total_update == 0) {
76 77
			System.out.println("Done, no update done.");
77
		} else {
78
		}
79
		else {
78 80
			System.out.println("Done, " + total_update + " update(s) done.");
79 81
		}
80 82
	}
tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/devtools/ImportPluginXMLFromOneFile.java (revision 2500)
20 20
 *
21 21
 */
22 22
public class ImportPluginXMLFromOneFile {
23

  
23
	
24 24
	public static void main(String[] args) throws UnsupportedEncodingException, FileNotFoundException, IOException {
25

  
25
		
26 26
		WorkspaceMessagesManager wmm = new WorkspaceMessagesManager();
27 27
		LinkedHashMap<File, PluginMessagesManager> h = wmm.getPluginMessages();
28

  
29
		String langs[] = { "", "_fr", "_ru" };
30

  
28
		
29
		String langs[] = { "_ru" }; // "", "_fr",
30
		
31 31
		System.out.println("Importing messages...");
32 32
		int total_update = 0;
33 33
		for (String lang : langs) {
34 34
			System.out.println(" For lang='" + lang + "'...");
35

  
35
			
36 36
			File mergedPropertiesFile = new File(wmm.getWorkspaceLocation(), "org.txm.translate.rcp/bundle" + lang + ".properties");
37 37
			Properties mergedProperties = new Properties();
38 38
			mergedProperties.load(IOUtils.getReader(mergedPropertiesFile));
39

  
39
			
40 40
			if (mergedProperties.size() == 0) {
41 41
				System.out.println(" No messages to update");
42 42
				return;
43 43
			}
44

  
44
			
45 45
			int update = 0;
46

  
46
			
47 47
			for (File project : h.keySet()) {
48

  
48
				
49 49
				PluginMessagesManager messages = h.get(project);
50

  
50
				
51 51
				// messages.put(mergedLang, key, value);
52 52
				for (String key : messages.getOsgiKeys()) {
53

  
53
					
54 54
					String merged_key = messages.getMessageFullName() + "." + key;
55 55
					// System.out.println(merged_key);
56 56
					if (mergedProperties.containsKey(merged_key)) {
......
59 59
					}
60 60
				}
61 61
			}
62

  
62
			
63 63
			if (update == 0) {
64 64
				System.out.println(" Done, no update done.");
65
			} else {
65
			}
66
			else {
66 67
				System.out.println(" Done, " + update + " update(s) done.");
67 68
			}
68 69
			total_update += update;
69 70
		}
70

  
71
		
71 72
		for (PluginMessagesManager messages : h.values()) {
72
			messages.saveChanges(true);
73
			messages.saveChanges(true, true, false); // only save OSGI messages
73 74
		}
74

  
75
		
75 76
		if (total_update == 0) {
76 77
			System.out.println("Done, no update done.");
77
		} else {
78
		}
79
		else {
78 80
			System.out.println("Done, " + total_update + " update(s) done.");
79 81
		}
80 82
	}
tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/devtools/ImportMessagesTable.java (revision 2500)
24 24
public class ImportMessagesTable {
25 25
	
26 26
	File dir;
27
	
27 28
	String lang;
28 29
	
29 30
	public ImportMessagesTable(String lang) {
......
37 38
	
38 39
	public boolean run(String prefix, File tableFile) throws Exception {
39 40
		if (!dir.exists()) {
40
			System.out.println("dir nto found: "+dir);
41
			System.out.println("dir nto found: " + dir);
41 42
			return false;
42 43
		}
43 44
		
44 45
		if (!tableFile.exists()) {
45
			System.out.println("table file nto found: "+tableFile);
46
			System.out.println("table file nto found: " + tableFile);
46 47
			return false;
47 48
		}
48 49
		
49
		File langPropertiesFile = new File(dir, prefix+"_"+lang+".properties");
50
		File langPropertiesFile = new File(dir, prefix + "_" + lang + ".properties");
50 51
		Properties slave = new Properties() {
52
			
51 53
			@Override
52 54
			public synchronized Enumeration<Object> keys() {
53 55
				TreeSet<Object> set = new TreeSet<Object>(PluginMessagesManager.comp);
......
55 57
				return Collections.enumeration(set);
56 58
			}
57 59
		};
58
		File defaultPropertiesFile = new File(dir, prefix+".properties");
60
		File defaultPropertiesFile = new File(dir, prefix + ".properties");
59 61
		Properties master = new Properties() {
62
			
60 63
			@Override
61 64
			public synchronized Enumeration<Object> keys() {
62 65
				TreeSet<Object> set = new TreeSet<Object>(PluginMessagesManager.comp);
......
75 78
		int keyIndex = -1;
76 79
		int langIndex = -1;
77 80
		int defaultIndex = -1;
78
		for (int c = 0 ; c < ncol ; c++) {
81
		for (int c = 0; c < ncol; c++) {
79 82
			Cell cell = headerRow.getCellByIndex(c);
80 83
			if ("KEY".equals(cell.getDisplayText())) {
81 84
				keyIndex = c;
82
			} else if (lang.equals(cell.getDisplayText().toLowerCase())) {
85
			}
86
			else if (lang.equals(cell.getDisplayText().toLowerCase())) {
83 87
				langIndex = c;
84
			} else if ("DEFAULT".equals(cell.getDisplayText())) {
88
			}
89
			else if ("DEFAULT".equals(cell.getDisplayText())) {
85 90
				defaultIndex = c;
86 91
			}
87 92
		}
88 93
		
89 94
		if (keyIndex == -1) {
90
			System.out.println("KEY columns not found in "+headerRow);
95
			System.out.println("KEY columns not found in " + headerRow);
91 96
			return false;
92 97
		}
93 98
		if (langIndex == -1) {
94
			System.out.println(lang+" columns not found in "+headerRow);
99
			System.out.println(lang + " columns not found in " + headerRow);
95 100
			return false;
96 101
		}
97 102
		if (defaultIndex == -1) {
98
			System.out.println("DEFAULT columns not found in "+headerRow);
103
			System.out.println("DEFAULT columns not found in " + headerRow);
99 104
			return false;
100 105
		}
101 106
		
......
111 116
			}
112 117
		}
113 118
		
114
		slave.store(IOUtils.getWriter(langPropertiesFile), "imported from "+tableFile);
115
		master.store(IOUtils.getWriter(defaultPropertiesFile), "imported from "+tableFile);
119
		slave.store(IOUtils.getWriter(langPropertiesFile), "imported from " + tableFile);
120
		master.store(IOUtils.getWriter(defaultPropertiesFile), "imported from " + tableFile);
116 121
		
117
		System.out.println("Import saved in master="+defaultPropertiesFile);
118
		System.out.println("Import saved in slave="+langPropertiesFile);
122
		System.out.println("Import saved in master=" + defaultPropertiesFile);
123
		System.out.println("Import saved in slave=" + langPropertiesFile);
119 124
		
120 125
		return true;
121 126
	}
122 127
	
123 128
	public static void main(String[] args) throws Exception {
124 129
		String prefix = "bundle"; // messages
125
		System.out.println(new ImportMessagesTable("fr").run(prefix, new File(prefix+"_fr-slh.odt")));
130
		System.out.println(new ImportMessagesTable("ru").run(prefix, new File(prefix + "_ru.odt")));
126 131
	}
127 132
}
tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/i18n/PluginMessagesManager.java (revision 2500)
31 31
import org.txm.utils.io.IOUtils;
32 32

  
33 33
/**
34
 *  
34
 * 
35 35
 * Check any missing key in both of messages.properties and Message.java files
36 36
 *
37 37
 * @author mdecorde
......
39 39
 *
40 40
 */
41 41
public class PluginMessagesManager {
42
	
42 43
	/**
43 44
	 * Files encoding.
44 45
	 */
45 46
	public static String UTF8 = "UTF-8";
46

  
47
	
47 48
	public final static String FILE_SEPARATOR = System.getProperty("file.separator");
48

  
49
	
49 50
	/**
50 51
	 * Debug state.
51 52
	 */
52 53
	protected boolean debug;
53

  
54
	
54 55
	/**
55 56
	 * Project root directory.
56 57
	 */
57 58
	protected File projectDirectory;
58

  
59
	
59 60
	/**
60 61
	 * Java message file, eg.: TXMCoreMessages.java, ConcordanceUIMessages.java, etc.
61 62
	 */
62 63
	protected File javaMessageFile;
63

  
64
	
64 65
	/**
65 66
	 * Source files of the project.
66 67
	 */
67 68
	protected ArrayList<File> srcFiles;
68

  
69
	
69 70
	/**
70 71
	 * Extensions to use when creating the source files list.
71 72
	 */
72
	protected String[] srcFilesExtensions = new String[] {"java", "groovy"};
73

  
74

  
73
	protected String[] srcFilesExtensions = new String[] { "java", "groovy" };
74
	
75
	
75 76
	/**
76 77
	 * Global REGEX containing all keys to later use for search in files.
77 78
	 */
78 79
	protected Pattern keysGlobalREGEX;
79

  
80
	
80 81
	/**
81 82
	 * Index of the keys used and their associated files.
82 83
	 */
83
	protected TreeMap<String, TreeSet<File>> usedKeysFilesIndex = new TreeMap<String, TreeSet<File>>();
84

  
84
	protected TreeMap<String, TreeSet<File>> usedKeysFilesIndex = new TreeMap<>();
85
	
85 86
	/**
86 87
	 * the XXXMessages.java messages keys
87 88
	 */
88
	TreeSet<String> messageKeys = new TreeSet<String>();
89

  
89
	TreeSet<String> messageKeys = new TreeSet<>();
90
	
90 91
	/**
91 92
	 * plugin.xml file -> contains eventually keys
92 93
	 */
93 94
	protected File pluginXMLFile;
94

  
95
	
95 96
	public File getPluginXMLFile() {
96 97
		return pluginXMLFile;
97 98
	}
98

  
99
	
99 100
	public TreeSet<String> getOsgiKeys() {
100 101
		return osgiKeys;
101 102
	}
102

  
103
	
103 104
	public TreeMap<File, HashMap<String, String>> getOsgiLangs() {
104 105
		return osgiLangs;
105 106
	}
106

  
107
	
107 108
	/**
108 109
	 * the OSGI-INF/l10n/bundle[_lang].properties OSGI message keys
109 110
	 */
110
	TreeSet<String> osgiKeys = new TreeSet<String>();
111

  
111
	TreeSet<String> osgiKeys = new TreeSet<>();
112
	
112 113
	/**
113 114
	 * The OSGI messages stored by properties file
114 115
	 */
115
	TreeMap<File, HashMap<String, String>> osgiLangs = new TreeMap<File, HashMap<String, String>>();
116

  
116
	TreeMap<File, HashMap<String, String>> osgiLangs = new TreeMap<>();
117
	
117 118
	/**
118 119
	 * Stores the key modifications for further saves in the source files
119 120
	 */
120
	HashMap<String, String> keyModifications = new HashMap<String, String>();
121

  
121
	HashMap<String, String> keyModifications = new HashMap<>();
122
	
122 123
	/**
123 124
	 * The messages stored by properties file
124 125
	 */
125
	TreeMap<File, HashMap<String, String>> langs = new TreeMap<File, HashMap<String, String>>();
126

  
126
	TreeMap<File, HashMap<String, String>> langs = new TreeMap<>();
127
	
127 128
	/**
128 129
	 * the properties files langs
129 130
	 */
130
	BiHashMap<File, String> file2lang = new BiHashMap<File, String>();
131

  
131
	BiHashMap<File, String> file2lang = new BiHashMap<>();
132
	
132 133
	/**
133 134
	 * 
134 135
	 * @param projectDirectory
......
140 141
	public PluginMessagesManager(File projectDirectory) throws UnsupportedEncodingException, FileNotFoundException, IOException {
141 142
		this(projectDirectory, false);
142 143
	}
143

  
144
	
144 145
	/**
145 146
	 * 
146 147
	 * @param projectDirectory
......
152 153
	public PluginMessagesManager(File projectDirectory, boolean debug) throws UnsupportedEncodingException, FileNotFoundException, IOException {
153 154
		this(projectDirectory, findMessageFile(projectDirectory), debug);
154 155
	}
155

  
156

  
157

  
156
	
157
	
158
	
158 159
	/**
159 160
	 * 
160 161
	 * @param projectDirectory
......
166 167
	public PluginMessagesManager(File projectDirectory, File javaMessageFile) throws UnsupportedEncodingException, FileNotFoundException, IOException {
167 168
		this(projectDirectory, javaMessageFile, false);
168 169
	}
169

  
170

  
171

  
170
	
171
	
172
	
172 173
	/**
173 174
	 * 
174 175
	 * @param projectDirectory
......
178 179
	 * @throws IOException
179 180
	 */
180 181
	public PluginMessagesManager(File projectDirectory, File javaMessageFile, boolean debug) throws UnsupportedEncodingException, FileNotFoundException, IOException {
181

  
182
		
182 183
		this.javaMessageFile = javaMessageFile;
183 184
		this.projectDirectory = projectDirectory;
184 185
		this.pluginXMLFile = new File(projectDirectory, "plugin.xml");
185
		this.srcFiles = new ArrayList<File>();
186
		this.srcFiles = new ArrayList<>();
186 187
		this.debug = debug;
187

  
188
		
188 189
		if (debug) {
189 190
			System.out.println("********************************************************************************************************************");
190 191
			System.out.println("PluginMessagesManager.PluginMessages(): project root directory = " + this.projectDirectory);
191 192
			System.out.println("PluginMessagesManager.PluginMessages(): java message file = " + this.javaMessageFile);
192 193
		}
193

  
194
		
194 195
		// create the project source files list
195 196
		this.createSourceFilesList();
196

  
197
		//this.createKeysGlobalREGEX();
197
		
198
		// this.createKeysGlobalREGEX();
198 199
		this.createUsedKeysFilesIndex();
199

  
200

  
200
		
201
		
201 202
		if (this.javaMessageFile != null) {
202

  
203
			
203 204
			File[] propFiles = javaMessageFile.getParentFile().listFiles(IOUtils.HIDDENFILE_FILTER);
204 205
			for (File propFile : propFiles) {
205 206
				String name = propFile.getName();
206 207
				if (!name.endsWith(".properties")) continue;
207
				//messages.properties
208
				//messages_xx.properties
208
				// messages.properties
209
				// messages_xx.properties
209 210
				String lang = name.substring(8, name.indexOf(".properties"));
210 211
				langs.put(propFile, new HashMap<String, String>());
211 212
				file2lang.put(propFile, lang);
212

  
213
				
213 214
				HashMap<String, String> hash = langs.get(propFile);
214

  
215
				
215 216
				Properties props1 = new Properties();
216 217
				props1.load(IOUtils.getReader(propFile, UTF8));
217 218
				for (Object k : props1.keySet()) {
218 219
					hash.put(k.toString(), props1.get(k).toString());
219 220
				}
220 221
			}
221

  
222
			
222 223
			BufferedReader reader2 = new BufferedReader(new InputStreamReader(new FileInputStream(javaMessageFile), UTF8));
223 224
			String line2 = reader2.readLine();
224 225
			while (line2 != null) {
225 226
				line2 = line2.trim();
226

  
227
				
227 228
				if (line2.startsWith("public static String")) {
228 229
					int idx = line2.indexOf("//");
229 230
					if (idx > 0 && line2.contains("\"")) { // remove comment from line
230
						//System.out.println("COMMENT DETECTED AFTER KEY: line="+line2+" IN "+javaMessageFile);
231
						// System.out.println("COMMENT DETECTED AFTER KEY: line="+line2+" IN "+javaMessageFile);
231 232
						line2 = line2.substring(0, idx).trim();
232 233
					}
233 234
					if (line2.endsWith(";") && !line2.contains("=") && !line2.contains("\"")) {
234
						line2 = line2.substring(21, line2.length() -1);
235

  
236
						if(debug)	{
235
						line2 = line2.substring(21, line2.length() - 1);
236
						
237
						if (debug) {
237 238
							System.out.println("PluginMessagesManager.PluginMessagesManager(): messages key: " + line2 + " added.");
238 239
						}
239 240
						messageKeys.add(line2);
240 241
					}
241 242
				}
242

  
243
				
243 244
				line2 = reader2.readLine();
244 245
			}
245 246
			reader2.close();
246

  
247

  
248
			if(debug)	{
247
			
248
			
249
			if (debug) {
249 250
				System.out.println("PluginMessagesManager.PluginMessagesManager(): number of keys: " + this.messageKeys.size() + ".");
250 251
			}
251

  
252
			// try loading OSGI messages 
252
			
253
			// try loading OSGI messages
253 254
			if (pluginXMLFile.exists()) {
254 255
				ArrayList<String> result = IOUtils.findWithGroup(pluginXMLFile, "\"%([^\"]+)\"");
255 256
				osgiKeys.addAll(result);
256

  
257
				
257 258
				File osgiInf = new File(projectDirectory, "OSGI-INF/l10n");
258 259
				if (osgiInf.exists()) {
259 260
					for (File propFile : osgiInf.listFiles(IOUtils.HIDDENFILE_FILTER)) {
260 261
						if (propFile.getName().startsWith("bundle") && propFile.getName().endsWith(".properties")) {
261 262
							Properties props = new Properties();
262 263
							props.load(IOUtils.getReader(propFile, "ISO-8859-1"));
263
							HashMap<String, String> h = new HashMap<String, String>();
264
							for (Object k : props.keySet()) h.put(k.toString(), props.getProperty(k.toString()));
264
							HashMap<String, String> h = new HashMap<>();
265
							for (Object k : props.keySet())
266
								h.put(k.toString(), props.getProperty(k.toString()));
265 267
							osgiLangs.put(propFile, h);
266 268
						}
267 269
					}
268 270
				}
269
				//			System.out.println(osgiKeys);
270
				//			System.out.println(osgiLangs);
271
				// System.out.println(osgiKeys);
272
				// System.out.println(osgiLangs);
271 273
			}
272

  
273
			if(debug)	{
274
			
275
			if (debug) {
274 276
				this.dumpUsedKeysFilesIndex();
275 277
			}
276 278
		}
......
280 282
			}
281 283
		}
282 284
	}
283

  
284
	//		/**
285
	//		 * Creates a global REGEX containing all keys to later search in files.
286
	//		 */
287
	//		public void createKeysGlobalREGEX()	{
288
	//			
289
	//			if(messageKeys.size() == 0) {
290
	//				return;
291
	//			}
292
	//			
293
	//			StringBuffer buffer = new StringBuffer();
294
	//			buffer.append(this.getMessageClassName() + "\\\\.(");
295
	//			
296
	//			int i = 0;
297
	//			for (String key : messageKeys) {
298
	//				if(i > 0)	{
299
	//					buffer.append("|" + key);	
300
	//				}
301
	//				else {
302
	//					buffer.append(key);
303
	//				}
304
	//				i++;
305
	//			}
306
	//			
307
	//			// remove first pipe
308
	//			//buffer.deleteCharAt(0);
309
	//			
310
	//			this.keysGlobalREGEX = Pattern.compile("(" + buffer + "))");
311
	//			
312
	//			if(debug)	{
313
	//				System.out.println("PluginMessagesManager.createKeysGlobalREGEX(): REGEX created: " + this.keysGlobalREGEX + ".");
314
	//			}
315
	//			
316
	//		}
317

  
318

  
285
	
286
	// /**
287
	// * Creates a global REGEX containing all keys to later search in files.
288
	// */
289
	// public void createKeysGlobalREGEX() {
290
	//
291
	// if(messageKeys.size() == 0) {
292
	// return;
293
	// }
294
	//
295
	// StringBuffer buffer = new StringBuffer();
296
	// buffer.append(this.getMessageClassName() + "\\\\.(");
297
	//
298
	// int i = 0;
299
	// for (String key : messageKeys) {
300
	// if(i > 0) {
301
	// buffer.append("|" + key);
302
	// }
303
	// else {
304
	// buffer.append(key);
305
	// }
306
	// i++;
307
	// }
308
	//
309
	// // remove first pipe
310
	// //buffer.deleteCharAt(0);
311
	//
312
	// this.keysGlobalREGEX = Pattern.compile("(" + buffer + "))");
313
	//
314
	// if(debug) {
315
	// System.out.println("PluginMessagesManager.createKeysGlobalREGEX(): REGEX created: " + this.keysGlobalREGEX + ".");
316
	// }
317
	//
318
	// }
319
	
320
	
319 321
	/**
320 322
	 * Creates a global REGEX containing all keys to later search in files.
321 323
	 */
322
	public void createKeysGlobalREGEX()	{
324
	public void createKeysGlobalREGEX() {
323 325
		StringBuffer buffer = new StringBuffer();
324 326
		for (String key : messageKeys) {
325 327
			buffer.append("|" + this.getKeyFullName(key).replaceAll("\\.", "\\\\."));
326 328
		}
327

  
329
		
328 330
		// remove first pipe
329 331
		buffer.deleteCharAt(0);
330

  
332
		
331 333
		this.keysGlobalREGEX = Pattern.compile("(" + buffer + ")");
332

  
333
		if(debug)	{
334
		
335
		if (debug) {
334 336
			System.out.println("PluginMessagesManager.createKeysGlobalREGEX(): REGEX created: " + this.keysGlobalREGEX + ".");
335 337
		}
336

  
338
		
337 339
	}
338

  
339

  
340

  
340
	
341
	
342
	
341 343
	public static File findMessageFile(File projectDirectory2) {
342
		File messagesPackageDir = new File(projectDirectory2, "src/"+projectDirectory2.getName().replaceAll("\\.", "/")+"/messages");
343

  
344
		File messagesPackageDir = new File(projectDirectory2, "src/" + projectDirectory2.getName().replaceAll("\\.", "/") + "/messages");
345
		
344 346
		if (!messagesPackageDir.exists()) {
345
			messagesPackageDir = new File(projectDirectory2, "src/java/"+projectDirectory2.getName().replaceAll("\\.", "/")+"/messages");
347
			messagesPackageDir = new File(projectDirectory2, "src/java/" + projectDirectory2.getName().replaceAll("\\.", "/") + "/messages");
346 348
		}
347

  
349
		
348 350
		if (!messagesPackageDir.exists()) {
349
			messagesPackageDir = new File(projectDirectory2, "src/main/java/"+projectDirectory2.getName().replaceAll("\\.", "/")+"/messages");
351
			messagesPackageDir = new File(projectDirectory2, "src/main/java/" + projectDirectory2.getName().replaceAll("\\.", "/") + "/messages");
350 352
		}
351

  
353
		
352 354
		if (!messagesPackageDir.exists()) {
353 355
			return null;
354 356
		}
355

  
357
		
356 358
		for (File messagesJavaFile : messagesPackageDir.listFiles(IOUtils.HIDDENFILE_FILTER)) {
357 359
			if (messagesJavaFile.isDirectory()) continue;
358 360
			if (!messagesJavaFile.getName().endsWith("Messages.java")) continue;
......
360 362
		}
361 363
		return null;
362 364
	}
363

  
364
	//	public static File findMessageFile(File projectDirectory2) {
365
	////		System.out.println("PluginMessagesManager.findMessageFile() " + FILE_SEPARATOR);
366
	//		File messagesPackageDir = new File(projectDirectory2, "src" + FILE_SEPARATOR + projectDirectory2.getName().replaceAll("\\.", "\\" + FILE_SEPARATOR) + FILE_SEPARATOR + "messages");
365
	
366
	// public static File findMessageFile(File projectDirectory2) {
367
	//// System.out.println("PluginMessagesManager.findMessageFile() " + FILE_SEPARATOR);
368
	// File messagesPackageDir = new File(projectDirectory2, "src" + FILE_SEPARATOR + projectDirectory2.getName().replaceAll("\\.", "\\" + FILE_SEPARATOR) + FILE_SEPARATOR + "messages");
367 369
	//
368
	//		if (!messagesPackageDir.exists()) {
369
	//			messagesPackageDir = new File(projectDirectory2, "src" + FILE_SEPARATOR + "java" + FILE_SEPARATOR + projectDirectory2.getName().replaceAll("\\.", "\\" + FILE_SEPARATOR) + FILE_SEPARATOR + "messages");
370
	//		}
370
	// if (!messagesPackageDir.exists()) {
371
	// messagesPackageDir = new File(projectDirectory2, "src" + FILE_SEPARATOR + "java" + FILE_SEPARATOR + projectDirectory2.getName().replaceAll("\\.", "\\" + FILE_SEPARATOR) + FILE_SEPARATOR +
372
	// "messages");
373
	// }
371 374
	//
372
	//		if (!messagesPackageDir.exists()) {
373
	//			messagesPackageDir = new File(projectDirectory2, "src" + FILE_SEPARATOR + "main" + FILE_SEPARATOR + "java" + FILE_SEPARATOR + projectDirectory2.getName().replaceAll("\\.", "\\" + FILE_SEPARATOR) + FILE_SEPARATOR + "messages");
374
	//		}
375
	// if (!messagesPackageDir.exists()) {
376
	// messagesPackageDir = new File(projectDirectory2, "src" + FILE_SEPARATOR + "main" + FILE_SEPARATOR + "java" + FILE_SEPARATOR + projectDirectory2.getName().replaceAll("\\.", "\\" +
377
	// FILE_SEPARATOR) + FILE_SEPARATOR + "messages");
378
	// }
375 379
	//
376
	//		if (!messagesPackageDir.exists()) {
377
	//			return null;
378
	//		}
380
	// if (!messagesPackageDir.exists()) {
381
	// return null;
382
	// }
379 383
	//
380
	//		for (File messagesJavaFile : messagesPackageDir.listFiles(IOUtils.HIDDENFILE_FILTER)) {
381
	//			if (messagesJavaFile.isDirectory()) continue;
382
	//			if (!messagesJavaFile.getName().endsWith("Messages.java")) continue;
383
	//			return messagesJavaFile;
384
	//		}
385
	//		return null;
386
	//	}
387

  
388

  
389

  
384
	// for (File messagesJavaFile : messagesPackageDir.listFiles(IOUtils.HIDDENFILE_FILTER)) {
385
	// if (messagesJavaFile.isDirectory()) continue;
386
	// if (!messagesJavaFile.getName().endsWith("Messages.java")) continue;
387
	// return messagesJavaFile;
388
	// }
389
	// return null;
390
	// }
391
	
392
	
393
	
390 394
	/**
391 395
	 * Creates/updates the index of the keys used and their associated files.
392
	 * @throws IOException 
396
	 * 
397
	 * @throws IOException
393 398
	 */
394
	public void createUsedKeysFilesIndex() throws IOException	{
395
		this.usedKeysFilesIndex = new TreeMap<String, TreeSet<File>>();
396

  
399
	public void createUsedKeysFilesIndex() throws IOException {
400
		this.usedKeysFilesIndex = new TreeMap<>();
401
		
397 402
		// Old version, based on real key name
398
		//		for (File file : this.srcFiles) {
399
		//			for (String key : messageKeys) {
400
		//				if(debug) {
401
		//					System.out.println("PluginMessagesManager.createUsedKeysIndex(): looking for key " + this.getKeyFullName(key) + " in project source files...");
402
		//				}
403
		//				String lines = IOUtils.getText(file, PluginMessagesManager.ENCODING);
404
		//				if(lines.contains(this.getKeyFullName(key)))	{
405
		//					if (!this.usedKeysFilesIndex.containsKey(key)) {
406
		//						this.usedKeysFilesIndex.put(key, new TreeSet<File>());
407
		//					}
408
		//					this.usedKeysFilesIndex.get(key).add(file);
409
		//				};
410
		//			}
411
		//		}
412

  
403
		// for (File file : this.srcFiles) {
404
		// for (String key : messageKeys) {
405
		// if(debug) {
406
		// System.out.println("PluginMessagesManager.createUsedKeysIndex(): looking for key " + this.getKeyFullName(key) + " in project source files...");
407
		// }
408
		// String lines = IOUtils.getText(file, PluginMessagesManager.ENCODING);
409
		// if(lines.contains(this.getKeyFullName(key))) {
410
		// if (!this.usedKeysFilesIndex.containsKey(key)) {
411
		// this.usedKeysFilesIndex.put(key, new TreeSet<File>());
412
		// }
413
		// this.usedKeysFilesIndex.get(key).add(file);
414
		// };
415
		// }
416
		// }
417
		
413 418
		// New version using REGEX
414 419
		for (File file : this.srcFiles) {
415 420
			if (!file.exists()) continue;
416 421
			String lines = IOUtils.getText(file, PluginMessagesManager.UTF8);
417

  
422
			
418 423
			Matcher m = WorkspaceMessagesManager.KEY_REGEX.matcher(lines);
419
			//Matcher m = this.keysGlobalREGEX.matcher(lines);
424
			// Matcher m = this.keysGlobalREGEX.matcher(lines);
420 425
			while (m.find()) {
421 426
				// Get the matching string
422 427
				String key = m.group();
423

  
428
				
424 429
				if (!this.usedKeysFilesIndex.containsKey(key)) {
425 430
					this.usedKeysFilesIndex.put(key, new TreeSet<File>());
426 431
				}
427 432
				this.usedKeysFilesIndex.get(key).add(file);
428

  
429
				if(debug) {
430
					System.out.println("PluginMessagesManager.createUsedKeysFilesIndex(): messages key: " + key + " added for file " + file +  ".");
433
				
434
				if (debug) {
435
					System.out.println("PluginMessagesManager.createUsedKeysFilesIndex(): messages key: " + key + " added for file " + file + ".");
431 436
				}
432

  
437
				
433 438
			}
434

  
439
			
435 440
		}
436 441
	}
437

  
438

  
442
	
443
	
439 444
	/**
440 445
	 * Dumps in console the index of the keys used and their associated files.
441 446
	 */
442
	public void dumpUsedKeysFilesIndex()	{
443

  
447
	public void dumpUsedKeysFilesIndex() {
448
		
444 449
		System.out.println("PluginMessagesManager.dumpUsedKeysIndex(): dumping used keys files index...");
445

  
446
		if(this.usedKeysFilesIndex == null)	{
450
		
451
		if (this.usedKeysFilesIndex == null) {
447 452
			System.out.println("PluginMessagesManager.dumpUsedKeysIndex(): project have no used keys.");
448 453
			return;
449 454
		}
450

  
455
		
451 456
		for (Map.Entry<String, TreeSet<File>> entry : this.usedKeysFilesIndex.entrySet()) {
452 457
			System.out.println("key: " + entry.getKey());
453
			if(entry.getValue().isEmpty())	{
458
			if (entry.getValue().isEmpty()) {
454 459
				System.out.println("   file(s): -not used in any file of the project " + this.getProjectDirectory() + "-");
455 460
			}
456
			else	{
457
				for(File file : entry.getValue())	{
461
			else {
462
				for (File file : entry.getValue()) {
458 463
					System.out.println("   file(s): " + file);
459 464
				}
460 465
			}
461 466
		}
462

  
467
		
463 468
		System.out.println("PluginMessagesManager.dumpUsedKeysIndex(): number of used keys: " + this.usedKeysFilesIndex.size() + ".");
464 469
	}
465

  
470
	
466 471
	/***
467 472
	 * @param key
468 473
	 * @return all source files using the specified message key (except the main Java message file).
......
470 475
	public TreeSet<File> getFilesUsingKey(String key) {
471 476
		if (usedKeysFilesIndex.containsKey(key)) {
472 477
			return this.usedKeysFilesIndex.get(key);
473
		} else {
474
			return new TreeSet<File>();
475 478
		}
479
		else {
480
			return new TreeSet<>();
481
		}
476 482
	}
477

  
483
	
478 484
	/***
479 485
	 * @param key local key name
480 486
	 * @return all source files using the specified local message key (except the main Java message file).
......
482 488
	public TreeSet<File> getFilesUsingLocalKey(String key) {
483 489
		return getFilesUsingKey(getKeyFullName(key));
484 490
	}
485

  
486

  
491
	
492
	
487 493
	/**
488 494
	 * Returns the keys of all messages that are not used in the project itself.
495
	 * 
489 496
	 * @return a sorted list containing all unused keys
490 497
	 */
491
	public ArrayList<String> getUnusedKeys()	{
498
	public ArrayList<String> getUnusedKeys() {
492 499
		return getUnusedKeys(usedKeysFilesIndex, debug);
493 500
	}
494

  
501
	
495 502
	/**
496 503
	 * @param usedKeysFilesIndex
497 504
	 * 
498 505
	 * @return a sorted list containing all unused keys of all messages that are not used in the used key files index.
499 506
	 */
500
	public static ArrayList<String> getUnusedKeys(TreeMap<String, TreeSet<File>> usedKeysFilesIndex, boolean debug)	{
501
		ArrayList<String> unusedKeys = new ArrayList<String>();
507
	public static ArrayList<String> getUnusedKeys(TreeMap<String, TreeSet<File>> usedKeysFilesIndex, boolean debug) {
508
		ArrayList<String> unusedKeys = new ArrayList<>();
502 509
		for (Map.Entry<String, TreeSet<File>> entry : usedKeysFilesIndex.entrySet()) {
503
			if(entry.getValue().isEmpty())	{
504

  
505
				if(debug)	{
510
			if (entry.getValue().isEmpty()) {
511
				
512
				if (debug) {
506 513
					System.out.println("PluginMessagesManager.getUnusedKeys(): unused key found: " + entry.getKey() + ".");
507 514
				}
508

  
515
				
509 516
				unusedKeys.add(entry.getKey());
510 517
			}
511 518
		}
512

  
519
		
513 520
		Collections.sort(unusedKeys);
514 521
		return unusedKeys;
515 522
	}
516

  
523
	
517 524
	/**
518 525
	 * @param lang
519 526
	 * @return the map of the messages keys and values for the specified language.
......
522 529
		if (javaMessageFile != null) {
523 530
			File p = new File(javaMessageFile.getParentFile(), "messages" + lang + ".properties");
524 531
			return langs.get(p);
525
		} else {
526
			return new HashMap<String, String>();
527 532
		}
533
		else {
534
			return new HashMap<>();
535
		}
528 536
	}
529

  
537
	
530 538
	/**
531 539
	 * @return the map of the messages keys and values for the main language.
532 540
	 */
533 541
	public HashMap<String, String> getMessagesForDefaultLang() {
534 542
		return this.getMessagesForLang(""); //$NON-NLS-1$
535 543
	}
536

  
544
	
537 545
	public void put(String lang, String key, String message) {
538 546
		messageKeys.add(key);
539

  
540
		File p = new File(javaMessageFile.getParentFile(), "messages"+lang+".properties");
541

  
547
		
548
		File p = new File(javaMessageFile.getParentFile(), "messages" + lang + ".properties");
549
		
542 550
		if (!langs.containsKey(p)) {
543 551
			langs.put(p, new HashMap<String, String>());
544 552
			file2lang.put(p, lang);
545 553
		}
546

  
554
		
547 555
		if (message == null) {
548 556
			langs.get(p).remove(key);
549
		} else {
557
		}
558
		else {
550 559
			langs.get(p).put(key, message);
551 560
		}
552 561
	}
553

  
554

  
562
	
563
	
555 564
	public void putOSGI(String lang, String key, String message) {
556 565
		osgiKeys.add(key);
557

  
558
		File p = new File(projectDirectory, "OSGI-INF/l10n/bundle"+lang+".properties");
559

  
566
		
567
		File p = new File(projectDirectory, "OSGI-INF/l10n/bundle" + lang + ".properties");
568
		
560 569
		if (!osgiLangs.containsKey(p)) {
561 570
			osgiLangs.put(p, new HashMap<String, String>());
562 571
		}
563

  
572
		
564 573
		if (message == null) {
565 574
			osgiLangs.get(p).remove(key);
566
		} else {
575
		}
576
		else {
567 577
			osgiLangs.get(p).put(key, message);
568 578
		}
569 579
	}
570

  
580
	
571 581
	public String get(String lang, String key) {
572 582
		File p = new File(javaMessageFile.getParentFile(), "messages" + lang + ".properties");
573

  
583
		
574 584
		if (!file2lang.containsKey(p)) return null;
575

  
585
		
576 586
		return langs.get(p).get(key);
577 587
	}
578

  
588
	
579 589
	public TreeSet<String> getMessageKeys() {
580 590
		return messageKeys;
581 591
	}
582

  
592
	
583 593
	public File getMessageFile() {
584 594
		return javaMessageFile;
585 595
	}
586

  
596
	
587 597
	public String getMessageClassName() {
588 598
		if (javaMessageFile == null) return "";
589 599
		return javaMessageFile.getName().substring(0, javaMessageFile.getName().length() - 5);
590 600
	}
591

  
601
	
592 602
	public String getMessageFullClassName() {
593 603
		if (javaMessageFile == null) return "";
594 604
		return javaMessageFile.getAbsolutePath().substring(javaMessageFile.getAbsolutePath().lastIndexOf("org" + FILE_SEPARATOR + "txm" + FILE_SEPARATOR),
595 605
				javaMessageFile.getAbsolutePath().length() - 5).replace(FILE_SEPARATOR, ".");
596 606
	}
597

  
607
	
598 608
	/**
599 609
	 * @return the XXXMessages.java class name without the 'Messages' part
600 610
	 */
601 611
	public String getMessageName() {
602 612
		if (javaMessageFile == null) return "";
603
		return javaMessageFile.getName().substring(0, javaMessageFile.getName().length()-5-8);
613
		return javaMessageFile.getName().substring(0, javaMessageFile.getName().length() - 5 - 8);
604 614
	}
605

  
615
	
606 616
	public String getMessageFullName() {
607 617
		if (javaMessageFile == null) return "";
608
		return javaMessageFile.getAbsolutePath().substring(javaMessageFile.getAbsolutePath().lastIndexOf("org" + FILE_SEPARATOR + "txm" + FILE_SEPARATOR) + 8, 
618
		return javaMessageFile.getAbsolutePath().substring(javaMessageFile.getAbsolutePath().lastIndexOf("org" + FILE_SEPARATOR + "txm" + FILE_SEPARATOR) + 8,
609 619
				javaMessageFile.getAbsolutePath().length() - 5 - 8).replace(FILE_SEPARATOR, ".");
610 620
	}
611

  
621
	
612 622
	/**
613 623
	 * Returns the full name of the specified key including the Java message class name.
624
	 * 
614 625
	 * @param key
615 626
	 * @return
616 627
	 */
617
	public String getKeyFullName(String key)	{
628
	public String getKeyFullName(String key) {
618 629
		return this.getMessageClassName() + "." + key;
619 630
	}
620

  
631
	
621 632
	public static Collator col = Collator.getInstance(Locale.FRANCE);
633
	
622 634
	public static Comparator comp = new Comparator<String>() {
635
		
623 636
		@Override
624 637
		public int compare(String arg0, String arg1) {
625 638
			return col.compare(arg0, arg1);
......
630 643
	}
631 644
	
632 645
	public static String convertToUnicode(String entry) {
633
        char[] chtb = entry.toCharArray();
634
        StringBuffer temp = new StringBuffer(6*chtb.length);
635
        int BIT_MASK = (1 << 16);
636
        for(int i = 0; i < chtb.length; i++) {
637
            temp.append("\\u");
638
            temp.append(Integer.toHexString(chtb[ i] | BIT_MASK).substring(1));
639
        }
640
        return temp.toString();
641
    }
642

  
646
		char[] chtb = entry.toCharArray();
647
		StringBuffer temp = new StringBuffer(6 * chtb.length);
648
		int BIT_MASK = (1 << 16);
649
		for (int i = 0; i < chtb.length; i++) {
650
			temp.append("\\u");
651
			temp.append(Integer.toHexString(chtb[i] | BIT_MASK).substring(1));
652
		}
653
		return temp.toString();
654
	}
643 655
	
656
	
644 657
	public void saveChanges(boolean replaceFiles) throws IOException {
645

  
658
		saveChanges(replaceFiles, true, true);
659
	}
660
	
661
	public void saveChanges(boolean replaceFiles, boolean doOsgi, boolean doMessages) throws IOException {
662
		
646 663
		if (javaMessageFile == null) return;
647

  
664
		
648 665
		// 1 Write bundle*.properties prop File
649
		for (File propFile : osgiLangs.keySet()) {
650

  
651
			Properties props = new Properties() {
652
				@Override
653
				public synchronized Enumeration<Object> keys() {
654
					TreeSet<Object> set = new TreeSet<Object>(comp);
655
					set.addAll(super.keySet());
656
					return Collections.enumeration(set);
666
		if (doOsgi) {
667
			for (File propFile : osgiLangs.keySet()) {
668
				
669
				Properties props = new Properties() {
670
					
671
					@Override
672
					public synchronized Enumeration<Object> keys() {
673
						TreeSet<Object> set = new TreeSet<Object>(comp);
674
						set.addAll(super.keySet());
675
						return Collections.enumeration(set);
676
					}
677
				};
678
				HashMap<String, String> h = osgiLangs.get(propFile);
679
				for (String k : h.keySet()) {
680
					props.setProperty(k, h.get(k));
657 681
				}
658
			};
659
			HashMap<String, String> h = osgiLangs.get(propFile);
660
			for (String k : h.keySet()) {
661
				props.setProperty(k, h.get(k));
682
				
683
				File newPropFile = new File(propFile.getParentFile(), propFile.getName() + ".new");
684
				if (replaceFiles) {
685
					propFile.delete();
686
					newPropFile = propFile;
687
				}
688
				
689
				props.store(IOUtils.getWriter(newPropFile, "ISO-8859-1"), "TXM OSGI messages generated by the PluginMessagesManager class");
662 690
			}
663

  
664
			File newPropFile = new File(propFile.getParentFile(), propFile.getName()+".new");
665
			if (replaceFiles) {
666
				propFile.delete();
667
				newPropFile = propFile;
668
			}
669
			
670
			props.store(IOUtils.getWriter(newPropFile, "ISO-8859-1"), "TXM OSGI messages generated by the PluginMessagesManager class");
671 691
		}
672 692
		
673 693
		// 2 Write messages*.properties prop File
674
		for (File propFile : langs.keySet()) {
675

  
676
			Properties props = new Properties() {
677
				@Override
678
				public synchronized Enumeration<Object> keys() {
679
					TreeSet<Object> set = new TreeSet<Object>(comp);
680
					set.addAll(super.keySet());
681
					return Collections.enumeration(set);
694
		if (doMessages) {
695
			for (File propFile : langs.keySet()) {
696
				
697
				Properties props = new Properties() {
698
					
699
					@Override
700
					public synchronized Enumeration<Object> keys() {
701
						TreeSet<Object> set = new TreeSet<Object>(comp);
702
						set.addAll(super.keySet());
703
						return Collections.enumeration(set);
704
					}
705
				};
706
				HashMap<String, String> h = langs.get(propFile);
707
				for (String k : h.keySet()) {
708
					props.setProperty(k, h.get(k));
682 709
				}
683
			};
684
			HashMap<String, String> h = langs.get(propFile);
685
			for (String k : h.keySet()) {
686
				props.setProperty(k, h.get(k));
710
				
711
				File newPropFile = new File(propFile.getParentFile(), propFile.getName() + ".new");
712
				if (replaceFiles) {
713
					propFile.delete();
714
					newPropFile = propFile;
715
				}
716
				props.store(IOUtils.getWriter(newPropFile, UTF8), "TXM messages generated by the PluginMessagesManager class");
687 717
			}
688

  
689
			File newPropFile = new File(propFile.getParentFile(), propFile.getName()+".new");
718
			
719
			
720
			// 3 write Java message File
721
			File newJavaMessageFile = new File(javaMessageFile.getParentFile(), javaMessageFile.getName() + ".new");
722
			
723
			ArrayList<String> lines = IOUtils.getLines(javaMessageFile, UTF8);
724
			TreeSet<String> oldKeys = new TreeSet<>(IOUtils.findWithGroup(javaMessageFile, "public static String ([^\"=;]+);"));
725
			TreeSet<String> newKeys = new TreeSet<>(messageKeys);
726
			TreeSet<String> writtenKeys = new TreeSet<>();
727
			
728
			newKeys.removeAll(oldKeys);
729
			newKeys.removeAll(keyModifications.values()); // now contains only the very newly created keys
730
			
690 731
			if (replaceFiles) {
691
				propFile.delete();
692
				newPropFile = propFile;
732
				newJavaMessageFile = javaMessageFile;
693 733
			}
694
			props.store(IOUtils.getWriter(newPropFile, UTF8), "TXM messages generated by the PluginMessagesManager class");
695
		}
696

  
697
		// 3 write Java message File
698
		File newJavaMessageFile = new File(javaMessageFile.getParentFile(), javaMessageFile.getName()+".new");
699

  
700
		ArrayList<String> lines = IOUtils.getLines(javaMessageFile, UTF8);
701
		TreeSet<String> oldKeys = new TreeSet<String>(IOUtils.findWithGroup(javaMessageFile, "public static String ([^\"=;]+);"));
702
		TreeSet<String> newKeys = new TreeSet<String>(messageKeys);
703
		TreeSet<String> writtenKeys = new TreeSet<String>();
704

  
705
		newKeys.removeAll(oldKeys);
706
		newKeys.removeAll(keyModifications.values()); // now contains only the very newly created keys
707

  
708
		if (replaceFiles) {
709
			newJavaMessageFile = javaMessageFile;
710
		}
711

  
712
		PrintWriter out = IOUtils.getWriter(newJavaMessageFile, UTF8);
713

  
714
		// update lines
715
		for (String line : lines) {
716
			String l = line.trim();// remove tabs
717
			String comments = "";
718
			int idx = l.indexOf("//"); // remove comments
719
			if (idx > 0) {
720
				comments = l.substring(idx).trim();
721
				l = l.substring(0, idx).trim();
722
			}
723

  
724
			if (l.startsWith("private static final String BUNDLE_NAME")) {
725
				out.println(line);
726

  
727
				// write the totally new keys
728
				if (newKeys.size() > 0) {
729
					out.println("\t");
734
			
735
			PrintWriter out = IOUtils.getWriter(newJavaMessageFile, UTF8);
736
			
737
			// update lines
738
			for (String line : lines) {
739
				String l = line.trim();// remove tabs
740
				String comments = "";
741
				int idx = l.indexOf("//"); // remove comments
742
				if (idx > 0) {
743
					comments = l.substring(idx).trim();
744
					l = l.substring(0, idx).trim();
730 745
				}
731
				for (String key : newKeys) {
732
					if (writtenKeys.contains(key)) continue; // key already written
733
					out.println("\tpublic static String "+key+";");
734
					writtenKeys.add(key);
746
				
747
				if (l.startsWith("private static final String BUNDLE_NAME")) {
748
					out.println(line);
749
					
750
					// write the totally new keys
751
					if (newKeys.size() > 0) {
752
						out.println("\t");
753
					}
754
					for (String key : newKeys) {
755
						if (writtenKeys.contains(key)) continue; // key already written
756
						out.println("\tpublic static String " + key + ";");
757
						writtenKeys.add(key);
758
					}
735 759
				}
736
			} else if (l.startsWith("public static String") && l.endsWith(";") && !l.contains("=") && !l.contains("\"")) {
737

  
738
				String key = l.substring(21, l.length() -1);
739
				if (messageKeys.contains(key)) {
740
					if (writtenKeys.contains(key)) continue; // key already written
741
					out.println(line); // keep the line
742
					writtenKeys.add(key);
743
				} else if (keyModifications.containsKey(key)){
744
					// the key has been renamed
745
					if (writtenKeys.contains(keyModifications.get(key))) continue; // key already written
746
					out.println("\tpublic static String "+keyModifications.get(key)+"; "+comments);
747
					writtenKeys.add(keyModifications.get(key));
748
				} else {
749
					// the key has been removed
760
				else if (l.startsWith("public static String") && l.endsWith(";") && !l.contains("=") && !l.contains("\"")) {
761
					
762
					String key = l.substring(21, l.length() - 1);
763
					if (messageKeys.contains(key)) {
764
						if (writtenKeys.contains(key)) continue; // key already written
765
						out.println(line); // keep the line
766
						writtenKeys.add(key);
767
					}
768
					else if (keyModifications.containsKey(key)) {
769
						// the key has been renamed
770
						if (writtenKeys.contains(keyModifications.get(key))) continue; // key already written
771
						out.println("\tpublic static String " + keyModifications.get(key) + "; " + comments);
772
						writtenKeys.add(keyModifications.get(key));
773
					}
774
					else {
775
						// the key has been removed
776
					}
750 777
				}
751
			} else {
752
				out.println(line);
778
				else {
779
					out.println(line);
780
				}
753 781
			}
782
			out.close();
754 783
		}
755

  
756
		out.close();
757 784
	}
758

  
785
	
759 786
	public void summary() {
760

  
787
		
761 788
		System.out.println(getMessageClassName());
762

  
789
		
763 790
		System.out.println("Messages keys");
764 791
		for (String key : messageKeys) {
765 792
			System.out.println(key);
766 793
		}
767

  
794
		
768 795
		System.out.println("Langs");
769 796
		for (File lang : langs.keySet()) {
770 797
			System.out.println("  ------------------------------------------------------------------------------------------------------------------------------");
771 798
			System.out.println("  " + lang);
772 799
			System.out.println("  ------------------------------------------------------------------------------------------------------------------------------");
773 800
			HashMap<String, String> hash = langs.get(lang);
774
			System.out.println(" keys="+ hash.keySet());
801
			System.out.println(" keys=" + hash.keySet());
775 802
			for (String key : hash.keySet()) {
776
				System.out.println("  " + key + "="+hash.get(key));
803
				System.out.println("  " + key + "=" + hash.get(key));
777 804
			}
778 805
		}
779 806
	}
780

  
807
	
781 808
	/**
782
	 * Parses the specified path and stores a list of the source files. 
809
	 * Parses the specified path and stores a list of the source files.
783 810
	 */
784
	private void createSourceFilesList(File path)	{
811
	private void createSourceFilesList(File path) {
785 812
		File[] list = path.listFiles(IOUtils.HIDDENFILE_FILTER);
786

  
813
		
787 814
		if (list == null) {
788 815
			return;
789 816
		}
790

  
817
		
791 818
		for (File file : list) {
792 819
			if (file.isDirectory()) {
793 820
				this.createSourceFilesList(file);
794 821
			}
795 822
			else if (!file.equals(this.javaMessageFile)
796
					&& Arrays.asList(this.srcFilesExtensions).contains(FilenameUtils.getExtension(file.getName())) 
797
					) {
798

  
823
					&& Arrays.asList(this.srcFilesExtensions).contains(FilenameUtils.getExtension(file.getName()))) {
824
				
799 825
				if (debug) {
800 826
					System.out.println("PluginMessagesManager.createSourceFilesList(): adding source files " + file + ".");
801 827
				}
802
				else	{
803
					//System.out.print(".");
828
				else {
829
					// System.out.print(".");
804 830
				}
805

  
831
				
806 832
				this.srcFiles.add(file);
807 833
			}
808 834
		}
809 835
	}
810

  
836
	
811 837
	/**
812 838
	 * Parses the project and stores a list of the source files.
813 839
	 */
814
	public void createSourceFilesList()	{
815

  
840
	public void createSourceFilesList() {
841
		
816 842
		if (debug) {
817 843
			System.out.println("PluginMessagesManager.loadSourceFilesList(): creating source files list for extensions [" + StringUtils.join(this.srcFilesExtensions, ", ") + "]...");
818 844
		}
819

  
845
		
820 846
		this.createSourceFilesList(this.projectDirectory);
821

  
822

  
823
		if(debug) {
847
		
848
		
849
		if (debug) {
824 850
			System.out.println("PluginMessagesManager.loadSourceFilesList(): done. Source files count = " + this.srcFiles.size() + ".");
825 851
		}
826 852
	}
827

  
853
	
828 854
	/**
829 855
	 * Rename a key and update in the properties file the keys
830 856
	 * 
......
834 860
	 * @param newName
835 861
	 */
836 862
	public void renameKey(String oldName, String newName) {
837

  
863
		
838 864
		if (!messageKeys.contains(oldName)) {
839 865
			System.err.println("PluginMessagesManager.renameKey(): key=" + oldName + " not found, aborting renaming to " + newName + ".");
840 866
			return;
841 867
		}
842

  
868
		
843 869
		// continue only if key name has changed
844
		if(oldName.equals(newName))	{
845
			if(debug)	{
870
		if (oldName.equals(newName)) {
871
			if (debug) {
846 872
				System.out.println("PluginMessagesManager.renameKey(): no changes, skipped key: " + oldName + " = " + newName);
847 873
			}
848 874
			return;
849 875
		}
850

  
876
		
851 877
		messageKeys.remove(oldName);
852 878
		messageKeys.add(newName);
853

  
879
		
854 880
		for (File p : langs.keySet()) {
855 881
			HashMap<String, String> h = langs.get(p);
856 882
			if (h.containsKey(oldName)) {
857
				if (h.containsKey(newName) 
883
				if (h.containsKey(newName)
858 884
						&& !h.get(newName).equals(h.get(oldName))) { // a value is already set for the new key
859
					System.err.println("PluginMessagesManager.renameKey(): WARNING new key=" + newName + " already set in "+p+" with value="+h.get(newName)+" new value="+h.get(oldName));
860
				} else {
885
					System.err.println("PluginMessagesManager.renameKey(): WARNING new key=" + newName + " already set in " + p + " with value=" + h.get(newName) + " new value=" + h.get(oldName));
886
				}
887
				else {
861 888
					h.put(newName, h.get(oldName));
862 889
				}
863 890
				h.remove(oldName);
864 891
			}
865 892
		}
866

  
867
		//System.out.println("M+ "+oldName+" -> "+newName);
893
		
894
		// System.out.println("M+ "+oldName+" -> "+newName);
868 895
		keyModifications.put(oldName, newName);
869 896
	}
870

  
897
	
871 898
	/**
872 899
	 * Remove a messages from XXMessages.java and messages.properties files
873 900
	 * 
......
878 905
			System.err.println("PluginMessagesManager.removeKey(): key=" + key + " not found, aborting removing.");
879 906
			return;
880 907
		}
881

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff