Project

General

Profile

4286a_1.patch

Sergey Ivanovskiy, 09/13/2019 05:46 AM

Download (49 KB)

View differences:

src/com/goldencode/p2j/ui/ClientExports.java 2019-09-13 09:26:59 +0000
316 316
 * design policies are required to maximize the performance of the remote
317 317
 * UI as well as to keep the remote UI implementation as simple as possible.
318 318
 */
319
public interface ClientExports
319
public interface ClientExports extends ObjectStorage
320 320
{
321 321
   /**
322 322
    * Rings a bell on the terminal.
src/com/goldencode/p2j/ui/ClientStorageProxy.java 2019-09-13 09:26:59 +0000
1
/*
2
** Module   : ClientStorageProxy.java
3
** Abstract : Implements the proxy for the client object storage that can be used on the server.
4
**
5
** Copyright (c) 2019, Golden Code Development Corporation.
6
**
7
** -#- -I- --Date-- ---------------------------------Description---------------------------------
8
** 001 SBI 20190911 Created initial version.
9
*/
10

  
11
/*
12
** This program is free software: you can redistribute it and/or modify
13
** it under the terms of the GNU Affero General Public License as
14
** published by the Free Software Foundation, either version 3 of the
15
** License, or (at your option) any later version.
16
**
17
** This program is distributed in the hope that it will be useful,
18
** but WITHOUT ANY WARRANTY; without even the implied warranty of
19
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
** GNU Affero General Public License for more details.
21
**
22
** You may find a copy of the GNU Affero GPL version 3 at the following
23
** location: https://www.gnu.org/licenses/agpl-3.0.en.html
24
** 
25
** Additional terms under GNU Affero GPL version 3 section 7:
26
** 
27
**   Under Section 7 of the GNU Affero GPL version 3, the following additional
28
**   terms apply to the works covered under the License.  These additional terms
29
**   are non-permissive additional terms allowed under Section 7 of the GNU
30
**   Affero GPL version 3 and may not be removed by you.
31
** 
32
**   0. Attribution Requirement.
33
** 
34
**     You must preserve all legal notices or author attributions in the covered
35
**     work or Appropriate Legal Notices displayed by works containing the covered
36
**     work.  You may not remove from the covered work any author or developer
37
**     credit already included within the covered work.
38
** 
39
**   1. No License To Use Trademarks.
40
** 
41
**     This license does not grant any license or rights to use the trademarks
42
**     Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
43
**     of Golden Code Development Corporation. You are not authorized to use the
44
**     name Golden Code, FWD, or the names of any author or contributor, for
45
**     publicity purposes without written authorization.
46
** 
47
**   2. No Misrepresentation of Affiliation.
48
** 
49
**     You may not represent yourself as Golden Code Development Corporation or FWD.
50
** 
51
**     You may not represent yourself for publicity purposes as associated with
52
**     Golden Code Development Corporation, FWD, or any author or contributor to
53
**     the covered work, without written authorization.
54
** 
55
**   3. No Misrepresentation of Source or Origin.
56
** 
57
**     You may not represent the covered work as solely your work.  All modified
58
**     versions of the covered work must be marked in a reasonable way to make it
59
**     clear that the modified work is not originating from Golden Code Development
60
**     Corporation or FWD.  All modified versions must contain the notices of
61
**     attribution required in this license.
62
*/
63

  
64
package com.goldencode.p2j.ui;
65

  
66

  
67
/**
68
 * Represents the server side client storage proxy
69
 */
70
public class ClientStorageProxy implements ObjectStorage
71
{
72
   /** The client exported API */
73
   private final ClientExports client;
74
   
75
   /**
76
    * Creates a proxy object.
77
    * 
78
    * @param    client
79
    *           The delegate that represents the client exported API.
80
    */
81
   public ClientStorageProxy(ClientExports client)
82
   {
83
      this.client = client;
84
   }
85

  
86
   /**
87
    * Retrieves the number value of the given key from this storage.
88
    * 
89
    * @param    key
90
    *           The given key
91
    * 
92
    * @return   The number value of the given key 
93
    */
94
   @Override
95
   public Number getNumber(String key)
96
   {
97
      return client.getNumber(key);
98
   }
99

  
100
   /**
101
    * Saves the number value of this key in this storage.
102
    * 
103
    * @param    key
104
    *           The given key
105
    * @param    value
106
    *           The value of the given key
107
    */
108
   @Override
109
   public void setNumber(String key, Number value)
110
   {
111
      client.setNumber(key, value);
112
   }
113

  
114
   /**
115
    * Retrieves the boolean value of the given key from this storage.
116
    * 
117
    * @param    key
118
    *           The given key
119
    * 
120
    * @return   The boolean value of the given key
121
    */
122
   @Override
123
   public Boolean getBoolean(String key)
124
   {
125
      return client.getBoolean(key);
126
   }
127

  
128
   /**
129
    * Saves the boolean value of this key in this storage.
130
    * 
131
    * @param    key
132
    *           The given key
133
    * @param    value
134
    *           The value of the given key
135
    */
136
   @Override
137
   public void setBoolean(String key, Boolean value)
138
   {
139
      client.setBoolean(key, value);
140
   }
141

  
142
   /**
143
    * Retrieves the string value of the given key from this storage.
144
    * 
145
    * @param    key
146
    *           The given key
147
    * 
148
    * @return   The string value of the given key
149
    */
150
   @Override
151
   public String getString(String key)
152
   {
153
      return client.getString(key);
154
   }
155

  
156
   /**
157
    * Saves the string value of this key in this storage.
158
    * 
159
    * @param    key
160
    *           The given key
161
    * @param    value
162
    *           The value of the given key
163
    */
164
   @Override
165
   public void setString(String key, String value)
166
   {
167
      client.setString(key, value);
168
   }
169

  
170
   /**
171
    * Retrieves the object value of the given key from this storage.
172
    * 
173
    * @param    key
174
    *           The given key
175
    * @param    clazz
176
    *           The java class that represents this object
177
    * 
178
    * @return   The object value of the given key
179
    */
180
   @SuppressWarnings("rawtypes")
181
   @Override
182
   public Object getObject(String key, Class clazz)
183
   {
184
      return client.getObject(key, clazz);
185
   }
186

  
187
   /**
188
    * Sets the object value of the given key for this storage.
189
    * 
190
    * @param    key
191
    *           The given key
192
    * @param    value
193
    *           The object value
194
    */
195
   @Override
196
   public void setObject(String key, Object value)
197
   {
198
      client.setObject(key, value);
199
   }
200
}
src/com/goldencode/p2j/ui/KeyValueStorage.java 2019-09-13 09:26:59 +0000
1
/*
2
** Module   : KeyValueStorage.java
3
** Abstract : Defines methods to store and retrieve key and value pairs.
4
**
5
** Copyright (c) 2019, Golden Code Development Corporation.
6
**
7
** -#- -I- --Date-- ---------------------------------Description---------------------------------
8
** 001 SBI 20190911 Created initial version.
9
*/
10

  
11
/*
12
** This program is free software: you can redistribute it and/or modify
13
** it under the terms of the GNU Affero General Public License as
14
** published by the Free Software Foundation, either version 3 of the
15
** License, or (at your option) any later version.
16
**
17
** This program is distributed in the hope that it will be useful,
18
** but WITHOUT ANY WARRANTY; without even the implied warranty of
19
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
** GNU Affero General Public License for more details.
21
**
22
** You may find a copy of the GNU Affero GPL version 3 at the following
23
** location: https://www.gnu.org/licenses/agpl-3.0.en.html
24
** 
25
** Additional terms under GNU Affero GPL version 3 section 7:
26
** 
27
**   Under Section 7 of the GNU Affero GPL version 3, the following additional
28
**   terms apply to the works covered under the License.  These additional terms
29
**   are non-permissive additional terms allowed under Section 7 of the GNU
30
**   Affero GPL version 3 and may not be removed by you.
31
** 
32
**   0. Attribution Requirement.
33
** 
34
**     You must preserve all legal notices or author attributions in the covered
35
**     work or Appropriate Legal Notices displayed by works containing the covered
36
**     work.  You may not remove from the covered work any author or developer
37
**     credit already included within the covered work.
38
** 
39
**   1. No License To Use Trademarks.
40
** 
41
**     This license does not grant any license or rights to use the trademarks
42
**     Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
43
**     of Golden Code Development Corporation. You are not authorized to use the
44
**     name Golden Code, FWD, or the names of any author or contributor, for
45
**     publicity purposes without written authorization.
46
** 
47
**   2. No Misrepresentation of Affiliation.
48
** 
49
**     You may not represent yourself as Golden Code Development Corporation or FWD.
50
** 
51
**     You may not represent yourself for publicity purposes as associated with
52
**     Golden Code Development Corporation, FWD, or any author or contributor to
53
**     the covered work, without written authorization.
54
** 
55
**   3. No Misrepresentation of Source or Origin.
56
** 
57
**     You may not represent the covered work as solely your work.  All modified
58
**     versions of the covered work must be marked in a reasonable way to make it
59
**     clear that the modified work is not originating from Golden Code Development
60
**     Corporation or FWD.  All modified versions must contain the notices of
61
**     attribution required in this license.
62
*/
63

  
64
package com.goldencode.p2j.ui;
65

  
66

  
67
/**
68
 * This interface defines access methods for a key value storage.
69
 */
70
public interface KeyValueStorage
71
{
72
   /**
73
    * Retrieves the number value of the given key from this storage.
74
    * 
75
    * @param    key
76
    *           The given key
77
    * 
78
    * @return   The number value of the given key 
79
    */
80
   Number getNumber(String key);
81
   
82
   /**
83
    * Saves the number value of this key in this storage.
84
    * 
85
    * @param    key
86
    *           The given key
87
    * @param    value
88
    *           The value of the given key
89
    */
90
   void setNumber(String key, Number value);
91
   
92
   /**
93
    * Retrieves the boolean value of the given key from this storage.
94
    * 
95
    * @param    key
96
    *           The given key
97
    * 
98
    * @return   The boolean value of the given key
99
    */
100
   Boolean getBoolean(String key);
101
   
102
   /**
103
    * Saves the boolean value of this key in this storage.
104
    * 
105
    * @param    key
106
    *           The given key
107
    * @param    value
108
    *           The value of the given key
109
    */
110
   void setBoolean(String key, Boolean value);
111
   
112
   /**
113
    * Retrieves the string value of the given key from this storage.
114
    * 
115
    * @param    key
116
    *           The given key
117
    * 
118
    * @return   The string value of the given key
119
    */
120
   String getString(String key);
121
   
122
   /**
123
    * Saves the string value of this key in this storage.
124
    * 
125
    * @param    key
126
    *           The given key
127
    * @param    value
128
    *           The value of the given key
129
    */
130
   void setString(String key, String value);
131
}
src/com/goldencode/p2j/ui/KeyValueStorageAdapter.java 2019-09-13 09:26:59 +0000
1
/*
2
** Module   : KeyValueStorageAdapter.java
3
** Abstract : Implements the adapter for the KeyValueStorage backend and the client object storage.
4
**
5
** Copyright (c) 2019, Golden Code Development Corporation.
6
**
7
** -#- -I- --Date-- ---------------------------------Description---------------------------------
8
** 001 SBI 20190911 Created initial version.
9
*/
10

  
11
/*
12
** This program is free software: you can redistribute it and/or modify
13
** it under the terms of the GNU Affero General Public License as
14
** published by the Free Software Foundation, either version 3 of the
15
** License, or (at your option) any later version.
16
**
17
** This program is distributed in the hope that it will be useful,
18
** but WITHOUT ANY WARRANTY; without even the implied warranty of
19
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
** GNU Affero General Public License for more details.
21
**
22
** You may find a copy of the GNU Affero GPL version 3 at the following
23
** location: https://www.gnu.org/licenses/agpl-3.0.en.html
24
** 
25
** Additional terms under GNU Affero GPL version 3 section 7:
26
** 
27
**   Under Section 7 of the GNU Affero GPL version 3, the following additional
28
**   terms apply to the works covered under the License.  These additional terms
29
**   are non-permissive additional terms allowed under Section 7 of the GNU
30
**   Affero GPL version 3 and may not be removed by you.
31
** 
32
**   0. Attribution Requirement.
33
** 
34
**     You must preserve all legal notices or author attributions in the covered
35
**     work or Appropriate Legal Notices displayed by works containing the covered
36
**     work.  You may not remove from the covered work any author or developer
37
**     credit already included within the covered work.
38
** 
39
**   1. No License To Use Trademarks.
40
** 
41
**     This license does not grant any license or rights to use the trademarks
42
**     Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
43
**     of Golden Code Development Corporation. You are not authorized to use the
44
**     name Golden Code, FWD, or the names of any author or contributor, for
45
**     publicity purposes without written authorization.
46
** 
47
**   2. No Misrepresentation of Affiliation.
48
** 
49
**     You may not represent yourself as Golden Code Development Corporation or FWD.
50
** 
51
**     You may not represent yourself for publicity purposes as associated with
52
**     Golden Code Development Corporation, FWD, or any author or contributor to
53
**     the covered work, without written authorization.
54
** 
55
**   3. No Misrepresentation of Source or Origin.
56
** 
57
**     You may not represent the covered work as solely your work.  All modified
58
**     versions of the covered work must be marked in a reasonable way to make it
59
**     clear that the modified work is not originating from Golden Code Development
60
**     Corporation or FWD.  All modified versions must contain the notices of
61
**     attribution required in this license.
62
*/
63

  
64
package com.goldencode.p2j.ui;
65

  
66
import java.io.*;
67

  
68
import com.fasterxml.jackson.core.*;
69
import com.fasterxml.jackson.databind.*;
70

  
71

  
72
/**
73
 * Implements a string key value user's storage backed by java user preferences file storage.
74
 */
75
public class KeyValueStorageAdapter implements ObjectStorage
76
{
77
   /** Object to JSON converter*/
78
   private final ObjectMapper mapper;
79
   
80
   /** The backed key and value storage */
81
   private KeyValueStorage backend;
82
   
83
   /**
84
    * Creates this adapter.
85
    */
86
   public KeyValueStorageAdapter()
87
   {
88
      this.mapper = new ObjectMapper();
89
   }
90
   
91
   /**
92
    * Retrieves the number value of the given key from this storage.
93
    * 
94
    * @param    key
95
    *           The given key
96
    * 
97
    * @return   The number value of the given key 
98
    */
99
   @Override
100
   public Number getNumber(String key)
101
   {
102
      return this.backend.getNumber(key);
103
   }
104

  
105
   /**
106
    * Saves the number value of this key in this storage.
107
    * 
108
    * @param    key
109
    *           The given key
110
    * @param    value
111
    *           The value of the given key
112
    */
113
   @Override
114
   public void setNumber(String key, Number value)
115
   {
116
      this.backend.setNumber(key, value);
117
   }
118

  
119
   /**
120
    * Retrieves the boolean value of the given key from this storage.
121
    * 
122
    * @param    key
123
    *           The given key
124
    * 
125
    * @return   The boolean value of the given key
126
    */
127
   @Override
128
   public Boolean getBoolean(String key)
129
   {
130
      return this.backend.getBoolean(key);
131
   }
132

  
133
   /**
134
    * Saves the boolean value of this key in this storage.
135
    * 
136
    * @param    key
137
    *           The given key
138
    * @param    value
139
    *           The value of the given key
140
    */
141
   @Override
142
   public void setBoolean(String key, Boolean value)
143
   {
144
      this.backend.setBoolean(key, value);
145
   }
146

  
147
   /**
148
    * Retrieves the string value of the given key from this storage.
149
    * 
150
    * @param    key
151
    *           The given key
152
    * 
153
    * @return   The string value of the given key
154
    */
155
   @Override
156
   public String getString(String key)
157
   {
158
      return this.backend.getString(key);
159
   }
160

  
161
   @Override
162
   public void setString(String key, String value)
163
   {
164
      this.backend.setString(key, value);
165
   }
166

  
167
   /**
168
    * Sets the backend key and value storage.
169
    * 
170
    * @param    backend
171
    *           The backend key and value storage
172
    */
173
   public void setBackend(KeyValueStorage backend)
174
   {
175
      this.backend = backend;
176
   }
177
   
178
   /**
179
    * Retrieves the object value of the given key from this storage.
180
    * 
181
    * @param    key
182
    *           The given key
183
    * @param    clazz
184
    *           The java class that represents this object
185
    * 
186
    * @return   The object value of the given key
187
    */
188
   @SuppressWarnings("rawtypes")
189
   @Override
190
   public Object getObject(String key, Class clazz)
191
   {
192
      return parseJSON(key, clazz);
193
   }
194

  
195
   /**
196
    * Sets the object value of the given key for this storage.
197
    * 
198
    * @param    key
199
    *           The given key
200
    * @param    value
201
    *           The object value
202
    */
203
   public void setObject(String key, Object value)
204
   {
205
      try
206
      {
207
         String json = mapper.writeValueAsString(value);
208
         backend.setString(key, json);
209
      }
210
      catch (JsonProcessingException e)
211
      {
212
         e.printStackTrace();
213
      }
214

  
215
   }
216

  
217
   /**
218
    * The template method to get the object from its json presentation retrieved from the storage
219
    * by the given key.
220
    * 
221
    * @param    key
222
    *           The given key
223
    * @param    clazz
224
    *           The java class that represents this object
225
    * 
226
    * @return   The object value of the given key
227
    */
228
   private <T> T parseJSON(String key, Class<T> clazz)
229
   {
230
      String content = backend.getString(key);
231
      
232
      if (content != null)
233
      {
234
         try
235
         {
236
            return mapper.readValue(content, clazz);
237
         }
238
         catch (IOException e)
239
         {
240
            e.printStackTrace();
241
         }
242
      }
243
      
244
      return null;
245
   }
246
}
src/com/goldencode/p2j/ui/LogicalTerminal.java 2019-09-13 09:27:00 +0000
1216 1216
   /** Helper to use the TM without any context local lookups. */
1217 1217
   private TransactionManager.TransactionHelper tm;
1218 1218
   
1219
   /** The client local storage proxy */
1220
   private ObjectStorage clientLocalStorage;
1219 1221
   /**
1220 1222
    * Constructor.
1221 1223
    */
......
1251 1253
         client = (ClientExports) RemoteObject.obtainLocalInstance(ClientExports.class, true);
1252 1254
      }
