annotate src/org/tn5250j/GlobalConfigure.java @ 20:69a407d33146 tn5250

adding tn5250 files
author Carl Byington <carl@five-ten-sg.com>
date Tue, 03 Jun 2014 10:27:54 -0700
parents
children 94abfc6441a4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
1 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
2 * Title: GlobalConfigure.java
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
3 * Copyright: Copyright (c) 2001, 2002, 2003
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
4 * Company:
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
5 * @author Kenneth J. Pouncey
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
6 * @version 0.1
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
7 *
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
8 * Description:
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
9 *
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
10 * This program is free software; you can redistribute it and/or modify
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
11 * it under the terms of the GNU General Public License as published by
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
12 * the Free Software Foundation; either version 2, or (at your option)
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
13 * any later version.
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
14 *
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
15 * This program is distributed in the hope that it will be useful,
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
18 * GNU General Public License for more details.
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
19 *
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
20 * You should have received a copy of the GNU General Public License
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
21 * along with this software; see the file COPYING. If not, write to
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
22 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
23 * Boston, MA 02111-1307 USA
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
24 *
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
25 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
26 package org.tn5250j;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
27
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
28 import java.io.BufferedReader;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
29 import java.io.File;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
30 import java.io.FileInputStream;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
31 import java.io.FileNotFoundException;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
32 import java.io.FileOutputStream;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
33 import java.io.FileReader;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
34 import java.io.FileWriter;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
35 import java.io.IOException;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
36 import java.io.PrintWriter;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
37 import java.util.Hashtable;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
38 import java.util.Properties;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
39
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
40 import javax.swing.JOptionPane;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
41
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
42 import com.five-ten-sg.connectbot.TerminalView;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
43 import org.tn5250j.interfaces.ConfigureFactory;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
44 import org.tn5250j.tools.logging.TN5250jLogFactory;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
45 import org.tn5250j.tools.logging.TN5250jLogger;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
46
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
47 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
48 * Utility class for referencing global settings and functions of which at most
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
49 * one instance can exist per VM.
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
50 *
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
51 * Use GlobalConfigure.instance() to access this instance.
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
52 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
53 public class GlobalConfigure extends ConfigureFactory {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
54
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
55 public static final String TN5250J_FOLDER = ".tn5250j";
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
56
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
57 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
58 * A handle to the unique GlobalConfigure class
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
59 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
60 static private GlobalConfigure _instance;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
61
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
62 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
63 * A handle to the the Global Properties
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
64 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
65 static private Properties settings;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
66
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
67 static private Hashtable registry = new Hashtable();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
68 static private Hashtable headers = new Hashtable(); //LUC GORRENS
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
69
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
70 // Moved to ConfigureFactory
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
71 // static final public String SESSIONS = "sessions";
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
72 static final public File ses = new File(SESSIONS);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
73 // static final public String MACROS = "macros";
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
74 // static final public String KEYMAP = "keymap";
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
75
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
76 private final TN5250jLogger log = TN5250jLogFactory.getLogger (this.getClass());
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
77
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
78 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
79 * The constructor is made protected to allow overriding.
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
80 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
81 public GlobalConfigure() {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
82 if (_instance == null) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
83 // initialize the settings information
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
84 initialize();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
85 // set our instance to this one.
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
86 _instance = this;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
87 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
88 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
89
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
90 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
91 *
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
92 * @return The unique instance of this class.
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
93 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
94 static public GlobalConfigure instance() {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
95
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
96 if (_instance == null) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
97 _instance = new GlobalConfigure();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
98 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
99 return _instance;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
100
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
101 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
102
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
103 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
104 * Initialize the properties registry for use later.
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
105 *
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
106 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
107 private void initialize() {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
108 verifySettingsFolder();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
109 loadSettings();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
110 loadSessions();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
111 loadMacros();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
112 loadKeyStrokes();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
113 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
114
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
115 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
116 * check if folder %USERPROFILE%/.tn5250j exists
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
117 * and create if necessary
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
118 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
119 private void verifySettingsFolder() {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
120 final String settingsfolder = settingsFolder();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
121 final File f = new File (settingsfolder);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
122 if (!f.exists()) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
123 try {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
124 if (log.isInfoEnabled()) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
125 log.info("Settings folder '"+settingsfolder+"' doesn't exist. Will created now.");
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
126 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
127 f.mkdir();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
128 } catch (Exception e) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
129 if (log.isWarnEnabled()) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
130 log.warn("Couldn't create settings folder '"+settingsfolder+"'", e);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
131 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
132 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
133 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
134 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
135
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
136 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
137 * Load the sessions properties
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
138 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
139 private void loadSessions() {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
140
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
141 setProperties(SESSIONS,SESSIONS,"------ Sessions --------",true);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
142 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
143
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
144 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
145 * Load the macros
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
146 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
147 private void loadMacros() {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
148
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
149 setProperties(MACROS,MACROS,"------ Macros --------",true);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
150
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
151 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
152
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
153 private void loadKeyStrokes() {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
154
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
155 setProperties(KEYMAP,KEYMAP,
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
156 "------ Key Map key=keycode,isShiftDown,isControlDown,isAltDown,isAltGrDown --------",
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
157 true);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
158
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
159 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
160
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
161 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
162 * Reload the environment settings.
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
163 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
164 @Override
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
165 public void reloadSettings() {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
166 if (log.isInfoEnabled()) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
167 log.info("reloading settings");
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
168 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
169 loadSettings();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
170 loadSessions();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
171 loadMacros();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
172 loadKeyStrokes();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
173 if (log.isInfoEnabled()) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
174 log.info("Done (reloading settings).");
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
175 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
176 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
177
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
178 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
179 * Loads the emulator setting from the setting(s) file
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
180 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
181 private void loadSettings() {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
182
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
183 FileInputStream in = null;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
184 settings = new Properties();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
185
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
186 try {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
187 in = new FileInputStream(settingsFile());
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
188 settings.load(in);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
189 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
190 catch (FileNotFoundException fnfea) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
191 log.info(" Information Message: "
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
192 + fnfea.getMessage() + ". The file " + settingsFile()
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
193 + " will be created for first time use.");
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
194 checkLegacy();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
195 saveSettings();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
196 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
197 catch (IOException ioea) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
198 log.warn("IO Exception accessing File "
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
199 + settingsFile() + " for the following reason : "
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
200 + ioea.getMessage());
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
201 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
202 catch (SecurityException sea) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
203 log.warn("Security Exception for file "
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
204 + settingsFile() + " This file can not be "
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
205 + "accessed because : " + sea.getMessage());
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
206 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
207 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
208
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
209 private void checkDirs() {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
210 // we now check to see if the settings directory is a directory. If not then we create it
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
211 File sd = new File(settings.getProperty("emulator.settingsDirectory"));
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
212 if (!sd.isDirectory())
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
213 sd.mkdirs();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
214 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
215
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
216 private void checkLegacy() {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
217 // we check if the sessions file already exists in the directory
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
218 // if it does exist we are working with an old install so we
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
219 // need to set the settings directory to the users directory
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
220 // SESSIONS is declared as a string, so we just can use the keyword here.
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
221 if(ses.exists()) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
222 int cfc;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
223 cfc = JOptionPane.showConfirmDialog(null,
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
224 "Dear User,\n\n" +
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
225 "Seems you are using an old version of tn5250j.\n" +
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
226 "In meanwhile the application became multi-user capable,\n" +
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
227 "which means ALL the config- and settings-files are\n" +
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
228 "placed in your home-dir to avoid further problems in\n" +
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
229 "the near future.\n\n" +
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
230 "You have the choice to choose if you want the files\n" +
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
231 "to be copied or not, please make your choice !\n\n" +
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
232 "Shall we copy the files to the new location ?",
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
233 "Old install detected", JOptionPane.WARNING_MESSAGE,
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
234 JOptionPane.YES_NO_OPTION);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
235 if (cfc == 0) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
236 // Here we do a checkdir so we know the destination-dir exists
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
237 checkDirs();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
238 copyConfigs(SESSIONS);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
239 copyConfigs(MACROS);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
240 copyConfigs(KEYMAP);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
241 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
242 else {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
243 JOptionPane.showMessageDialog(null,
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
244 "Dear User,\n\n" +
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
245 "You choosed not to copy the file.\n" +
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
246 "This means the program will end here.\n\n" +
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
247 "To use this NON-STANDARD behaviour start tn5250j\n" +
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
248 "with -Demulator.settingsDirectory=<settings-dir> \n" +
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
249 "as a parameter to avoid this question all the time.",
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
250 "Using NON-STANDARD behaviour", JOptionPane.WARNING_MESSAGE);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
251 System.exit(0);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
252 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
253 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
254 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
255
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
256 private void copyConfigs(String sesFile) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
257 /** Copy the config-files to the user's home-dir */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
258 String srcFile = System.getProperty("user.dir") + File.separator + sesFile;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
259 String dest = System.getProperty("user.home") +
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
260 File.separator + TN5250J_FOLDER + File.separator + sesFile;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
261 File rmvFile = new File(sesFile);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
262 try {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
263 FileReader r = new FileReader(srcFile);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
264 BufferedReader b = new BufferedReader(r);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
265
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
266 FileWriter w = new FileWriter(dest);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
267 PrintWriter p = new PrintWriter(w);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
268 String regel = b.readLine();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
269 while (regel != null) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
270 p.println(regel);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
271 regel = b.readLine();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
272 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
273 b.close();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
274 p.close();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
275 rmvFile.delete();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
276 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
277 catch (FileNotFoundException e) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
278 log.warn(srcFile + " not found !");
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
279 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
280 catch (IOException e) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
281 log.warn("Global io-error !");
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
282 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
283 catch (ArrayIndexOutOfBoundsException e) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
284 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
285 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
286
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
287 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
288 * Save the settings for the global configuration
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
289 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
290 @Override
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
291 public void saveSettings() {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
292
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
293 try {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
294 FileOutputStream out = new FileOutputStream(settingsFile());
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
295 settings.store(out,"----------------- tn5250j Global Settings --------------");
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
296 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
297 catch (FileNotFoundException fnfe) {}
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
298 catch (IOException ioe) {}
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
299 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
300
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
301 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
302 * Save the setting in the registry using the key passed in with no header
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
303 * output.
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
304 *
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
305 * @param regKey
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
306 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
307 @Override
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
308 public void saveSettings(String regKey) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
309
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
310 saveSettings(regKey,"");
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
311 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
312
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
313 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
314 * Save the settings in the registry using the key passed with a header
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
315 * in the output.
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
316 *
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
317 * @param regKey
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
318 * @param Header
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
319 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
320 @Override
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
321 public void saveSettings(String regKey, String header) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
322
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
323 saveSettings(regKey,regKey,header);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
324 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
325
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
326 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
327 * Save the settings in the registry using the key passed with a header
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
328 * in the output.
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
329 *
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
330 * @param regKey
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
331 * @param Header
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
332 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
333 @Override
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
334 public void saveSettings(String regKey, String fileName, String header) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
335
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
336 if (registry.containsKey(regKey)) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
337 try {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
338 FileOutputStream out = new FileOutputStream(
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
339 settingsDirectory() + fileName);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
340 Properties props = (Properties)registry.get(regKey);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
341 props.store(out,header);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
342 out.flush();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
343 out.close();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
344 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
345 catch (FileNotFoundException fnfe) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
346 log.warn("File not found : writing file "
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
347 + fileName + ". Description of error is "
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
348 + fnfe.getMessage());
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
349 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
350 catch (IOException ioe) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
351 log.warn("IO Exception : writing file "
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
352 + fileName + ". Description of error is "
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
353 + ioe.getMessage());
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
354 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
355 catch (SecurityException se) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
356 log.warn("Security Exception : writing file "
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
357 + fileName + ". Description of error is "
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
358 + se.getMessage());
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
359 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
360
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
361 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
362
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
363 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
364
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
365 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
366 * Place the Properties in the registry under a given registry name
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
367 *
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
368 * @param regKey
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
369 * @param regProps
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
370 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
371 @Override
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
372 public void setProperties(String regKey, Properties regProps) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
373
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
374 registry.put(regKey, regProps);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
375
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
376 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
377
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
378 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
379 * Set the properties for the given registry key.
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
380 *
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
381 * @param regKey
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
382 * @param fileName
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
383 * @param header
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
384 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
385 @Override
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
386 public void setProperties(String regKey, String fileName, String header) { //LG NEW
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
387 setProperties(regKey, fileName, header, false);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
388 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
389
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
390 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
391 * Set the properties for the given registry key.
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
392 *
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
393 * @param regKey
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
394 * @param fileName
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
395 * @param header
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
396 * @param createFile
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
397 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
398 @Override
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
399 public void setProperties(String regKey, String fileName, String header,
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
400 boolean createFile) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
401
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
402 FileInputStream in = null;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
403 Properties props = new Properties();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
404 headers.put(regKey, header);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
405
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
406 try {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
407 in = new FileInputStream(settingsDirectory() + fileName);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
408 props.load(in);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
409
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
410 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
411 catch (FileNotFoundException fnfe) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
412
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
413 if (createFile) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
414 log.info(" Information Message: " + fnfe.getMessage()
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
415 + ". The file " + fileName + " will"
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
416 + " be created for first time use.");
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
417
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
418 saveSettings(regKey,header);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
419
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
420 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
421 else {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
422
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
423 log.info(" Information Message: " + fnfe.getMessage()
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
424 + ".");
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
425
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
426 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
427 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
428 catch (IOException ioe) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
429 log.warn("IO Exception accessing File "+ fileName +
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
430 " for the following reason : "
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
431 + ioe.getMessage());
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
432 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
433 catch (SecurityException se) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
434 log.warn("Security Exception for file "+ fileName
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
435 + ". This file can not be accessed because : "
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
436 + se.getMessage());
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
437 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
438
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
439 registry.put(regKey,props);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
440
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
441 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
442
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
443 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
444 * Returns the properties associated with a given registry key.
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
445 *
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
446 * @param regKey
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
447 * @return
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
448 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
449 @Override
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
450 public Properties getProperties(String regKey) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
451
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
452 if (registry.containsKey(regKey)) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
453 return (Properties)registry.get(regKey);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
454 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
455 return null;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
456 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
457
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
458 public Properties getProperties() {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
459 return settings;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
460 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
461
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
462 @Override
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
463 public Properties getProperties(String regKey,String fileName) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
464 return getProperties(regKey,fileName,false,"",false);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
465 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
466
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
467 @Override
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
468 public Properties getProperties(String regKey,String fileName,
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
469 boolean createFile, String header) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
470 return getProperties(regKey,fileName,false,"",false);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
471 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
472
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
473 @Override
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
474 public Properties getProperties(String regKey,String fileName,
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
475 boolean createFile,String header,
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
476 boolean reloadIfLoaded) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
477
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
478 if (!registry.containsKey(regKey) || reloadIfLoaded) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
479
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
480 FileInputStream in = null;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
481 Properties props = new Properties();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
482 headers.put(regKey, header);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
483
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
484 try {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
485 in = new FileInputStream(settingsDirectory()
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
486 + fileName);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
487 props.load(in);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
488
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
489 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
490 catch (FileNotFoundException fnfe) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
491
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
492 if (createFile) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
493 log.info(" Information Message: " + fnfe.getMessage()
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
494 + ". The file " + fileName + " will"
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
495 + " be created for first time use.");
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
496
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
497 registry.put(regKey,props);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
498
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
499 saveSettings(regKey,header);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
500
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
501 return props;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
502
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
503 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
504 else {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
505
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
506 log.info(" Information Message: " + fnfe.getMessage()
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
507 + ".");
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
508
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
509 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
510 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
511 catch (IOException ioe) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
512 log.warn("IO Exception accessing File "+ fileName +
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
513 " for the following reason : "
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
514 + ioe.getMessage());
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
515 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
516 catch (SecurityException se) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
517 log.warn("Security Exception for file "+ fileName
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
518 + ". This file can not be accessed because : "
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
519 + se.getMessage());
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
520 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
521
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
522 registry.put(regKey,props);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
523
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
524 return props;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
525 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
526 else {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
527 return (Properties)registry.get(regKey);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
528 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
529 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
530
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
531 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
532 * Returns the setting from the given key of the global properties or the
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
533 * default passed if the property does not exist.
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
534 *
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
535 * @param key
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
536 * @param def
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
537 * @return
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
538 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
539 @Override
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
540 public String getProperty(String key, String def) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
541 if (settings.containsKey(key))
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
542 return settings.getProperty(key);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
543 else
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
544 return def;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
545 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
546
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
547 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
548 * Returns the setting from the given key of the global properties.
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
549 *
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
550 * @param key
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
551 * @return
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
552 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
553 @Override
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
554 public String getProperty(String key) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
555 return settings.getProperty(key);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
556 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
557
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
558 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
559 * Private helper to return the full path to the settings file
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
560 *
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
561 * @return
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
562 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
563 private String settingsFile() {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
564 return settingsDirectory() + "tn5250jstartup.cfg";
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
565
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
566 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
567
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
568 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
569 * Private helper to return the settings directory
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
570 *
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
571 * @return
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
572 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
573 private String settingsDirectory() {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
574 return settingsFolder() + File.separator;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
575
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
576 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
577
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
578 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
579 * Private helper to return the settings folder path
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
580 *
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
581 * @return
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
582 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
583 private String settingsFolder() {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
584 return TerminalView.android_home_directory + File.separator + TN5250J_FOLDER;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
585
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
586 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
587
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
588 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
589 * Not sure yet so be careful using this.
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
590 *
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
591 * @return
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
592 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
593 public ClassLoader getClassLoader() {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
594
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
595 ClassLoader loader = GlobalConfigure.class.getClassLoader();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
596 if (loader == null)
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
597 loader = ClassLoader.getSystemClassLoader();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
598
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
599 return loader;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
600 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
601
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
602 }