annotate src/org/tn5250j/GlobalConfigure.java @ 22:e067ee54f638 tn5250

adding tn5250 files
author Carl Byington <carl@five-ten-sg.com>
date Tue, 03 Jun 2014 10:40:11 -0700
parents 94abfc6441a4
children 5949eb469a79
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
21
94abfc6441a4 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 20
diff changeset
40 import com.five_ten_sg.connectbot.TerminalView;
20
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
41 import org.tn5250j.interfaces.ConfigureFactory;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
42 import org.tn5250j.tools.logging.TN5250jLogFactory;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
43 import org.tn5250j.tools.logging.TN5250jLogger;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
44
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
45 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
46 * 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
47 * one instance can exist per VM.
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
48 *
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
49 * Use GlobalConfigure.instance() to access this instance.
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 public class GlobalConfigure extends ConfigureFactory {
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 static final String TN5250J_FOLDER = ".tn5250j";
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 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
56 * A handle to the unique GlobalConfigure class
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 static private GlobalConfigure _instance;
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 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
61 * A handle to the the Global Properties
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 static private Properties settings;
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 Hashtable registry = new Hashtable();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
66 static private Hashtable headers = new Hashtable(); //LUC GORRENS
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
67 private final TN5250jLogger log = TN5250jLogFactory.getLogger (this.getClass());
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
68
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 * The constructor is made protected to allow overriding.
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
71 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
72 public GlobalConfigure() {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
73 if (_instance == null) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
74 // initialize the settings information
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
75 initialize();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
76 // set our instance to this one.
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
77 _instance = this;
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 }
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 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
82 *
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
83 * @return The unique instance of this class.
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
84 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
85 static public GlobalConfigure instance() {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
86
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
87 if (_instance == null) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
88 _instance = new GlobalConfigure();
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 return _instance;
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 }
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 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
95 * Initialize the properties registry for use later.
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
96 *
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
97 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
98 private void initialize() {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
99 verifySettingsFolder();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
100 loadSettings();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
101 loadSessions();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
102 loadMacros();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
103 loadKeyStrokes();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
104 }
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 * check if folder %USERPROFILE%/.tn5250j exists
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
108 * and create if necessary
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
109 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
110 private void verifySettingsFolder() {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
111 final String settingsfolder = settingsFolder();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
112 final File f = new File (settingsfolder);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
113 if (!f.exists()) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
114 try {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
115 if (log.isInfoEnabled()) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
116 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
117 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
118 f.mkdir();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
119 } catch (Exception e) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
120 if (log.isWarnEnabled()) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
121 log.warn("Couldn't create settings folder '"+settingsfolder+"'", e);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
122 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
123 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
124 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
125 }
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 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
128 * Load the sessions properties
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
129 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
130 private void loadSessions() {
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 setProperties(SESSIONS,SESSIONS,"------ Sessions --------",true);
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 * Load the macros
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
137 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
138 private void loadMacros() {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
139
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
140 setProperties(MACROS,MACROS,"------ Macros --------",true);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
141
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 private void loadKeyStrokes() {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
145
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
146 setProperties(KEYMAP,KEYMAP,
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
147 "------ Key Map key=keycode,isShiftDown,isControlDown,isAltDown,isAltGrDown --------",
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
148 true);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
149
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 * Reload the environment settings.
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 @Override
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
156 public void reloadSettings() {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
157 if (log.isInfoEnabled()) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
158 log.info("reloading settings");
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 loadSettings();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
161 loadSessions();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
162 loadMacros();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
163 loadKeyStrokes();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
164 if (log.isInfoEnabled()) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
165 log.info("Done (reloading settings).");
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
166 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
167 }
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 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
170 * Loads the emulator setting from the setting(s) file
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
171 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
172 private void loadSettings() {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
173
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
174 FileInputStream in = null;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
175 settings = new Properties();
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 try {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
178 in = new FileInputStream(settingsFile());
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
179 settings.load(in);
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 catch (FileNotFoundException fnfea) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
182 log.info(" Information Message: "
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
183 + fnfea.getMessage() + ". The file " + settingsFile()
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
184 + " will be created for first time use.");
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
185 saveSettings();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
186 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
187 catch (IOException ioea) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
188 log.warn("IO Exception accessing File "
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
189 + settingsFile() + " for the following reason : "
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
190 + ioea.getMessage());
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
191 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
192 catch (SecurityException sea) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
193 log.warn("Security Exception for file "
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
194 + settingsFile() + " This file can not be "
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
195 + "accessed because : " + sea.getMessage());
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 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
198
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
199 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
200 * Save the settings for the global configuration
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 @Override
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
203 public void saveSettings() {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
204
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
205 try {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
206 FileOutputStream out = new FileOutputStream(settingsFile());
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
207 settings.store(out,"----------------- tn5250j Global Settings --------------");
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 catch (FileNotFoundException fnfe) {}
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
210 catch (IOException ioe) {}
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
211 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
212
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
213 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
214 * 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
215 * output.
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
216 *
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
217 * @param regKey
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
218 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
219 @Override
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
220 public void saveSettings(String regKey) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
221
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
222 saveSettings(regKey,"");
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
223 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
224
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
225 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
226 * 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
227 * in the output.
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
228 *
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
229 * @param regKey
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
230 * @param Header
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
231 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
232 @Override
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
233 public void saveSettings(String regKey, String header) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
234
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
235 saveSettings(regKey,regKey,header);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
236 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
237
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
238 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
239 * 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
240 * in the output.
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 * @param regKey
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
243 * @param Header
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
244 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
245 @Override
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
246 public void saveSettings(String regKey, String fileName, String header) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
247
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
248 if (registry.containsKey(regKey)) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
249 try {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
250 FileOutputStream out = new FileOutputStream(
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
251 settingsDirectory() + fileName);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
252 Properties props = (Properties)registry.get(regKey);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
253 props.store(out,header);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
254 out.flush();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
255 out.close();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
256 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
257 catch (FileNotFoundException fnfe) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
258 log.warn("File not found : writing file "
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
259 + fileName + ". Description of error is "
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
260 + fnfe.getMessage());
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
261 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
262 catch (IOException ioe) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
263 log.warn("IO Exception : writing file "
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
264 + fileName + ". Description of error is "
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
265 + ioe.getMessage());
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
266 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
267 catch (SecurityException se) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
268 log.warn("Security Exception : writing file "
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
269 + fileName + ". Description of error is "
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
270 + se.getMessage());
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
271 }
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 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
274
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
275 }
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 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
278 * 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
279 *
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
280 * @param regKey
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
281 * @param regProps
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 @Override
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
284 public void setProperties(String regKey, Properties regProps) {
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 registry.put(regKey, regProps);
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 }
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 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
291 * Set the properties for the given registry key.
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 * @param regKey
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
294 * @param fileName
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
295 * @param header
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 @Override
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
298 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
299 setProperties(regKey, fileName, header, false);
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 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
303 * Set the properties for the given registry key.
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 * @param fileName
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
307 * @param header
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
308 * @param createFile
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 @Override
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
311 public void setProperties(String regKey, String fileName, String header,
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
312 boolean createFile) {
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 FileInputStream in = null;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
315 Properties props = new Properties();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
316 headers.put(regKey, header);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
317
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
318 try {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
319 in = new FileInputStream(settingsDirectory() + fileName);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
320 props.load(in);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
321
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 catch (FileNotFoundException fnfe) {
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 if (createFile) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
326 log.info(" Information Message: " + fnfe.getMessage()
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
327 + ". The file " + fileName + " will"
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
328 + " be created for first time use.");
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 saveSettings(regKey,header);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
331
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 else {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
334
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
335 log.info(" Information Message: " + fnfe.getMessage()
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
336 + ".");
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
337
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
338 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
339 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
340 catch (IOException ioe) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
341 log.warn("IO Exception accessing File "+ fileName +
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
342 " for the following reason : "
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
343 + ioe.getMessage());
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 (SecurityException se) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
346 log.warn("Security Exception for file "+ fileName
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
347 + ". This file can not be accessed because : "
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
348 + se.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
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
351 registry.put(regKey,props);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
352
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
353 }
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 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
356 * Returns the properties associated with a given registry key.
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
357 *
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
358 * @param regKey
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
359 * @return
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 @Override
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
362 public Properties getProperties(String regKey) {
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 if (registry.containsKey(regKey)) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
365 return (Properties)registry.get(regKey);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
366 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
367 return null;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
368 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
369
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
370 public Properties getProperties() {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
371 return settings;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
372 }
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 @Override
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
375 public Properties getProperties(String regKey,String fileName) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
376 return getProperties(regKey,fileName,false,"",false);
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 @Override
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
380 public Properties getProperties(String regKey,String fileName,
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
381 boolean createFile, String header) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
382 return getProperties(regKey,fileName,false,"",false);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
383 }
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
22
e067ee54f638 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 21
diff changeset
386 public Properties getProperties(String regKey,
e067ee54f638 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 21
diff changeset
387 String fileName,
e067ee54f638 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 21
diff changeset
388 boolean createFile,
e067ee54f638 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 21
diff changeset
389 String header,
e067ee54f638 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 21
diff changeset
390 boolean reloadIfLoaded) {
20
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
391
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
392 if (!registry.containsKey(regKey) || reloadIfLoaded) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
393
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
394 FileInputStream in = null;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
395 Properties props = new Properties();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
396 headers.put(regKey, header);
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 try {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
399 in = new FileInputStream(settingsDirectory()
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
400 + fileName);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
401 props.load(in);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
402
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
403 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
404 catch (FileNotFoundException fnfe) {
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 if (createFile) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
407 log.info(" Information Message: " + fnfe.getMessage()
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
408 + ". The file " + fileName + " will"
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
409 + " be created for first time use.");
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 registry.put(regKey,props);
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 saveSettings(regKey,header);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
414
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
415 return props;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
416
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 else {
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 log.info(" Information Message: " + fnfe.getMessage()
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
421 + ".");
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 }
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 catch (IOException ioe) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
426 log.warn("IO Exception accessing File "+ fileName +
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
427 " for the following reason : "
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
428 + ioe.getMessage());
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
429 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
430 catch (SecurityException se) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
431 log.warn("Security Exception for file "+ fileName
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
432 + ". This file can not be accessed because : "
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
433 + se.getMessage());
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
434 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
435
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
436 registry.put(regKey,props);
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 return props;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
439 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
440 else {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
441 return (Properties)registry.get(regKey);
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
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 * 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
447 * default passed if the property does not exist.
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 * @param key
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
450 * @param def
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
451 * @return
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
452 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
453 @Override
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
454 public String getProperty(String key, String def) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
455 if (settings.containsKey(key))
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
456 return settings.getProperty(key);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
457 else
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
458 return def;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
459 }
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 * 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
463 *
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
464 * @param key
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
465 * @return
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 String getProperty(String key) {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
469 return settings.getProperty(key);
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
470 }
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 * 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
474 *
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
475 * @return
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
476 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
477 private String settingsFile() {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
478 return settingsDirectory() + "tn5250jstartup.cfg";
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 }
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
481
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
482 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
483 * Private helper to return the settings directory
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
484 *
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
485 * @return
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
486 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
487 private String settingsDirectory() {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
488 return settingsFolder() + File.separator;
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 }
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 /**
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
493 * Private helper to return the settings folder path
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
494 *
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
495 * @return
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 private String settingsFolder() {
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
498 return TerminalView.android_home_directory + File.separator + TN5250J_FOLDER;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
499
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
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 * Not sure yet so be careful using this.
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
504 *
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
505 * @return
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
506 */
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
507 public ClassLoader getClassLoader() {
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 ClassLoader loader = GlobalConfigure.class.getClassLoader();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
510 if (loader == null)
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
511 loader = ClassLoader.getSystemClassLoader();
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
512
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
513 return loader;
69a407d33146 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
514 }
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 }