1253 1255
      
1256
      clientLocalStorage = new ClientStorageProxy(client);
1257
      
1254 1258
      ErrorManager.setSystemAlertBoxes(!client.isChui());
1255 1259

  
1256 1260
      // create the main window BUT DO NOT PUSH IT since a duplicate instance
......
7807 7811
   }
7808 7812
   
7809 7813
   /**
7814
    * Gets the client local storage.
7815
    * 
7816
    * @return   The client local storage
7817
    */
7818
   public static ObjectStorage getClientStorage()
7819
   {
7820
      return locate().clientLocalStorage;
7821
   }
7822
   
7823
   /**
7810 7824
    * Read the legacy text metrics for all the texts and each font defined in the font table, for
7811 7825
    * this user.
7812 7826
    *
src/com/goldencode/p2j/ui/ObjectStorage.java 2019-09-13 09:27:00 +0000
1
/*
2
** Module   : ObjectStorage.java
3
** Abstract : Extends a key and value storage to be used as a client object storage.
4
**
5
** Copyright (c) 2019, Golden Code Development Corporation.
6
**
7
** -#- -I- --Date-- ---------------------------------Description---------------------------------
8
** 001 SBI 20190911 Created initial version.
9
*/
10

  
11
/*
12
** This program is free software: you can redistribute it and/or modify
13
** it under the terms of the GNU Affero General Public License as
14
** published by the Free Software Foundation, either version 3 of the
15
** License, or (at your option) any later version.
16
**
17
** This program is distributed in the hope that it will be useful,
18
** but WITHOUT ANY WARRANTY; without even the implied warranty of
19
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
** GNU Affero General Public License for more details.
21
**
22
** You may find a copy of the GNU Affero GPL version 3 at the following
23
** location: https://www.gnu.org/licenses/agpl-3.0.en.html
24
** 
25
** Additional terms under GNU Affero GPL version 3 section 7:
26
** 
27
**   Under Section 7 of the GNU Affero GPL version 3, the following additional
28
**   terms apply to the works covered under the License.  These additional terms
29
**   are non-permissive additional terms allowed under Section 7 of the GNU
30
**   Affero GPL version 3 and may not be removed by you.
31
** 
32
**   0. Attribution Requirement.
33
** 
34
**     You must preserve all legal notices or author attributions in the covered
35
**     work or Appropriate Legal Notices displayed by works containing the covered
36
**     work.  You may not remove from the covered work any author or developer
37
**     credit already included within the covered work.
38
** 
39
**   1. No License To Use Trademarks.
40
** 
41
**     This license does not grant any license or rights to use the trademarks
42
**     Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
43
**     of Golden Code Development Corporation. You are not authorized to use the
44
**     name Golden Code, FWD, or the names of any author or contributor, for
45
**     publicity purposes without written authorization.
46
** 
47
**   2. No Misrepresentation of Affiliation.
48
** 
49
**     You may not represent yourself as Golden Code Development Corporation or FWD.
50
** 
51
**     You may not represent yourself for publicity purposes as associated with
52
**     Golden Code Development Corporation, FWD, or any author or contributor to
53
**     the covered work, without written authorization.
54
** 
55
**   3. No Misrepresentation of Source or Origin.
56
** 
57
**     You may not represent the covered work as solely your work.  All modified
58
**     versions of the covered work must be marked in a reasonable way to make it
59
**     clear that the modified work is not originating from Golden Code Development
60
**     Corporation or FWD.  All modified versions must contain the notices of
61
**     attribution required in this license.
62
*/
63

  
64
package com.goldencode.p2j.ui;
65

  
66

  
67
/**
68
 * Added methods to persist object values of keys. Extends this key value storage interface to be
69
 * an object storage interface. 
70
 */
