Framework Professional Edition Package


com.prosyst.util.resprovider
Interface ResourceProvider


public interface ResourceProvider

ResourceProvider is used to access resources provided by bundles installed on the OSGi Framework. Such resource bundles should have the following manifest header to determine the resources configuration file: Resource-Config: xxx_config.xml

Example of resource configuration file:

    <resource-provider>
      <resource>
        <type>ICQ.oven</type>
        <file>/resources/oven</file>
      </resource>
    </resource-provider>
 
There are two kinds of resources:
  1. Words or sentences in different languages
  2. Images or files that are different for the different languages. Or some images (files) can be the same for different languages.
The content of the file tag has to contain the file pathname and the file name without the ".properties" file extension and without language and contry suffix. For example: You have following files In the configuration file you have to write
    <file>/resources/oven</file>
 
The bundle that uses the ResourceProvider has to describe in its manifest header the used resource types:
Resource-Type: ICQ.oven, xxx
If there is a duplicate resource id in the property files of different types then the first found will be used.

For example:
In the properties file from type ICQ.oven there is:

1=YES
In the properties file from type xxx there is:
1=NO
You want the resource with id 1. The result will be "YES" because ICQ.oven is before the xxx in the manifest header.

The resource ids of the property files can be Strings or numbers. Strings are deprecated. If there are numbers, the XML has to contain one or more range tags. For example:

   ....
   <resource>
     <type>...</type>
     <file>...</file>
     <range>1:99</range>
     <range>200:500</range>
   </resource>
   ...
 
If the desired resource is a String with dynamic parameters, this method may format the resource according to the given resource parameters (if not null) and java.text.MessageFormat will be used. The supported parameter format is:
    resource_id = <message_part_0> {0} <message_part_1> {1} ... <messane_part_n> {n} ...
 
Where {n} (n >= 0) defines the user parameters.

Let's have the following resource example:

"The file with location XXX will be deleted. Are you sure?"
For English we will have the following message template:
1 = The file with location {0} will be deleted. Are you sure?
For French we will have the following message template:
1 = Le fichier avec le nom "{0}" sera supprime.  Etes-vous sur?
And for German we will have the following message template:
1 = Die Akte mit relativer Satznummer {0} wird gelöscht. Sind Sie sicher?
When the user want to use this message he/she must invoke the following:
String formatted = resourceProvider.getString(1, new Object[] {"d:\\my_files\\my_file.del"});
If you know that one language will be used for the entire system the method setLocale can be used to set the new Locale for the entire system. After that you can use other methods to get the resources without to give the current Locale. Of course when the language in the entire system is changed, the method setLocale has to be called again.

Since:
$Date: 2006/09/18 08:29:46 $
Author:
Stoyan Zoubev, Lubomir Mitev

