Class Resources


  • public class Resources
    extends java.lang.Object
    This class loads and holds the resources for Magellan.
    Version:
    1.0, 29.04.2007
    Author:
    Thoralf Rickert
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Resources.ResourceFilenameFilter
      A small filter for resource file names...
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static java.io.PrintWriter pw  
      protected static java.io.StringWriter sw  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      java.lang.StringBuilder check()
      Checks if all resource bundle contain the same set of keys.
      static java.net.URL file2URL​(java.io.File file)  
      static java.lang.String get​(java.lang.String key)
      Returns the resource for the resource key in the default locale of the running machine.
      static java.lang.String get​(java.lang.String key, boolean returnKey)
      Returns the resource for the resource key in the default locale of the running machine.
      static java.lang.String get​(java.lang.String key, java.lang.Object... args)
      Returns the resource for the resource key in the default locale of the running machine.
      static java.lang.String get​(java.lang.String key, java.util.Locale locale, boolean returnKey)
      Returns the resource for the resource key in the given locale.
      static java.util.List<java.util.Locale> getAvailableLocales()
      Returns a list of all available translations including the default translation as ENGLISH.
      static java.lang.String getFormatted​(java.lang.String key, java.lang.Object... args)
      Returns the resource for the resource key in the default locale of the running machine.
      static Resources getInstance()
      This method returns the singleton of this class
      java.util.Enumeration<java.lang.String> getKeys​(java.util.Locale locale)  
      static java.lang.String getOrderTranslation​(java.lang.String key)
      static java.lang.String getOrderTranslation​(java.lang.String key, java.util.Locale locale)
      Deprecated.
      Use Rules.getOrder(key).getTranslation(locale)
      protected java.lang.String getResource​(java.lang.String key, java.util.Locale locale)
      This method tries to find a resource in the set of bundles.
      static java.util.ResourceBundle getResourceBundle​(java.util.Locale locale)
      This method returns the wanted resourcebundle.
      static java.io.File getResourceDirectory()
      Returns the current resource directory.
      static java.net.URL getResourceURL​(java.lang.String path)
      Returns an URL pointing to the file indicated by path.
      static java.lang.String getRuleItemTranslation​(java.lang.String key)
      Attempts to get the translation of the given rulesItem (german) key in the current order locale.
      static java.lang.String getRuleItemTranslation​(java.lang.String key, java.util.Locale locale)
      Attempts to get the translation of the given order key in the given locale.
      static java.util.Collection<java.net.URL> getStaticPaths()
      Returns the resource paths the static methods of this class operate on.
      void initialize​(java.io.File pResourceDirectory, java.lang.String prefix)
      This method makes it possible to add specific resource files to this Resources map.
      static void initStaticPaths​(java.util.Properties settings)
      loads RessourcePaths(static) from the given settings
      static void main​(java.lang.String[] args)  
      static void setNullResource​(boolean setNull)
      Switch to trivial mode that always returnes the key.
      void setResourceDirectory​(java.io.File resourceDirectory)
      Changes the resource directory.
      static void setStaticPaths​(java.util.Collection<java.net.URL> paths)
      Tells this loader which resource paths to search for classes and resources when operating statically.
      static void storePaths​(java.util.Collection<java.net.URL> resourcePaths, java.util.Properties settings)
      Stores the specified resource paths to the specified settings.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • sw

        protected static java.io.StringWriter sw
      • pw

        protected static java.io.PrintWriter pw
    • Method Detail

      • getInstance

        public static Resources getInstance()
        This method returns the singleton of this class
      • setResourceDirectory

        public void setResourceDirectory​(java.io.File resourceDirectory)
        Changes the resource directory.
        Parameters:
        resourceDirectory -
      • getResourceDirectory

        public static java.io.File getResourceDirectory()
        Returns the current resource directory.
        Returns:
        the current resource directory
      • initialize

        public void initialize​(java.io.File pResourceDirectory,
                               java.lang.String prefix)
        This method makes it possible to add specific resource files to this Resources map. F.e. call initialize("mapedit_") to search and load resource files from files called "mapedit_resources.properties".
      • check

        public java.lang.StringBuilder check()
        Checks if all resource bundle contain the same set of keys.
        Returns:
        A list of all resources that are not identical
      • getAvailableLocales

        public static java.util.List<java.util.Locale> getAvailableLocales()
        Returns a list of all available translations including the default translation as ENGLISH.
      • getResourceBundle

        public static java.util.ResourceBundle getResourceBundle​(java.util.Locale locale)
        This method returns the wanted resourcebundle.
      • get

        public static java.lang.String get​(java.lang.String key)
        Returns the resource for the resource key in the default locale of the running machine. If the resource is not available in this locale, this method tries to find the resource in the default resources.
        Parameters:
        key - should not contain spaces
        Returns:
        the value for the key. If the key could not be found in any resource, the key is returned.
      • get

        public static java.lang.String get​(java.lang.String key,
                                           java.lang.Object... args)
        Returns the resource for the resource key in the default locale of the running machine. If the resource is not available in this locale, this method tries to find the resource in the default resources.
        Parameters:
        key - should not contain spaces
        args - These arguments are applied to the resource. See Format.format(Object).
        Returns:
        the value for the key. If the key could not be found in any resource, the key is returned.
      • get

        public static java.lang.String get​(java.lang.String key,
                                           boolean returnKey)
        Returns the resource for the resource key in the default locale of the running machine. If the resource is not available in this locale, this method tries to find the resource in the default resources.
        Parameters:
        key - should not contain spaces
        returnKey -
        Returns:
        the value for the key. If the key could not be found in any resource, the key is returned if returnKey==true, otherwise null is returned.
      • getKeys

        public java.util.Enumeration<java.lang.String> getKeys​(java.util.Locale locale)
      • get

        public static java.lang.String get​(java.lang.String key,
                                           java.util.Locale locale,
                                           boolean returnKey)
        Returns the resource for the resource key in the given locale. If the resource is not available in this locale the method tries to find the resource in the default locale of this machine and if it is not available in this locale too then it tries the default resource.
        Parameters:
        key - should not contain spaces
        locale - This locale is used before default locales
        returnKey -
        Returns:
        the value for the key. If the key could not be found in any resource, the key is returned if returnKey==true, otherwise null is returned.
      • getFormatted

        public static java.lang.String getFormatted​(java.lang.String key,
                                                    java.lang.Object... args)
        Returns the resource for the resource key in the default locale of the running machine. If the resource is not available in this locale, this method tries to find the resource in the default resources.
      • getOrderTranslation

        @Deprecated
        public static java.lang.String getOrderTranslation​(java.lang.String key)
        Attempts to get the translation of the given order key in the current order locale. If no translation is found, the key is returned.
        Parameters:
        key - An order key
        Returns:
        The translation as found in the Resources or the key if no translation is found
      • getRuleItemTranslation

        public static java.lang.String getRuleItemTranslation​(java.lang.String key)
        Attempts to get the translation of the given rulesItem (german) key in the current order locale. If no translation is found, the key is returned.
        Parameters:
        key - An string key of a name of an Item in rules.cr
        Returns:
        The translation as found in the Resources or the key if no translation is found
      • getRuleItemTranslation

        public static java.lang.String getRuleItemTranslation​(java.lang.String key,
                                                              java.util.Locale locale)
        Attempts to get the translation of the given order key in the given locale. If no translation is found, the key is returned.
        Parameters:
        key - An rule item key. May contain spaces, but they will be removed before lookup.
        locale -
        Returns:
        The translation as found in the Resources or the key if no translation is found
      • getOrderTranslation

        @Deprecated
        public static java.lang.String getOrderTranslation​(java.lang.String key,
                                                           java.util.Locale locale)
        Deprecated.
        Use Rules.getOrder(key).getTranslation(locale)
        Attempts to get the translation of the given order key in the given locale. If no translation is found, the key is returned.
        Parameters:
        key - An order key. May contain spaces, but they will be removed before lookup.
        locale - If this is null, the DEFAULT locale is used.
        Returns:
        The translation as found in the Resources or the key if no translation is found
      • getStaticPaths

        public static java.util.Collection<java.net.URL> getStaticPaths()
        Returns the resource paths the static methods of this class operate on.
        See Also:
        ResourcePathClassLoader
      • setStaticPaths

        public static void setStaticPaths​(java.util.Collection<java.net.URL> paths)
        Tells this loader which resource paths to search for classes and resources when operating statically.
      • initStaticPaths

        public static void initStaticPaths​(java.util.Properties settings)
        loads RessourcePaths(static) from the given settings
        Parameters:
        settings -
      • storePaths

        public static void storePaths​(java.util.Collection<java.net.URL> resourcePaths,
                                      java.util.Properties settings)
        Stores the specified resource paths to the specified settings.
      • getResource

        protected java.lang.String getResource​(java.lang.String key,
                                               java.util.Locale locale)
        This method tries to find a resource in the set of bundles.
        Parameters:
        key - should not contain spaces
        locale - If this is null, the DEFAULT locale is used.
        Returns:
        The value for this key in the resources or null if the key couldn't be found in any of the registered bundles
      • main

        public static void main​(java.lang.String[] args)
      • file2URL

        public static java.net.URL file2URL​(java.io.File file)
                                     throws java.net.MalformedURLException
        Throws:
        java.net.MalformedURLException
      • getResourceURL

        public static java.net.URL getResourceURL​(java.lang.String path)
        Returns an URL pointing to the file indicated by path. If the file does not exist, a corresponding file in the resource directory is tried.
        Parameters:
        path -
      • setNullResource

        public static void setNullResource​(boolean setNull)
        Switch to trivial mode that always returnes the key.
        Parameters:
        setNull -