71
public interface ObjectStorage extends KeyValueStorage
72
{
73
   /**
74
    * Retrieves the object value of the given key from this storage.
75
    * 
76
    * @param    key
77
    *           The given key
78
    * @param    clazz
79
    *           The java class that represents this object
80
    * 
81
    * @return   The object value of the given key
82
    */
83
   @SuppressWarnings("rawtypes")
84
   Object getObject(String key, Class clazz);
85
   
86
   /**
87
    * Sets the object value of the given key for this storage.
88
    * 
89
    * @param    key
90
    *           The given key
91
    * @param    value
92
    *           The object value
93
    */
94
   void setObject(String key, Object value);
95
}
src/com/goldencode/p2j/ui/UserPreferences.java 2019-09-13 09:27:00 +0000
1
/*
2
** Module   : UserPreferences.java
3
** Abstract : Implements the key and value storage that can be used to persist users settings.
4
**
5
** Copyright (c) 2019, Golden Code Development Corporation.
6
**
7
** -#- -I- --Date-- ---------------------------------Description---------------------------------
8
** 001 SBI 20190911 Created initial version.
9
*/
10

  
11
/*
12
** This program is free software: you can redistribute it and/or modify
13
** it under the terms of the GNU Affero General Public License as
14
** published by the Free Software Foundation, either version 3 of the
15
** License, or (at your option) any later version.
16
**
17
** This program is distributed in the hope that it will be useful,
18
** but WITHOUT ANY WARRANTY; without even the implied warranty of
19
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
** GNU Affero General Public License for more details.
21
**
22
** You may find a copy of the GNU Affero GPL version 3 at the following
23
** location: https://www.gnu.org/licenses/agpl-3.0.en.html
24
** 
25
** Additional terms under GNU Affero GPL version 3 section 7:
26
** 
27
**   Under Section 7 of the GNU Affero GPL version 3, the following additional
28
**   terms apply to the works covered under the License.  These additional terms
29
**   are non-permissive additional terms allowed under Section 7 of the GNU
30
**   Affero GPL version 3 and may not be removed by you.
31
** 
32
**   0. Attribution Requirement.
33
** 
34
**     You must preserve all legal notices or author attributions in the covered
35
**     work or Appropriate Legal Notices displayed by works containing the covered
36
**     work.  You may not remove from the covered work any author or developer
37
**     credit already included within the covered work.
38
** 
39
**   1. No License To Use Trademarks.
40
** 
41
**     This license does not grant any license or rights to use the trademarks
42
**     Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
43
**     of Golden Code Development Corporation. You are not authorized to use the
44
**     name Golden Code, FWD, or the names of any author or contributor, for
45
**     publicity purposes without written authorization.
46
** 
47
**   2. No Misrepresentation of Affiliation.
48
** 
49
**     You may not represent yourself as Golden Code Development Corporation or FWD.
50
** 
51
**     You may not represent yourself for publicity purposes as associated with
52
**     Golden Code Development Corporation, FWD, or any author or contributor to
53
**     the covered work, without written authorization.
54
** 
55
**   3. No Misrepresentation of Source or Origin.
56
** 
57
**     You may not represent the covered work as solely your work.  All modified
58
**     versions of the covered work must be marked in a reasonable way to make it
59
**     clear that the modified work is not originating from Golden Code Development
60
**     Corporation or FWD.  All modified versions must contain the notices of
61
**     attribution required in this license.
62
*/
63

  
64
package com.goldencode.p2j.ui;
65

  
66
import java.util.prefs.*;
67

  
68
/**
69
 * Implements the user's key and value storage based on java user preferences API.
70
 */