Method Summary
 java.lang.Object getResource(boolean isURL, java.lang.String resourceID, java.util.Locale locale, java.lang.Object[] params)
          Get resource from resource providers, represented as bundles, installed on the OSGi Framework.
 java.lang.Object getResource(java.lang.String resourceType, java.lang.String resourceID, java.util.Locale locale, java.lang.Object[] params)
          Get resource from resource providers, represented as bundles, installed on the OSGi Framework.
 java.lang.String getString(int resourceID)
          Get resource according to specific id.
 java.lang.String getString(int resourceID, java.util.Locale locale)
          Get resource according to specific id.
 java.lang.String getString(int resourceID, java.util.Locale locale, java.lang.Object[] params)
          Get resource according to specific id.
 java.lang.String getString(int resourceID, java.lang.Object[] params)
          Get resource according to specific id.
 java.lang.String getString(java.lang.String resourceID)
          Get resource according to specific id.
 java.lang.String getString(java.lang.String[] resourceTypes, int resourceID)
          Get resource according to specific id and resource types.
 java.lang.String getString(java.lang.String[] resourceTypes, int resourceID, java.util.Locale locale)
          Get resource according to specific id and resource types.
 java.lang.String getString(java.lang.String[] resourceTypes, int resourceID, java.util.Locale[] locale, java.lang.Object[] params)
          Get resource according to specific id and resource types.
 java.lang.String getString(java.lang.String[] resourceTypes, int resourceID, java.util.Locale locale, java.lang.Object[] params)
          Get resource according to specific id and resource types.
 java.lang.String getString(java.lang.String[] resourceTypes, int resourceID, java.lang.Object[] params)
          Get resource according to specific id and resource types.
 java.lang.String getString(java.lang.String[] resourceTypes, java.lang.String resourceID)
          Get resource according to specific id and resource types.
 java.lang.String getString(java.lang.String[] resourceTypes, java.lang.String resourceID, java.util.Locale locale)
          Get resource according to specific id and resource types.
 java.lang.String getString(java.lang.String[] resourceTypes, java.lang.String resourceID, java.util.Locale[] locale, java.lang.Object[] params)
          Get resource according to specific id and resource types.
 java.lang.String getString(java.lang.String[] resourceTypes, java.lang.String resourceID, java.util.Locale locale, java.lang.Object[] params)
          Get resource according to specific id and resource types.
 java.lang.String getString(java.lang.String[] resourceTypes, java.lang.String resourceID, java.lang.Object[] params)
          Get resource according to specific id and resource types.
 java.lang.String getString(java.lang.String resourceID, java.util.Locale locale)
          Get resource according to specific id.
 java.lang.String getString(java.lang.String resourceID, java.util.Locale locale, java.lang.Object[] params)
          Get resource according to specific id.
 java.lang.String getString(java.lang.String resourceID, java.lang.Object[] params)
          Get resource according to specific id.
 java.lang.String[] getTypes()
          You can get the types which are described in the manifest
 java.net.URL getURL(int resourceID)
          Get resource according to specific id from the bundle which contains this id.
 java.net.URL getURL(int resourceID, java.util.Locale locale)
          Get resource according to specific id from the bundle which contains this id.
 java.net.URL getURL(java.lang.String resourceID)
          Get resource according to specific id from the bundle which contains this id.
 java.net.URL getURL(java.lang.String[] resourceTypes, int resourceID)
          Get resource according to specific id and types from the bundle which contains this id.
 java.net.URL getURL(java.lang.String[] resourceTypes, int resourceID, java.util.Locale locale)
          Get resource according to specific id and types from the bundle which contains this id.
 java.net.URL getURL(java.lang.String[] resourceTypes, int resourceID, java.util.Locale[] locale)
          Get resource according to specific id and types from the bundle which contains this id.
 java.net.URL getURL(java.lang.String[] resourceTypes, java.lang.String resourceID)
          Get resource according to specific id and types from the bundle which contains this id.
 java.net.URL getURL(java.lang.String[] resourceTypes, java.lang.String resourceID, java.util.Locale locale)
          Get resource according to specific id and types from the bundle which contains this id.
 java.net.URL getURL(java.lang.String[] resourceTypes, java.lang.String resourceID, java.util.Locale[] locale)
          Get resource according to specific id and types from the bundle which contains this id.
 java.net.URL getURL(java.lang.String resourceID, java.util.Locale locale)
          Get resource according to specific id from the bundle which contains this id.
 void setLocale(java.util.Locale locale)
          You can set locale for the entire system and the Resource Provider will use it when you get a resource whitout locale.
 

Method Detail

getResource

java.lang.Object getResource(boolean isURL,
                             java.lang.String resourceID,
                             java.util.Locale locale,
                             java.lang.Object[] params)
Get resource from resource providers, represented as bundles, installed on the OSGi Framework. The resource will be localized according to the specific locale. If the properties file is not found the default locale will be used (as returned by Locale.getDefault()).

Parameters:
isURL - the type of the resource. If it's true then java.net.URL will be returned otherwise - java.lang.String
resourceID - the id of the resource
locale - the desired locale of the resource, if null then the locale for the entire system will be used.
params - the set of arguments, that will be used to format the dynamic parameters of the string resource. If no formatting is necessary or this is not a string resource, pass a null value.
Returns:
the resource object. It can be either instance of String or URL, it depends on the parameter isString.

getResource

java.lang.Object getResource(java.lang.String resourceType,
                             java.lang.String resourceID,
                             java.util.Locale locale,
                             java.lang.Object[] params)
Get resource from resource providers, represented as bundles, installed on the OSGi Framework. This method have to be used only if the bundle hasn't Resource-Type in the manifest header The resource will be localized according to the specific locale. If the properties file is not found the default locale will be used (as returned by Locale.getDefault()).

