Package net.solarnetwork.node.setup
Class SetupResourceUtils
java.lang.Object
net.solarnetwork.node.setup.SetupResourceUtils
Utility methods for setup resources.
- Version:
- 1.0
- Author:
- matt
-
Field Summary
FieldsModifier and TypeFieldDescriptionGet a default mapping of file extensions to associated content types.static final PatternA pattern to match locale specifications in filenames. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringbaseFilenameForPath(String path) Get a base filename for a given path, without any extension or locale specifier.static LocalelocaleForLanguage(String lang) Get a locale for just a language.static LocalelocaleForPath(String path) Get aLocalebased on a path.static intlocaleScore(SetupResource rsrc, Locale desiredLocale, Locale defaultLocale) Assign a score to a resource for how closely it matches the desired locale.
-
Field Details
-
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
Get a default mapping of file extensions to associated content types.
-
-
Method Details
-
localeForPath
Get aLocalebased on a path. The path is expected to followResourceBundlenaming conventions, for examplefile.txtfor no locale,file_en.txtfor a specific language, andfile_en_US.txtfor 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
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
pathis null.
-
localeForLanguage
Get a locale for just a language.- Parameters:
lang- The language to get the locale for.- Returns:
- The Locale, or null if
langis null.
-
localeScore
Assign a score to a resource for how closely it matches the desired locale.- Parameters:
rsrc- The resource to testdesiredLocale- The desired locale.defaultLocale- The default locale to use for resources whereSetupResource.getLocale()returns null.- Returns:
- A matching score. Higher values more closely match. If
Integer.MAX_VALUEis returned then the match is exact.
-