com.izforge.izpack.installer
Class ResourceManager

java.lang.Object
  extended by com.izforge.izpack.installer.ResourceManager

public class ResourceManager
extends java.lang.Object

With this ResourceManager you are able to get resources from the jar file.

All resources are loaded language dependent as it's done in java.util.ResourceBundle. To set a language dependent resource just append '_' and the locale to the end of the Resourcename

Example:

  • InfoPanel.info - for default value
  • InfoPanel.info_deu - for german value
  • InfoPanel.info_eng - for english value

  • This class is almost a singleton. It is created once using create by the installer and later, the instance is retrieved using getInstance.

    Author:
    Marcus Stursberg

    Field Summary
    private  AutomatedInstallData installData
              Contains the given InstallData
    private static ResourceManager instance
              The instance of this class.
    private  java.lang.String locale
              Contains the current language of the installer The locale is taken from InstallData#installData#getAttribute("langpack") If there is no language set, the language is english.
    protected  java.lang.String resourceBasePath
              The base path where to find the resources
     
    Constructor Summary
    protected ResourceManager(AutomatedInstallData data)
              Constructor.
     
    Method Summary
    static ResourceManager create(AutomatedInstallData data)
              Create the resource manager.
     javax.swing.ImageIcon getImageIconResource(java.lang.String resource)
              Returns a laguage dependent ImageIcon for the given Resource
     java.io.InputStream getInputStream(java.lang.String resource)
              Returns an InputStream contains the given Resource The Resource is loaded language dependen by the informations from this.locale If there is no Resource for the current language found, the default Resource is given.
    static ResourceManager getInstance()
              Return the resource manager.
    private  java.lang.String getLanguageResourceString(java.lang.String resource)
              This method is used to get the language dependent path of the given resource.
     java.lang.String getLocale()
              Returns the locale for the resourcefiles.
     java.lang.String getTextResource(java.lang.String resource)
              Returns a text resource from the jar file.
     java.lang.String getTextResource(java.lang.String resource, java.lang.String encoding)
              Returns a text resource from the jar file.
     java.net.URL getURL(java.lang.String resource)
              Returns a URL refers to the given Resource
     void setLocale(java.lang.String locale)
              Sets the locale for the resourcefiles.
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Field Detail

    locale

    private java.lang.String locale
    Contains the current language of the installer The locale is taken from InstallData#installData#getAttribute("langpack") If there is no language set, the language is english.


    resourceBasePath

    protected final java.lang.String resourceBasePath
    The base path where to find the resources

    See Also:
    Constant Field Values

    installData

    private AutomatedInstallData installData
    Contains the given InstallData


    instance

    private static ResourceManager instance
    The instance of this class.

    Constructor Detail

    ResourceManager

    protected ResourceManager(AutomatedInstallData data)
    Constructor. Protected because this is a singleton.

    Parameters:
    data - - the current installData
    Method Detail

    create

    public static ResourceManager create(AutomatedInstallData data)
    Create the resource manager.

    This method should be called only once. If it is called a second time, the already existing instance is returned. The resource manager should be called after the language has been set in AutomatedInstallData.localeISO3

    Parameters:
    data - the installation information
    Returns:
    the created instance

    getInstance

    public static ResourceManager getInstance()
    Return the resource manager.

    Returns:
    the resource manager instance, null if no instance has been created

    getLanguageResourceString

    private java.lang.String getLanguageResourceString(java.lang.String resource)
                                                throws ResourceNotFoundException
    This method is used to get the language dependent path of the given resource. If there is a resource for the current language the path of the language dependen resource is returnd. If there's no resource for the current lanuage the default path is returned.

    Parameters:
    resource - Resource to load language dependen
    Returns:
    the language dependent path of the given resource
    Throws:
    ResourceNotFoundException - If the resource is not found

    getInputStream

    public java.io.InputStream getInputStream(java.lang.String resource)
                                       throws ResourceNotFoundException
    Returns an InputStream contains the given Resource The Resource is loaded language dependen by the informations from this.locale If there is no Resource for the current language found, the default Resource is given.

    Parameters:
    resource - The resource to load
    Returns:
    an InputStream contains the requested resource
    Throws:
    ResourceNotFoundException - Description of the Exception
    ResourceNotFoundException - thrown if there is no resource found

    getURL

    public java.net.URL getURL(java.lang.String resource)
                        throws ResourceNotFoundException
    Returns a URL refers to the given Resource

    Parameters:
    resource - the resource to load
    Returns:
    A languagedependen URL spezifies the requested resource
    Throws:
    ResourceNotFoundException - Description of the Exception
    ResourceNotFoundException - thrown if there is no resource found

    getTextResource

    public java.lang.String getTextResource(java.lang.String resource,
                                            java.lang.String encoding)
                                     throws ResourceNotFoundException,
                                            java.io.IOException
    Returns a text resource from the jar file. The resource is loaded by ResourceManager#getResource and then converted into text.

    Parameters:
    resource - - a text resource to load
    encoding - - the encoding, which should be used to read the resource
    Returns:
    a String contains the text of the resource
    Throws:
    ResourceNotFoundException - if the resource can not be found
    java.io.IOException - if the resource can not be loaded

    getTextResource

    public java.lang.String getTextResource(java.lang.String resource)
                                     throws ResourceNotFoundException,
                                            java.io.IOException
    Returns a text resource from the jar file. The resource is loaded by ResourceManager#getResource and then converted into text.

    Parameters:
    resource - - a text resource to load
    Returns:
    a String contains the text of the resource
    Throws:
    ResourceNotFoundException - if the resource can not be found
    java.io.IOException - if the resource can not be loaded

    getImageIconResource

    public javax.swing.ImageIcon getImageIconResource(java.lang.String resource)
                                               throws ResourceNotFoundException,
                                                      java.io.IOException
    Returns a laguage dependent ImageIcon for the given Resource

    Parameters:
    resource - resrouce of the Icon
    Returns:
    a ImageIcon loaded from the given Resource
    Throws:
    ResourceNotFoundException - thrown when the resource can not be found
    java.io.IOException - if the resource can not be loaded

    setLocale

    public void setLocale(java.lang.String locale)
    Sets the locale for the resourcefiles. The locale is taken from InstallData#installData#getAttribute("langpack") If there is no language set, the default language is english.

    Parameters:
    locale - of the resourcefile

    getLocale

    public java.lang.String getLocale()
    Returns the locale for the resourcefiles. The locale is taken from InstallData#installData#getAttribute("langpack") If there is no language set, the default language is english.

    Returns:
    the current language