Enhanced resource management.

cusax-fix
Yana Stamcheva 17 years ago
parent ebb735b2d0
commit cc7bb6ce26

@ -14,10 +14,8 @@
import javax.imageio.*;
import javax.swing.*;
import net.java.sip.communicator.service.resources.*;
import net.java.sip.communicator.util.*;
import org.osgi.framework.*;
/**
@ -33,58 +31,72 @@ public class ResourceManagementServiceImpl
private static Logger logger =
Logger.getLogger(ResourceManagementServiceImpl.class);
private Hashtable colorPacks;
private Map<String, String> colorResources;
private ResourcePack colorPack = null;
private Hashtable imagePacks;
private Map<String, String> imageResources;
private ResourcePack imagePack = null;
private Hashtable languagePacks;
private LanguagePack languagePack = null;
private Hashtable settingsPacks;
private Map<String, String> settingsResources;
private ResourcePack settingsPack = null;
private Hashtable soundPacks;
private Map<String, String> soundResources;
private ResourcePack soundPack = null;
/**
* Initializes already registered default resource packs.
*/
ResourceManagementServiceImpl()
{
ResourceManagementActivator.bundleContext.addServiceListener(this);
colorPacks =
getDefaultPacks(ColorPack.class.getName(),
colorPack =
getDefaultResourcePack(ColorPack.class.getName(),
ColorPack.RESOURCE_NAME_DEFAULT_VALUE);
imagePacks =
getDefaultPacks(ImagePack.class.getName(),
ImagePack.RESOURCE_NAME_DEFAULT_VALUE);
if (colorPack != null)
colorResources = getResources(colorPack);
imagePack =
getDefaultResourcePack(ImagePack.class.getName(),
ImagePack.RESOURCE_NAME_DEFAULT_VALUE);
languagePacks =
getDefaultPacks(LanguagePack.class.getName(),
LanguagePack.RESOURCE_NAME_DEFAULT_VALUE);
if (imagePack != null)
imageResources = getResources(imagePack);
settingsPacks =
getDefaultPacks(SettingsPack.class.getName(),
SettingsPack.RESOURCE_NAME_DEFAULT_VALUE);
languagePack =
(LanguagePack) getDefaultResourcePack(LanguagePack.class.getName(),
LanguagePack.RESOURCE_NAME_DEFAULT_VALUE);
soundPacks =
getDefaultPacks( SoundPack.class.getName(),
SoundPack.RESOURCE_NAME_DEFAULT_VALUE);
settingsPack =
getDefaultResourcePack(SettingsPack.class.getName(),
SettingsPack.RESOURCE_NAME_DEFAULT_VALUE);
if (settingsPack != null)
settingsResources = getResources(settingsPack);
soundPack =
getDefaultResourcePack(SoundPack.class.getName(),
SoundPack.RESOURCE_NAME_DEFAULT_VALUE);
if (soundPack != null)
soundResources = getResources(soundPack);
}
/**
* Returns a map of default <tt>ResourcePack</tt>s, corresponding to the
* given className and typeName.
*
* @param className The name of the class of resource packs, for example
* ColorPacl class name.
* @param typeName The name of type of resource packs.
* @return a map of default <tt>ResourcePack</tt>s, corresponding to the
* given className and typeName.
* Searches for the <tt>ResourcePack</tt> corresponding to the given
* <tt>className</tt> and <tt></tt>.
* @param className The name of the resource class.
* @param typeName The name of the type we're looking for.
* For example: RESOURCE_NAME_DEFAULT_VALUE
* @return the <tt>ResourcePack</tt> corresponding to the given
* <tt>className</tt> and <tt></tt>.
*/
private Hashtable<ResourcePack, ResourceBundle> getDefaultPacks(
String className,
String typeName)
private ResourcePack getDefaultResourcePack(String className,
String typeName)
{
Hashtable<ResourcePack, ResourceBundle> resourcePackList
= new Hashtable<ResourcePack, ResourceBundle>();
ServiceReference[] serRefs = null;
String osgiFilter =
@ -110,104 +122,30 @@ private Hashtable<ResourcePack, ResourceBundle> getDefaultPacks(
(ResourcePack) ResourceManagementActivator.bundleContext.
getService(serRefs[i]);
ResourceBundle rb
= getResourceBundle(rp);
resourcePackList.put(rp, rb);
return rp;
}
}
return resourcePackList;
}
/**
* Returns the <tt>ResourceBundle</tt> corresponding to the given
* <tt>ResourcePack</tt>.
*
* @param resourcePack the <tt>ResourcePack</tt> for which we're searching
* the bundle.
* @return the <tt>ResourceBundle</tt> corresponding to the given
* <tt>ResourcePack</tt>.
*/
private ResourceBundle getResourceBundle(ResourcePack resourcePack)
{
String baseName = resourcePack.getResourcePackBaseName();
return ResourceBundle.getBundle(
baseName,
Locale.getDefault(),
resourcePack.getClass().getClassLoader());
}
/**
* Returns a list of language <tt>ResourceBundle</tt>s obtained for the
* given locale.
*
* @param locale the <tt>Locale</tt> which we're searching for
* @return the list of language <tt>ResourceBundle</tt>s obtained for the
* given locale.
*/
private Vector<ResourceBundle> getLanguagePacksForLocale(Locale locale)
{
Vector localePacks = new Vector();
Enumeration packsEnum = languagePacks.keys();
while (packsEnum.hasMoreElements())
{
LanguagePack langPack = (LanguagePack) packsEnum.nextElement();
ResourceBundle rBundle = ResourceBundle.getBundle(
langPack.getResourcePackBaseName(),
locale,
langPack.getClass().getClassLoader());
if (rBundle != null)
localePacks.add(rBundle);
}
return localePacks;
return null;
}
/**
* Returns the String corresponding to the given key.
* Returns the <tt>Map</tt> of (key, value) pairs contained in the given
* resource pack.
*
* @param key the key for the string we're searching for.
* @param resourceBundles the Enumeration of <tt>ResourceBundle</tt>s, where
* to search
* @return the String corresponding to the given key.
* @param resourcePack The <tt>ResourcePack</tt> from which we're obtaining
* the resources.
* @return the <tt>Map</tt> of (key, value) pairs contained in the given
* resource pack.
*/
private String findString( String key,
Enumeration<ResourceBundle> resourceBundles)
private Map<String, String> getResources(ResourcePack resourcePack)
{
ResourceBundle resourceBundle;
while (resourceBundles.hasMoreElements())
{
resourceBundle = resourceBundles.nextElement();
try
{
String value = resourceBundle.getString(key);
if (value != null)
{
return value;
}
}
catch (MissingResourceException e)
{
// If we don't find the resource in the this resource bundle
// we continue the search.
continue;
}
}
// nothing found
return null;
return resourcePack.getResources();
}
/**
* Handles <tt>ServiceEvent</tt>s in order to update the list of registered
* <tt>ResourcePack</tt>s.
* Handles all <tt>ServiceEvent</tt>s corresponding to <tt>ResourcePack</tt>
* being registered or unregistered.
*/
public void serviceChanged(ServiceEvent event)
{
@ -225,94 +163,97 @@ public void serviceChanged(ServiceEvent event)
{
logger.info("Resource registered " + resourcePack);
String resourceBaseName = resourcePack.getResourcePackBaseName();
Map<String, String> resources = getResources(resourcePack);
ResourceBundle resourceBundle = ResourceBundle.getBundle(
resourceBaseName,
Locale.getDefault(),
resourcePack.getClass().getClassLoader());
if(resourcePack instanceof ColorPack)
if(resourcePack instanceof ColorPack && colorPack == null)
{
if (colorPacks == null)
colorPacks = new Hashtable();
colorPacks.put(resourcePack, getResourceBundle(resourcePack));
colorPack = resourcePack;
colorResources = resources;
}
else if(resourcePack instanceof ImagePack)
else if(resourcePack instanceof ImagePack && imagePack == null)
{
if (imagePacks == null)
imagePacks = new Hashtable();
imagePacks.put(resourcePack, getResourceBundle(resourcePack));
imagePack = resourcePack;
imageResources = resources;
}
else if(resourcePack instanceof LanguagePack)
else if(resourcePack instanceof LanguagePack && languagePack == null)
{
if (languagePacks == null)
languagePacks = new Hashtable();
languagePacks.put(resourcePack, getResourceBundle(resourcePack));
languagePack = (LanguagePack) resourcePack;
}
else if(resourcePack instanceof SettingsPack)
else if(resourcePack instanceof SettingsPack && settingsPack == null)
{
if (settingsPacks == null)
settingsPacks = new Hashtable();
settingsPacks.put(resourcePack, getResourceBundle(resourcePack));
settingsPack = resourcePack;
settingsResources = resources;
}
else if(resourcePack instanceof SoundPack)
else if(resourcePack instanceof SoundPack && soundPack == null)
{
if (soundPacks == null)
soundPacks = new Hashtable();
soundPacks.put(resourcePack, getResourceBundle(resourcePack));
soundPack = resourcePack;
soundResources = resources;
}
}
else if (event.getType() == ServiceEvent.UNREGISTERING)
{
if(resourcePack instanceof ColorPack)
if(resourcePack instanceof ColorPack
&& colorPack.equals(resourcePack))
{
colorPacks =
getDefaultPacks(ColorPack.class.getName(),
ColorPack.RESOURCE_NAME_DEFAULT_VALUE);
colorPack =
getDefaultResourcePack(ColorPack.class.getName(),
ColorPack.RESOURCE_NAME_DEFAULT_VALUE);
if (colorPack != null)
colorResources = getResources(colorPack);
}
else if(resourcePack instanceof ImagePack)
else if(resourcePack instanceof ImagePack
&& imagePack.equals(resourcePack))
{
imagePacks =
getDefaultPacks(ImagePack.class.getName(),
ImagePack.RESOURCE_NAME_DEFAULT_VALUE);
imagePack =
getDefaultResourcePack(ImagePack.class.getName(),
ImagePack.RESOURCE_NAME_DEFAULT_VALUE);
if (imagePack != null)
imageResources = getResources(imagePack);
}
else if(resourcePack instanceof LanguagePack)
else if(resourcePack instanceof LanguagePack
&& languagePack.equals(resourcePack))
{
languagePacks =
getDefaultPacks(LanguagePack.class.getName(),
LanguagePack.RESOURCE_NAME_DEFAULT_VALUE);
languagePack =
(LanguagePack) getDefaultResourcePack(
LanguagePack.class.getName(),
LanguagePack.RESOURCE_NAME_DEFAULT_VALUE);
}
else if(resourcePack instanceof SettingsPack)
else if(resourcePack instanceof SettingsPack
&& settingsPack.equals(resourcePack))
{
settingsPacks =
getDefaultPacks(SettingsPack.class.getName(),
SettingsPack.RESOURCE_NAME_DEFAULT_VALUE);
settingsPack =
getDefaultResourcePack(SettingsPack.class.getName(),
SettingsPack.RESOURCE_NAME_DEFAULT_VALUE);
if (settingsPack != null)
settingsResources = getResources(settingsPack);
}
else if(resourcePack instanceof SoundPack)
else if(resourcePack instanceof SoundPack
&& soundPack.equals(resourcePack))
{
soundPacks =
getDefaultPacks(SoundPack.class.getName(),
SoundPack.RESOURCE_NAME_DEFAULT_VALUE);
soundPack =
getDefaultResourcePack(SoundPack.class.getName(),
SoundPack.RESOURCE_NAME_DEFAULT_VALUE);
if (soundPack != null)
soundResources = getResources(soundPack);
}
}
}
/**
* Returns the int representation of the color corresponding to the given
* key.
* Returns the int representation of the color corresponding to the
* given key.
*
* @return the int representation of the color corresponding to the given
* key.
* @param key The key of the color in the colors properties file.
* @return the int representation of the color corresponding to the
* given key.
*/
public int getColor(String key)
{
String res = findString(key, colorPacks.elements());
String res = colorResources.get(key);
if(res == null)
{
@ -325,15 +266,16 @@ public int getColor(String key)
}
/**
* Returns the String representation of the color corresponding to the given
* key.
* Returns the string representation of the color corresponding to the
* given key.
*
* @return the String representation of the color corresponding to the given
* key.
* @param key The key of the color in the colors properties file.
* @return the string representation of the color corresponding to the
* given key.
*/
public String getColorString(String key)
{
String res = findString(key, colorPacks.elements());
String res = colorResources.get(key);
if(res == null)
{
@ -346,34 +288,30 @@ public String getColorString(String key)
}
/**
* Loads a stream from a given identifier.
* Returns the <tt>InputStream</tt> of the image corresponding to the given
* path.
*
* @param path The path to the image from a location that's present in the
* classpath.
* @return The stream for the given identifier.
* @param path The path to the image file.
* @return the <tt>InputStream</tt> of the image corresponding to the given
* path.
*/
public InputStream getImageInputStreamForPath(String path)
{
// Get the first image pack class loader and try to obtain the image
// input stream from the given path.
if (imagePacks.keys().hasMoreElements())
{
return imagePacks.keys().nextElement().getClass()
.getClassLoader().getResourceAsStream(path);
}
return null;
return imagePack.getClass().getClassLoader().getResourceAsStream(path);
}
/**
* Loads a stream from a given identifier.
* Returns the <tt>InputStream</tt> of the image corresponding to the given
* key.
*
* @param streamKey The identifier of the stream.
* @return The stream for the given identifier.
* @param streamKey The identifier of the image in the resource properties
* file.
* @return the <tt>InputStream</tt> of the image corresponding to the given
* key.
*/
public InputStream getImageInputStream(String streamKey)
{
String path = findString(streamKey, imagePacks.elements());
String path = imageResources.get(streamKey);
if (path == null || path.length() == 0)
{
@ -383,16 +321,16 @@ public InputStream getImageInputStream(String streamKey)
return getImageInputStreamForPath(path);
}
/**
* Loads an url from a given identifier.
* Returns the <tt>URL</tt> of the image corresponding to the given key.
*
* @param urlKey The identifier of the url.
* @return The url for the given identifier.
* @param urlKey The identifier of the image in the resource properties file.
* @return the <tt>URL</tt> of the image corresponding to the given key
*/
public URL getImageURL(String urlKey)
{
String path = findString(urlKey, imagePacks.elements());
String path = imageResources.get(urlKey);
if (path == null || path.length() == 0)
{
@ -403,37 +341,32 @@ public URL getImageURL(String urlKey)
}
/**
* Returns the path corresponding to the given key.
* Returns the image path corresponding to the given key.
*
* @return the path corresponding to the given key.
* @param key The identifier of the image in the resource properties file.
* @return the image path corresponding to the given key.
*/
public String getImagePath(String key)
{
return findString(key, imagePacks.elements());
return imageResources.get(key);
}
/**
* Returns the URL corresponding to the given path.
* @return the URL corresponding to the given path.
* Returns the <tt>URL</tt> of the image corresponding to the given path.
*
* @param path The path to the given image file.
* @return the <tt>URL</tt> of the image corresponding to the given path.
*/
public URL getImageURLForPath(String path)
{
// Get the first image pack class loader and try to obtain the image
// input stream from the given path.
if (imagePacks.keys().hasMoreElements())
{
return imagePacks.keys().nextElement().getClass()
.getClassLoader().getResource(path);
}
return null;
return imagePack.getClass().getClassLoader().getResource(path);
}
// Language pack methods
/**
* Returns an internationalized string corresponding to the given key.
*
* @param key The key of the string.
* @param key The identifier of the string in the resources properties file.
* @return An internationalized string corresponding to the given key.
*/
public String getI18NString(String key)
@ -444,7 +377,7 @@ public String getI18NString(String key)
/**
* Returns an internationalized string corresponding to the given key.
*
* @param key The key of the string.
* @param key The identifier of the string in the resources properties file.
* @param locale The locale.
* @return An internationalized string corresponding to the given key and
* given locale.
@ -457,7 +390,7 @@ public String getI18NString(String key, Locale locale)
/**
* Returns an internationalized string corresponding to the given key.
*
* @param key The key of the string.
* @param key The identifier of the string.
* @return An internationalized string corresponding to the given key.
*/
public String getI18NString(String key, String[] params)
@ -468,16 +401,17 @@ public String getI18NString(String key, String[] params)
/**
* Returns an internationalized string corresponding to the given key.
*
* @param key The key of the string.
* @param key The identifier of the string in the resources properties
* file.
* @param locale The locale.
* @return An internationalized string corresponding to the given key.
*/
public String getI18NString(String key, String[] params, Locale locale)
{
Enumeration resourceBundles
= getLanguagePacksForLocale(locale).elements();
Map<String, String> stringResources
= languagePack.getResources(locale);
String resourceString = findString(key, resourceBundles);
String resourceString = stringResources.get(key);
if (resourceString == null)
{
@ -505,7 +439,7 @@ public String getI18NString(String key, String[] params, Locale locale)
/**
* Returns an internationalized string corresponding to the given key.
*
* @param key The key of the string.
* @param key The identifier of the string in the resources properties file.
* @return An internationalized string corresponding to the given key.
*/
public char getI18nMnemonic(String key)
@ -516,16 +450,16 @@ public char getI18nMnemonic(String key)
/**
* Returns an internationalized string corresponding to the given key.
*
* @param key The key of the string.
* @param key The identifier of the string in the resources properties file.
* @param locale The locale that we'd like to receive the result in.
* @return An internationalized string corresponding to the given key.
*/
public char getI18nMnemonic(String key, Locale locale)
{
Enumeration resourceBundles
= getLanguagePacksForLocale(locale).elements();
Map<String,String> stringResources
= languagePack.getResources(locale);
String resourceString = findString(key, resourceBundles);
String resourceString = stringResources.get(key);
if (resourceString == null)
{
@ -542,27 +476,27 @@ public char getI18nMnemonic(String key, Locale locale)
return 0;
}
/**
* Returns the configuration String corresponding to the given
* key.
* Returns the int value of the corresponding configuration key.
*
* @return the configuration String corresponding to the given
* key.
* @param key The identifier of the string in the resources properties file.
* @return the int value of the corresponding configuration key.
*/
public String getSettingsString(String key)
{
return findString(key, settingsPacks.elements());
return settingsResources.get(key);
}
/**
* Returns the int value corresponding to the given key.
* Returns the int value of the corresponding configuration key.
*
* @return the int value corresponding to the given key.
* @param key The identifier of the string in the resources properties file.
* @return the int value of the corresponding configuration key.
*/
public int getSettingsInt(String key)
{
String resourceString = findString(key, settingsPacks.elements());
String resourceString = settingsResources.get(key);
if (resourceString == null)
{
@ -572,52 +506,34 @@ public int getSettingsInt(String key)
return Integer.parseInt(resourceString);
}
/**
* Loads an url from a given identifier.
* Returns an <tt>URL</tt> from a given identifier.
*
* @param urlKey The identifier of the url.
* @return The url for the given identifier.
*/
public URL getSettingsURL(String urlKey)
{
String path = findString(urlKey, settingsPacks.elements());
String path = settingsResources.get(urlKey);
if (path == null || path.length() == 0)
{
logger.warn("Missing resource for key: " + urlKey);
return null;
}
return getSettingsURLForPath(path);
}
/**
* Returns the URL corresponding to the given path.
* @return the URL corresponding to the given path.
*/
private URL getSettingsURLForPath(String path)
{
// Get the first settings pack class loader and try to obtain the image
// input stream from the given path.
if (settingsPacks.keys().hasMoreElements())
{
return settingsPacks.keys().nextElement().getClass()
.getClassLoader().getResource(path);
}
return null;
return settingsPack.getClass().getClassLoader().getResource(path);
}
/**
* Loads a stream from a given identifier.
* Returns a stream from a given identifier.
*
* @param streamKey The identifier of the stream.
* @return The stream for the given identifier.
*/
public InputStream getSettingsInputStream(String streamKey)
{
String path = findString(streamKey, settingsPacks.elements());
String path = settingsResources.get(streamKey);
if (path == null || path.length() == 0)
{
@ -625,35 +541,20 @@ public InputStream getSettingsInputStream(String streamKey)
return null;
}
return getSettingsInputStreamForPath(path);
}
/**
* Returns the InputStream corresponding to the given path.
*
* @return the InputStream corresponding to the given path.
*/
private InputStream getSettingsInputStreamForPath(String path)
{
// Get the first settings pack class loader and try to obtain the image
// input stream from the given path.
if (settingsPacks.keys().hasMoreElements())
{
return settingsPacks.keys().nextElement().getClass()
.getClassLoader().getResourceAsStream(path);
}
return null;
return settingsPack.getClass()
.getClassLoader().getResourceAsStream(path);
}
/**
* Return the URL corresponding to the given key.
* Returns the <tt>URL</tt> of the sound corresponding to the given
* property key.
*
* @return the URL corresponding to the given key.
* @return the <tt>URL</tt> of the sound corresponding to the given
* property key.
*/
public URL getSoundURL(String urlKey)
{
String path = findString(urlKey, soundPacks.elements());
String path = settingsResources.get(urlKey);
if (path == null || path.length() == 0)
{
@ -663,108 +564,16 @@ public URL getSoundURL(String urlKey)
return getSoundURLForPath(path);
}
/**
* Returns the <tt>URL</tt> of the sound corresponding to the given path.
*
* @return the <tt>URL</tt> of the sound corresponding to the given path.
*/
public URL getSoundURLForPath(String path)
{
// Get the first settings pack class loader and try to obtain the image
// input stream from the given path.
if (soundPacks.keys().hasMoreElements())
{
return soundPacks.keys().nextElement().getClass()
.getClassLoader().getResource(path);
}
return null;
}
public Iterator getCurrentColors()
{
ResourceBundle colorResourceBundle
= (ResourceBundle) colorPacks.elements().nextElement();
Enumeration colorKeys = colorResourceBundle.getKeys();
List colorList = new ArrayList();
while (colorKeys.hasMoreElements())
{
colorList.add(colorKeys.nextElement());
}
return colorList.iterator();
}
public Iterator getCurrentImages()
{
ResourceBundle imageResourceBundle
= (ResourceBundle) imagePacks.elements().nextElement();
Enumeration imageKeys = imageResourceBundle.getKeys();
List imageList = new ArrayList();
while (imageKeys.hasMoreElements())
{
imageList.add(imageKeys.nextElement());
}
return imageList.iterator();
}
public Iterator getCurrentSettings()
{
ResourceBundle settingsResourceBundle
= (ResourceBundle) settingsPacks.elements().nextElement();
Enumeration settingKeys = settingsResourceBundle.getKeys();
List settingList = new ArrayList();
while (settingKeys.hasMoreElements())
{
settingList.add(settingKeys.nextElement());
}
return settingList.iterator();
}
public Iterator getCurrentSounds()
{
ResourceBundle soundResourceBundle
= (ResourceBundle) soundPacks.elements().nextElement();
Enumeration soundKeys = soundResourceBundle.getKeys();
List soundList = new ArrayList();
while (soundKeys.hasMoreElements())
{
soundList.add(soundKeys.nextElement());
}
return soundList.iterator();
return soundPack.getClass().getClassLoader().getResource(path);
}
public Iterator getAvailableLocales()
{
LanguagePack languagePack
= (LanguagePack) languagePacks.keys().nextElement();
return languagePack.getAvailableLocales();
}
public Iterator getI18nStringsByLocale(Locale l)
{
ResourceBundle langResourceBundle
= (ResourceBundle) languagePacks.elements().nextElement();
Enumeration languageKeys = langResourceBundle.getKeys();
List languageList = new ArrayList();
while (languageKeys.hasMoreElements())
{
languageList.add(languageKeys.nextElement());
}
return languageList.iterator();
}
/**
* Loads an image from a given image identifier.
*

@ -6,28 +6,93 @@
*/
package net.java.sip.communicator.plugin.defaultresourcepack;
import java.util.*;
import net.java.sip.communicator.service.resources.*;
/**
*
* The default color resource pack.
*
* @author Damian Minkov
* @author Yana Stamcheva
*/
public class DefaultColorPackImpl
implements ColorPack
{
private static final String DEFAULT_RESOURCE_PATH
= "resources.colors.colors";
public String getResourcePackBaseName()
/**
* 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()
{
return "resources.colors.colorResources";
ResourceBundle resourceBundle
= ResourceBundle.getBundle(DEFAULT_RESOURCE_PATH);
Map<String, String> resources = new Hashtable<String, String>();
this.initResources(resourceBundle, resources);
return resources;
}
/**
* Returns the name of this resource pack.
*
* @return the name of this resource pack.
*/
public String getName()
{
return "Default Color Resources";
}
/**
* Returns the description of this resource pack.
*
* @return the description of this resource pack.
*/
public String getDescription()
{
return "Provide SIP Communicator default Color resource pack.";
return "Provide SIP Communicator default color 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 colorKeys = resourceBundle.getKeys();
while (colorKeys.hasMoreElements())
{
String key = (String) colorKeys.nextElement();
String value = resourceBundle.getString(key);
if (key.startsWith("$reference"))
{
ResourceBundle referenceBundle
= ResourceBundle.getBundle(value);
initResources( referenceBundle,
resources);
}
else
{
resources.put(key, value);
}
}
}
}

@ -6,28 +6,92 @@
*/
package net.java.sip.communicator.plugin.defaultresourcepack;
import java.util.*;
import net.java.sip.communicator.service.resources.*;
/**
*
* The default image resource pack.
*
* @author Damian Minkov
* @author Yana Stamcheva
*/
public class DefaultImagePackImpl
implements ImagePack
{
private static final String DEFAULT_RESOURCE_PATH
= "resources.images.images";
public String getResourcePackBaseName()
/**
* 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()
{
return "resources.images.images";
ResourceBundle resourceBundle
= ResourceBundle.getBundle(DEFAULT_RESOURCE_PATH);
Map<String, String> resources = new Hashtable<String, String>();
this.initResources(resourceBundle, resources);
return resources;
}
/**
* Returns the name of this resource pack.
*
* @return the name of this resource pack.
*/
public String getName()
{
return "Default Image Resources";
}
/**
* Returns the description of this resource pack.
*
* @return the description of this resource pack.
*/
public String getDescription()
{
return "Provide SIP Communicator default Image 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 imageKeys = resourceBundle.getKeys();
while (imageKeys.hasMoreElements())
{
String key = (String) imageKeys.nextElement();
String value = resourceBundle.getString(key);
if (key.startsWith("$reference"))
{
ResourceBundle referenceBundle
= ResourceBundle.getBundle(value);
initResources(referenceBundle, resources);
}
else
{
resources.put(key, value);
}
}
}
}

@ -20,81 +20,102 @@
public class DefaultLanguagePackImpl
implements LanguagePack
{
private Logger logger = Logger.getLogger(DefaultLanguagePackImpl.class);
private static final String DEFAULT_RESOURCE_PATH
= "resources.languages.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);
private ArrayList localeList = new ArrayList();
Map<String, String> resources = new Hashtable<String, String>();
public DefaultLanguagePackImpl()
{
try
{
JarFile jf = new JarFile(getJarfileName());
this.initResources(resourceBundle, Locale.getDefault(), resources);
Enumeration resources = jf.entries();
while (resources.hasMoreElements())
{
JarEntry je = (JarEntry) resources.nextElement();
Locale locale;
String entryName = je.getName();
if (entryName.matches("resources/languages/.*\\.properties"))
{
int localeIndex = entryName.indexOf('_');
if (localeIndex == -1)
locale = new Locale("EN");
else
{
String localeName =
entryName.substring(localeIndex + 1,
entryName.indexOf('.'));
locale = new Locale(localeName);
}
localeList.add(locale);
}
}
}
catch (java.io.IOException e)
{
logger.error("Cannot load locales.", e);
}
return resources;
}
public String getResourcePackBaseName()
/**
* Returns a <tt>Map</tt>, containing all [key, value] pairs for the given
* locale.
*
* @param locale The <tt>Locale</tt> we're looking for.
* @return a <tt>Map</tt>, containing all [key, value] pairs for the given
* locale.
*/
public Map<String, String> getResources(Locale locale)
{
return "resources.languages.resources";
}
ResourceBundle resourceBundle
= ResourceBundle.getBundle(DEFAULT_RESOURCE_PATH);
public Iterator getAvailableLocales()
{
return localeList.iterator();
Map<String, String> resources = new Hashtable<String, String>();
this.initResources(resourceBundle, locale, resources);
return resources;
}
/**
* Returns the name of this resource pack.
*
* @return the name of this resource pack.
*/
public String getName()
{
return "Default Language Resources";
}
/**
* Returns the description of this resource pack.
*
* @return the description of this resource pack.
*/
public String getDescription()
{
return "Provide SIP Communicator default Language resource pack.";
}
private String getJarfileName()
/**
* 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 locale The locale we're looking for.
* @param resources A <tt>Map</tt> that would store the data.
*/
private void initResources( ResourceBundle resourceBundle,
Locale locale,
Map<String, String> resources)
{
// Get the location of the jar file and the jar file name
java.net.URL outputURL =
DefaultLanguagePackImpl.class.getProtectionDomain().getCodeSource()
.getLocation();
Enumeration colorKeys = resourceBundle.getKeys();
String outputString = outputURL.toString();
while (colorKeys.hasMoreElements())
{
String key = (String) colorKeys.nextElement();
String value = resourceBundle.getString(key);
String[] parseString;
parseString = outputString.split("file:");
if (key.startsWith("$reference"))
{
ResourceBundle referenceBundle
= ResourceBundle.getBundle( value,
locale);
String jarFilename = parseString[1];
return jarFilename;
initResources(referenceBundle, locale, resources);
}
else
{
resources.put(key, value);
}
}
}
}

@ -6,28 +6,92 @@
*/
package net.java.sip.communicator.plugin.defaultresourcepack;
import java.util.*;
import net.java.sip.communicator.service.resources.*;
/**
*
* The default settings resource pack.
*
* @author Damian Minkov
* @author Yana Stamcheva
*/
public class DefaultSettingsPackImpl
implements SettingsPack
{
private static final String DEFAULT_RESOURCE_PATH
= "resources.config.defaults";
public String getResourcePackBaseName()
/**
* 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()
{
return "resources.config.defaults";
ResourceBundle resourceBundle
= ResourceBundle.getBundle(DEFAULT_RESOURCE_PATH);
Map<String, String> resources = new Hashtable<String, String>();
this.initResources(resourceBundle, resources);
return resources;
}
/**
* Returns the name of this resource pack.
*
* @return the name of this resource pack.
*/
public String getName()
{
return "Default Settings Resources";
}
/**
* Returns the description of this resource pack.
*
* @return the description of this resource pack.
*/
public String getDescription()
{
return "Provide SIP Communicator default Settings resource pack.";
return "Provide SIP Communicator default settings 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 settingKeys = resourceBundle.getKeys();
while (settingKeys.hasMoreElements())
{
String key = (String) settingKeys.nextElement();
String value = resourceBundle.getString(key);
if (key.startsWith("$reference"))
{
ResourceBundle referenceBundle
= ResourceBundle.getBundle(value);
initResources(referenceBundle, resources);
}
else
{
resources.put(key, value);
}
}
}
}

@ -6,28 +6,93 @@
*/
package net.java.sip.communicator.plugin.defaultresourcepack;
import java.util.*;
import net.java.sip.communicator.service.resources.*;
/**
*
* The default sound resource pack.
*
* @author Damian Minkov
* @author Yana Stamcheva
*/
public class DefaultSoundPackImpl
implements SoundPack
{
public String getResourcePackBaseName()
private static final String DEFAULT_RESOURCE_PATH
= "resources.sounds.sounds";
/**
* 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()
{
return "resources.sounds.sounds";
ResourceBundle resourceBundle
= ResourceBundle.getBundle(DEFAULT_RESOURCE_PATH);
Map<String, String> resources = new Hashtable<String, String>();
this.initResources(resourceBundle, resources);
return resources;
}
/**
* Returns the name of this resource pack.
*
* @return the name of this resource pack.
*/
public String getName()
{
return "Default Sounds Resources";
}
/**
* Returns the description of this resource pack.
*
* @return the description of this resource pack.
*/
public String getDescription()
{
return "Provide SIP Communicator default Sounds resource pack.";
return "Provide SIP Communicator default sounds 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 soundKeys = resourceBundle.getKeys();
while (soundKeys.hasMoreElements())
{
String key = (String) soundKeys.nextElement();
String value = resourceBundle.getString(key);
if (key.startsWith("$reference"))
{
ResourceBundle referenceBundle
= ResourceBundle.getBundle(value);
initResources(referenceBundle, resources);
}
else
{
resources.put(key, value);
}
}
}
}

@ -16,6 +16,15 @@ public interface LanguagePack
extends ResourcePack
{
public String RESOURCE_NAME_DEFAULT_VALUE = "DefaultLanguagePack";
public Iterator getAvailableLocales();
/**
* Returns a <tt>Map</tt>, containing all [key, value] pairs for the given
* locale.
*
* @param locale The <tt>Locale</tt> we're looking for.
* @return a <tt>Map</tt>, containing all [key, value] pairs for the given
* locale.
*/
public Map<String, String> getResources(Locale locale);
}

@ -22,58 +22,67 @@ public interface ResourceManagementService
{
// Color pack methods
/**
* Loads an Color value for the given key
* Returns the int representation of the color corresponding to the
* given key.
*
* @param key The identifier of the color.
* @return The color value as int.
* @param key The key of the color in the colors properties file.
* @return the int representation of the color corresponding to the
* given key.
*/
public int getColor(String key);
/**
* Loads an Color value for the given key
* Returns the string representation of the color corresponding to the
* given key.
*
* @param key The identifier of the color.
* @return The color value as String.
* @param key The key of the color in the colors properties file.
* @return the string representation of the color corresponding to the
* given key.
*/
public String getColorString(String key);
/**
* Loads a stream from a given path.
* Returns the <tt>InputStream</tt> of the image corresponding to the given
* path.
*
* @param path The path of the stream.
* @return The stream for the given identifier.
* @param path The path to the image file.
* @return the <tt>InputStream</tt> of the image corresponding to the given
* path.
*/
public InputStream getImageInputStreamForPath(String path);
/**
* Loads a stream from a given identifier.
* Returns the <tt>InputStream</tt> of the image corresponding to the given
* key.
*
* @param streamKey The identifier of the stream.
* @return The stream for the given identifier.
* @param streamKey The identifier of the image in the resource properties
* file.
* @return the <tt>InputStream</tt> of the image corresponding to the given
* key.
*/
public InputStream getImageInputStream(String streamKey);
/**
* Loads an url from a given identifier.
* Returns the <tt>URL</tt> of the image corresponding to the given key.
*
* @param urlKey The identifier of the url.
* @return The url for the given identifier.
* @param urlKey The identifier of the image in the resource properties file.
* @return the <tt>URL</tt> of the image corresponding to the given key
*/
public URL getImageURL(String urlKey);
/**
* Loads an url from a given path.
* Returns the <tt>URL</tt> of the image corresponding to the given path.
*
* @param path The path for the url.
* @return The url for the given identifier.
* @param path The path to the given image file.
* @return the <tt>URL</tt> of the image corresponding to the given path.
*/
public URL getImageURLForPath(String path);
/**
* Returns the value of the given key for image resources.
* Returns the image path corresponding to the given key.
*
* @param key The key.
* @return String value for the given image key.
* @param key The identifier of the image in the resource properties file.
* @return the image path corresponding to the given key.
*/
public String getImagePath(String key);
@ -81,7 +90,7 @@ public interface ResourceManagementService
/**
* Returns an internationalized string corresponding to the given key.
*
* @param key The key of the string.
* @param key The identifier of the string in the resources properties file.
* @return An internationalized string corresponding to the given key.
*/
public String getI18NString(String key);
@ -89,36 +98,39 @@ public interface ResourceManagementService
/**
* Returns an internationalized string corresponding to the given key.
*
* @param key The key of the string.
* @param l The locale.
* @param key The identifier of the string in the resources properties file.
* @param locale The locale.
* @return An internationalized string corresponding to the given key and
* given locale.
*/
public String getI18NString(String key, Locale l);
public String getI18NString(String key, Locale locale);
/**
* Returns an internationalized string corresponding to the given key.
*
* @param key The key of the string.
* @param params params to be replaced in the returned string
* @return An internationalized string corresponding to the given key.
* @param key The identifier of the string in the resources properties file.
* @param locale The locale.
* @return An internationalized string corresponding to the given key and
* given locale.
*/
public String getI18NString(String key, String[] params);
/**
* Returns an internationalized string corresponding to the given key.
*
* @param key The key of the string
* @param params params to be replaced in the returned string.
* @param l The locale.
* @param key The identifier of the string in the resources properties file.
* @param params An array of parameters to be replaced in the returned
* string.
* @param locale The locale.
* @return An internationalized string corresponding to the given key.
*/
public String getI18NString(String key, String[] params, Locale l);
public String getI18NString(String key, String[] params, Locale locale);
/**
* Returns an internationalized string corresponding to the given key.
*
* @param key The key of the string.
* @param key The identifier of the string in the resources properties file.
* @param locale The locale that we'd like to receive the result in.
* @return An internationalized string corresponding to the given key.
*/
public char getI18nMnemonic(String key);
@ -151,18 +163,18 @@ public interface ResourceManagementService
public InputStream getSettingsInputStream(String streamKey);
/**
* Returns a String for the setting corresponding to the given key.
* Returns the int value of the corresponding configuration key.
*
* @param key The key of the setting.
* @return String to the corresponding resource.
* @param key The identifier of the string in the resources properties file.
* @return the int value of the corresponding configuration key.
*/
public String getSettingsString(String key);
/**
* Returns an int for the setting corresponding to the given key.
* Returns the int value of the corresponding configuration key.
*
* @param key The key of the setting.
* @return int to the corresponding resource.
* @param key The identifier of the string in the resources properties file.
* @return the int value of the corresponding configuration key.
*/
public int getSettingsInt(String key);
@ -182,50 +194,7 @@ public interface ResourceManagementService
* @return Url to the corresponding resource.
*/
public URL getSoundURLForPath(String path);
/**
* Returns all color keys that can be obtained from this service.
*
* @return Iterator to all color keys.
*/
public Iterator getCurrentColors();
/**
* Returns all image keys that can be obtained from this service.
*
* @return Iterator to all image keys.
*/
public Iterator getCurrentImages();
/**
* Returns all color settings that can be obtained from this service.
*
* @return Iterator to all settings keys.
*/
public Iterator getCurrentSettings();
/**
* Returns all color sounds that can be obtained from this service.
*
* @return Iterator to all sounds keys.
*/
public Iterator getCurrentSounds();
/**
* Returns all available locales for the translated texts.
*
* @return Iterator to all locales.
*/
public Iterator getAvailableLocales();
/**
* Returns all string keys that can be obtained from
* this service for the given locale.
*
* @return Iterator to all string keys.
*/
public Iterator getI18nStringsByLocale(Locale l);
/**
* Constructs an <tt>ImageIcon</tt> from the specified image ID and returns
* it.
@ -235,7 +204,7 @@ public interface ResourceManagementService
* identifier.
*/
public ImageIcon getImage(String imageID);
/**
* Loads the image with the specified ID and returns a byte array
* containing it.

@ -6,15 +6,37 @@
*/
package net.java.sip.communicator.service.resources;
import java.util.*;
/**
*
* The <tt>ResourcePack</tt> service.
*
* @author Damian Minkov
*/
public interface ResourcePack
{
public String RESOURCE_NAME = "ResourceName";
public String getResourcePackBaseName();
/**
* 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();
/**
* Returns the name of this resource pack.
*
* @return the name of this resource pack.
*/
public String getName();
/**
* Returns the description of this resource pack.
*
* @return the description of this resource pack.
*/
public String getDescription();
}

Loading…
Cancel
Save