comparison src/org/tn5250j/GlobalConfigure.java @ 25:5949eb469a79 tn5250

adding tn5250 files, native android logging
author Carl Byington <carl@five-ten-sg.com>
date Tue, 03 Jun 2014 12:10:21 -0700
parents e067ee54f638
children b29b39f386a4
comparison
equal deleted inserted replaced
24:d1c549560aff 25:5949eb469a79
37 import java.util.Hashtable; 37 import java.util.Hashtable;
38 import java.util.Properties; 38 import java.util.Properties;
39 39
40 import com.five_ten_sg.connectbot.TerminalView; 40 import com.five_ten_sg.connectbot.TerminalView;
41 import org.tn5250j.interfaces.ConfigureFactory; 41 import org.tn5250j.interfaces.ConfigureFactory;
42 import org.tn5250j.tools.logging.TN5250jLogFactory; 42 import android.util.Log;
43 import org.tn5250j.tools.logging.TN5250jLogger; 43
44 44
45 /** 45 /**
46 * Utility class for referencing global settings and functions of which at most 46 * Utility class for referencing global settings and functions of which at most
47 * one instance can exist per VM. 47 * one instance can exist per VM.
48 * 48 *
62 */ 62 */
63 static private Properties settings; 63 static private Properties settings;
64 64
65 static private Hashtable registry = new Hashtable(); 65 static private Hashtable registry = new Hashtable();
66 static private Hashtable headers = new Hashtable(); //LUC GORRENS 66 static private Hashtable headers = new Hashtable(); //LUC GORRENS
67 private final TN5250jLogger log = TN5250jLogFactory.getLogger (this.getClass()); 67
68 68
69 /** 69 /**
70 * The constructor is made protected to allow overriding. 70 * The constructor is made protected to allow overriding.
71 */ 71 */
72 public GlobalConfigure() { 72 public GlobalConfigure() {
110 private void verifySettingsFolder() { 110 private void verifySettingsFolder() {
111 final String settingsfolder = settingsFolder(); 111 final String settingsfolder = settingsFolder();
112 final File f = new File (settingsfolder); 112 final File f = new File (settingsfolder);
113 if (!f.exists()) { 113 if (!f.exists()) {
114 try { 114 try {
115 if (log.isInfoEnabled()) { 115 Log.i(TAG,"Settings folder '"+settingsfolder+"' doesn't exist. Will created now.");
116 log.info("Settings folder '"+settingsfolder+"' doesn't exist. Will created now.");
117 }
118 f.mkdir(); 116 f.mkdir();
119 } catch (Exception e) { 117 } catch (Exception e) {
120 if (log.isWarnEnabled()) { 118 Log.w(TAG,"Couldn't create settings folder '"+settingsfolder+"'", e);
121 log.warn("Couldn't create settings folder '"+settingsfolder+"'", e);
122 }
123 } 119 }
124 } 120 }
125 } 121 }
126 122
127 /** 123 /**
152 /** 148 /**
153 * Reload the environment settings. 149 * Reload the environment settings.
154 */ 150 */
155 @Override 151 @Override
156 public void reloadSettings() { 152 public void reloadSettings() {
157 if (log.isInfoEnabled()) { 153 Log.i(TAG,"reloading settings");
158 log.info("reloading settings");
159 }
160 loadSettings(); 154 loadSettings();
161 loadSessions(); 155 loadSessions();
162 loadMacros(); 156 loadMacros();
163 loadKeyStrokes(); 157 loadKeyStrokes();
164 if (log.isInfoEnabled()) { 158 Log.i(TAG,"Done (reloading settings).");
165 log.info("Done (reloading settings).");
166 }
167 } 159 }
168 160
169 /** 161 /**
170 * Loads the emulator setting from the setting(s) file 162 * Loads the emulator setting from the setting(s) file
171 */ 163 */
177 try { 169 try {
178 in = new FileInputStream(settingsFile()); 170 in = new FileInputStream(settingsFile());
179 settings.load(in); 171 settings.load(in);
180 } 172 }
181 catch (FileNotFoundException fnfea) { 173 catch (FileNotFoundException fnfea) {
182 log.info(" Information Message: " 174 Log.i(TAG," Information Message: "
183 + fnfea.getMessage() + ". The file " + settingsFile() 175 + fnfea.getMessage() + ". The file " + settingsFile()
184 + " will be created for first time use."); 176 + " will be created for first time use.");
185 saveSettings(); 177 saveSettings();
186 } 178 }
187 catch (IOException ioea) { 179 catch (IOException ioea) {
188 log.warn("IO Exception accessing File " 180 Log.w(TAG,"IO Exception accessing File "
189 + settingsFile() + " for the following reason : " 181 + settingsFile() + " for the following reason : "
190 + ioea.getMessage()); 182 + ioea.getMessage());
191 } 183 }
192 catch (SecurityException sea) { 184 catch (SecurityException sea) {
193 log.warn("Security Exception for file " 185 Log.w(TAG,"Security Exception for file "
194 + settingsFile() + " This file can not be " 186 + settingsFile() + " This file can not be "
195 + "accessed because : " + sea.getMessage()); 187 + "accessed because : " + sea.getMessage());
196 } 188 }
197 } 189 }
198 190
253 props.store(out,header); 245 props.store(out,header);
254 out.flush(); 246 out.flush();
255 out.close(); 247 out.close();
256 } 248 }
257 catch (FileNotFoundException fnfe) { 249 catch (FileNotFoundException fnfe) {
258 log.warn("File not found : writing file " 250 Log.w(TAG,"File not found : writing file "
259 + fileName + ". Description of error is " 251 + fileName + ". Description of error is "
260 + fnfe.getMessage()); 252 + fnfe.getMessage());
261 } 253 }
262 catch (IOException ioe) { 254 catch (IOException ioe) {
263 log.warn("IO Exception : writing file " 255 Log.w(TAG,"IO Exception : writing file "
264 + fileName + ". Description of error is " 256 + fileName + ". Description of error is "
265 + ioe.getMessage()); 257 + ioe.getMessage());
266 } 258 }
267 catch (SecurityException se) { 259 catch (SecurityException se) {
268 log.warn("Security Exception : writing file " 260 Log.w(TAG,"Security Exception : writing file "
269 + fileName + ". Description of error is " 261 + fileName + ". Description of error is "
270 + se.getMessage()); 262 + se.getMessage());
271 } 263 }
272 264
273 } 265 }
321 313
322 } 314 }
323 catch (FileNotFoundException fnfe) { 315 catch (FileNotFoundException fnfe) {
324 316
325 if (createFile) { 317 if (createFile) {
326 log.info(" Information Message: " + fnfe.getMessage() 318 Log.i(TAG," Information Message: " + fnfe.getMessage()
327 + ". The file " + fileName + " will" 319 + ". The file " + fileName + " will"
328 + " be created for first time use."); 320 + " be created for first time use.");
329 321
330 saveSettings(regKey,header); 322 saveSettings(regKey,header);
331 323
332 } 324 }
333 else { 325 else {
334 326
335 log.info(" Information Message: " + fnfe.getMessage() 327 Log.i(TAG," Information Message: " + fnfe.getMessage()
336 + "."); 328 + ".");
337 329
338 } 330 }
339 } 331 }
340 catch (IOException ioe) { 332 catch (IOException ioe) {
341 log.warn("IO Exception accessing File "+ fileName + 333 Log.w(TAG,"IO Exception accessing File "+ fileName +
342 " for the following reason : " 334 " for the following reason : "
343 + ioe.getMessage()); 335 + ioe.getMessage());
344 } 336 }
345 catch (SecurityException se) { 337 catch (SecurityException se) {
346 log.warn("Security Exception for file "+ fileName 338 Log.w(TAG,"Security Exception for file "+ fileName
347 + ". This file can not be accessed because : " 339 + ". This file can not be accessed because : "
348 + se.getMessage()); 340 + se.getMessage());
349 } 341 }
350 342
351 registry.put(regKey,props); 343 registry.put(regKey,props);
402 394
403 } 395 }
404 catch (FileNotFoundException fnfe) { 396 catch (FileNotFoundException fnfe) {
405 397
406 if (createFile) { 398 if (createFile) {
407 log.info(" Information Message: " + fnfe.getMessage() 399 Log.i(TAG," Information Message: " + fnfe.getMessage()
408 + ". The file " + fileName + " will" 400 + ". The file " + fileName + " will"
409 + " be created for first time use."); 401 + " be created for first time use.");
410 402
411 registry.put(regKey,props); 403 registry.put(regKey,props);
412 404
415 return props; 407 return props;
416 408
417 } 409 }
418 else { 410 else {
419 411
420 log.info(" Information Message: " + fnfe.getMessage() 412 Log.i(TAG," Information Message: " + fnfe.getMessage()
421 + "."); 413 + ".");
422 414
423 } 415 }
424 } 416 }
425 catch (IOException ioe) { 417 catch (IOException ioe) {
426 log.warn("IO Exception accessing File "+ fileName + 418 Log.w(TAG,"IO Exception accessing File "+ fileName +
427 " for the following reason : " 419 " for the following reason : "
428 + ioe.getMessage()); 420 + ioe.getMessage());
429 } 421 }
430 catch (SecurityException se) { 422 catch (SecurityException se) {
431 log.warn("Security Exception for file "+ fileName 423 Log.w(TAG,"Security Exception for file "+ fileName
432 + ". This file can not be accessed because : " 424 + ". This file can not be accessed because : "
433 + se.getMessage()); 425 + se.getMessage());
434 } 426 }
435 427
436 registry.put(regKey,props); 428 registry.put(regKey,props);