71
public class UserPreferences implements KeyValueStorage
72
{
73
   /** The back end key and value storage */
74
   private final Preferences backend = Preferences.userRoot();
75
   
76
   /**
77
    * Retrieves the value of the given key from this storage.
78
    * 
79
    * @param    key
80
    *           The given key
81
    * 
82
    * @return   The number value of the given key 
83
    */
84
   @Override
85
   public Number getNumber(String key)
86
   {
87
      String stringValue = backend.get(key,null);
88
      
89
      if (stringValue == null || "null".equals(stringValue))
90
      {
91
         return null;
92
      }
93
      
94
      return Double.valueOf(stringValue);
95
   }
96

  
97
   /**
98
    * Saves the number value of this key in this storage.
99
    * 
100
    * @param    key
101
    *           The given key
102
    * @param    value
103
    *           The value of the given key
104
    */
105
   @Override
106
   public void setNumber(String key, Number value)
107
   {
108
      backend.put(key, String.valueOf(value));
109
   }
110

  
111
   /**
112
    * Retrieves the boolean value of the given key from this storage.
113
    * 
114
    * @param    key
115
    *           The given key
116
    * 
117
    * @return   The boolean value of the given key
118
    */
119
   @Override
120
   public Boolean getBoolean(String key)
121
   {
122
      String stringValue = backend.get(key,null);
123
      
124
      if (stringValue == null || "null".equals(stringValue))
125
      {
126
         return null;
127
      }
128
      
129
      return Boolean.valueOf(stringValue);
130
   }
131

  
132
   /**
133
    * Saves the boolean value of this key in this storage.
134
    * 
135
    * @param    key
136
    *           The given key
137
    * @param    value
138
    *           The value of the given key
139
    */
140
   @Override
141
   public void setBoolean(String key, Boolean value)
142
   {
143
      backend.put(key, String.valueOf(value));
144
   }
145

  
146
   /**
147
    * Retrieves the string value of the given key from this storage.
148
    * 
149
    * @param    key
150
    *           The given key
151
    * 
152
    * @return   The string value of the given key
153
    */
154
   @Override
155
   public String getString(String key)
156
   {
157
      String stringValue = backend.get(key,null);
158
      
159
      if (stringValue == null || "null".equals(stringValue))
160
      {
161
         return null;
162
      }
163
      
164
      return stringValue;
165
   }
166

  
167
   /**
168
    * Saves the string value of this key in this storage.
169
    * 
170
    * @param    key
171
    *           The given key
172
    * @param    value
173
    *           The value of the given key
174
    */
175
   @Override
176
   public void setString(String key, String value)
177
   {
178
      backend.put(key, String.valueOf(value));
179
   }
180
}
src/com/goldencode/p2j/ui/chui/ThinClient.java 2019-09-13 09:27:00 +0000
23540 23540
         this.op = op;