Parameters:
resourceType - the type of the resource. If it starts with url: then java.net.URL will be returned otherwise - java.lang.String
resourceID - the id of the resource
locale - the desired locale of the resource, if null then the locale for the entire system will be used.
params - the set of arguments, that will be used to format the dynamic parameters of the string resource. If no formatting is necessary or this is not a string resource, pass a null value.
Returns:
the resource object. It can be either instance of String or URL, it depends on the parameter isString.

getString

java.lang.String getString(java.lang.String resourceID)
Get resource according to specific id. The returned resource will no be formatted. If you set a locale for the entire system it will be used. Otherwise default locale will be used.

Parameters:
resourceID - the id of the resource
Returns:
the resource string or the resourceID if it is missing.

getString

java.lang.String getString(java.lang.String resourceID,
                           java.util.Locale locale)
Get resource according to specific id. The returned resource will no be formatted. The resource will be localized according to the specific locale. If the properties file is not found the default locale will be used (as returned by Locale.getDefault()).

Parameters:
resourceID - the id of the resource
locale - the desired locale of the resource, if null then the locale for the entire system will be used.
Returns:
the resource string or the resourceID if it is missing.

getString

java.lang.String getString(java.lang.String resourceID,
                           java.lang.Object[] params)
Get resource according to specific id. The returned resource can be formatted. If you set a locale for the entire system it will be used. Otherwise default locale will be used.

Parameters:
resourceID - the id of the resource
params - the set of arguments, that will be used to format the dynamic parameters of the string resource. If no formatting is necessary or this is not a string resource, pass a null value.
Returns:
the resource string or the resourceID if it is missing.

getString

java.lang.String getString(java.lang.String resourceID,
                           java.util.Locale locale,
                           java.lang.Object[] params)
Get resource according to specific id. The returned resource can be formatted. The resource will be localized according to the specific locale. If the properties file is not found the default locale will be used (as returned by Locale.getDefault()).

Parameters:
resourceID - the id of the resource
locale - the desired locale of the resource, if null then the locale for the entire system will be used.
params - the set of arguments, that will be used to format the dynamic parameters of the string resource. If no formatting is necessary or this is not a string resource, pass a null value.
Returns:
the resource string or the resourceID if it is missing.

getString

java.lang.String getString(java.lang.String[] resourceTypes,
                           java.lang.String resourceID)
Get resource according to specific id and resource types. The returned resource will no be formatted. If there is description of the resource types in the bundle manifest they will not be used. If you set a locale for the entire system it will be used. Otherwise default locale will be used. The resourceTypes can not be null.

Parameters:
resourceTypes - the resource types.
resourceID - the id of the resource
Returns:
the resource string or the resourceID if it is missing.
Throws:
java.lang.NullPointerException - if the resourceTypes is null.

getString

java.lang.String getString(java.lang.String[] resourceTypes,
                           java.lang.String resourceID,
                           java.util.Locale locale)
Get resource according to specific id and resource types. The returned resource will no be formatted. If there is description of the resource types in the bundle manifest they will not be used. The resource will be localized according to the specific locale. If the properties file is not found the default locale will be used (as returned by Locale.getDefault()). The resourceTypes can not be null.

Parameters:
resourceTypes - the resource types.
resourceID - the id of the resource
locale - the desired locale of the resource, if null then the locale for the entire system will be used.
Returns:
the resource string or the resourceID if it is missing.
Throws:
java.lang.NullPointerException - if the resourceTypes is null.

getString

java.lang.String getString(java.lang.String[] resourceTypes,
                           java.lang.String resourceID,
                           java.lang.Object[] params)
Get resource according to specific id and resource types. The returned resource can be formatted. If there is description of the resource types in the bundle manifest they will not be used. If you set a locale for the entire system it will be used. Otherwise default locale will be used. The resourceTypes can not be null.

Parameters:
resourceTypes - the resource types.
resourceID - the id of the resource
params - the set of arguments, that will be used to format the dynamic parameters of the string resource. If no formatting is necessary or this is not a string resource, pass a null value.
Returns:
the resource string or the resourceID if it is missing.
Throws:
java.lang.NullPointerException - if the resourceTypes is null.

