1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
|
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.plugin.skinresourcepack;
import java.net.*;
import java.util.*;
import org.osgi.framework.*;
import net.java.sip.communicator.service.resources.*;
import net.java.sip.communicator.util.*;
/**
* The skin resource pack.
*
* @author Adam Netocny
*/
public class SkinResourcePack
implements BundleActivator,
SkinPack
{
/**
* The <tt>Logger</tt> used by the <tt>SkinResourcePack</tt> and its
* instances for logging output.
*/
private static final Logger logger
= Logger.getLogger(SkinResourcePack.class);
/**
* The default resource path.
*/
private static final String DEFAULT_RESOURCE_PATH = "info";
/**
* The resource path of skin images.
*/
private static final String DEFAULT_IMAGE_RESOURCE_PATH = "images.images";
/**
* The resource path of skin colors.
*/
private static final String DEFAULT_COLOR_RESOURCE_PATH = "colors.colors";
/**
* The resource path f skin styles.
*/
private static final String DEFAULT_STYLE_RESOURCE_PATH = "styles.styles";
/**
* The resource path f skin settings.
*/
private static final String DEFAULT_SETTINGS_RESOURCE_PATH
= "settings.settings";
/**
* The bundle context.
*/
private static BundleContext bundleContext;
/**
* Buffer for resource files found.
*/
private static Hashtable<String, Iterator<String>> ressourcesFiles
= new Hashtable<String, Iterator<String>>();
/**
* A map of all skin image resources.
*/
private Map<String, String> imageResources = null;
/**
* A map of all skin style resources.
*/
private Map<String, String> styleResources = null;
/**
* A map of all skin color resources.
*/
private Map<String, String> colorResources = null;
/**
* A map of all skin settings resources.
*/
private Map<String, String> sttingsResources = null;
/**
* Starts the bundle.
* @param bc BundleContext
* @throws Exception -
*/
public void start(BundleContext bc)
throws Exception
{
bundleContext = bc;
Hashtable<String, String> props = new Hashtable<String, String>();
props.put(ResourcePack.RESOURCE_NAME,
SkinPack.RESOURCE_NAME_DEFAULT_VALUE);
bundleContext.registerService(SkinPack.class.getName(),
this,
props);
}
/**
* Stops the bundle.
* @param bc BundleContext
* @throws Exception -
*/
public void stop(BundleContext bc) throws Exception {}
/**
* Returns a <tt>Map</tt>, containing all [key, value] pairs for image
* resource pack.
*
* @return a <tt>Map</tt>, containing all [key, value] pairs for image
* resource pack.
*/
public Map<String, String> getImageResources()
{
if(imageResources != null)
{
return imageResources;
}
Map<String, String> resources = new TreeMap<String, String>();
try
{
ResourceBundle resourceBundle
= ResourceBundle.getBundle(DEFAULT_IMAGE_RESOURCE_PATH);
this.initResources(resourceBundle, resources);
}
catch (MissingResourceException ex)
{
logger.info("Failed to obtain bundle from image resource path.", ex);
}
this.initImagePluginResources(resources);
imageResources = resources;
return resources;
}
/**
* Returns a <tt>Map</tt>, containing all [key, value] pairs for style
* resource pack.
*
* @return a <tt>Map</tt>, containing all [key, value] pairs for style
* resource pack.
*/
public Map<String, String> getStyleResources()
{
if(styleResources != null)
{
return styleResources;
}
Map<String, String> resources = new TreeMap<String, String>();
try
{
ResourceBundle resourceBundle
= ResourceBundle.getBundle(DEFAULT_STYLE_RESOURCE_PATH);
this.initResources(resourceBundle, resources);
}
catch (MissingResourceException ex)
{
logger.info("Failed to obtain bundle from style resource path.", ex);
}
this.initStylePluginResources(resources);
styleResources = resources;
return resources;
}
/**
* Returns a <tt>Map</tt>, containing all [key, value] pairs for color
* resource pack.
*
* @return a <tt>Map</tt>, containing all [key, value] pairs for color
* resource pack.
*/
public Map<String, String> getColorResources()
{
if(colorResources != null)
{
return colorResources;
}
Map<String, String> resources = new TreeMap<String, String>();
try
{
ResourceBundle resourceBundle
= ResourceBundle.getBundle(DEFAULT_COLOR_RESOURCE_PATH);
this.initResources(resourceBundle, resources);
}
catch (MissingResourceException ex)
{
logger.info("Failed to obtain bundle from color resource path.", ex);
}
this.initColorPluginResources(resources);
colorResources = resources;
return resources;
}
/**
* Returns a <tt>Map</tt>, containing all [key, value] pairs for color
* resource pack.
*
* @return a <tt>Map</tt>, containing all [key, value] pairs for color
* resource pack.
*/
public Map<String, String> getSettingsResources()
{
if(sttingsResources != null)
{
return sttingsResources;
}
Map<String, String> resources = new TreeMap<String, String>();
try
{
ResourceBundle resourceBundle
= ResourceBundle.getBundle(DEFAULT_SETTINGS_RESOURCE_PATH);
this.initResources(resourceBundle, resources);
}
catch (MissingResourceException ex)
{
logger.info("Failed to obtain bundle from color resource path.", ex);
}
this.initSettingsPluginResources(resources);
sttingsResources = resources;
return resources;
}
/**
* Returns a <tt>Map</tt>, containing all [key, value] pairs for this
* resource pack.
*
* @return a <tt>Map</tt>, containing all [key, value] pairs for this
* resource pack.
*/
public Map<String, String> getResources()
{
ResourceBundle resourceBundle
= ResourceBundle.getBundle(DEFAULT_RESOURCE_PATH);
Map<String, String> resources = new TreeMap<String, String>();
this.initResources(resourceBundle, resources);
resources.putAll(getImageResources());
resources.putAll(getStyleResources());
resources.putAll(getColorResources());
return resources;
}
/**
* Returns the name of this resource pack.
*
* @return the name of this resource pack.
*/
public String getName()
{
Map<String, String> resources = getResources();
String name = resources.get("display_name");
if(name != null)
{
return name + " Skin Resources";
}
else
{
return "Skin Resources";
}
}
/**
* Returns the description of this resource pack.
*
* @return the description of this resource pack.
*/
public String getDescription()
{
Map<String, String> resources = getResources();
String name = resources.get("display_name");
if(name != null)
{
return "Provide SIP Communicator " + name + " skin resource pack.";
}
else
{
return "Provide SIP Communicator skin resource pack.";
}
}
/**
* Fills the given resource map with all (key,value) pairs obtained from the
* given <tt>ResourceBundle</tt>. This method will look in the properties
* files for references to other properties files and will include in the
* final map data from all referenced files.
*
* @param resourceBundle The initial <tt>ResourceBundle</tt>, corresponding
* to the "main" properties file.
* @param resources A <tt>Map</tt> that would store the data.
*/
private void initResources( ResourceBundle resourceBundle,
Map<String, String> resources)
{
Enumeration<String> colorKeys = resourceBundle.getKeys();
while (colorKeys.hasMoreElements())
{
String key = colorKeys.nextElement();
String value = resourceBundle.getString(key);
resources.put(key, value);
}
}
/**
* Finds all plugin image resources, matching the "images-*.properties"
* pattern and adds them to this resource pack.
* @param resources the map of key, value image resource pairs
*/
private void initImagePluginResources(Map<String, String> resources)
{
Iterator<String> pluginProperties
= findResourcePaths("images", "images-*.properties");
while (pluginProperties.hasNext())
{
String resourceBundleName = pluginProperties.next();
ResourceBundle resourceBundle
= ResourceBundle.getBundle(
resourceBundleName.substring(
0, resourceBundleName.indexOf(".properties")));
initResources(resourceBundle, resources);
}
}
/**
* Finds all plugin style resources, matching the "styles-*.properties"
* pattern and adds them to this resource pack.
* @param resources the map of key, value stype resource pairs
*/
private void initStylePluginResources(Map<String, String> resources)
{
Iterator<String> pluginProperties
= findResourcePaths("styles", "styles-*.properties");
while (pluginProperties.hasNext())
{
String resourceBundleName = pluginProperties.next();
ResourceBundle resourceBundle
= ResourceBundle.getBundle(
resourceBundleName.substring(
0, resourceBundleName.indexOf(".properties")));
initResources(resourceBundle, resources);
}
}
/**
* Finds all plugin color resources, matching the "colors-*.properties"
* pattern and adds them to this resource pack.
* @param resources the map of key, value color resource pairs
*/
private void initColorPluginResources(Map<String, String> resources)
{
Iterator<String> pluginProperties
= findResourcePaths("colors", "colors-*.properties");
while (pluginProperties.hasNext())
{
String resourceBundleName = pluginProperties.next();
ResourceBundle resourceBundle
= ResourceBundle.getBundle(
resourceBundleName.substring(
0, resourceBundleName.indexOf(".properties")));
initResources(resourceBundle, resources);
}
}
/**
* Finds all plugin style resources, matching the "styles-*.properties"
* pattern and adds them to this resource pack.
*
* @param resources the map of key, value type resource pairs
*/
private void initSettingsPluginResources(Map<String, String> resources)
{
Iterator<String> pluginProperties
= findResourcePaths("settings", "settings-*.properties");
while (pluginProperties.hasNext())
{
String resourceBundleName = pluginProperties.next();
ResourceBundle resourceBundle
= ResourceBundle.getBundle(
resourceBundleName.substring(
0, resourceBundleName.indexOf(".properties")));
initResources(resourceBundle, resources);
}
}
/**
* Finds all properties files for the given path in this bundle.
*
* @param path the path pointing to the properties files.
* @param pattern the pattern for properties files
* (ex. "colors-*.properties")
* @return an <tt>Iterator</tt> over a list of all properties files found
* for the given path and pattern
*/
protected static Iterator<String> findResourcePaths(String path,
String pattern)
{
Iterator<String> bufferedResult
= ressourcesFiles.get(path + "/" + pattern);
if (bufferedResult != null) {
return bufferedResult;
}
ArrayList<String> propertiesList = new ArrayList<String>();
@SuppressWarnings ("unchecked")
Enumeration<URL> propertiesUrls = bundleContext.getBundle()
.findEntries(path,
pattern,
false);
if (propertiesUrls != null)
{
while (propertiesUrls.hasMoreElements())
{
URL propertyUrl = propertiesUrls.nextElement();
// Remove the first slash.
String propertyFilePath
= propertyUrl.getPath().substring(1);
// Replace all slashes with dots.
propertyFilePath = propertyFilePath.replaceAll("/", ".");
propertiesList.add(propertyFilePath);
}
}
Iterator<String> result = propertiesList.iterator();
ressourcesFiles.put(path + pattern, result);
return result;
}
}
|