23541 23541
      }
23542 23542
   }
23543

  
23544
   /**
23545
    * Gets the client storage.
23546
    * 
23547
    * @return   The client storage
23548
    */
23549
   public ObjectStorage getClientStorage()
23550
   {
23551
      return getOutputManager().getDriver().getClientStorage();
23552
   }
23553

  
23554
   /**
23555
    * Retrieves the object value of the given key from the client storage.
23556
    * 
23557
    * @param    key
23558
    *           The given key
23559
    * @param    clazz
23560
    *           The java class that represents this object
23561
    * 
23562
    * @return   The object value of the given key
23563
    */
23564
   @Override
23565
   public Object getObject(String key, Class clazz)
23566
   {
23567
      return getClientStorage().getObject(key, clazz);
23568
   }
23569

  
23570
   /**
23571
    * Sets the object value of the given key for the client storage.
23572
    * 
23573
    * @param    key
23574
    *           The given key
23575
    * @param    value
23576
    *           The object value
23577
    */
23578
   @Override
23579
   public void setObject(String key, Object value)
23580
   {
23581
      getClientStorage().setObject(key, value);
23582
   }
23583

  
23584
   /**
23585
    * Retrieves the number value of the given key from the client storage.
23586
    * 
23587
    * @param    key
23588
    *           The given key
23589
    * 
23590
    * @return   The number value of the given key 
23591
    */