getString

java.lang.String getString(java.lang.String[] resourceTypes,
                           java.lang.String resourceID,
                           java.util.Locale locale,
                           java.lang.Object[] params)
Get resource according to specific id and resource types. The returned resource can be formatted. If there is description of the resource types in the bundle manifest they will not be used. The resource will be localized according to the specific locale. If the properties file is not found the default locale will be used (as returned by Locale.getDefault()). The resourceTypes can not be null.

Parameters:
resourceTypes - the resource types.
resourceID - the id of the resource
locale - the desired locale of the resource, if null then the locale for the entire system will be used.
params - the set of arguments, that will be used to format the dynamic parameters of the string resource. If no formatting is necessary or this is not a string resource, pass a null value.
Returns:
the resource string or the resourceID if it is missing.
Throws:
java.lang.NullPointerException - if the resourceTypes is null.

getString

java.lang.String getString(java.lang.String[] resourceTypes,
                           java.lang.String resourceID,
                           java.util.Locale[] locale,
                           java.lang.Object[] params)
Get resource according to specific id and resource types. The returned resource can be formatted. If there is description of the resource types in the bundle manifest they will not be used. The resource will be localized according to the specific locales. If the properties files are not found the default locale will be used (as returned by Locale.getDefault()). The resourceTypes can not be null.

Parameters:
resourceTypes - the resource types.
resourceID - the id of the resource
locale - the desired locales of the resource, if null then the locale for the entire system will be used.
params - the set of arguments, that will be used to format the dynamic parameters of the string resource. If no formatting is necessary or this is not a string resource, pass a null value.
Returns:
the resource string or the resourceID if it is missing.
Throws:
java.lang.NullPointerException - if the resourceTypes is null.

getString

java.lang.String getString(int resourceID)
Get resource according to specific id. The returned resource will no be formatted. If you set a locale for the entire system it will be used. Otherwise default locale will be used.

Parameters:
resourceID - the id of the resource
Returns:
the resource string or a string representation of the argument resourceID in base 10.

getString

java.lang.String getString(int resourceID,
                           java.util.Locale locale)
Get resource according to specific id. The returned resource will no be formatted. The resource will be localized according to the specific locale. If the properties file is not found the default locale will be used (as returned by Locale.getDefault()).

Parameters:
resourceID - the id of the resource
locale - the desired locale of the resource, if null then the locale for the entire system will be used.
Returns:
the resource string or a string representation of the argument resourceID in base 10.

getString

java.lang.String getString(int resourceID,
                           java.lang.Object[] params)
Get resource according to specific id. The returned resource can be formatted. If you set a locale for the entire system it will be used. Otherwise default locale will be used.

Parameters:
resourceID - the id of the resource
params - the set of arguments, that will be used to format the dynamic parameters of the string resource. If no formatting is necessary or this is not a string resource, pass a null value.
Returns:
the resource string or a string representation of the argument resourceID in base 10.

getString

java.lang.String getString(int resourceID,
                           java.util.Locale locale,
                           java.lang.Object[] params)
Get resource according to specific id. The returned resource can be formatted. The resource will be localized according to the specific locale. If the properties file is not found the default locale will be used (as returned by Locale.getDefault()).

Parameters:
resourceID - the id of the resource
locale - the desired locale of the resource, if null then the locale for the entire system will be used.
params - the set of arguments, that will be used to format the dynamic parameters of the string resource. If no formatting is necessary or this is not a string resource, pass a null value.
Returns:
the resource string or a string representation of the argument resourceID in base 10.

getString

java.lang.String getString(java.lang.String[] resourceTypes,
                           int resourceID)
Get resource according to specific id and resource types. The returned resource will no be formatted. If there is description of the resource types in the bundle manifest they will not be used. If you set a locale for the entire system it will be used. Otherwise default locale will be used. The resourceTypes can not be null.

Parameters:
resourceTypes - the resource types.
resourceID - the id of the resource
Returns:
the resource string or a string representation of the argument resourceID in base 10.
Throws:
java.lang.NullPointerException - if the resourceTypes is null.

getString

java.lang.String getString(java.lang.String[] resourceTypes,
                           int resourceID,
                           java.util.Locale locale)
