Example usage for org.springframework.core.io.support LocalizedResourceHelper findLocalizedResource

List of usage examples for org.springframework.core.io.support LocalizedResourceHelper findLocalizedResource

Introduction

In this page you can find the example usage for org.springframework.core.io.support LocalizedResourceHelper findLocalizedResource.

Prototype

public Resource findLocalizedResource(String name, String extension, @Nullable Locale locale) 

Source Link

Document

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.

Usage

From source file:org.centralperf.helper.view.AbstractPOIExcelView.java

/**
* Creates the workbook from an existing XLS document.
* @param url the URL of the Excel template without localization part nor extension
* @param request current HTTP request//from  w w  w . ja  v a  2 s  . c om
* @return the HSSFWorkbook
* @throws Exception in case of failure
*/
protected Workbook getTemplateSource(String url, HttpServletRequest request) throws Exception {
    LocalizedResourceHelper helper = new LocalizedResourceHelper(getApplicationContext());
    Locale userLocale = RequestContextUtils.getLocale(request);
    Resource inputFile = helper.findLocalizedResource(url, EXTENSION, userLocale);

    // Create the Excel document from the source.
    if (logger.isDebugEnabled()) {
        logger.debug("Loading Excel workbook from " + inputFile);
    }
    return new XSSFWorkbook(inputFile.getInputStream());
}

From source file:com.vh.ds.iam.web.front.jxl.AbstractJxlView.java

/**
 * Create the workbook from an existing XLS document.
 * @param url the URL of the Excel template without localization part nor extension
 * @param request current HTTP request// w  w w . ja  va 2s .  c o m
 * @return the template workbook
 * @throws Exception in case of failure
 */
protected Workbook getTemplateSource(String url, HttpServletRequest request) throws Exception {
    LocalizedResourceHelper helper = new LocalizedResourceHelper(getApplicationContext());
    Locale userLocale = RequestContextUtils.getLocale(request);
    Resource inputFile = helper.findLocalizedResource(url, EXTENSION, userLocale);

    // Create the Excel document from the source.
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Loading Excel workbook from {}", inputFile);
    }
    return Workbook.getWorkbook(inputFile.getInputStream());
}