23592
   @Override
23593
   public Number getNumber(String key)
23594
   {
23595
      return getClientStorage().getNumber(key);
23596
   }
23597

  
23598
   /**
23599
    * Saves the number value of this key in the client storage.
23600
    * 
23601
    * @param    key
23602
    *           The given key
23603
    * @param    value
23604
    *           The value of the given key
23605
    */
23606
   @Override
23607
   public void setNumber(String key, Number value)
23608
   {
23609
      getClientStorage().setNumber(key, value);
23610
   }
23611

  
23612
   /**
23613
    * Retrieves the boolean value of the given key from the client storage.
23614
    * 
23615
    * @param    key
23616
    *           The given key
23617
    * 
23618
    * @return   The boolean value of the given key
23619
    */
23620
   @Override
23621
   public Boolean getBoolean(String key)
23622
   {
23623
      return getClientStorage().getBoolean(key);
23624
   }
23625

  
23626
   /**
23627
    * Saves the boolean value of this key in the client storage.
23628
    * 
23629
    * @param    key
23630
    *           The given key
23631
    * @param    value
23632
    *           The value of the given key
23633
    */
23634
   @Override
23635
   public void setBoolean(String key, Boolean value)
23636
   {
23637
      getClientStorage().setBoolean(key, value);
23638
   }
23639

  
23640
   /**
23641
    * Retrieves the string value of the given key from the client storage.
23642
    * 
23643
    * @param    key
23644
    *           The given key
23645
    * 
23646
    * @return   The string value of the given key
23647
    */
23648
   @Override
23649
   public String getString(String key)
23650
   {
23651
      return getClientStorage().getString(key);
23652
   }
23653

  
23654
   /**
23655
    * Saves the string value of this key in the client storage.
23656
    * 
23657
    * @param    key
23658
    *           The given key
23659
    * @param    value
23660
    *           The value of the given key
23661
    */
23662
   @Override
23663
   public void setString(String key, String value)
23664
   {
23665
      getClientStorage().setString(key, value);
23666
   }
23543 23667
}
src/com/goldencode/p2j/ui/client/driver/AbstractDriver.java 2019-09-13 09:27:00 +0000
62 62

  
63 63
package com.goldencode.p2j.ui.client.driver;
64 64

  
65

  
65 66
import com.goldencode.p2j.main.*;
67
import com.goldencode.p2j.ui.*;
66 68
import com.goldencode.p2j.ui.client.*;
67 69

  
68 70
/**
......
92 94
   /** Terminal type name. */
93 95
   private String term;
94 96
   
97
   /** The driver local storage that is persistent over sessions */
98
   private KeyValueStorageAdapter storage;
99
   
95 100
   /**
96 101
    * Construct a new instance.
97 102
    *
......
110 115
      this.direct  = direct;
111 116
      this.isChui  = isChui;
112 117
      this.term    = term;
118
      storage = new KeyValueStorageAdapter();
119
      // set the default key value storage
120
      storage.setBackend(new UserPreferences());
113 121
   }
114 122

  
115 123
   /**
......
222 230
   }
223 231

  
224 232
   /**
233
    * Returns the client key and value storage.
234
    * 
235
    * @return   The client key and value storage
236
    */
237
   @Override
238
   public KeyValueStorageAdapter getClientStorage()
239
   {
240
      return storage;
241
   }
242

  
243
   /**
225 244
    * Assigns the flag determining if the current driver is running in batch mode.
226 245
    * 
227 246
    * @param    batch
src/com/goldencode/p2j/ui/client/driver/ScreenDriver.java 2019-09-13 09:27:00 +0000
303 303
   public ChildProcessFactory getChildProcessFactory();
304 304
   
305 305
   /**
306
    * Returns the client key and value storage.
307
    * 
308
    * @return   The client key and value storage
309
    */
310
   public ObjectStorage getClientStorage();
311
   
312
   /**
306 313
    * Driver initialization.
307 314
    */
308 315
   public void init();
src/com/goldencode/p2j/ui/client/driver/web/WebClientMessageTypes.java 2019-09-13 09:27:00 +0000
411 411
   /** Sets the background image for the virtual desktop. */
412 412
   public static final byte MSG_SET_DESKTOP_IMAGE = (byte) 0xF5;
413 413

  
414
   /** Sets the value of the key for the client key and value storage. */
415
   public static final byte MSG_SET_KEY_VALUE = (byte) 0xF6;
416

  
417
   /** Gets the value of the key from the client key and value storage. */
418
   public static final byte MSG_GET_KEY_VALUE = (byte) 0xF7;
419

  
414 420
   /** Wraps the large message from the client to the sequence of this partial type messages. */
415 421
   public static final byte MSG_PARTIAL = (byte) 0xFE;
416 422
   
src/com/goldencode/p2j/ui/client/driver/web/res/p2j.socket.js 2019-09-13 09:27:00 +0000
437 437

  
438 438
                  /** Destroy a driver-maintained widget. */
439 439
                  MSG_DESTROY_WIDGET : 0xB4,