Get resource according to specific id and resource types. The returned resource will no be formatted. If there is description of the resource types in the bundle manifest they will not be used. The resource will be localized according to the specific locale. If the properties file is not found the default locale will be used (as returned by Locale.getDefault()). The resourceTypes can not be null.

Parameters:
resourceTypes - the resource types.
resourceID - the id of the resource
locale - the desired locale of the resource, if null then the locale for the entire system will be used.
Returns:
the resource string or a string representation of the argument resourceID in base 10.
Throws:
java.lang.NullPointerException - if the resourceTypes is null.

getString

java.lang.String getString(java.lang.String[] resourceTypes,
                           int resourceID,
                           java.lang.Object[] params)
Get resource according to specific id and resource types. The returned resource can be formatted. If there is description of the resource types in the bundle manifest they will not be used. If you set a locale for the entire system it will be used. Otherwise default locale will be used. The resourceTypes can not be null.

Parameters:
resourceTypes - the resource types.
resourceID - the id of the resource
params - the set of arguments, that will be used to format the dynamic parameters of the string resource. If no formatting is necessary or this is not a string resource, pass a null value.
Returns:
the resource string or a string representation of the argument resourceID in base 10.
Throws:
java.lang.NullPointerException - if the resourceTypes is null.

getString

java.lang.String getString(java.lang.String[] resourceTypes,
                           int resourceID,
                           java.util.Locale locale,
                           java.lang.Object[] params)
Get resource according to specific id and resource types. The returned resource can be formatted. If there is description of the resource types in the bundle manifest they will not be used. The resource will be localized according to the specific locale. If the properties file is not found the default locale will be used (as returned by Locale.getDefault()). The resourceTypes can not be null.

Parameters:
resourceTypes - the resource types.
resourceID - the id of the resource
locale - the desired locale of the resource, if null then the locale for the entire system will be used.
params - the set of arguments, that will be used to format the dynamic parameters of the string resource. If no formatting is necessary or this is not a string resource, pass a null value.
Returns:
the resource string or a string representation of the argument resourceID in base 10.
Throws:
java.lang.NullPointerException - if the resourceTypes is null.

getString

java.lang.String getString(java.lang.String[] resourceTypes,
                           int resourceID,
                           java.util.Locale[] locale,
                           java.lang.Object[] params)
Get resource according to specific id and resource types. The returned resource can be formatted. If there is description of the resource types in the bundle manifest they will not be used. The resource will be localized according to the specific locales. If the properties files are not found the default locale will be used (as returned by Locale.getDefault()). The resourceTypes can not be null.

Parameters:
resourceTypes - the resource types.
resourceID - the id of the resource
locale - the desired locales of the resource, if null then the locale for the entire system will be used.
params - the set of arguments, that will be used to format the dynamic parameters of the string resource. If no formatting is necessary or this is not a string resource, pass a null value.
Returns:
the resource string or a string representation of the argument resourceID in base 10.
Throws:
java.lang.NullPointerException - if the resourceTypes is null.

getURL

java.net.URL getURL(java.lang.String resourceID)
Get resource according to specific id from the bundle which contains this id. If you set a locale for the entire system it will be used. Otherwise default locale will be used.

Parameters:
resourceID - the id of the resource
Returns:
the resource java.net.URL or null.

getURL

java.net.URL getURL(java.lang.String resourceID,
                    java.util.Locale locale)
Get resource according to specific id from the bundle which contains this id. The resource will be localized according to the specific locale. If the properties file is not found the default locale will be used (as returned by Locale.getDefault()).

Parameters:
resourceID - the id of the resource
locale - the desired locale of the resource, if null then the locale for the entire system will be used.
Returns:
the resource java.net.URL or null.

getURL

java.net.URL getURL(java.lang.String[] resourceTypes,
                    java.lang.String resourceID)
Get resource according to specific id and types from the bundle which contains this id. If there is description of the resource types in the bundle manifest they will not be used. If you set a locale for the entire system it will be used. Otherwise default locale will be used. The resourceTypes can not be null.

Parameters:
resourceTypes - the resource types.
resourceID - the id of the resource
Returns:
the resource java.net.URL or null.
Throws:
java.lang.NullPointerException - if the resourceTypes is null.

getURL

