Top Description Fields Constructors Methods
org.springframework.core.io.support

public Class LocalizedResourceHelper

extends Object
Class Inheritance
Imports
java.util.Locale, org.springframework.core.io.DefaultResourceLoader, .Resource, .ResourceLoader, org.springframework.lang.Nullable, org.springframework.util.Assert

Helper class for loading a localized resource, specified through name, extension and current locale.
Author
Juergen Hoeller
Since
1.2.5

Field Summary

Modifier and TypeField and Description
public static final String
DEFAULT_SEPARATOR

The default separator to use in-between file name parts: an underscore.

private final ResourceLoader
private String

Constructor Summary

AccessConstructor and Description
public
LocalizedResourceHelper()

Create a new LocalizedResourceHelper with a DefaultResourceLoader.

public
LocalizedResourceHelper(ResourceLoader
the ResourceLoader to use
resourceLoader
)

Create a new LocalizedResourceHelper with the given ResourceLoader.

Method Summary

Modifier and TypeMethod and Description
public Resource

Returns:

the most specific localized resource found
findLocalizedResource
(String
the name of the file, without localization part nor extension
name
,
String
the file extension (e.g. ".xls")
extension
,
Locale
the current locale (may be null)
locale
)

Find the most specific localized resource for the given name, extension and locale:

The file will be searched with locations in the following order, similar to java.util.ResourceBundle's search order:

  • [name]_[language]_[country]_[variant][extension]
  • [name]_[language]_[country][extension]
  • [name]_[language][extension]
  • [name][extension]
public void
setSeparator(String separator)

Set the separator to use in-between file name parts.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_SEPARATORback to summary
public static final String DEFAULT_SEPARATOR

The default separator to use in-between file name parts: an underscore.

resourceLoaderback to summary
private final ResourceLoader resourceLoader
separatorback to summary
private String separator

Constructor Detail

LocalizedResourceHelperback to summary
public LocalizedResourceHelper()

Create a new LocalizedResourceHelper with a DefaultResourceLoader.

See Also
org.springframework.core.io.DefaultResourceLoader
LocalizedResourceHelperback to summary
public LocalizedResourceHelper(ResourceLoader resourceLoader)

Create a new LocalizedResourceHelper with the given ResourceLoader.

Parameters
resourceLoader:ResourceLoader

the ResourceLoader to use

Method Detail

findLocalizedResourceback to summary
public Resource findLocalizedResource(String name, String extension, Locale locale)

Find the most specific localized resource for the given name, extension and locale:

The file will be searched with locations in the following order, similar to java.util.ResourceBundle's search order:

  • [name]_[language]_[country]_[variant][extension]
  • [name]_[language]_[country][extension]
  • [name]_[language][extension]
  • [name][extension]

If none of the specific files can be found, a resource descriptor for the default location will be returned.

Parameters
name:String

the name of the file, without localization part nor extension

extension:String

the file extension (e.g. ".xls")

locale:Locale

the current locale (may be null)

Returns:Resource

the most specific localized resource found

See Also
java.util.ResourceBundle
setSeparatorback to summary
public void setSeparator(String separator)

Set the separator to use in-between file name parts. Default is an underscore ("_").