440
                
440
                  
441 441
                  /** Place a driver-maintained widget. */
442 442
                  MSG_PLACE_WIDGET : 0xB5,
443
               
443
                  
444 444
                  /** Change the visibility for a driver-maintained widget. */
445 445
                  MSG_SET_WIDGET_VISIBILITY : 0xB6,
446
               
446
                  
447 447
                  /** Change the sensitivity for a driver-maintained widget. */
448 448
                  MSG_SET_WIDGET_SENSITIVITY : 0xB7,
449 449
   
......
462 462
                  /** Sets the background image for the virtual desktop. */
463 463
                  MSG_SET_DESKTOP_IMAGE : 0xF5,
464 464
                  
465
                  /** Sets the value of the key for the client key and value storage. */
466
                  MSG_SET_KEY_VALUE : 0xF6,
467

  
468
                  /** Gets the value of the key from the client key and value storage. */
469
                  MSG_GET_KEY_VALUE : 0xF7,
470

  
465 471
                  /** Wraps the large message from the client to the sequence of this partial type messages. */
466 472
                  MSG_PARTIAL : 0xFE,
467 473
                  
......
2905 2911
            
2906 2912
            send(msg);
2907 2913
            break;
2914
         case types.MSG_GET_KEY_VALUE:
2915
            var offset = 1;
2916

  
2917
            var msgId = me.readInt32BinaryMessage(message, offset);
2918
            offset = offset + 4;
2919
            
2920
            var keyLength = me.readInt32BinaryMessage(message, offset);
2921
            offset = offset + 4;
2922

  
2923
            var key  = me.readStringBinaryMessageByLength(message, offset, keyLength);
2924
            offset = offset + keyLength * 2;
2925
            
2926
            var value = p2j.restoreObject(key, true);
2927
            var value = String(value);
2928
            var valueLength = value.length;
2929
            
2930
            // create the response message
2931
            var msg = new Uint8Array(1 + 4 + 4 + valueLength * 2);
2932
            
2933
            offset = 0;
2934
            msg[offset] = types.MSG_GET_KEY_VALUE;
2935
            offset += 1;
2936

  
2937
            writeInt32BinaryMessage(msg, offset, msgId);
2938
            offset += 4;
2939
            
2940
            writeInt32BinaryMessage(msg, offset, valueLength);
2941
            offset += 4;
2942
            
2943
            writeStringBinaryMessage(msg, offset, value);
2944
            
2945
            send(msg);
2946
            break;
2947
         case types.MSG_SET_KEY_VALUE:
2948
            var offset = 1;
2949

  
2950
            var msgId = me.readInt32BinaryMessage(message, offset);
2951
            offset = offset + 4;
2952
            
2953
            var keyLength = me.readInt32BinaryMessage(message, offset);
2954
            offset = offset + 4;
2955

  
2956
            var key  = me.readStringBinaryMessageByLength(message, offset, keyLength);
2957
            offset = offset + keyLength * 2;
2958
            
2959
            var valueLength = me.readInt32BinaryMessage(message, offset);
2960
            offset = offset + 4;
2961

  
2962
            var value  = me.readStringBinaryMessageByLength(message, offset, valueLength);
2963
            
2964
            p2j.saveObject(key, value, true);
2965
            break;
2908 2966
         case types.MSG_GET_TEXT_WIDTHS:
2909 2967
            // text widths
2910 2968

  
src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebDriver.java 2019-09-13 09:27:00 +0000
455 455
                                         new GenericWebSocketCreator<WebClientProtocol>(websock),
456 456
                                         cpres,
457 457
                                         hdlrs);
458
      getClientStorage().setBackend(new WebClientKeyValueStorage(websock));
458 459
   }
459 460

  
460 461
   /**
src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebSocket.java 2019-09-13 09:27:00 +0000
3156 3156
         
3157 3157
         handled = true;
3158 3158
      }
3159
      else if (message[offset] == MSG_GET_KEY_VALUE)
3160
      {
3161
         offset = offset + 1;
3162

  
3163
         int msgId = readMessageInt32(message, offset);
3164
         offset = offset + 4;
3165
         
3166
         int valueLen = readMessageInt32(message, offset);
3167
         offset = offset + 4;
3168
         
3169
         String value = readMessageText(message, offset, offset + 2 * valueLen);
3170
         
3171
         receiveResult(msgId, value);
3172
         
3173
         handled = true;
3174
      }
3159 3175
      
3160 3176
      return handled;
3161 3177
   }
......
3545 3561
   }
3546 3562

  
3547 3563
   /**
3564
    * Gets the string value of the given key from the browser local storage.
3565
    * 
3566
    * @param    key
3567
    *           The given key
3568
    * 
3569
    * @return   
3570
    */
3571
   public String getStringValue(String key)
3572
   {
3573
      int len = 1;   // type
3574
      len = len + 4; // msg ID
3575
      len = len + 4; // key.length()
3576
      int keyLen = key.length();
3577
      len = len + keyLen * 2; // key
3578
      
3579
      int offset = 0;
3580
      byte[] message = new byte[len];
3581
      int msgId = nextMessageId();
3582

  
3583
      message[offset++] = MSG_GET_KEY_VALUE;
3584

  
3585
      writeMessageInt32(message, offset, msgId);
3586
      offset += 4;
3587

  
3588
      writeMessageInt32(message, offset, keyLen);
3589
      offset += 4;
3590

  
3591
      writeMessageText(message, offset, key);
3592

  
3593
      sendBinaryMessage(message);
3594
      
3595
      Object res = waitForResult(msgId);
3596
      
3597
      if (res instanceof String)
3598
      {
3599
         return (String) res;
3600
      }
3601
      
3602
      return null;
3603
   }
3604

  
3605
   /**
3606
    * Sets the value of the given key into the browser local storage.
3607
    * 
3608
    * @param    key
3609
    *           The given key
3610
    * @param    value
3611
    *           The key value to be stored into the browser local storage.
3612
    */