java.net.URL getURL(java.lang.String[] resourceTypes,
                    java.lang.String resourceID,
                    java.util.Locale locale)
Get resource according to specific id and types from the bundle which contains this id. If there is description of the resource types in the bundle manifest they will not be used. The resource will be localized according to the specific locale. If the properties file is not found the default locale will be used (as returned by Locale.getDefault()). The resourceTypes can not be null.

Parameters:
resourceTypes - the resource types.
resourceID - the id of the resource
locale - the desired locale of the resource, if null then the locale for the entire system will be used.
Returns:
the resource java.net.URL or null.
Throws:
java.lang.NullPointerException - if the resourceTypes is null.

getURL

java.net.URL getURL(java.lang.String[] resourceTypes,
                    java.lang.String resourceID,
                    java.util.Locale[] locale)
Get resource according to specific id and types from the bundle which contains this id. If there is description of the resource types in the bundle manifest they will not be used. The resource will be localized according to the specific locales. If the properties files are not found the default locale will be used (as returned by Locale.getDefault()). The resourceTypes can not be null.

Parameters:
resourceTypes - the resource types.
resourceID - the id of the resource
locale - the desired locales of the resource, if null then the locale for the entire system will be used.
Returns:
the resource java.net.URL or null.
Throws:
java.lang.NullPointerException - if the resourceTypes is null.

getURL

java.net.URL getURL(int resourceID)
Get resource according to specific id from the bundle which contains this id. If you set a locale for the entire system it will be used. Otherwise default locale will be used.

Parameters:
resourceID - the id of the resource
Returns:
the resource java.net.URL or null.

getURL

java.net.URL getURL(int resourceID,
                    java.util.Locale locale)
Get resource according to specific id from the bundle which contains this id. The resource will be localized according to the specific locale. If the properties file is not found the default locale will be used (as returned by Locale.getDefault()).

Parameters:
resourceID - the id of the resource
locale - the desired locale of the resource, if null then the locale for the entire system will be used.
Returns:
the resource java.net.URL or null.

getURL

java.net.URL getURL(java.lang.String[] resourceTypes,
                    int resourceID)
Get resource according to specific id and types from the bundle which contains this id. If there is description of the resource types in the bundle manifest they will not be used. If you set a locale for the entire system it will be used. Otherwise default locale will be used. The resourceTypes can not be null.

Parameters:
resourceTypes - the resource types.
resourceID - the id of the resource
Returns:
the resource java.net.URL or null.
Throws:
java.lang.NullPointerException - if the resourceTypes is null.

getURL

java.net.URL getURL(java.lang.String[] resourceTypes,
                    int resourceID,
                    java.util.Locale locale)
Get resource according to specific id and types from the bundle which contains this id. If there is description of the resource types in the bundle manifest they will not be used. The resource will be localized according to the specific locale. If the properties file is not found the default locale will be used (as returned by Locale.getDefault()). The resourceTypes can not be null.

Parameters:
resourceTypes - the resource types.
resourceID - the id of the resource
locale - the desired locale of the resource, if null then the locale for the entire system will be used.
Returns:
the resource java.net.URL or null.
Throws:
java.lang.NullPointerException - if the resourceTypes is null.

getURL

java.net.URL getURL(java.lang.String[] resourceTypes,
                    int resourceID,
                    java.util.Locale[] locale)
Get resource according to specific id and types from the bundle which contains this id. If there is description of the resource types in the bundle manifest they will not be used. The resource will be localized according to the specific locales. If the properties files are not found the default locale will be used (as returned by Locale.getDefault()). The resourceTypes can not be null.

Parameters:
resourceTypes - the resource types.
resourceID - the id of the resource
locale - the desired locales of the resource, if null then the locale for the entire system will be used.
Returns:
the resource java.net.URL or null.
Throws:
java.lang.NullPointerException - if the resourceTypes is null.

getTypes

java.lang.String[] getTypes()
You can get the types which are described in the manifest

Returns:
the types

setLocale

void setLocale(java.util.Locale locale)
You can set locale for the entire system and the Resource Provider will use it when you get a resource whitout locale. You can set null to remove this locale for the entire system.

Parameters:
locale - the locale for the entire system

Framework Professional Edition Package


Copyright © 1999-2007 ProSyst Software GmbH. All Rights Reserved