Class SetupResourceUtils

java.lang.Object
net.solarnetwork.node.setup.SetupResourceUtils

public final class SetupResourceUtils extends Object
Utility methods for setup resources.
Version:
1.0
Author:
matt
  • Field Details

    • LOCALE_PAT

      public static final Pattern LOCALE_PAT
      A pattern to match locale specifications in filenames. Matches with 2 groups: the language, the country. The country is a nested group, so is actually referred by as group {code 3}.
    • DEFAULT_FILENAME_EXTENSION_CONTENT_TYPES

      public static final Map<String,String> DEFAULT_FILENAME_EXTENSION_CONTENT_TYPES
      Get a default mapping of file extensions to associated content types.
  • Method Details

    • localeForPath

      public static Locale localeForPath(String path)
      Get a Locale based on a path. The path is expected to follow ResourceBundle naming conventions, for example file.txt for no locale, file_en.txt for a specific language, and file_en_US.txt for a language plus country variant.
      Parameters:
      path - The path to derive a locale from.
      Returns:
      The Locale, or null if not appropriate or none found.
    • baseFilenameForPath

      public static String baseFilenameForPath(String path)
      Get a base filename for a given path, without any extension or locale specifier.
      Parameters:
      path - The path to get the base filename from.
      Returns:
      The base filename, or null if path is null.
    • localeForLanguage

      public static Locale localeForLanguage(String lang)
      Get a locale for just a language.
      Parameters:
      lang - The language to get the locale for.
      Returns:
      The Locale, or null if lang is null.
    • localeScore

      public static int localeScore(SetupResource rsrc, Locale desiredLocale, Locale defaultLocale)
      Assign a score to a resource for how closely it matches the desired locale.
      Parameters:
      rsrc - The resource to test
      desiredLocale - The desired locale.
      defaultLocale - The default locale to use for resources where SetupResource.getLocale() returns null.
      Returns:
      A matching score. Higher values more closely match. If Integer.MAX_VALUE is returned then the match is exact.