3613
   public void setStringValue(String key, String value)
3614
   {
3615
      int len = 1;                // type
3616
      len = len + 4;              // msg ID
3617
      len = len + 4;              // key.length()
3618
      int keyLen = key.length();
3619
      len = len + keyLen * 2;     // key
3620
      len = len + 4;              // value.length()
3621
      int valueLen = value.length();
3622
      len = len + valueLen * 2;   // value
3623
      
3624
      int offset = 0;
3625
      byte[] message = new byte[len];
3626
      int msgId = nextMessageId();
3627

  
3628
      message[offset++] = MSG_SET_KEY_VALUE;
3629

  
3630
      writeMessageInt32(message, offset, msgId);
3631
      offset += 4;
3632

  
3633
      writeMessageInt32(message, offset, keyLen);
3634
      offset += 4;
3635

  
3636
      writeMessageText(message, offset, key);
3637
      offset += keyLen * 2;
3638
      
3639
      writeMessageInt32(message, offset, valueLen);
3640
      offset += 4;
3641

  
3642
      writeMessageText(message, offset, value);
3643

  
3644
      sendBinaryMessage(message);
3645
   }
3646

  
3647
   /**
3548 3648
    * Get the widths of the specified texts, using the given fonts.
3549 3649
    *
3550 3650
    * @param    fonts
src/com/goldencode/p2j/ui/client/gui/driver/web/WebClientKeyValueStorage.java 2019-09-13 09:27:00 +0000
1
/*
2
** Module   : WebClientKeyValueStorage.java
3
** Abstract : Implements the web client key and value storage.
4
**
5
** Copyright (c) 2019, Golden Code Development Corporation.
6
**
7
** -#- -I- --Date-- ---------------------------------Description---------------------------------
8
** 001 SBI 20190911 Created initial version.
9
*/
10

  
11
/*
12
** This program is free software: you can redistribute it and/or modify
13
** it under the terms of the GNU Affero General Public License as
14
** published by the Free Software Foundation, either version 3 of the
15
** License, or (at your option) any later version.
16
**
17
** This program is distributed in the hope that it will be useful,
18
** but WITHOUT ANY WARRANTY; without even the implied warranty of
19
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
** GNU Affero General Public License for more details.
21
**
22
** You may find a copy of the GNU Affero GPL version 3 at the following
23
** location: https://www.gnu.org/licenses/agpl-3.0.en.html
24
** 
25
** Additional terms under GNU Affero GPL version 3 section 7:
26
** 
27
**   Under Section 7 of the GNU Affero GPL version 3, the following additional
28
**   terms apply to the works covered under the License.  These additional terms
29
**   are non-permissive additional terms allowed under Section 7 of the GNU
30
**   Affero GPL version 3 and may not be removed by you.
31
** 
32
**   0. Attribution Requirement.
33
** 
34
**     You must preserve all legal notices or author attributions in the covered
35
**     work or Appropriate Legal Notices displayed by works containing the covered
36
**     work.  You may not remove from the covered work any author or developer
37
**     credit already included within the covered work.
38
** 
39
**   1. No License To Use Trademarks.
40
** 
41
**     This license does not grant any license or rights to use the trademarks
42
**     Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
43
**     of Golden Code Development Corporation. You are not authorized to use the
44
**     name Golden Code, FWD, or the names of any author or contributor, for
45
**     publicity purposes without written authorization.
46
** 
47
**   2. No Misrepresentation of Affiliation.
48
** 
49
**     You may not represent yourself as Golden Code Development Corporation or FWD.
50
** 
51
**     You may not represent yourself for publicity purposes as associated with
52
**     Golden Code Development Corporation, FWD, or any author or contributor to
53
**     the covered work, without written authorization.
54
** 
55
**   3. No Misrepresentation of Source or Origin.
56
** 
57
**     You may not represent the covered work as solely your work.  All modified
58
**     versions of the covered work must be marked in a reasonable way to make it
59
**     clear that the modified work is not originating from Golden Code Development
60
**     Corporation or FWD.  All modified versions must contain the notices of
61
**     attribution required in this license.
62
*/
63

  
64
package com.goldencode.p2j.ui.client.gui.driver.web;
65

  
66
import com.goldencode.p2j.ui.*;
67

  
68

  
69
/**
70
 * Represents the web client key and value storage.
71
 */
72
public class WebClientKeyValueStorage implements KeyValueStorage
73
{
74
   /** The web socket object that is responsible for the communication with the js client */
75
   private final GuiWebSocket webSocket;
76
   
77
   
78
   /**
79
    * Creates the web client storage.
80
    * 
81
    * @param    webSocket
82
    *           The web socket object
83
    */
84
   public WebClientKeyValueStorage(GuiWebSocket webSocket)
85
   {
86
      this.webSocket = webSocket;
87
   }
88

  
89
   /**
90
    * Retrieves the number value of the given key from this storage.
91
    * 
92
    * @param    key
93
    *           The given key
94
    * 
95
    * @return   The number value of the given key 
96
    */
97
   @Override
98
   public Number getNumber(String key)
99
   {
100
      String stringValue = webSocket.getStringValue(key);
101
      
102
      if (stringValue == null || "null".equals(stringValue))
103
      {
104
         return null;
105
      }
106
      
107
      return Double.valueOf(stringValue);
108
   }
109

  
110
   /**
111
    * Saves the number value of this key in this storage.
112
    * 
113
    * @param    key
114
    *           The given key
115
    * @param    value
116
    *           The value of the given key
117
    */
118
   @Override
119
   public void setNumber(String key, Number value)
120
   {
121
      webSocket.setStringValue(key, String.valueOf(value));
122
   }
123

  
124
   /**
125
    * Retrieves the boolean value of the given key from this storage.
... This diff was truncated because it exceeds the maximum size that can be displayed.